Skip to content

Commit 43671d6

Browse files
Merge pull request #3 from servicetitan/add-test-for-internal-services
Add test for internal services.
2 parents 2773083 + 77f7987 commit 43671d6

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

LazyProxy.Unity.Tests/UnityExtensionTests.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
using System;
2+
using System.Runtime.CompilerServices;
23
using Moq;
34
using Unity;
45
using Unity.Exceptions;
56
using Unity.Injection;
67
using Unity.Lifetime;
78
using Xunit;
89

10+
[assembly: InternalsVisibleTo("LazyProxy.DynamicTypes")]
11+
912
namespace LazyProxy.Unity.Tests
1013
{
1114
public class UnityExtensionTests
@@ -57,6 +60,16 @@ public Service2()
5760
public string Method(string arg) => "service2->" + arg;
5861
}
5962

63+
internal interface IInternalService
64+
{
65+
string Get();
66+
}
67+
68+
internal class InternalService : IInternalService
69+
{
70+
public string Get() => "InternalService";
71+
}
72+
6073
[Fact]
6174
public void ServiceCtorMustBeExecutedAfterMethodIsCalledAndOnlyOnce()
6275
{
@@ -281,5 +294,16 @@ public void RegistrationMustThrowAnExceptionForNonInterfaces()
281294
{
282295
Assert.Throws<NotSupportedException>(() => new UnityContainer().RegisterLazy<Service1, Service1>());
283296
}
297+
298+
[Fact]
299+
public void InternalsVisibleToAttributeMustAllowToResolveInternalServices()
300+
{
301+
var result = new UnityContainer()
302+
.RegisterLazy<IInternalService, InternalService>()
303+
.Resolve<IInternalService>()
304+
.Get();
305+
306+
Assert.Equal("InternalService", result);
307+
}
284308
}
285309
}

0 commit comments

Comments
 (0)