Created
June 24, 2014 13:50
-
-
Save urasandesu/e603d5ea79d2a5d61fc2 to your computer and use it in GitHub Desktop.
How to use Prig in combination with FakeItEasy.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using FakeItEasy; | |
using NUnit.Framework; | |
using System; | |
using System.ComponentModel; | |
using System.Prig; | |
using Urasandesu.Prig.Framework; | |
namespace MockingDelegatesSample | |
{ | |
[TestFixture] | |
public class FakeItEasyTest | |
{ | |
[Test] | |
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(); | |
} | |
[Test] | |
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); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
NotifyingObject class is same as this example.