Exemplo n.º 1
0
            public void Should_dispose_the_serviceScope()
            {
                // Arrange
                // The service scope
                var serviceScopeMock = new Mock <IServiceScope>();

                serviceScopeMock.Setup(x => x.Dispose()).Verifiable();

                // The scope factory (used internally by CreateScope)
                var serviceScopeFactoryMock = new Mock <IServiceScopeFactory>();

                serviceScopeFactoryMock.Setup(x => x.CreateScope()).Returns(serviceScopeMock.Object);

                // The global service provider
                var serviceProviderMock = new Mock <IServiceProvider>();

                serviceProviderMock.Setup(x => x.GetService(typeof(IServiceScopeFactory))).Returns(serviceScopeFactoryMock.Object);

                // The subject under test
                var sut = new SeederManagerFactory(serviceProviderMock.Object);

                // Act
                sut.Dispose();

                // Assert
                serviceScopeMock.Verify(x => x.Dispose(), Times.Once);
            }
Exemplo n.º 2
0
            public void Should_return_the_expected_ISeederManager()
            {
                // Arrange
                var expectedSeederManager = new Mock <ISeederManager <SeederDbContext> >();
                var services = new ServiceCollection();

                services.AddScoped(sp => expectedSeederManager.Object);
                var serviceProvider = services.BuildServiceProvider();
                var sut             = new SeederManagerFactory(serviceProvider);

                // Act
                var result = sut.Create <SeederDbContext>();

                // Assert
                Assert.Same(expectedSeederManager.Object, result);
            }