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