Exemple #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
 }
Exemple #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
 }
Exemple #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);
        }
Exemple #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);
        }
Exemple #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);
        }
        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
        }
Exemple #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
        }
Exemple #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
        }
Exemple #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);
        }
 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
 }