Skip to content

Instantly share code, notes, and snippets.

@urasandesu
Created June 24, 2014 13:50
Show Gist options
  • Select an option

  • Save urasandesu/e603d5ea79d2a5d61fc2 to your computer and use it in GitHub Desktop.

Select an option

Save urasandesu/e603d5ea79d2a5d61fc2 to your computer and use it in GitHub Desktop.
How to use Prig in combination with FakeItEasy.
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);
}
}
}
}
@urasandesu
Copy link
Copy Markdown
Author

NotifyingObject class is same as this example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment