Exemple #1
0
        public void GetService_ShouldResolveServicesFromLifetimeScope()
        {
            // Arrange
            var builder = new ContainerBuilder();
            var service = new DummyService();
            builder.RegisterInstance(service);
            var scope = new ServiceScope(builder.Build());

            // Act
            var result = scope.GetService(typeof(DummyService));

            // Assert
            result.Should().Be(service);
        }
Exemple #2
0
        public void GetService_ShouldResolveServicesFromServiceScope()
        {
            // Arrange
            var service = new DummyService();
            var microsoftServiceScopeMock = new Mock <IServiceScope>();
            var systemServiceProviderMock = new Mock <IServiceProvider>();

            microsoftServiceScopeMock.SetupGet(x => x.ServiceProvider).Returns(systemServiceProviderMock.Object);
            systemServiceProviderMock.Setup(x => x.GetService(typeof(DummyService))).Returns(service);
            var scope = new ServiceScope(microsoftServiceScopeMock.Object);

            // Act
            var result = scope.GetService(typeof(DummyService));

            // Assert
            result.Should().Be(service);
        }