Skip to content
Draft
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
10 changes: 10 additions & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,15 @@
<PackageVersion Include="Microsoft.EntityFrameworkCore.InMemory" Version="9.0.8" />

<PackageVersion Include="Swashbuckle.AspNetCore" Version="9.0.4" />

<!-- Packages for test projects -->
<PackageVersion Include="xunit" Version="2.9.3"/>
<PackageVersion Include="coverlet.collector" Version="6.0.4"/>
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.14.1"/>
<PackageVersion Include="xunit.runner.visualstudio" Version="3.1.4"/>
<PackageVersion Include="Shouldly" Version="4.3.0" />
<PackageVersion Include="Bogus" Version="35.6.3" />
<PackageVersion Include="NSubstitute" Version="5.3.0" />

</ItemGroup>
</Project>
17 changes: 17 additions & 0 deletions FastCrud.sln
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
README.md = README.md
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{CF0D1A6D-895C-4E47-8FF1-A4C7EE067309}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FastCrud.Core.Tests.Unit", "test\FastCrud.Core.Tests.Unit\FastCrud.Core.Tests.Unit.csproj", "{B1378196-FC23-4177-96F7-7A9672A521B9}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -138,6 +142,18 @@ Global
{76A2E96E-A92C-4D05-A65D-1D3DCBC8546D}.Release|x64.Build.0 = Release|Any CPU
{76A2E96E-A92C-4D05-A65D-1D3DCBC8546D}.Release|x86.ActiveCfg = Release|Any CPU
{76A2E96E-A92C-4D05-A65D-1D3DCBC8546D}.Release|x86.Build.0 = Release|Any CPU
{B1378196-FC23-4177-96F7-7A9672A521B9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B1378196-FC23-4177-96F7-7A9672A521B9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B1378196-FC23-4177-96F7-7A9672A521B9}.Debug|x64.ActiveCfg = Debug|Any CPU
{B1378196-FC23-4177-96F7-7A9672A521B9}.Debug|x64.Build.0 = Debug|Any CPU
{B1378196-FC23-4177-96F7-7A9672A521B9}.Debug|x86.ActiveCfg = Debug|Any CPU
{B1378196-FC23-4177-96F7-7A9672A521B9}.Debug|x86.Build.0 = Debug|Any CPU
{B1378196-FC23-4177-96F7-7A9672A521B9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B1378196-FC23-4177-96F7-7A9672A521B9}.Release|Any CPU.Build.0 = Release|Any CPU
{B1378196-FC23-4177-96F7-7A9672A521B9}.Release|x64.ActiveCfg = Release|Any CPU
{B1378196-FC23-4177-96F7-7A9672A521B9}.Release|x64.Build.0 = Release|Any CPU
{B1378196-FC23-4177-96F7-7A9672A521B9}.Release|x86.ActiveCfg = Release|Any CPU
{B1378196-FC23-4177-96F7-7A9672A521B9}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -152,5 +168,6 @@ Global
{20DCAE37-FAA8-4DB2-9756-5EB3D307843A} = {A86BA826-473E-B95F-3AC8-6831E1DD27DB}
{D88FAE2D-7768-4566-8447-AD9C5C56EC45} = {A86BA826-473E-B95F-3AC8-6831E1DD27DB}
{76A2E96E-A92C-4D05-A65D-1D3DCBC8546D} = {5D20AA90-6969-D8BD-9DCD-8634F4692FDA}
{B1378196-FC23-4177-96F7-7A9672A521B9} = {CF0D1A6D-895C-4E47-8FF1-A4C7EE067309}
EndGlobalSection
EndGlobal
39 changes: 39 additions & 0 deletions test/FastCrud.Core.Tests.Unit/CreateTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using FastCrud.Abstractions.Abstractions;
using FastCrud.Abstractions.Query;
using FastCrud.Core.Services;
using FastCrud.Core.Tests.Unit.Dtos;
using FastCrud.Core.Tests.Unit.Models;
using NSubstitute;

namespace FastCrud.Core.Tests.Unit;

public class CreateTests
{
// Service Under Test
private readonly CrudService<TestCustomer, Guid,
TestCustomerCreateDto, TestCustomerUpdateDto> _service;

// Dependencies
private readonly IRepository<TestCustomer, Guid> _repository
= Substitute.For<IRepository<TestCustomer, Guid>>();
private readonly IObjectMapper _mapper
= Substitute.For<IObjectMapper>();
private readonly IEnumerable<IModelValidator<TestCustomer>> _validators
= new List<IModelValidator<TestCustomer>>();
private readonly IServiceProvider _serviceProvider
= Substitute.For<IServiceProvider>();
private readonly IQueryEngine _queryEngine
= Substitute.For<IQueryEngine>();

public CreateTests()
{
_service = new CrudService<TestCustomer, Guid, TestCustomerCreateDto, TestCustomerUpdateDto>
(_repository, _mapper, _validators, _serviceProvider, _queryEngine);
}

[Fact]
public async Task Create_ShouldThrowArgumentException_WhenInputIsNull()
{

}
}
7 changes: 7 additions & 0 deletions test/FastCrud.Core.Tests.Unit/Dtos/TestCustomerDtos.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace FastCrud.Core.Tests.Unit.Dtos;

public record TestCustomerCreateDto(string FirstName, string LastName, string Email);

public record TestCustomerUpdateDto(string FirstName, string LastName, string Email);

public record TestCustomerReadDto(Guid Id, string FirstName, string LastName, string Email);
28 changes: 28 additions & 0 deletions test/FastCrud.Core.Tests.Unit/FastCrud.Core.Tests.Unit.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector"/>
<PackageReference Include="Microsoft.NET.Test.Sdk"/>
<PackageReference Include="xunit" />
<PackageReference Include="xunit.runner.visualstudio"/>
<PackageReference Include="Shouldly"/>
<PackageReference Include="Bogus"/>
<PackageReference Include="NSubstitute"/>
</ItemGroup>

<ItemGroup>
<Using Include="Xunit"/>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\FastCrud.Core\FastCrud.Core.csproj" />
</ItemGroup>

</Project>
13 changes: 13 additions & 0 deletions test/FastCrud.Core.Tests.Unit/Models/TestCustomer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace FastCrud.Core.Tests.Unit.Models;

public sealed class TestCustomer
{
// private Customer()
// {}

public Guid Id { get; private set; }
public string FirstName { get; private set; }
public string LastName { get; private set; }
public string Email { get; private set; }
public DateTime CreatedUtc { get; private set; }
}