Tests: Add coverage tests for ScriptsBundler and StylesBundler.
This commit is contained in:
21
VAR.WebFormsCore.Tests/Code/ScriptsBundlerTests.cs
Normal file
21
VAR.WebFormsCore.Tests/Code/ScriptsBundlerTests.cs
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
using Xunit;
|
||||||
|
using VAR.WebFormsCore.Code;
|
||||||
|
using VAR.WebFormsCore.Tests.Fakes;
|
||||||
|
|
||||||
|
namespace VAR.WebFormsCore.Tests.Code;
|
||||||
|
|
||||||
|
public class ScriptsBundlerTests
|
||||||
|
{
|
||||||
|
[Fact]
|
||||||
|
public void ProcessRequest__Base__IntrinsicScripts()
|
||||||
|
{
|
||||||
|
FakeWebContext fakeWebContext = new();
|
||||||
|
ScriptsBundler scriptsBundler = new();
|
||||||
|
|
||||||
|
scriptsBundler.ProcessRequest(fakeWebContext);
|
||||||
|
|
||||||
|
Assert.Single(fakeWebContext.FakeWritePackages);
|
||||||
|
|
||||||
|
// TODO: Verify contents of intrinsic scripts
|
||||||
|
}
|
||||||
|
}
|
||||||
21
VAR.WebFormsCore.Tests/Code/StylesBundlerTests.cs
Normal file
21
VAR.WebFormsCore.Tests/Code/StylesBundlerTests.cs
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
using Xunit;
|
||||||
|
using VAR.WebFormsCore.Code;
|
||||||
|
using VAR.WebFormsCore.Tests.Fakes;
|
||||||
|
|
||||||
|
namespace VAR.WebFormsCore.Tests.Code;
|
||||||
|
|
||||||
|
public class StylesBundlerTests
|
||||||
|
{
|
||||||
|
[Fact]
|
||||||
|
public void ProcessRequest__Base__IntrinsicStyles()
|
||||||
|
{
|
||||||
|
FakeWebContext fakeWebContext = new();
|
||||||
|
StylesBundler stylesBundler = new();
|
||||||
|
|
||||||
|
stylesBundler.ProcessRequest(fakeWebContext);
|
||||||
|
|
||||||
|
Assert.Single(fakeWebContext.FakeWritePackages);
|
||||||
|
|
||||||
|
// TODO: Verify contents of intrinsic styles
|
||||||
|
}
|
||||||
|
}
|
||||||
77
VAR.WebFormsCore.Tests/Fakes/FakeWebContext.cs
Normal file
77
VAR.WebFormsCore.Tests/Fakes/FakeWebContext.cs
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
using VAR.WebFormsCore.Code;
|
||||||
|
|
||||||
|
namespace VAR.WebFormsCore.Tests.Fakes;
|
||||||
|
|
||||||
|
public class FakeWebContext : IWebContext
|
||||||
|
{
|
||||||
|
public string RequestPath => string.Empty;
|
||||||
|
|
||||||
|
public string RequestMethod => string.Empty;
|
||||||
|
|
||||||
|
public Dictionary<string, string?> RequestHeader { get; } = new();
|
||||||
|
|
||||||
|
public Dictionary<string, string> RequestCookies { get; } = new();
|
||||||
|
|
||||||
|
public Dictionary<string, string?> RequestQuery { get; } = new();
|
||||||
|
|
||||||
|
public Dictionary<string, string?> RequestForm { get; } = new();
|
||||||
|
|
||||||
|
public struct WritePackage
|
||||||
|
{
|
||||||
|
public string? Text { get; set; }
|
||||||
|
public byte[]? Bin { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<WritePackage> FakeWritePackages { get; } = new();
|
||||||
|
|
||||||
|
public void ResponseWrite(string text)
|
||||||
|
{
|
||||||
|
FakeWritePackages.Add(new WritePackage { Text = text, });
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ResponseWriteBin(byte[] content)
|
||||||
|
{
|
||||||
|
FakeWritePackages.Add(new WritePackage { Bin = content, });
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ResponseFlush()
|
||||||
|
{
|
||||||
|
// NOTE: Nothing to do
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ResponseRedirect(string url)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AddResponseCookie(string cookieName, string value, DateTime? expiration = null)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DelResponseCookie(string cookieName)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool ResponseHasStarted => false;
|
||||||
|
|
||||||
|
public int ResponseStatusCode { get; set; }
|
||||||
|
|
||||||
|
public string? ResponseContentType { get; set; }
|
||||||
|
|
||||||
|
public void SetResponseHeader(string key, string value)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void PrepareCacheableResponse()
|
||||||
|
{
|
||||||
|
// TODO: Mark as Cacheable response
|
||||||
|
}
|
||||||
|
|
||||||
|
public void PrepareUncacheableResponse()
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user