Skip to content

Commit

Permalink
Run unit tests in pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
sleeuwen committed Mar 13, 2024
1 parent ebb84e4 commit 321c18b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/dotnetcore.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ jobs:
run: dotnet restore
- name: Build
run: dotnet build --configuration Release --no-restore
- name: Test
run: dotnet test --configuration Release --no-build
- name: Validate generated css files
run: |
test -s Samples/AspNetCore.SassCompiler.BlazorSample/Components/Pages/Counter.razor.css
Expand Down
13 changes: 7 additions & 6 deletions AspNetCore.SassCompiler.Tests/SassCompilerTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Text;
using Microsoft.Extensions.Logging.Abstractions;
using Xunit;

namespace AspNetCore.SassCompiler.Tests;
Expand All @@ -9,7 +10,7 @@ public class SassCompilerTests
public async Task CompileAsync_WithoutStreams_Success()
{
// Arrange
var sassCompiler = new SassCompiler();
var sassCompiler = new SassCompiler(NullLogger<SassCompiler>.Instance);

var tempDirectory = Path.Join(Path.GetTempPath(), Path.GetRandomFileName());
Directory.CreateDirectory(tempDirectory);
Expand Down Expand Up @@ -37,7 +38,7 @@ public async Task CompileAsync_WithoutStreams_Success()
public async Task CompileAsync_ThrowsWithInvalidArguments(string argument)
{
// Arrange
var sassCompiler = new SassCompiler();
var sassCompiler = new SassCompiler(NullLogger<SassCompiler>.Instance);

var input = new MemoryStream(Encoding.UTF8.GetBytes("body { color: black; }"));

Expand All @@ -54,7 +55,7 @@ public async Task CompileAsync_ThrowsWithInvalidArguments(string argument)
public async Task CompileAsync_ThrowsWithInvalidInput()
{
// Arrange
var sassCompiler = new SassCompiler();
var sassCompiler = new SassCompiler(NullLogger<SassCompiler>.Instance);

var input = new MemoryStream(Encoding.UTF8.GetBytes("body { color: black;"));

Expand All @@ -71,7 +72,7 @@ public async Task CompileAsync_ThrowsWithInvalidInput()
public async Task CompileAsync_ReturningOutputStream_Success()
{
// Arrange
var sassCompiler = new SassCompiler();
var sassCompiler = new SassCompiler(NullLogger<SassCompiler>.Instance);

var input = new MemoryStream(Encoding.UTF8.GetBytes("body { color: black; }"));

Expand All @@ -87,7 +88,7 @@ public async Task CompileAsync_ReturningOutputStream_Success()
public async Task CompileAsync_WithInputAndOutputStream_Success()
{
// Arrange
var sassCompiler = new SassCompiler();
var sassCompiler = new SassCompiler(NullLogger<SassCompiler>.Instance);

var input = new MemoryStream(Encoding.UTF8.GetBytes("body { color: black; }"));
var output = new MemoryStream();
Expand All @@ -104,7 +105,7 @@ public async Task CompileAsync_WithInputAndOutputStream_Success()
public async Task CompileToStringAsync_Success()
{
// Arrange
var sassCompiler = new SassCompiler();
var sassCompiler = new SassCompiler(NullLogger<SassCompiler>.Instance);

var input = new MemoryStream(Encoding.UTF8.GetBytes("body { color: black; }"));

Expand Down
13 changes: 12 additions & 1 deletion AspNetCore.SassCompiler/SassCompiler.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;

namespace AspNetCore.SassCompiler;

Expand All @@ -22,6 +22,13 @@ public interface ISassCompiler

internal class SassCompiler : ISassCompiler
{
private readonly ILogger<SassCompiler> _logger;

public SassCompiler(ILogger<SassCompiler> logger)
{
_logger = logger;
}

public async Task CompileAsync(string[] args)
{
var escapedArgs = args.Length > 0 ? '"' + string.Join("\" \"", args) + '"' : "";
Expand All @@ -32,6 +39,8 @@ public async Task CompileAsync(string[] args)

var errorOutput = new MemoryStream();

_logger.LogDebug("Executing sass command: {SassCommand}", $"{process.StartInfo.FileName} {process.StartInfo.Arguments}");

process.Start();
ChildProcessTracker.AddProcess(process);
await process.StandardOutput.BaseStream.CopyToAsync(Stream.Null);
Expand Down Expand Up @@ -68,6 +77,8 @@ public async Task CompileAsync(Stream input, Stream output, string[] args)

var errorOutput = new MemoryStream();

_logger.LogDebug("Executing sass command: {SassCommand}", $"{process.StartInfo.FileName} {process.StartInfo.Arguments}");

process.Start();
ChildProcessTracker.AddProcess(process);
await input.CopyToAsync(process.StandardInput.BaseStream);
Expand Down

0 comments on commit 321c18b

Please sign in to comment.