public void ResolveAll_NoRegisteration_ReturnsEmptyEnumerable() { var subject = new ServiceLocatorContainer(); var result = subject.ResolveAll <IDisposable>(); Assert.IsEmpty(result); }
private static IServiceLocator CreateServiceLocator(Configuration configuration) { var container = new ServiceLocatorContainer(configuration.ServiceLocatorSetup); container.RegisterSingleton <Configuration, Configuration>(configuration); return(new ServiceLocator(container)); }
public void Resolve_NonRegisteredTypeWithDefaultConstructor_ThrowsException() { var subject = new ServiceLocatorContainer(); Assert.Throws <InvalidOperationException>(() => { subject.Resolve <MemoryStream>(); }); }
public void Resolve_NonRegisteredInterface_ThrowsException() { var subject = new ServiceLocatorContainer(); Assert.Throws <InvalidOperationException>(() => { subject.Resolve <IDisposable>(); }); }
public void Resolve_NonRegisteredTypeWithDefaultConstructor_ThrowsException() { var subject = new ServiceLocatorContainer(); Assert.Throws<InvalidOperationException>(() => { subject.Resolve<MemoryStream>(); }); }
public void Resolve_NonRegisteredInterface_ThrowsException() { var subject = new ServiceLocatorContainer(); Assert.Throws<InvalidOperationException>(() => { subject.Resolve<IDisposable>(); }); }
public void Bootstrap() { // Register dependencies var builder = new ContainerBuilder(); new ApiBootstrapper().Bootstrap(builder, "N/A", "UnitTests"); var container = builder.Build(); ServiceLocatorContainer.SetCurrent(new ServiceLocator(container)); }
public void Resolve_MultipleRegisterations_ReturnsLastRegistration() { var subject = new ServiceLocatorContainer(); subject.Register <IDisposable, MemoryStream>(); subject.Register <IDisposable, StringWriter>(); IDisposable result = subject.Resolve <IDisposable>(); Assert.IsTrue(result is StringWriter); }
public void Resolve_RegisteredSingletonType_ReturnsSameInstancePerResolve() { var subject = new ServiceLocatorContainer(); subject.RegisterSingleton <IDisposable, MemoryStream>(); var first = subject.Resolve <IDisposable>() as MemoryStream; var second = subject.Resolve <IDisposable>() as MemoryStream; Assert.NotNull(first); Assert.NotNull(second); Assert.AreSame(first, second); }
public void Resolve_RegisteredType_CreatesNewInstancePerResolve() { var subject = new ServiceLocatorContainer(); subject.Register <IDisposable, MemoryStream>(); var first = subject.Resolve <IDisposable>() as MemoryStream; var second = subject.Resolve <IDisposable>() as MemoryStream; Assert.NotNull(first); Assert.NotNull(second); Assert.AreNotSame(first, second); }
public void ResolveAll_MultipleRegisterations_ReturnsInstanceOfEveryRegistration() { var subject = new ServiceLocatorContainer(); subject.Register <IDisposable, MemoryStream>(); subject.Register <IDisposable, StringWriter>(); var result = subject.ResolveAll <IDisposable>()?.ToList(); Assert.NotNull(result); Assert.AreEqual(2, result.Count); Assert.IsTrue(result.Any(x => x is StringWriter)); Assert.IsTrue(result.Any(x => x is MemoryStream)); }
public void Constructor_ValidSetup_InvokesSetup() { var setupMock = new Mock<IServiceLocatorSetup>(MockBehavior.Strict); IServiceLocatorContainer calledContainer = null; setupMock .Setup(setup => setup.Configure(It.IsAny<IServiceLocatorContainer>())) .Callback<IServiceLocatorContainer>(container => calledContainer = container) .Verifiable(); // Act var subject = new ServiceLocatorContainer(setupMock.Object); // Assert setupMock.Verify(); Assert.AreEqual(subject, calledContainer); }
public void Constructor_ValidSetup_InvokesSetup() { var setupMock = new Mock <IServiceLocatorSetup>(MockBehavior.Strict); IServiceLocatorContainer calledContainer = null; setupMock .Setup(setup => setup.Configure(It.IsAny <IServiceLocatorContainer>())) .Callback <IServiceLocatorContainer>(container => calledContainer = container) .Verifiable(); // Act var subject = new ServiceLocatorContainer(setupMock.Object); // Assert setupMock.Verify(); Assert.AreEqual(subject, calledContainer); }
public void Resolve_RegisteredSingletonType_ReturnsSameInstancePerResolve() { var subject = new ServiceLocatorContainer(); subject.RegisterSingleton<IDisposable, MemoryStream>(); var first = subject.Resolve<IDisposable>() as MemoryStream; var second = subject.Resolve<IDisposable>() as MemoryStream; Assert.NotNull(first); Assert.NotNull(second); Assert.AreSame(first, second); }
public void Resolve_RegisteredType_CreatesNewInstancePerResolve() { var subject = new ServiceLocatorContainer(); subject.Register<IDisposable, MemoryStream>(); var first = subject.Resolve<IDisposable>() as MemoryStream; var second = subject.Resolve<IDisposable>() as MemoryStream; Assert.NotNull(first); Assert.NotNull(second); Assert.AreNotSame(first, second); }