Skip to content

Commit

Permalink
Add tests for entry controller
Browse files Browse the repository at this point in the history
  • Loading branch information
cwetanow committed Apr 22, 2017
1 parent f7a3039 commit a2746ac
Showing 1 changed file with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using Logs.Authentication.Contracts;
using System.Web.Mvc;
using Logs.Authentication.Contracts;
using Logs.Models;
using Logs.Services.Contracts;
using Logs.Web.Controllers;
using Logs.Web.Models.Logs;
Expand All @@ -16,6 +18,9 @@ public void TestEditEntry_ShouldCallEntryServiceEditEntryCorrectly(int entryId,
{
// Arrange
var mockedService = new Mock<IEntryService>();
mockedService.Setup(s => s.EditEntry(It.IsAny<int>(), It.IsAny<string>()))
.Returns(new LogEntry());

var mockedProvider = new Mock<IAuthenticationProvider>();

var controller = new EntriesController(mockedService.Object, mockedProvider.Object);
Expand All @@ -29,11 +34,35 @@ public void TestEditEntry_ShouldCallEntryServiceEditEntryCorrectly(int entryId,
mockedService.Verify(s => s.EditEntry(entryId, content), Times.Once);
}

[TestCase(1, "content")]
public void TestEditEntry_ShouldSetViewModelContentCorrectly(int entryId, string content)
{
// Arrange
var mockedService = new Mock<IEntryService>();
mockedService.Setup(s => s.EditEntry(It.IsAny<int>(), It.IsAny<string>()))
.Returns(new LogEntry { Content = content });

var mockedProvider = new Mock<IAuthenticationProvider>();

var controller = new EntriesController(mockedService.Object, mockedProvider.Object);

var model = new LogEntryViewModel { EntryId = entryId, Content = content };

// Act
var result = controller.EditEntry(model);

// Assert
Assert.AreEqual(content, ((LogEntryViewModel)result.Model).Content);
}

[TestCase(1, "content")]
public void TestEditEntry_ShouldSetViewModelCorrectly(int entryId, string content)
{
// Arrange
var mockedService = new Mock<IEntryService>();
mockedService.Setup(s => s.EditEntry(It.IsAny<int>(), It.IsAny<string>()))
.Returns(new LogEntry { Content = content });

var mockedProvider = new Mock<IAuthenticationProvider>();

var controller = new EntriesController(mockedService.Object, mockedProvider.Object);
Expand Down

0 comments on commit a2746ac

Please sign in to comment.