Recently started using JustMock to create unit tests so my knowledge is limited at time. I have the below test code with occurrence expectations on a few arrangements for different objects set. The intention was that the mocked ItemCollection and mocked RadComboBox objects were to be used 3 times to avoid having to create them again, since nothing about the calls change and the mocked SelectionChangedEventArgs object was to be recreated each time with different arrangements.
However, when I assert the expectations on mockSelectionChangedEventArgs, somehow that is also asserting the expectations on itemCollection_Single and radComboBox_Single which both fail because at the time there has only been one call on each of Count and Items. By the end when I do assert the expectations on itemCollection_Single and radComboBox_Single it would be 3 as in my expectations since I would have used them 3 times.
Why does asserting all expectations on mockSelectionChangedEventArgs assert them on the other two objects? I cannot find any documentation on this scenario. I can avoid this issue by specifically mocking mockSelectionChangedEventArgs.AddedItems and mockSelectionChangedEventArgs.OriginalSource, but I don't see why that is necessary.
However, when I assert the expectations on mockSelectionChangedEventArgs, somehow that is also asserting the expectations on itemCollection_Single and radComboBox_Single which both fail because at the time there has only been one call on each of Count and Items. By the end when I do assert the expectations on itemCollection_Single and radComboBox_Single it would be 3 as in my expectations since I would have used them 3 times.
Why does asserting all expectations on mockSelectionChangedEventArgs assert them on the other two objects? I cannot find any documentation on this scenario. I can avoid this issue by specifically mocking mockSelectionChangedEventArgs.AddedItems and mockSelectionChangedEventArgs.OriginalSource, but I don't see why that is necessary.
ItemCollection itemCollection_Single = Mock.Create<ItemCollection>(Behavior.Strict);
Mock.Arrange(() => itemCollection_Single.Count).Returns(2).Occurs(3, nameof(itemCollection_Single.Count));
RadComboBox radComboBox_Single = Mock.Create<RadComboBox>(Behavior.Strict);
Mock.Arrange(() => radComboBox_Single.Items).Returns(itemCollection_Single).Occurs(3, nameof(radComboBox_Single.Items));
mockSelectionChangedEventArgs = Mock.Create<SelectionChangedEventArgs>(Behavior.Strict);
Mock.Arrange(() => mockSelectionChangedEventArgs.AddedItems).Returns(new List<ParameterValue>() { selectionRuleRow.AllowedValues[0] }).Occurs(2, nameof(mockSelectionChangedEventArgs.AddedItems));
Mock.Arrange(() => mockSelectionChangedEventArgs.OriginalSource).Returns(radComboBox_Single).Occurs(1, nameof(mockSelectionChangedEventArgs.OriginalSource));
selectionRuleRow.MultipleEnumSelectionChanged.Execute(mockSelectionChangedEventArgs);
Assert.AreEqual(expected: "Yes", actual: selectionRuleRow.Value);
Assert.IsTrue(selectionRuleRow.CanApply);
Mock.Assert(mockSelectionChangedEventArgs); // ==> fails because of set expectations on itemCollection_Single and radComboBox_Single
//Mock.Assert(() => mockSelectionChangedEventArgs.AddedItems, Occurs.Exactly(1));
//Mock.Assert(() => mockSelectionChangedEventArgs.OriginalSource, Occurs.Exactly(1));