Skip to content

Commit

Permalink
Adicionado novos itens reutilizáveis na camada de domínio
Browse files Browse the repository at this point in the history
  • Loading branch information
fosouzadev committed Sep 18, 2024
1 parent 742d110 commit 74b7331
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 2 deletions.
7 changes: 7 additions & 0 deletions src/FoSouzaDev.Common.Domain/Entities/Entity.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace FoSouzaDev.Common.Domain.Entities;

public abstract class Entity(Guid id, DateTimeOffset creationDateTime)
{
public Guid Id { get; private init; } = id;
public DateTimeOffset CreationDateTime { get; private init; } = creationDateTime;
}
4 changes: 2 additions & 2 deletions src/FoSouzaDev.Common.Domain/FoSouzaDev.Common.Domain.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<IsPackable>true</IsPackable>
<PackageId>$(AssemblyName)</PackageId>
<Version>1.1.3</Version>
<Version>1.2.0</Version>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<Authors>Felipe Souza</Authors>
<RepositoryUrl>https://github.com/fosouzadev/common-domain</RepositoryUrl>
Expand All @@ -15,7 +15,7 @@
</PropertyGroup>

<ItemGroup>
<None Include="..\..\README.md" Pack="true" PackagePath="\"/>
<None Include="..\..\README.md" Pack="true" PackagePath="\" />
</ItemGroup>

</Project>
8 changes: 8 additions & 0 deletions src/FoSouzaDev.Common.Domain/Repositories/IAddRepository.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using FoSouzaDev.Common.Domain.Entities;

namespace FoSouzaDev.Common.Domain.Repositories;

public interface IAddRepository<T> where T : Entity
{
Task AddAsync(T entity);
}
9 changes: 9 additions & 0 deletions src/FoSouzaDev.Common.Domain/Repositories/IGetRepository.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using FoSouzaDev.Common.Domain.Entities;

namespace FoSouzaDev.Common.Domain.Repositories;

public interface IGetRepository<T> where T : Entity
{
Task<T> GetByIdAsync(Guid id);
Task<T> GetByIdOrThrowAsync(Guid id);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using FoSouzaDev.Common.Domain.Entities;

namespace FoSouzaDev.Common.Domain.Repositories;

public interface IRemoveRepository<T> where T : Entity
{
Task RemoveAsync(Guid id);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using FoSouzaDev.Common.Domain.Entities;

namespace FoSouzaDev.Common.Domain.Repositories;

public interface IUpdateRepository<T> where T : Entity
{
Task UpdateAsync(T entity);
}
28 changes: 28 additions & 0 deletions tests/FoSouzaDev.Common.Domain.UnitaryTests/Entities/EntityTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using AutoFixture;
using FluentAssertions;
using FoSouzaDev.Common.Domain.Entities;

namespace FoSouzaDev.Common.Domain.UnitaryTests.Entities;

public sealed class EntityTest : BaseTest
{
private class DummyEntity(Guid id, DateTimeOffset creationDateTime)
: Entity(id, creationDateTime)
{
}

[Fact]
public void Constructor_Success_CreateAnEntity()
{
// Arrange
Guid expectedId = Guid.NewGuid();
DateTimeOffset expectedCreationDateTime = base.Fixture.Create<DateTimeOffset>();

// Act
DummyEntity entity = new(expectedId, expectedCreationDateTime);

// Assert
entity.Id.Should().Be(expectedId);
entity.CreationDateTime.Should().Be(expectedCreationDateTime);
}
}

0 comments on commit 74b7331

Please sign in to comment.