Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 0 additions & 116 deletions Controllers/TodoItemsController.cs

This file was deleted.

14 changes: 0 additions & 14 deletions Models/TodoContext.cs

This file was deleted.

12 changes: 0 additions & 12 deletions Models/TodoItem.cs

This file was deleted.

11 changes: 0 additions & 11 deletions Models/TodoItemDTO.cs

This file was deleted.

26 changes: 0 additions & 26 deletions Program.cs

This file was deleted.

18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,17 @@
# TodoService
## Todo application

**Requirements and additional updates**
- BLL and DAL layers are added, main TodoApiDTO is renamed to Todo.
- Unit tests are written for Todo: controllers and Todo.BLL: services
- Added swagger and implemented MS SQL, appsettings.json are updated
- Implemented Automapper and repository pattern
- Added exceptions model for API error handling
- Updated TodoItemDTO model, added separate DTO models for create and update operations

**Layers/folder structure and unit tests**

![folders_tests](https://github.com/ebushuev/VelvetechTestTask/assets/84620072/c5aa40d2-5d64-4527-b1d7-fbed16207189)

**Live application on Swagger**

![swagger](https://github.com/ebushuev/VelvetechTestTask/assets/84620072/99a9f0e2-2cd0-4328-9af7-2d53f0269aff)
55 changes: 0 additions & 55 deletions Startup.cs

This file was deleted.

30 changes: 30 additions & 0 deletions Todo.BLL.Tests/Todo.BLL.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
<PackageReference Include="Moq" Version="4.18.4" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.1.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Todo.BLL\Todo.BLL.csproj" />
<ProjectReference Include="..\Todo.DAL\Todo.DAL.csproj" />
</ItemGroup>

</Project>
103 changes: 103 additions & 0 deletions Todo.BLL.Tests/TodoItemServiceTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
using Moq;
using Todo.BLL.Interfaces;
using Todo.BLL.Services;
using Todo.DAL;
using Todo.DAL.Entities;
using Xunit;

namespace Todo.BLL.Tests;

public class TodoItemServiceTests
{
private readonly Mock<IRepository<TodoItem>> repositoryMock;
private readonly ITodoItemService todoItemService;

public TodoItemServiceTests()
{
repositoryMock = new Mock<IRepository<TodoItem>>();
todoItemService = new TodoItemService(repositoryMock.Object);
}

[Fact]
public async Task GetTodoItemsAsync_ShouldReturnAllTodoItems()
{
// Arrange
repositoryMock.Setup(repo => repo.GetAll(false)).ReturnsAsync(GetTestTodoItems());

// Act
var todoItems = await todoItemService.GetTodoItemsAsync(false);

// Assert
repositoryMock.Verify(t => t.GetAll(false));
Assert.NotNull(todoItems);
}

[Fact]
public async Task GetTodoItemAsync_ShouldReturnTodoItemById()
{
// Arrange
var todoItems = GetTestTodoItems();
var id = todoItems[0].Id;

repositoryMock.Setup(repo => repo.GetByCondition(l => l.Id == id, false)).ReturnsAsync(todoItems[0]);

// Act
var result = await todoItemService.GetTodoItemAsync(id, false);

// Assert
Assert.Equal(todoItems[0], result);
}

[Fact]
public async Task CreateToDoItemAsync_ShouldAddNewTodoItem()
{
// Arrange
var todoItem = GetTestTodoItems()[0];

// Act
await todoItemService.CreateToDoItemAsync(todoItem);

// Assert
repositoryMock.Verify(t => t.Create(It.IsAny<TodoItem>()));
repositoryMock.Verify(t => t.SaveChanges());
}

[Fact]
public async Task UpdateTodoItemAsync_ShouldUpdateTodoItem_CallOnce()
{
// Arrange
var todoItem = GetTestTodoItems()[0];

// Act
await todoItemService.UpdateTodoItemAsync(todoItem);

// Assert
repositoryMock.Verify(t => t.Update(todoItem), Times.Once);
repositoryMock.Verify(t => t.SaveChanges());
}

[Fact]
public async Task DeleteTodoItemAsync_ShouldDeleteTodoItem_CallOnce()
{
// Arrange
var todoItem = GetTestTodoItems()[0];

// Act
await todoItemService.DeleteTodoItemAsync(todoItem);

// Assert
repositoryMock.Verify(t => t.Delete(todoItem), Times.Once);
repositoryMock.Verify(t => t.SaveChanges());
}

private List<TodoItem> GetTestTodoItems()
{
return new List<TodoItem>
{
new TodoItem { Id = Guid.NewGuid(), Name = "Buy groceries", IsComplete = false },
new TodoItem { Id = Guid.NewGuid(), Name = "Do laundry", IsComplete = true },
new TodoItem { Id = Guid.NewGuid(), Name = "Read a book", IsComplete = false }
};
}

}
Loading