This is a migrated thread and some comments may be shown as answers.

check Property never called

1 Answer 12 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Ryan
Top achievements
Rank 1
Ryan asked on 22 Mar 2011, 04:51 PM
How can I arrange the mock to assert that a property setter is never called?

I've tried the following: 
Mock.ArrangeSet(() => mockVirtualEntity.EffectiveFrom = DateTime.Now).IgnoreArguments().OccursNever();

I dont care what the value being set is - I just want to make sure the property setter is never called?

1 Answer, 1 is accepted

Sort by
0
Ricky
Telerik team
answered on 25 Mar 2011, 10:59 AM
Hi Ryan,

Thanks again for your question. Yes it is possible to assert property set for any values. Below is a test that shows how you can arrange property set with Arg.IsAny<T>():

[TestMethod, ExpectedException(typeof(MockAssertionException))]
 public void ShouldThowForOccursNeverForAnyValue()
 {
     var foo = Mock.Create<IFoo>();
     Mock.ArrangeSet(() => foo.EffectiveFrom = Arg.IsAny<DateTime>()).OccursNever();
     foo.EffectiveFrom = DateTime.Now;
     Mock.Assert(foo);
 }


Similarly, it is also possible to assert the specific property for above setup in the following way:

Mock.AssertSet(() => foo.EffectiveFrom = Arg.IsAny<DateTime>());

Moreover, you can also write the first test in this way:

[TestMethod, ExpectedException(typeof(MockAssertionException))]
public void ShouldThowForOccursNeverForAnyValueWithIgnoreArguments()
{
    var foo = Mock.Create<IFoo>();
    Mock.ArrangeSet(() => foo.EffectiveFrom = DateTime.Now).IgnoreArguments().OccursNever();
    foo.EffectiveFrom = DateTime.Now;
    Mock.Assert(foo);
}

Finally, i have attached the test project to let you have a look. Please do feel free to write us back for any other issues.

Kind Regards,
Ricky
the Telerik team
Tags
General Discussions
Asked by
Ryan
Top achievements
Rank 1
Answers by
Ricky
Telerik team
Share this question
or