Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create tests for ToDoItemSearchService #562

Merged
merged 3 commits into from
Jun 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
using Ardalis.Result;
using Ardalis.Specification;
using Clean.Architecture.Core.Interfaces;
using Clean.Architecture.Core.ProjectAggregate;
using Clean.Architecture.Core.Services;
using Clean.Architecture.SharedKernel.Interfaces;
using Moq;
using Xunit;

namespace Clean.Architecture.UnitTests.Core.Services;

public class ToDoItemSearchServiceTests
{
private readonly IToDoItemSearchService _service;
private readonly Mock<IRepository<Project>> _mockRepo = new();

public ToDoItemSearchServiceTests()
{
_service = new ToDoItemSearchService(_mockRepo.Object);

}

[Fact]
public async Task ReturnsValidationErrors()
{
var projects = await _service.GetAllIncompleteItemsAsync(0, string.Empty);

Assert.NotEmpty(projects.ValidationErrors);
}

[Fact]
public async Task ReturnsProjectNotFound()
{
var projects = await _service.GetAllIncompleteItemsAsync(100, "Hello");

Assert.Equal(ResultStatus.NotFound, projects.Status);
}

[Fact]
public async Task ReturnsAllIncompleteItems()
{
var title = "Some Title";
var project = new Project("Cool Project", PriorityStatus.Backlog);

project.AddItem(new ToDoItem
{
Title = title,
Description = "Some Description"
});

_mockRepo.Setup(x => x.FirstOrDefaultAsync(It.IsAny<ISpecification<Project>>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(project);

var projects = await _service.GetAllIncompleteItemsAsync(1, title);

Assert.Empty(projects.ValidationErrors);
Assert.Equal(projects.Value.First().Title, title);
Assert.Equal(project.Items.Count(), projects.Value.Count);
}
}