From 74b7331f4cac3ae68e75e60e8fdb2c414a0f690b Mon Sep 17 00:00:00 2001 From: Felipe Date: Wed, 18 Sep 2024 20:05:22 -0300 Subject: [PATCH] =?UTF-8?q?Adicionado=20novos=20itens=20reutiliz=C3=A1veis?= =?UTF-8?q?=20na=20camada=20de=20dom=C3=ADnio?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Entities/Entity.cs | 7 +++++ .../FoSouzaDev.Common.Domain.csproj | 4 +-- .../Repositories/IAddRepository.cs | 8 ++++++ .../Repositories/IGetRepository.cs | 9 ++++++ .../Repositories/IRemoveRepository.cs | 8 ++++++ .../Repositories/IUpdateRepository.cs | 8 ++++++ .../Entities/EntityTest.cs | 28 +++++++++++++++++++ 7 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 src/FoSouzaDev.Common.Domain/Entities/Entity.cs create mode 100644 src/FoSouzaDev.Common.Domain/Repositories/IAddRepository.cs create mode 100644 src/FoSouzaDev.Common.Domain/Repositories/IGetRepository.cs create mode 100644 src/FoSouzaDev.Common.Domain/Repositories/IRemoveRepository.cs create mode 100644 src/FoSouzaDev.Common.Domain/Repositories/IUpdateRepository.cs create mode 100644 tests/FoSouzaDev.Common.Domain.UnitaryTests/Entities/EntityTest.cs diff --git a/src/FoSouzaDev.Common.Domain/Entities/Entity.cs b/src/FoSouzaDev.Common.Domain/Entities/Entity.cs new file mode 100644 index 0000000..8acaa68 --- /dev/null +++ b/src/FoSouzaDev.Common.Domain/Entities/Entity.cs @@ -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; +} \ No newline at end of file diff --git a/src/FoSouzaDev.Common.Domain/FoSouzaDev.Common.Domain.csproj b/src/FoSouzaDev.Common.Domain/FoSouzaDev.Common.Domain.csproj index 06a9f69..a33851a 100644 --- a/src/FoSouzaDev.Common.Domain/FoSouzaDev.Common.Domain.csproj +++ b/src/FoSouzaDev.Common.Domain/FoSouzaDev.Common.Domain.csproj @@ -6,7 +6,7 @@ true $(AssemblyName) - 1.1.3 + 1.2.0 MIT Felipe Souza https://github.com/fosouzadev/common-domain @@ -15,7 +15,7 @@ - + \ No newline at end of file diff --git a/src/FoSouzaDev.Common.Domain/Repositories/IAddRepository.cs b/src/FoSouzaDev.Common.Domain/Repositories/IAddRepository.cs new file mode 100644 index 0000000..4532a48 --- /dev/null +++ b/src/FoSouzaDev.Common.Domain/Repositories/IAddRepository.cs @@ -0,0 +1,8 @@ +using FoSouzaDev.Common.Domain.Entities; + +namespace FoSouzaDev.Common.Domain.Repositories; + +public interface IAddRepository where T : Entity +{ + Task AddAsync(T entity); +} \ No newline at end of file diff --git a/src/FoSouzaDev.Common.Domain/Repositories/IGetRepository.cs b/src/FoSouzaDev.Common.Domain/Repositories/IGetRepository.cs new file mode 100644 index 0000000..cd330e8 --- /dev/null +++ b/src/FoSouzaDev.Common.Domain/Repositories/IGetRepository.cs @@ -0,0 +1,9 @@ +using FoSouzaDev.Common.Domain.Entities; + +namespace FoSouzaDev.Common.Domain.Repositories; + +public interface IGetRepository where T : Entity +{ + Task GetByIdAsync(Guid id); + Task GetByIdOrThrowAsync(Guid id); +} \ No newline at end of file diff --git a/src/FoSouzaDev.Common.Domain/Repositories/IRemoveRepository.cs b/src/FoSouzaDev.Common.Domain/Repositories/IRemoveRepository.cs new file mode 100644 index 0000000..656f40c --- /dev/null +++ b/src/FoSouzaDev.Common.Domain/Repositories/IRemoveRepository.cs @@ -0,0 +1,8 @@ +using FoSouzaDev.Common.Domain.Entities; + +namespace FoSouzaDev.Common.Domain.Repositories; + +public interface IRemoveRepository where T : Entity +{ + Task RemoveAsync(Guid id); +} \ No newline at end of file diff --git a/src/FoSouzaDev.Common.Domain/Repositories/IUpdateRepository.cs b/src/FoSouzaDev.Common.Domain/Repositories/IUpdateRepository.cs new file mode 100644 index 0000000..fd828fe --- /dev/null +++ b/src/FoSouzaDev.Common.Domain/Repositories/IUpdateRepository.cs @@ -0,0 +1,8 @@ +using FoSouzaDev.Common.Domain.Entities; + +namespace FoSouzaDev.Common.Domain.Repositories; + +public interface IUpdateRepository where T : Entity +{ + Task UpdateAsync(T entity); +} \ No newline at end of file diff --git a/tests/FoSouzaDev.Common.Domain.UnitaryTests/Entities/EntityTest.cs b/tests/FoSouzaDev.Common.Domain.UnitaryTests/Entities/EntityTest.cs new file mode 100644 index 0000000..afa149c --- /dev/null +++ b/tests/FoSouzaDev.Common.Domain.UnitaryTests/Entities/EntityTest.cs @@ -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(); + + // Act + DummyEntity entity = new(expectedId, expectedCreationDateTime); + + // Assert + entity.Id.Should().Be(expectedId); + entity.CreationDateTime.Should().Be(expectedCreationDateTime); + } +} \ No newline at end of file