public void ValueWithRandomAdded_should_raise_PropertyChanged_event_with_its_name() { // Arrange var notifyingObject = new NotifyingObject(); var mockHandler = new Mock<PropertyChangedEventHandler>(); mockHandler.Setup(_ => _(It.IsAny<object>(), It.IsAny<PropertyChangedEventArgs>())); notifyingObject.PropertyChanged += mockHandler.Object; // Act notifyingObject.ValueWithRandomAdded = 42; // Assert mockHandler.Verify(_ => _(notifyingObject, It.Is<PropertyChangedEventArgs>(o => o.PropertyName == "ValueWithRandomAdded")), Times.Once()); }
public void ValueWithRandomAdded_should_raise_PropertyChanged_event_with_its_name() { // Arrange var notifyingObject = new NotifyingObject(); var mockHandler = MockRepository.GenerateStub<PropertyChangedEventHandler>(); mockHandler.Stub(_ => _(Arg<object>.Is.Anything, Arg<PropertyChangedEventArgs>.Is.Anything)); notifyingObject.PropertyChanged += mockHandler; // Act notifyingObject.ValueWithRandomAdded = 42; // Assert mockHandler.AssertWasCalled(_ => _(Arg<object>.Is.Same(notifyingObject), Arg<PropertyChangedEventArgs>.Matches(o => o.PropertyName == "ValueWithRandomAdded")), options => options.Repeat.Once()); }
public void ValueWithRandomAdded_should_raise_PropertyChanged_event_with_its_name() { // Arrange var notifyingObject = new NotifyingObject(); var mockHandler = Substitute.For<PropertyChangedEventHandler>(); mockHandler(Arg.Any<object>(), Arg.Any<PropertyChangedEventArgs>()); notifyingObject.PropertyChanged += mockHandler; // Act notifyingObject.ValueWithRandomAdded = 42; // Assert mockHandler.Received(1)(notifyingObject, Arg.Is<PropertyChangedEventArgs>(o => o.PropertyName == "ValueWithRandomAdded")); }
public void ValueWithRandomAdded_should_raise_PropertyChanged_event_with_its_name() { // Arrange var notifyingObject = new NotifyingObject(); var mockHandler = A.Fake<PropertyChangedEventHandler>(); A.CallTo(() => mockHandler(A<object>._, A<PropertyChangedEventArgs>._)); notifyingObject.PropertyChanged += mockHandler; // Act notifyingObject.ValueWithRandomAdded = 42; // Assert A.CallTo(() => mockHandler(notifyingObject, A<PropertyChangedEventArgs>.That.Matches(_ => _.PropertyName == "ValueWithRandomAdded"))).MustHaveHappened(); }
public void ValueWithRandomAdded_should_hold_passed_value_plus_random_value() { using (new IndirectionsContext()) { // Arrange var notifyingObject = new NotifyingObject(); var mockNext = MockRepository.GenerateStub<IndirectionFunc<Random, int>>(); mockNext.Stub(_ => _(Arg<Random>.Is.Anything)).Return(10); PRandom.Next().Body = mockNext; // Act notifyingObject.ValueWithRandomAdded = 32; var actual = notifyingObject.ValueWithRandomAdded; // Assert mockNext.AssertWasCalled(_ => _(Arg<Random>.Is.Anything), options => options.Repeat.Once()); Assert.AreEqual(42, actual); } }
public void ValueWithRandomAdded_should_hold_passed_value_plus_random_value() { using (new IndirectionsContext()) { // Arrange var notifyingObject = new NotifyingObject(); var mockNext = new Mock<IndirectionFunc<Random, int>>(); mockNext.Setup(_ => _(It.IsAny<Random>())).Returns(10); PRandom.Next().Body = mockNext.Object; // Act notifyingObject.ValueWithRandomAdded = 32; var actual = notifyingObject.ValueWithRandomAdded; // Assert mockNext.Verify(_ => _(It.IsAny<Random>()), Times.Once()); Assert.AreEqual(42, actual); } }
public void ValueWithRandomAdded_should_hold_passed_value_plus_random_value() { using (new IndirectionsContext()) { // Arrange var notifyingObject = new NotifyingObject(); var mockNext = Substitute.For<IndirectionFunc<Random, int>>(); mockNext(Arg.Any<Random>()).Returns(10); PRandom.Next().Body = mockNext; // Act notifyingObject.ValueWithRandomAdded = 32; var actual = notifyingObject.ValueWithRandomAdded; // Assert mockNext.Received(1)(Arg.Any<Random>()); Assert.AreEqual(42, actual); } }
public void ValueWithRandomAdded_should_hold_passed_value_plus_random_value() { using (new IndirectionsContext()) { // Arrange var notifyingObject = new NotifyingObject(); var mockNext = A.Fake<IndirectionFunc<Random, int>>(); A.CallTo(() => mockNext(A<Random>._)).Returns(10); PRandom.Next().Body = mockNext; // Act notifyingObject.ValueWithRandomAdded = 32; var actual = notifyingObject.ValueWithRandomAdded; // Assert A.CallTo(() => mockNext(A<Random>._)).MustHaveHappened(); Assert.AreEqual(42, actual); } }