Ejemplo n.º 1
0
        private static FakeCall CreateFakeCallToFooDotBar(object argument1, object argument2)
        {
            var call = FakeCall.Create <IFoo>("Bar", new[] { typeof(object), typeof(object) },
                                              new[] { argument1, argument2 });

            return(call);
        }
        public void IsApplicableTo_should_return_false_for_random_method_when_property_is_read_only()
        {
            var call = FakeCall.Create <IFoo>("Bar", new Type[] { }, new object[] { });

            var rule = CreateRule <IFoo, string>(x => x.ReadOnlyProperty);

            Assert.That(rule.IsApplicableTo(call), Is.False);
        }
        public void IsApplicableTo_should_return_true_when_call_is_made_to_virtual_method_on_superclass()
        {
            var call = FakeCall.Create <SubClass>("CallMe");

            var rule = CreateRule <SubClass>(x => x.CallMe());

            Assert.That(rule.IsApplicableTo(call), Is.True);
        }
        public void IsApplicableTo_should_return_true_when_method_matches_and_no_arguments_in_call()
        {
            var rule = CreateRule <IFoo>(x => x.Bar());

            var matchingCall = FakeCall.Create <IFoo>("Bar");

            Assert.That(rule.IsApplicableTo(matchingCall), Is.True);
        }
        public void IsApplicableTo_should_return_false_when_argument_doesnt_match()
        {
            var rule = CreateRule <IFoo>(x => x.Bar("test"));

            var nonMatchingCall = FakeCall.Create <IFoo>("Bar", new[] { typeof(object) }, new[] { "non matching" });

            Assert.That(rule.IsApplicableTo(nonMatchingCall), Is.False);
        }
        public void IsApplicableTo_should_return_false_when_method_doesnt_match()
        {
            var rule = CreateRule <IFoo>(x => x.Bar());

            var nonMatchingCall = FakeCall.Create <IFoo>("Baz", new Type[] {}, new object[] {});

            Assert.That(rule.IsApplicableTo(nonMatchingCall), Is.False);
        }
        public void Apply_should_use_arguments_from_call_when_calling_wrapped_object()
        {
            var wrapped = A.Fake <IFoo>();

            var call = FakeCall.Create <IFoo>("Bar", new[] { typeof(object), typeof(object) }, new object[] { "foo", "bar" });

            var rule = this.CreateRule(wrapped);

            rule.Apply(call);

            A.CallTo(() => wrapped.Bar("foo", "bar")).MustHaveHappened();
        }
        public void Apply_should_use_arguments_from_call_when_calling_wrapped_object()
        {
            var wrapped = A.Fake <IFoo>();

            var call = FakeCall.Create <IFoo>("Bar", new Type[] { typeof(object), typeof(object) }, new object[] { "foo", "bar" });

            var rule = this.CreateRule(wrapped);

            rule.Apply(call);

            Fake.Assert(wrapped).WasCalled(x => x.Bar("foo", "bar"));
        }
        public void Apply_should_assign_out_arguments()
        {
            // Arrange
            var wrapped = new TypeWithOutputArguments(10);
            var call    = FakeCall.Create <ITypeWithOutputArguments>("MethodWithOutputArgument", new[] { Type.GetType("System.Int32&") }, new object[] { 0 });
            var rule    = this.CreateRule(wrapped);

            // Act
            rule.Apply(call);

            // Assert
            call.Arguments[0].Should().Be(10);
        }
        public void IsApplicableTo_should_return_true_for_property_get_method_when_property_is_read_only()
        {
            var call = new FakeCall
            {
                FakedObject = A.Fake <IFoo>(),
                Arguments   = ArgumentCollection.Empty,
                Method      = typeof(IFoo).GetProperty("ReadOnlyProperty").GetGetMethod()
            };

            var rule = CreateRule <IFoo, string>(x => x.ReadOnlyProperty);

            Assert.That(rule.IsApplicableTo(call));
        }
Ejemplo n.º 11
0
        public void Apply_should_call_the_applicator_with_the_incoming_call()
        {
            IWritableFakeObjectCall callPassedToApplicator = null;
            var callPassedToRule = FakeCall.Create <IFoo>("Bar");

            var rule = CreateRule <IFoo>(x => x.Bar());

            rule.Applicator = x => callPassedToApplicator = x;

            rule.Apply(callPassedToRule);

            Assert.That(callPassedToApplicator, Is.SameAs(callPassedToRule));
        }
Ejemplo n.º 12
0
        public void Apply_should_call_the_applicator_with_the_incoming_call()
        {
            IInterceptedFakeObjectCall callPassedToApplicator = null;
            var callPassedToRule = FakeCall.Create <IFoo>("Bar");

            var rule = this.CreateRule();

            rule.Applicator = x => callPassedToApplicator = x;

            rule.Apply(callPassedToRule);

            callPassedToApplicator.Should().BeSameAs(callPassedToRule);
        }
        public void Apply_should_set_return_value_from_wrapped_object(int returnValue)
        {
            var wrapped = A.Fake <IFoo>();

            A.CallTo(() => wrapped.Baz()).Returns(returnValue);

            var call = FakeCall.Create <IFoo>("Baz", Type.EmptyTypes, Array.Empty <object>());

            var rule = this.CreateRule(wrapped);

            rule.Apply(call);

            call.ReturnValue.Should().Be(returnValue);
        }
Ejemplo n.º 14
0
        public void Apply_should_assign_out_arguments()
        {
            // Arrange
            var wrapped = new TypeWithOutputArguments(10);
            int i       = 0;
            var call    = FakeCall.Create <ITypeWithOutputArguments>(x => x.MethodWithOutputArgument(out i));
            var rule    = this.CreateRule(wrapped);

            // Act
            rule.Apply(call);

            // Assert
            call.Arguments[0].Should().Be(10);
        }
Ejemplo n.º 15
0
        public void Apply_should_set_return_value_from_wrapped_object([Values(0, 1, 2, 3, 5, 8)] int returnValue)
        {
            var wrapped = A.Fake <IFoo>();

            A.CallTo(() => wrapped.Baz()).Returns(returnValue);

            var call = FakeCall.Create <IFoo>("Baz", new Type[] { }, new object[] { });

            var rule = this.CreateRule(wrapped);

            rule.Apply(call);

            call.ReturnValue.Should().Be(returnValue);
        }
        public void Apply_should_set_return_value_from_wrapped_object([Values(0, 1, 2, 3, 5, 8)] int returnValue)
        {
            var wrapped = A.Fake <IFoo>();

            wrapped.Configure().CallsTo(x => x.Baz()).Returns(returnValue);

            var call = FakeCall.Create <IFoo>("Baz", new Type[] { }, new object[] { });

            var rule = this.CreateRule(wrapped);

            rule.Apply(call);

            Assert.That(call.ReturnValue, Is.EqualTo(returnValue));
        }
Ejemplo n.º 17
0
        public void Apply_should_assign_out_arguments()
        {
            // Arrange
            var wrapped = new TypeThatImplementsInterfaceWithOutAndRefArguments()
            {
                OutArgumentThatWillBeApplied = 10
            };

            var call = FakeCall.Create <ITypeWithOutAndRefArguments>("MethodWithOutArgument", new[] { Type.GetType("System.Int32&") }, new object[] { 0 });
            var rule = this.CreateRule(wrapped);

            // Act
            rule.Apply(call);

            // Assert
            Assert.That(call.Arguments[0], Is.EqualTo(10));
        }
Ejemplo n.º 18
0
        public void Apply_should_assign_reference_arguments()
        {
            // Arrange
            var wrapped = new TypeThatImplementsInterfaceWithOutputAndRefArguments
            {
                ReferenceArgumentThatWillBeApplied = 10
            };

            var call = FakeCall.Create <ITypeWithOutputAndRefArguments>("MethodWithReferenceArgument", new[] { Type.GetType("System.Int32&") }, new object[] { 0 });
            var rule = this.CreateRule(wrapped);

            // Act
            rule.Apply(call);

            // Assert
            call.Arguments[0].Should().Be(10);
        }
        private static IWritableFakeObjectCall CreateCallToBar(object argument)
        {
            var call = FakeCall.Create <IFoo>("Bar", new[] { typeof(object) }, new[] { argument });

            return(call);
        }
Ejemplo n.º 20
0
        public void GetDescription_should_render_method_name_and_empty_arguments_list_when_call_has_no_arguments()
        {
            var call = FakeCall.Create <object>("GetType");

            Assert.That(call.GetDescription(), Is.EqualTo("System.Object.GetType()"));
        }