-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Write tests for service get all sorted by date
- Loading branch information
Showing
2 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
src/Logs.Services.Tests/LogsServiceTests/GetAllSortedByDateTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq.Expressions; | ||
using Logs.Data.Contracts; | ||
using Logs.Factories; | ||
using Logs.Models; | ||
using Logs.Providers.Contracts; | ||
using Logs.Services.Contracts; | ||
using Moq; | ||
using NUnit.Framework; | ||
|
||
namespace Logs.Services.Tests.LogsServiceTests | ||
{ | ||
[TestFixture] | ||
public class GetAllSortedByDateTests | ||
{ | ||
[Test] | ||
public void TestGetAllSortedByDate_ShouldCallRepositoryGetAllCorrectly() | ||
{ | ||
// Arrange | ||
var expectedDescending = true; | ||
|
||
var mockedLogRepository = new Mock<IRepository<TrainingLog>>(); | ||
var mockedUnitOfWork = new Mock<IUnitOfWork>(); | ||
var mockedLogFactory = new Mock<ITrainingLogFactory>(); | ||
var mockedUserService = new Mock<IUserService>(); | ||
var mockedDateTimeProvider = new Mock<IDateTimeProvider>(); | ||
|
||
var service = new LogsService(mockedLogRepository.Object, | ||
mockedUnitOfWork.Object, | ||
mockedLogFactory.Object, | ||
mockedUserService.Object, | ||
mockedDateTimeProvider.Object); | ||
|
||
// Act | ||
service.GetAllSortedByDate(); | ||
|
||
// Assert | ||
mockedLogRepository.Verify(r => | ||
r.GetAll(It.IsAny<Expression<Func<TrainingLog, bool>>>(), It.IsAny<Expression<Func<TrainingLog, DateTime>>>(), expectedDescending), | ||
Times.Once); | ||
} | ||
|
||
[Test] | ||
public void TestGetAllSortedByDate_ShouldReturnCorrectly() | ||
{ | ||
// Arrange | ||
var logs = new List<TrainingLog>(); | ||
|
||
var mockedLogRepository = new Mock<IRepository<TrainingLog>>(); | ||
mockedLogRepository.Setup(r => r.GetAll(It.IsAny<Expression<Func<TrainingLog, bool>>>(), | ||
It.IsAny<Expression<Func<TrainingLog, DateTime>>>(), | ||
It.IsAny<bool>())) | ||
.Returns(logs); | ||
|
||
var mockedUnitOfWork = new Mock<IUnitOfWork>(); | ||
var mockedLogFactory = new Mock<ITrainingLogFactory>(); | ||
var mockedUserService = new Mock<IUserService>(); | ||
var mockedDateTimeProvider = new Mock<IDateTimeProvider>(); | ||
|
||
var service = new LogsService(mockedLogRepository.Object, | ||
mockedUnitOfWork.Object, | ||
mockedLogFactory.Object, | ||
mockedUserService.Object, | ||
mockedDateTimeProvider.Object); | ||
|
||
// Act | ||
var result = service.GetAllSortedByDate(); | ||
|
||
// Assert | ||
CollectionAssert.AreEqual(logs, result); | ||
} | ||
} | ||
} |