Skip to content

Instantly share code, notes, and snippets.

@worldbeater
Last active October 14, 2018 10:25
Show Gist options
  • Save worldbeater/667a90f9ca8a1c7f8a2b8ae98c765731 to your computer and use it in GitHub Desktop.
Save worldbeater/667a90f9ca8a1c7f8a2b8ae98c765731 to your computer and use it in GitHub Desktop.
[Fact]
public void ShouldValidateFormAndSendFeedback()
{
// Create stubs for all dependencies and inject them.
var sender = Substitute.For<ISender>();
var clock = Substitute.For<IClock>();
var feedback = new FeedbackViewModel(sender, clock);
feedback.HasErrors.Should().BeTrue();
// Emulate user input.
feedback.Message = "Message!";
feedback.Title = "Title!";
feedback.Section = 0;
feedback.Idea = true;
// Ensure there is no errors after we
// filled up the form properly.
feedback.HasErrors.Should().BeFalse();
// Emulate button click and ensure that the `Send()`
// method of the dependency was called only once.
feedback.Submit.Execute().Subscribe();
service.Received(1).Send("Title!", "Message!");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment