Exemplo n.º 1
0
        public void CreateThrowsArgumentNullExceptionWhenContextIsNullBecauseItsRequired()
        {
            // Arrange
            var sut     = new SubstituteRelay();
            var request = new object();
            // Act
            var e = Assert.Throws <ArgumentNullException>(() => sut.Create(request, null));

            // Assert
            Assert.Equal("context", e.ParamName);
        }
 public void CreateThrowsArgumentNullExceptionWhenContextIsNullBecauseItsRequired()
 {
     // Fixture setup
     var sut = new SubstituteRelay();
     var request = new object();
     // Exercise system
     var e = Assert.Throws<ArgumentNullException>(() => sut.Create(request, null));
     // Verify outcome
     Assert.Equal("context", e.ParamName);
     // Teardown
 }
Exemplo n.º 3
0
        public void CreateThrowsArgumentNullExceptionWhenContextIsNullBecauseItsRequired()
        {
            // Fixture setup
            var sut     = new SubstituteRelay();
            var request = new object();
            // Exercise system
            var e = Assert.Throws <ArgumentNullException>(() => sut.Create(request, null));

            // Verify outcome
            Assert.Equal("context", e.ParamName);
            // Teardown
        }
 public void CreateReturnsNoSpecimenWhenRequestedTypeIsNotAbstract()
 {
     // Fixture setup
     var sut = new SubstituteRelay();
     object request = typeof(string);
     var context = Substitute.For<ISpecimenContext>();
     // Exercise system
     object result = sut.Create(request, context);
     // Verify outcome
     var expected = new NoSpecimen(request);
     Assert.Equal(expected, result);
     // Teardown
 }
Exemplo n.º 5
0
        public void CreateReturnsNoSpecimenWhenRequestedTypeIsNotAbstract()
        {
            // Arrange
            var    sut     = new SubstituteRelay();
            object request = typeof(string);
            var    context = Substitute.For <ISpecimenContext>();
            // Act
            object result = sut.Create(request, context);
            // Assert
            var expected = new NoSpecimen();

            Assert.Equal(expected, result);
        }
Exemplo n.º 6
0
        public void CreateReturnsNoSpecimenWhenRequestedTypeIsNotAbstract()
        {
            // Fixture setup
            var    sut     = new SubstituteRelay();
            object request = typeof(string);
            var    context = Substitute.For <ISpecimenContext>();
            // Exercise system
            object result = sut.Create(request, context);
            // Verify outcome
            var expected = new NoSpecimen();

            Assert.Equal(expected, result);
            // Teardown
        }
 public void CreateReturnsObjectResolvedFromContextWhenRequestedTypeIsAbstractOrInterface(Type requestedType)
 {
     // Fixture setup
     var sut = new SubstituteRelay();
     object request = requestedType;
     object substitute = Substitute.For(new Type[] { requestedType }, new object[0]);
     var context = Substitute.For<ISpecimenContext>();
     context.Resolve(Arg.Is<SubstituteRequest>(r => r.TargetType == requestedType)).Returns(substitute);
     // Exercise system
     object result = sut.Create(request, context);
     // Verify outcome
     Assert.Same(substitute, result);
     // Teardown
 }
        public void ShouldNotRelayRequestIfSpecificationDoesNotMatch()
        {
            // Arrange
            var falseSpecification = new FalseRequestSpecification();
            var sut     = new SubstituteRelay(falseSpecification);
            var request = typeof(IInterface);
            var context = Substitute.For <ISpecimenContext>();

            // Act
            var result = sut.Create(request, context);

            // Assert
            Assert.IsType <NoSpecimen>(result);
        }
Exemplo n.º 9
0
        public void CreateReturnsObjectResolvedFromContextWhenRequestedTypeIsAbstractOrInterface(Type requestedType)
        {
            // Arrange
            var    sut        = new SubstituteRelay();
            object request    = requestedType;
            object substitute = Substitute.For(new Type[] { requestedType }, new object[0]);
            var    context    = Substitute.For <ISpecimenContext>();

            context.Resolve(Arg.Is <SubstituteRequest>(r => r.TargetType == requestedType)).Returns(substitute);
            // Act
            object result = sut.Create(request, context);

            // Assert
            Assert.Same(substitute, result);
        }
Exemplo n.º 10
0
        public void CreateReturnsNoSpecimenWhenRequestIsNotAType()
        {
            // Fixture setup
            var sut = new SubstituteRelay();
            object request = "beer";
            var context = Substitute.For<ISpecimenContext>();
            // Exercise system
            object result = sut.Create(request, context);
            // Verify outcome
#pragma warning disable 618
            var expected = new NoSpecimen(request);
#pragma warning restore 618
            Assert.Equal(expected, result);
            // Teardown
        }
Exemplo n.º 11
0
        public void CreateReturnsObjectResolvedFromContextWhenRequestedTypeIsAbstractOrInterface(Type requestedType)
        {
            // Fixture setup
            var    sut        = new SubstituteRelay();
            object request    = requestedType;
            object substitute = Substitute.For(new Type[] { requestedType }, new object[0]);
            var    context    = Substitute.For <ISpecimenContext>();

            context.Resolve(Arg.Is <SubstituteRequest>(r => r.TargetType == requestedType)).Returns(substitute);
            // Exercise system
            object result = sut.Create(request, context);

            // Verify outcome
            Assert.Same(substitute, result);
            // Teardown
        }
Exemplo n.º 12
0
        public void CreateReturnsNoSpecimenWhenRequestIsNotAType()
        {
            // Fixture setup
            var    sut     = new SubstituteRelay();
            object request = "beer";
            var    context = Substitute.For <ISpecimenContext>();
            // Exercise system
            object result = sut.Create(request, context);

            // Verify outcome
#pragma warning disable 618
            var expected = new NoSpecimen(request);
#pragma warning restore 618
            Assert.Equal(expected, result);
            // Teardown
        }
Exemplo n.º 13
0
        public void CreateThrowsInvalidOperationExceptionWhenResolvedObjectIsNotSubstituteAssumingInvalidConfiguration()
        {
            // Arrange
            var sut            = new SubstituteRelay();
            var request        = typeof(IComparable);
            var notASubstitute = new object();
            var context        = Substitute.For <ISpecimenContext>();

            context.Resolve(Arg.Any <object>()).Returns(notASubstitute);
            // Act
            var e = Assert.Throws <InvalidOperationException>(() => sut.Create(request, context));

            // Assert
            Assert.Contains(request.FullName, e.Message);
            Assert.Contains(typeof(SubstituteRequestHandler).FullName, e.Message);
            Assert.IsType <NotASubstituteException>(e.InnerException);
        }
Exemplo n.º 14
0
 public void CreateThrowsInvalidOperationExceptionWhenResolvedObjectIsNotSubstituteAssumingInvalidConfiguration()
 {
     // Fixture setup
     var sut = new SubstituteRelay();
     var request = typeof(IComparable);
     var notASubstitute = new object();
     var context = Substitute.For<ISpecimenContext>();
     context.Resolve(Arg.Any<object>()).Returns(notASubstitute);
     // Exercise system
     var e = Assert.Throws<InvalidOperationException>(() => sut.Create(request, context));
     // Verify outcome
     Assert.Contains(request.FullName, e.Message);
     Assert.Contains(typeof(SubstituteRequestHandler).FullName, e.Message); 
     Assert.IsType<NotASubstituteException>(e.InnerException);
     // Teardown
 }