public void CreateReturnsCorrectResultWhenSpecificationIsSatisfied( Type request) { // Fixture setup var specificationStub = new Mock <IRequestSpecification>(); specificationStub .Setup(s => s.IsSatisfiedBy(request)) .Returns(true); var expected = (Mock)typeof(Mock <>) .MakeGenericType(request) .GetConstructor(Type.EmptyTypes) .Invoke(null); var contextStub = new Mock <ISpecimenContext>(); contextStub .Setup(c => c.Resolve(typeof(Mock <>).MakeGenericType(request))) .Returns(expected); var sut = new MockRelay(specificationStub.Object); // Exercise system var actual = sut.Create(request, contextStub.Object); // Verify outcome Assert.Equal(expected.Object, actual); // Teardown }
public void CreateReturnsCorrectResultWhenSpecificationIsSatisfied( Type request) { // Fixture setup var specificationStub = new Mock<IRequestSpecification>(); specificationStub .Setup(s => s.IsSatisfiedBy(request)) .Returns(true); var expected = (Mock)typeof(Mock<>) .MakeGenericType(request) .GetConstructor(Type.EmptyTypes) .Invoke(null); var contextStub = new Mock<ISpecimenContext>(); contextStub .Setup(c => c.Resolve(typeof(Mock<>).MakeGenericType(request))) .Returns(expected); var sut = new MockRelay(specificationStub.Object); // Exercise system var actual = sut.Create(request, contextStub.Object); // Verify outcome Assert.Equal(expected.Object, actual); // Teardown }
public void CreateWithNullContextThrows() { // Fixture setup var sut = new MockRelay(); var dummyRequest = new object(); // Exercise system and verify outcome Assert.Throws<ArgumentNullException>(() => sut.Create(dummyRequest, null)); // Teardown }
public void CreateWithNullContextThrows() { // Arrange var sut = new MockRelay(); var dummyRequest = new object(); // Act & Assert Assert.Throws <ArgumentNullException>(() => sut.Create(dummyRequest, null)); }
public void CreateWithNullContextThrows() { // Fixture setup var sut = new MockRelay(); var dummyRequest = new object(); // Exercise system and verify outcome Assert.Throws <ArgumentNullException>(() => sut.Create(dummyRequest, null)); // Teardown }
public void CreateWithNonAbstractionRequestReturnsCorrectResult(object request) { // Fixture setup var sut = new MockRelay(); var dummyContext = new Mock<ISpecimenContext>().Object; // Exercise system var result = sut.Create(request, dummyContext); // Verify outcome var expectedResult = new NoSpecimen(request); Assert.Equal(expectedResult, result); // Teardown }
public void CreateWithNonAbstractionRequestReturnsCorrectResult(object request) { // Arrange var sut = new MockRelay(); var dummyContext = new Mock <ISpecimenContext>().Object; // Act var result = sut.Create(request, dummyContext); // Assert var expectedResult = new NoSpecimen(); Assert.Equal(expectedResult, result); }
public void CreateWithNonAbstractionRequestReturnsCorrectResult(object request) { // Fixture setup var sut = new MockRelay(); var dummyContext = new Mock <ISpecimenContext>().Object; // Exercise system var result = sut.Create(request, dummyContext); // Verify outcome var expectedResult = new NoSpecimen(); Assert.Equal(expectedResult, result); // Teardown }
public void CreateCorrectlyInvokesSpecification(Type request) { // Fixture setup var verified = false; Func <Type, bool> mockSpec = t => verified = t == request; var sut = new MockRelay(mockSpec); // Exercise system var contextDummy = new Mock <ISpecimenContext>(); sut.Create(request, contextDummy.Object); // Verify outcome Assert.True(verified, "Mock verified"); // Teardown }
public void CreateReturnsCorrectResultWhenContextReturnsNonMock() { // Fixture setup var request = typeof(IInterface); var mockType = typeof(Mock<>).MakeGenericType(request); var contextStub = new Mock<ISpecimenContext>(); contextStub.Setup(ctx => ctx.Resolve(mockType)).Returns(new object()); var sut = new MockRelay(); // Exercise system var result = sut.Create(request, contextStub.Object); // Verify outcome var expectedResult = new NoSpecimen(request); Assert.Equal(expectedResult, result); // Teardown }
public void CreateWithAbstractionRequestReturnsCorrectResult(Type request) { // Arrange var mockType = typeof(Mock <>).MakeGenericType(request); var mock = (Mock)Activator.CreateInstance(mockType); var contextStub = new Mock <ISpecimenContext>(); contextStub.Setup(ctx => ctx.Resolve(mockType)).Returns(mock); var sut = new MockRelay(); // Act var result = sut.Create(request, contextStub.Object); // Assert Assert.Equal(mock.Object, result); }
public void CreateReturnsCorrectResultWhenContextReturnsValidNonMockSpecimen(object validNonMockSpecimen) { // Arrange var request = typeof(IInterface); var mockType = typeof(Mock <>).MakeGenericType(request); var contextStub = new Mock <ISpecimenContext>(); contextStub.Setup(ctx => ctx.Resolve(mockType)).Returns(validNonMockSpecimen); var sut = new MockRelay(); // Act var result = sut.Create(request, contextStub.Object); // Assert Assert.Equal(validNonMockSpecimen, result); }
public void CreateWithAbstractionRequestReturnsCorrectResult(Type request) { // Fixture setup var mockType = typeof(Mock <>).MakeGenericType(request); var mock = (Mock)Activator.CreateInstance(mockType); var contextStub = new Mock <ISpecimenContext>(); contextStub.Setup(ctx => ctx.Resolve(mockType)).Returns(mock); var sut = new MockRelay(); // Exercise system var result = sut.Create(request, contextStub.Object); // Verify outcome Assert.Equal(mock.Object, result); // Teardown }
public void CreateReturnsCorrectResultWhenContextReturnsValidNonMockSpecimen(object validNonMockSpecimen) { // Fixture setup var request = typeof(IInterface); var mockType = typeof(Mock <>).MakeGenericType(request); var contextStub = new Mock <ISpecimenContext>(); contextStub.Setup(ctx => ctx.Resolve(mockType)).Returns(validNonMockSpecimen); var sut = new MockRelay(); // Exercise system var result = sut.Create(request, contextStub.Object); // Verify outcome Assert.Equal(validNonMockSpecimen, result); // Teardown }
public void CreateWhenSpecificationIsSatisfiedButRequestIsNotTypeReturnsCorrectResult() { // Fixture setup var specificationStub = new Mock<IRequestSpecification>(); specificationStub .Setup(s => s.IsSatisfiedBy(It.IsAny<object>())) .Returns(true); var sut = new MockRelay(specificationStub.Object); var request = new object(); // Exercise system var dummyContext = new Mock<ISpecimenContext>().Object; var actual = sut.Create(request, dummyContext); // Verify outcome var expected = new NoSpecimen(request); Assert.Equal(expected, actual); // Teardown }
public void CreateWhenSpecificationIsSatisfiedButRequestIsNotTypeReturnsCorrectResult() { // Arrange var specificationStub = new Mock <IRequestSpecification>(); specificationStub .Setup(s => s.IsSatisfiedBy(It.IsAny <object>())) .Returns(true); var sut = new MockRelay(specificationStub.Object); var request = new object(); // Act var dummyContext = new Mock <ISpecimenContext>().Object; var actual = sut.Create(request, dummyContext); // Assert var expected = new NoSpecimen(); Assert.Equal(expected, actual); }
public void CreateWhenSpecificationIsSatisfiedButRequestIsNotTypeReturnsCorrectResult() { // Fixture setup var specificationStub = new Mock <IRequestSpecification>(); specificationStub .Setup(s => s.IsSatisfiedBy(It.IsAny <object>())) .Returns(true); var sut = new MockRelay(specificationStub.Object); var request = new object(); // Exercise system var dummyContext = new Mock <ISpecimenContext>().Object; var actual = sut.Create(request, dummyContext); // Verify outcome var expected = new NoSpecimen(request); Assert.Equal(expected, actual); // Teardown }
public void CreateReturnsCorrectResultWhenContextReturnsNonMock() { // Fixture setup var request = typeof(IInterface); var mockType = typeof(Mock <>).MakeGenericType(request); var contextStub = new Mock <ISpecimenContext>(); contextStub.Setup(ctx => ctx.Resolve(mockType)).Returns(new object()); var sut = new MockRelay(); // Exercise system var result = sut.Create(request, contextStub.Object); // Verify outcome #pragma warning disable 618 var expectedResult = new NoSpecimen(request); #pragma warning restore 618 Assert.Equal(expectedResult, result); // Teardown }
public void CreateWithAbstractionRequestReturnsCorrectResult(Type request) { // Fixture setup var mockType = typeof(Mock<>).MakeGenericType(request); var mock = (Mock)Activator.CreateInstance(mockType); var contextStub = new Mock<ISpecimenContext>(); contextStub.Setup(ctx => ctx.Resolve(mockType)).Returns(mock); var sut = new MockRelay(); // Exercise system var result = sut.Create(request, contextStub.Object); // Verify outcome Assert.Equal(mock.Object, result); // Teardown }
public void CreateCorrectlyInvokesSpecification(Type request) { // Fixture setup var verified = false; Func<Type, bool> mockSpec = t => verified = t == request; var sut = new MockRelay(mockSpec); // Exercise system var contextDummy = new Mock<ISpecimenContext>(); sut.Create(request, contextDummy.Object); // Verify outcome Assert.True(verified, "Mock verified"); // Teardown }