Skip to content

Commit 6477f27

Browse files
committed
Fixing build
1 parent 589f6fa commit 6477f27

File tree

4 files changed

+68
-25
lines changed

4 files changed

+68
-25
lines changed

src/Configuration.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Linq;
4-
using System.Reflection;
54

65
using Microsoft.Extensions.DependencyInjection;
76

src/MDIExtension.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Text;
4-
using Unity.Extension;
1+
using Unity.Extension;
52
using Unity.Policy;
63

74
namespace Unity.Microsoft.DependencyInjection

tests/Microsoft.DependencyInjection.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
</PropertyGroup>
88

99
<ItemGroup>
10-
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Specification.Tests" Version="1.1.1" />
10+
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Specification.Tests" Version="2.0.0" />
1111
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" />
1212
<PackageReference Include="xunit" Version="2.3.1" />
1313
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
Lines changed: 66 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
using System;
2-
2+
using System.Collections;
3+
using System.Collections.Generic;
34
using Microsoft.Extensions.DependencyInjection;
45
using Microsoft.Extensions.DependencyInjection.Specification;
6+
using Microsoft.Extensions.DependencyInjection.Specification.Fakes;
7+
using Xunit;
58

69
namespace Unity.Microsoft.DependencyInjection.Tests
710
{
@@ -12,23 +15,67 @@ protected override IServiceProvider CreateServiceProvider(IServiceCollection ser
1215
var container = new UnityContainer();
1316
return container.Configure(serviceCollection);
1417
}
18+
19+
internal class TestServiceCollection : List<ServiceDescriptor>, IServiceCollection, IList<ServiceDescriptor>, ICollection<ServiceDescriptor>, IEnumerable<ServiceDescriptor>, IEnumerable
20+
{
21+
}
22+
23+
[Fact]
24+
public void Disposing_ScopeDisposesService()
25+
{
26+
27+
// Arrange
28+
29+
var collection = new TestServiceCollection();
30+
31+
collection.AddSingleton<IFakeSingletonService, FakeService>();
32+
collection.AddScoped<IFakeScopedService, FakeService>();
33+
collection.AddTransient<IFakeService, FakeService>();
34+
35+
36+
37+
var provider = CreateServiceProvider(collection);
38+
39+
FakeService disposableService;
40+
FakeService transient1;
41+
FakeService transient2;
42+
FakeService singleton;
43+
44+
45+
46+
// Act and Assert
47+
48+
var transient3 = Assert.IsType<FakeService>(provider.GetService<IFakeService>());
49+
50+
using (var scope = provider.CreateScope())
51+
{
52+
disposableService = (FakeService)scope.ServiceProvider.GetService<IFakeScopedService>();
53+
transient1 = (FakeService)scope.ServiceProvider.GetService<IFakeService>();
54+
transient2 = (FakeService)scope.ServiceProvider.GetService<IFakeService>();
55+
singleton = (FakeService)scope.ServiceProvider.GetService<IFakeSingletonService>();
56+
57+
58+
Assert.False(disposableService.Disposed);
59+
Assert.False(transient1.Disposed);
60+
Assert.False(transient2.Disposed);
61+
Assert.False(singleton.Disposed);
62+
63+
}
64+
65+
Assert.True(disposableService.Disposed);
66+
Assert.True(transient1.Disposed);
67+
Assert.True(transient2.Disposed);
68+
Assert.False(singleton.Disposed);
69+
70+
71+
var disposableProvider = provider as IDisposable;
72+
if (disposableProvider != null)
73+
{
74+
disposableProvider.Dispose();
75+
Assert.True(singleton.Disposed);
76+
Assert.True(transient3.Disposed);
77+
}
78+
79+
}
1580
}
16-
//public sealed class UnityDependencyInjectionTests : DependencyInjectionSpecificationTests
17-
//{
18-
// /// <inheritdoc />
19-
// protected override IServiceProvider CreateServiceProvider(IServiceCollection serviceCollection)
20-
// {
21-
// var container = new UnityContainer();
22-
// var provider = new ServiceProvider(container);
23-
24-
// foreach (ServiceDescriptor service in serviceCollection)
25-
// {
26-
// container.RegisterType(
27-
// service.ServiceType,
28-
// service.ImplementationType);
29-
// }
30-
31-
// return provider;
32-
// }
33-
//}
3481
}

0 commit comments

Comments
 (0)