Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [Theory]
- [InlineData("Article Title", "Article Content")]
- public void CreatePostShouldSaveArticleSetModelStateMessageAndRedirectWhenValidModelState(string title, string content)
- => MyController<ArticlesController> // Specify the controller under test.
- .Instance() // Create it from the globally registered services.
- .Calling(c => c.Create(new ArticleFormModel // Specify the action under test and provide valid model.
- {
- Title = title,
- Content = content
- }))
- .ShouldHave()
- .ValidModelState() // Assert valid model state.
- .AndAlso() // Provide additional assertions.
- .ShouldHave()
- .Data(data => data // Assert the database.
- .WithSet<Article>(set => // Assert the Article database set.
- {
- set.ShouldNotBeEmpty();
- set.SingleOrDefault(a => a.Title == title).ShouldNotBeNull(); // Validate our article is saved.
- }))
- .AndAlso() // Provide additional assertions.
- .ShouldHave()
- .TempData(tempData => tempData // Validate the TempData success message..
- .ContainingEntryWithKey(ControllerConstants.SuccessMessage))
- .AndAlso() // Provide additional assertions.
- .ShouldReturn()
- .Redirect(redirect => redirect // Validate redirect result.
- .To<UsersController>(c => c.Mine())); // Validate correct redirect to action.
Advertisement
Add Comment
Please, Sign In to add comment