Esempio n. 1
0
        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
        }
Esempio n. 2
0
        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
 }
Esempio n. 4
0
        public void CreateWithNullContextThrows()
        {
            // Arrange
            var sut          = new MockRelay();
            var dummyRequest = new object();

            // Act & Assert
            Assert.Throws <ArgumentNullException>(() =>
                                                  sut.Create(dummyRequest, null));
        }
Esempio n. 5
0
        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
 }
Esempio n. 7
0
        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);
        }
Esempio n. 8
0
        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
        }
Esempio n. 9
0
        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
        }
Esempio n. 10
0
        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
        }
Esempio n. 11
0
        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);
        }
Esempio n. 12
0
        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);
        }
Esempio n. 13
0
        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
        }
Esempio n. 14
0
        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
        }
Esempio n. 15
0
        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
        }
Esempio n. 16
0
        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);
        }
Esempio n. 17
0
        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
        }
Esempio n. 18
0
        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
        }
Esempio n. 19
0
        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
        }
Esempio n. 20
0
 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
 }