-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathUnitTestConfiguration.cs
More file actions
79 lines (61 loc) · 2.95 KB
/
UnitTestConfiguration.cs
File metadata and controls
79 lines (61 loc) · 2.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
using InertiaCore;
using InertiaCore.Extensions;
using InertiaCore.Ssr;
using InertiaCore.Utils;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
namespace InertiaCoreTests;
internal class DummySerializer : DefaultInertiaSerializer
{
}
public partial class Tests
{
[Test]
[Description("Test if the configuration registers properly necessary services and filters.")]
public void TestConfiguration()
{
Assert.Throws<NullReferenceException>(() => Inertia.GetVersion());
var builder = WebApplication.CreateBuilder();
Assert.DoesNotThrow(() => builder.Services.AddInertia());
Assert.Multiple(() =>
{
Assert.That(builder.Services.Any(s => s.ServiceType == typeof(IHttpContextAccessor)), Is.True);
Assert.That(builder.Services.Any(s => s.ServiceType == typeof(IHttpClientFactory)), Is.True);
Assert.That(builder.Services.Any(s => s.ServiceType == typeof(IResponseFactory)), Is.True);
Assert.That(builder.Services.Any(s => s.ServiceType == typeof(IGateway)), Is.True);
Assert.That(builder.Services.Any(s => s.ServiceType == typeof(IInertiaSerializer)), Is.True);
});
var mvcConfiguration =
builder.Services.FirstOrDefault(s => s.ServiceType == typeof(IConfigureOptions<MvcOptions>));
var mvcOptions = new MvcOptions();
(mvcConfiguration?.ImplementationInstance as ConfigureNamedOptions<MvcOptions>)?.Action?.Invoke(mvcOptions);
Assert.That(
mvcOptions.Filters.Any(f => (f as TypeFilterAttribute)?.ImplementationType == typeof(InertiaActionFilter)),
Is.True);
var app = builder.Build();
Assert.DoesNotThrow(() => app.UseInertia());
Assert.DoesNotThrow(() => Inertia.GetVersion());
}
[Test]
[Description("Test if the configuration registers properly custom JSON serializer.")]
public void TestSerializerConfiguration()
{
var builder = WebApplication.CreateBuilder();
builder.Services.AddInertia();
Assert.Multiple(() =>
{
Assert.That(builder.Services.Any(s => s.ServiceType == typeof(IInertiaSerializer)), Is.True);
Assert.That(builder.Services.Any(s => s.ImplementationType == typeof(DefaultInertiaSerializer)), Is.True);
Assert.That(builder.Services.Any(s => s.ImplementationType == typeof(DummySerializer)), Is.False);
});
Assert.DoesNotThrow(() => builder.Services.UseInertiaSerializer<DummySerializer>());
Assert.Multiple(() =>
{
Assert.That(builder.Services.Any(s => s.ServiceType == typeof(IInertiaSerializer)), Is.True);
Assert.That(builder.Services.Any(s => s.ImplementationType == typeof(DefaultInertiaSerializer)), Is.False);
Assert.That(builder.Services.Any(s => s.ImplementationType == typeof(DummySerializer)), Is.True);
});
}
}