public void GetInstanceResolvesInstanceUsingDryIoc() { var serviceType = typeof(string); var resolvedObject = String.Empty; var message = new Mock <Message>(MockBehavior.Loose).Object; _containerMock.SetupGet(c => c.CurrentScope).Returns(default(IScope)); _containerMock.SetupGet(c => c.ScopeContext).Returns(default(IScopeContext)); _containerMock.Setup(c => c.WithCurrentScope(It.IsAny <IScope>())).Returns(_newContainerMock.Object); _newContainerMock.Setup(c => c.Resolve(serviceType, IfUnresolved.Throw)).Returns(resolvedObject); var sut = new DryIocInstanceProvider(_containerMock.Object, serviceType); var instance = sut.GetInstance(_instanceContext, message); Assert.Equal(resolvedObject, instance); Assert.IsType(serviceType, instance); _newContainerMock.Verify(c => c.Resolve(serviceType, IfUnresolved.Throw), Times.Once); }
public void ContainerIsDisposedIfResolveThrows() { var serviceType = typeof(string); var resolvedObject = String.Empty; _containerMock.SetupGet(c => c.CurrentScope).Returns(default(IScope)); _containerMock.SetupGet(c => c.ScopeContext).Returns(default(IScopeContext)); _containerMock.Setup(c => c.WithCurrentScope(It.IsAny <IScope>())).Returns(_newContainerMock.Object); _newContainerMock.Setup(c => c.Resolve(serviceType, IfUnresolved.Throw)).Throws <InvalidOperationException>(); _newContainerMock.Setup(c => c.Dispose()); var sut = new DryIocInstanceProvider(_containerMock.Object, serviceType); Assert.Throws <InvalidOperationException>(() => sut.GetInstance(_instanceContext)); _containerMock.VerifyGet(c => c.CurrentScope, Times.Once); _containerMock.VerifyGet(c => c.ScopeContext, Times.Once); _containerMock.Verify(c => c.WithCurrentScope(It.IsAny <IScope>()), Times.Once); _newContainerMock.Verify(c => c.Resolve(serviceType, IfUnresolved.Throw), Times.Once); _newContainerMock.Verify(c => c.Dispose(), Times.Once); }
public void GetInstanceThrowsNullArgumentExceptionForNullArgument() { var sut = new DryIocInstanceProvider(_containerMock.Object, typeof(DryIocInstanceProviderTests)); Assert.Throws <ArgumentNullException>("instanceContext", () => sut.GetInstance(null)); }