-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
ScopedTestDerived.cs
67 lines (57 loc) · 1.5 KB
/
ScopedTestDerived.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
58
59
60
61
62
63
64
65
66
67
using Microsoft.Extensions.DependencyInjection;
using NUnit.Framework;
using Shouldly;
namespace SteroidsDI.Tests.Cases;
public class ScopedTestDerived : ScopedTestBase
{
protected override void ConfigureServices(IServiceCollection services)
{
base.ConfigureServices(services);
services.AddSingleton<IRepo, Repo>();
services.AddScoped<Dependency>();
}
/// <summary>
/// This method works in context of prepared unique DI scope like ASP.NET Core app does.
/// </summary>
[Test]
public void Scoped_Should_Work_1()
{
var repo = GetRequiredService<IRepo>();
repo.Name.ShouldBe("12345");
}
/// <summary>
/// This method works in context of prepared unique DI scope like ASP.NET Core app does.
/// </summary>
[Test]
public void Scoped_Should_Work_2()
{
var repo = GetRequiredService<IRepo>();
repo.Name.ShouldBe("12345");
}
/// <summary>
/// This method works in context of prepared unique scope like ASP.NET Core app does.
/// </summary>
[Test]
public void Scoped_Should_Work_3()
{
var repo = GetRequiredService<IRepo>();
repo.Name.ShouldBe("12345");
}
}
public interface IRepo
{
string Name { get; }
}
public class Repo : IRepo
{
private readonly Defer<Dependency> _dep;
public Repo(Defer<Dependency> dep)
{
_dep = dep;
}
public string Name => _dep.Value.Name;
}
public class Dependency
{
public virtual string Name => "12345";
}