Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cwetanow committed May 2, 2017
1 parent b6934fb commit a18d3e4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,23 @@ namespace Logs.Services.Tests.NutritionServiceTests
[TestFixture]
public class GetEntryByDateTests
{
[Test]
public void TestGetEntryByDate_ShouldCallRepositoryAll()
[TestCase("d547a40d-c45f-4c43-99de-0bfe9199ff95")]
public void TestGetEntryByDate_ShouldCallRepositoryAll(string userId)
{
// Arrange
var mockRepository = new Mock<IRepository<NutritionEntry>>();

var service = new NutritionService(mockRepository.Object);

// Act
service.GetEntryByDate(new DateTime());
service.GetEntryByDate(userId, new DateTime());

// Assert
mockRepository.Verify(r => r.All, Times.Once);
}

[TestCase(29, 7, 1999)]
public void TestGetEntryByDate_ThereIsNoEntry_ShouldReturnNull(int day, int month, int year)
[TestCase("d547a40d-c45f-4c43-99de-0bfe9199ff95", 29, 7, 1999)]
public void TestGetEntryByDate_ThereIsNoEntry_ShouldReturnNull(string userId, int day, int month, int year)
{
// Arrange
var date = new DateTime(year, month, day);
Expand All @@ -41,20 +41,18 @@ public void TestGetEntryByDate_ThereIsNoEntry_ShouldReturnNull(int day, int mont
var service = new NutritionService(mockRepository.Object);

// Act
var result = service.GetEntryByDate(date);
var result = service.GetEntryByDate(userId, date);

// Assert
Assert.IsNull(result);
}

[TestCase(11, 11, 1111)]
[TestCase(22, 11, 2012)]
[TestCase(29, 7, 1999)]
public void TestGetEntryByDate_ThereIsEntry_ShouldReturnCorrectly(int day, int month, int year)
[TestCase("d547a40d-c45f-4c43-99de-0bfe9199ff95", 11, 11, 1111)]
public void TestGetEntryByDate_ThereIsEntry_ShouldReturnCorrectly(string userId, int day, int month, int year)
{
// Arrange
var date = new DateTime(year, month, day);
var entry = new NutritionEntry { Date = date };
var entry = new NutritionEntry { Date = date, UserId = userId };

var entries = new List<NutritionEntry> { entry };

Expand All @@ -64,7 +62,7 @@ public void TestGetEntryByDate_ThereIsEntry_ShouldReturnCorrectly(int day, int m
var service = new NutritionService(mockRepository.Object);

// Act
var result = service.GetEntryByDate(date);
var result = service.GetEntryByDate(userId, date);

// Assert
Assert.AreSame(entry, result);
Expand Down
3 changes: 1 addition & 2 deletions src/Logs.Services/NutritionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ public NutritionService(IRepository<NutritionEntry> entryRepository)
public NutritionEntry GetEntryByDate(string userId, DateTime date)
{
var entry = this.entryRepository.All
.Where(e => e.UserId.Equals(userId))
.FirstOrDefault(e => e.Date.Equals(date));
.FirstOrDefault(e => e.UserId == userId && e.Date.Equals(date));

return entry;
}
Expand Down

0 comments on commit a18d3e4

Please sign in to comment.