public void SetupThrowsWhenContextIsNull()
 {
     // Fixture setup
     var mock = Substitute.For<object>();
     var sut = new NSubstituteVirtualMethodsCommand();
     // Exercise system and verify outcome
     Assert.Throws<ArgumentNullException>(
         () => sut.Execute(mock, null));
     // Teardown
 }
 public void SetsUpPropertyGettersToRetrieveReturnValueFromContext()
 {
     // Fixture setup
     var fixture = new Fixture();
     var frozenString = fixture.Freeze<string>();
     var substitute = Substitute.For<IInterfaceWithProperty>();
     var sut = new NSubstituteVirtualMethodsCommand();
     // Exercise system
     sut.Execute(substitute, new SpecimenContext(fixture));
     // Verify outcome
     var result = substitute.Property;
     Assert.Equal(frozenString, result);
     // Teardown
 }
        public void SetsUpInterfaceShadowedMethodsToRetrieveReturnValueFromContext()
        {
            // Fixture setup
            var fixture = new Fixture();
            var frozenString = fixture.Freeze<string>();
            var substitute = Substitute.For<IInterfaceWithNewMethod>();

            var sut = new NSubstituteVirtualMethodsCommand();
            // Exercise system
            sut.Execute(substitute, new SpecimenContext(fixture));
            // Verify outcome
            var result = (substitute as IInterfaceWithShadowedMethod).Method(0);
            Assert.Same(frozenString, result);
            // Teardown
        }
        public void SetsUpMethodsToReturnDifferentOutValueOnSubsequentCallsOfAnotherSubstitute()
        {
            var fixture = new Fixture();
            var substitute1 = Substitute.For<IInterfaceWithOutMethod>();
            var substitute2 = Substitute.For<IInterfaceWithOutMethod>();
            var sut = new NSubstituteVirtualMethodsCommand();

            sut.Execute(substitute1, new SpecimenContext(fixture));
            sut.Execute(substitute2, new SpecimenContext(fixture));

            int outResult1;
            substitute1.Method(out outResult1);
            int outResult2;
            substitute2.Method(out outResult2);
            Assert.NotEqual(outResult1, outResult2);
        }
        public void SetsUpMethodsToReturnDifferentOutValueOnSubsequentCallsWithAnotherParameter()
        {
            var fixture = new Fixture();
            var anonymousString1 = fixture.Create<string>();
            var anonymousString2 = fixture.Create<string>();
            var substitute = Substitute.For<IInterfaceWithParameterAndOutMethod>();
            var sut = new NSubstituteVirtualMethodsCommand();

            sut.Execute(substitute, new SpecimenContext(fixture));

            int outResult1;
            substitute.Method(anonymousString1, out outResult1);
            int outResult2;
            substitute.Method(anonymousString2, out outResult2);
            Assert.NotEqual(outResult1, outResult2);
        }
        public void SetsUpMethodsToReturnSameOutValueOnSubsequentCalls()
        {
            var fixture = new Fixture();
            var substitute = Substitute.For<IInterfaceWithOutMethod>();
            var sut = new NSubstituteVirtualMethodsCommand();

            sut.Execute(substitute, new SpecimenContext(fixture));

            int outResult1;
            substitute.Method(out outResult1);
            int outResult2;
            substitute.Method(out outResult2);
            Assert.Equal(outResult1, outResult2);
        }
        public void SetsUpMethodsToReturnDifferentValueOnSubsequentCallsOfAnotherSubstitute()
        {
            var fixture = new Fixture();
            var anonymousString = fixture.Create<string>();
            var substitute1 = Substitute.For<IInterfaceWithMethod>();
            var substitute2 = Substitute.For<IInterfaceWithMethod>();
            var sut = new NSubstituteVirtualMethodsCommand();

            sut.Execute(substitute1, new SpecimenContext(fixture));
            sut.Execute(substitute2, new SpecimenContext(fixture));

            var result1 = substitute1.Method(anonymousString);
            var result2 = substitute2.Method(anonymousString);
            Assert.NotEqual(result1, result2);
        }
        public void SetsUpMethodsToReturnSameValueOnSubsequentCalls()
        {
            var fixture = new Fixture();
            var anonymousString = fixture.Create<string>();
            var substitute = Substitute.For<IInterfaceWithMethod>();
            var sut = new NSubstituteVirtualMethodsCommand();

            sut.Execute(substitute, new SpecimenContext(fixture));

            var result1 = substitute.Method(anonymousString);
            var result2 = substitute.Method(anonymousString);
            Assert.Same(result1, result2);
        }
 public void SetsUpIndexers()
 {
     // Fixture setup
     var fixture = new Fixture();
     var anonymousIndex = fixture.Create<int>();
     var frozenInt = fixture.Freeze<int>();
     var substitute = Substitute.For<IInterfaceWithIndexer>();
     var sut = new NSubstituteVirtualMethodsCommand();
     // Exercise system
     sut.Execute(substitute, new SpecimenContext(fixture));
     // Verify outcome
     int result = substitute[anonymousIndex];
     Assert.Equal(frozenInt, result);
     // Teardown
 }
 public void IgnoresStaticMethods()
 {
     // Fixture setup
     var fixture = new Fixture();
     var substitute = Substitute.For<TypeWithStaticMethod>();
     var sut = new NSubstituteVirtualMethodsCommand();
     // Exercise system and verify outcome
     Assert.DoesNotThrow(() => sut.Execute(substitute, new SpecimenContext(fixture)));
 }
        public void IgnoresGenericMethods()
        {
            // Fixture setup
            var fixture = new Fixture();
            var frozenString = fixture.Freeze<string>();
            var substitute = Substitute.For<IInterfaceWithGenericMethod>();
            var sut = new NSubstituteVirtualMethodsCommand();
            // Exercise system and verify outcome
            Assert.DoesNotThrow(() => sut.Execute(substitute, new SpecimenContext(fixture)));

            Assert.NotEqual(frozenString, substitute.GenericMethod<string>());
        }
        public void IgnoresSealedMethods()
        {
            // Fixture setup
            var fixture = new Fixture();
            var frozenString = fixture.Freeze<string>();
            var substitute = Substitute.For<TypeWithSealedMembers>();
            var sut = new NSubstituteVirtualMethodsCommand();
            // Exercise system and verify outcome
            Assert.DoesNotThrow(() => sut.Execute(substitute, new SpecimenContext(fixture)));

            Assert.NotEqual(frozenString, substitute.ImplicitlySealedMethod());
            Assert.NotEqual(frozenString, substitute.ExplicitlySealedMethod());
        }
        public void SetsUpMethodsWithRefParameters()
        {
            var fixture = new Fixture();
            var frozenString = fixture.Freeze<string>();
            var substitute = Substitute.For<IInterfaceWithRefMethod>();
            var sut = new NSubstituteVirtualMethodsCommand();

            sut.Execute(substitute, new SpecimenContext(fixture));

            string refResult = null;
            substitute.Method(ref refResult);
            Assert.Equal(frozenString, refResult);
        }
 public void SetsUpMethodsLazily()
 {
     // Fixture setup
     var context = Substitute.For<ISpecimenContext>();
     var substitute = Substitute.For<IInterfaceWithParameterlessMethod>();
     var sut = new NSubstituteVirtualMethodsCommand();
     // Exercise system
     sut.Execute(substitute, context);
     // Verify outcome
     context.Received(0).Resolve(Arg.Any<object>());
     substitute.Method();
     context.Received(1).Resolve(Arg.Any<object>());
     // Teardown
 }
        public void IgnoresNonSubstituteSpecimens()
        {
            var context = Substitute.For<ISpecimenContext>();
            var specimen = new ConcreteTypeWithVirtualMembers();
            var sut = new NSubstituteVirtualMethodsCommand();

            Assert.DoesNotThrow(() => sut.Execute(specimen, context));
            context.DidNotReceiveWithAnyArgs().Resolve(null);
        }
 public void SetsUpMethodsWithParameters()
 {
     // Fixture setup
     var fixture = new Fixture();
     var anonymousString = fixture.Create<string>();
     var frozenString = fixture.Freeze<string>();
     var substitute = Substitute.For<IInterfaceWithMethod>();
     var sut = new NSubstituteVirtualMethodsCommand();
     // Exercise system
     sut.Execute(substitute, new SpecimenContext(fixture));
     // Verify outcome
     var result = substitute.Method(anonymousString);
     Assert.Same(frozenString, result);
     // Teardown
 }
 public void IgnoresVoidMethodsWithOutParameters()
 {
     // Fixture setup
     var fixture = new Fixture();
     var frozenInt = fixture.Freeze<int>();
     var substitute = Substitute.For<IInterfaceWithOutVoidMethod>();
     var sut = new NSubstituteVirtualMethodsCommand();
     // Exercise system
     sut.Execute(substitute, new SpecimenContext(fixture));
     // Verify outcome
     int outResult;
     substitute.Method(out outResult);
     Assert.NotEqual(frozenInt, outResult);
     // Teardown
 }