Skip to content

Instantly share code, notes, and snippets.

@dschenkelman
Created May 9, 2014 04:29
Show Gist options
  • Save dschenkelman/b476d386055a42b3b637 to your computer and use it in GitHub Desktop.
Save dschenkelman/b476d386055a42b3b637 to your computer and use it in GitHub Desktop.
fakewin8: Easy fakes for Windows Store apps unit tests
public class FakeNavigationService : INavigationService
{
public FakeAction<string> NavigateAction { get; set; }
public FakeAction GoBackAction { get; set; }
public void Navigate(string viewName)
{
this.NavigateAction.Invoke(viewName);
}
public void GoBack()
{
this.GoBackAction.Invoke();
}
}
public class FakeNavigationService : INavigationService
{
public FakeAction<string> NavigateAction { get; set; }
public FakeAction GoBackAction { get; set; }
public void Navigate(string view)
{
this.NavigateAction.Invoke(view);
}
public void GoBack()
{
this.GoBackAction.Invoke();
}
}
public interface INavigationService
{
void Navigate(string view);
void GoBack();
}
// arrange
this.fakeNavigationService.NavigateAction = FakeMethod.CreateFor<string>(view => { });
// act
// assert
Assert.AreEqual(1, this.fakeNavigationService.NavigateAction.NumberOfInvocations);
Assert.AreEqual("ViewName", this.fakeNavigationService.NavigateAction.Invocations.ElementAt(0).FirstParameter);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment