-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
ServiceCollectionExtensionsTests.cs
57 lines (44 loc) · 1.75 KB
/
ServiceCollectionExtensionsTests.cs
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
// Copyright 2022 Valters Melnalksnis
// Licensed under the Apache License 2.0.
// See LICENSE file in the project root for full license information.
using System;
using System.Collections.Generic;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using NodaTime;
namespace VMelnalksnis.PaperlessDotNet.DependencyInjection.Tests;
public sealed class ServiceCollectionExtensionsTests
{
private readonly IConfiguration _configuration = new ConfigurationBuilder()
.AddInMemoryCollection(new List<KeyValuePair<string, string?>>
{
new($"{PaperlessOptions.Name}:{nameof(PaperlessOptions.BaseAddress)}", "https://localhost:5002/"),
new($"{PaperlessOptions.Name}:{nameof(PaperlessOptions.Token)}", Guid.NewGuid().ToString("N")),
})
.Build();
[Fact]
public void AddPaperlessDotNet_ExplicitConfiguration_ShouldRegisterRequiredServices()
{
var serviceCollection = new ServiceCollection();
serviceCollection
.AddSingleton<IClock>(SystemClock.Instance)
.AddSingleton(DateTimeZoneProviders.Tzdb)
.AddPaperlessDotNet(_configuration);
using var serviceProvider = serviceCollection.BuildServiceProvider();
var paperlessClient = serviceProvider.GetRequiredService<IPaperlessClient>();
paperlessClient.Should().NotBeNull();
}
[Fact]
public void AddPaperlessDotNet_ShouldRegisterRequiredServices()
{
var serviceCollection = new ServiceCollection();
serviceCollection
.AddSingleton(_configuration)
.AddSingleton<IClock>(SystemClock.Instance)
.AddSingleton(DateTimeZoneProviders.Tzdb)
.AddPaperlessDotNet();
using var serviceProvider = serviceCollection.BuildServiceProvider();
var paperlessClient = serviceProvider.GetRequiredService<IPaperlessClient>();
paperlessClient.Should().NotBeNull();
}
}