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

Feat: Added domains already defined. #19

Merged
merged 2 commits into from
Jan 21, 2024
Merged
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
34 changes: 34 additions & 0 deletions EasyFinance.Common.Tests/AccessControl/UserBuilder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using EasyFinance.Domain.Models.AccessControl;

namespace EasyFinance.Common.Tests.AccessControl
{
public class UserBuilder : IBuilder<User>
{
private User user;

public UserBuilder()
{
this.user = new User();
}

public UserBuilder AddFirstName(string firstName)
{
this.user.SetFirstName(firstName);
return this;
}

public UserBuilder AddLastName(string lastName)
{
this.user.SetLastName(lastName);
return this;
}

public UserBuilder AddEnabled(bool enabled)
{
this.user.SetEnabled(enabled);
return this;
}

public User Build() => this.user;
}
}
35 changes: 35 additions & 0 deletions EasyFinance.Common.Tests/AccessControl/UserProjectBuilder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using EasyFinance.Domain.Models.AccessControl;
using EasyFinance.Domain.Models.FinancialProject;

namespace EasyFinance.Common.Tests.AccessControl
{
public class UserProjectBuilder : IBuilder<UserProject>
{
private UserProject userProject;

public UserProjectBuilder()
{
this.userProject = new UserProject();
}

public UserProjectBuilder AddUser(User user)
{
this.userProject.SetUser(user);
return this;
}

public UserProjectBuilder AddProject(Project project)
{
this.userProject.SetProject(project);
return this;
}

public UserProjectBuilder AddRole(Role role)
{
this.userProject.SetRole(role);
return this;
}

public UserProject Build() => this.userProject;
}
}
12 changes: 12 additions & 0 deletions EasyFinance.Common.Tests/EasyFinance.Common.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\EasyFinance.Domain\EasyFinance.Domain.csproj" />
</ItemGroup>

</Project>
29 changes: 29 additions & 0 deletions EasyFinance.Common.Tests/Financial/AttachmentBuilder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using EasyFinance.Domain.Models.AccessControl;
using EasyFinance.Domain.Models.Financial;

namespace EasyFinance.Common.Tests.Financial
{
public class AttachmentBuilder : IBuilder<Attachment>
{
private Attachment attachment;

public AttachmentBuilder()
{
this.attachment = new Attachment();
}

public AttachmentBuilder AddName(string name)
{
this.attachment.SetName(name);
return this;
}

public AttachmentBuilder AddCreatedBy(User createdBy)
{
this.attachment.SetCreatedBy(createdBy);
return this;
}

public Attachment Build() => this.attachment;
}
}
19 changes: 19 additions & 0 deletions EasyFinance.Common.Tests/Financial/BaseExpenseBuilder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System.Collections.Generic;
using EasyFinance.Domain.Models.Financial;

namespace EasyFinance.Common.Tests.Financial
{
public abstract class BaseExpenseBuilder<TEntity> : BaseFinancialBuilder<TEntity>
where TEntity : BaseExpense
{
protected BaseExpenseBuilder(TEntity baseFinancial) : base(baseFinancial)
{
}

public BaseExpenseBuilder<TEntity> AddItems(ICollection<ExpenseItem> Items)
{
this.entity.SetItems(Items);
return this;
}
}
}
50 changes: 50 additions & 0 deletions EasyFinance.Common.Tests/Financial/BaseFinancialBuilder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using System;
using System.Collections.Generic;
using EasyFinance.Domain.Models.AccessControl;
using EasyFinance.Domain.Models.Financial;

namespace EasyFinance.Common.Tests.Financial
{
public abstract class BaseFinancialBuilder<TEntity> : IBuilder<TEntity>
where TEntity : BaseFinancial
{
protected TEntity entity;

protected BaseFinancialBuilder(TEntity baseFinancial)
{
this.entity = baseFinancial;
}

public BaseFinancialBuilder<TEntity> AddName(string name)
{
this.entity.SetName(name);
return this;
}

public BaseFinancialBuilder<TEntity> AddDate(DateTime date)
{
this.entity.SetDate(date);
return this;
}

public BaseFinancialBuilder<TEntity> AddAmount(decimal amount)
{
this.entity.SetAmount(amount);
return this;
}

public BaseFinancialBuilder<TEntity> AddCreatedBy(User user)
{
this.entity.SetCreatedBy(user);
return this;
}

public BaseFinancialBuilder<TEntity> AddAttachments(ICollection<Attachment> attachments)
{
this.entity.SetAttachments(attachments);
return this;
}

public TEntity Build() => this.entity;
}
}
35 changes: 35 additions & 0 deletions EasyFinance.Common.Tests/Financial/CategoryBuilder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System.Collections.Generic;
using EasyFinance.Domain.Models.Financial;

namespace EasyFinance.Common.Tests.Financial
{
public class CategoryBuilder : IBuilder<Category>
{
private Category category;

public CategoryBuilder()
{
this.category = new Category();
}

public CategoryBuilder AddName(string name)
{
this.category.SetName(name);
return this;
}

public CategoryBuilder AddGoal(decimal goal)
{
this.category.SetGoal(goal);
return this;
}

public CategoryBuilder AddExpenses(ICollection<Expense> expenses)
{
this.category.SetExpenses(expenses);
return this;
}

public Category Build() => this.category;
}
}
17 changes: 17 additions & 0 deletions EasyFinance.Common.Tests/Financial/ExpenseBuilder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using EasyFinance.Domain.Models.Financial;

namespace EasyFinance.Common.Tests.Financial
{
public class ExpenseBuilder : BaseExpenseBuilder<Expense>
{
public ExpenseBuilder() : base(new Expense())
{
}

public ExpenseBuilder AddGoal(decimal goal)
{
this.entity.SetGoal(goal);
return this;
}
}
}
11 changes: 11 additions & 0 deletions EasyFinance.Common.Tests/Financial/ExpenseItemBuilder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using EasyFinance.Domain.Models.Financial;

namespace EasyFinance.Common.Tests.Financial
{
public class ExpenseItemBuilder : BaseExpenseBuilder<ExpenseItem>
{
public ExpenseItemBuilder() : base(new ExpenseItem())
{
}
}
}
11 changes: 11 additions & 0 deletions EasyFinance.Common.Tests/Financial/IncomeBuilder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using EasyFinance.Domain.Models.Financial;

namespace EasyFinance.Common.Tests.Financial
{
public class IncomeBuilder : BaseFinancialBuilder<Income>
{
public IncomeBuilder() : base(new Income())
{
}
}
}
42 changes: 42 additions & 0 deletions EasyFinance.Common.Tests/FinancialProject/ProjectBuilder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System.Collections.Generic;
using EasyFinance.Domain.Models.Financial;
using EasyFinance.Domain.Models.FinancialProject;

namespace EasyFinance.Common.Tests.FinancialProject
{
public class ProjectBuilder : IBuilder<Project>
{
private Project project;

public ProjectBuilder()
{
this.project = new Project();
}

public ProjectBuilder AddName(string name)
{
this.project.SetName(name);
return this;
}

public ProjectBuilder AddType(ProjectType type)
{
this.project.SetType(type);
return this;
}

public ProjectBuilder AddCategories(ICollection<Category> categories)
{
this.project.SetCategories(categories);
return this;
}

public ProjectBuilder AddIncomes(ICollection<Income> incomes)
{
this.project.SetIncomes(incomes);
return this;
}

public Project Build() => this.project;
}
}
7 changes: 7 additions & 0 deletions EasyFinance.Common.Tests/IBuilder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace EasyFinance.Common.Tests
{
public interface IBuilder<T> where T : class
{
T Build();
}
}
31 changes: 31 additions & 0 deletions EasyFinance.Domain.Tests/AccessControl/UserProjectTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using EasyFinance.Common.Tests.AccessControl;
using EasyFinance.Infrastructure;
using EasyFinance.Infrastructure.Exceptions;
using FluentAssertions;

namespace EasyFinance.Domain.Tests.AccessControl
{
public class UserProjectTests
{

[Fact]
public void AddUser_SendNull_ShouldThrowException()
{
var action = () => new UserProjectBuilder().AddUser(null).Build();

action.Should().Throw<ValidationException>()
.WithMessage(string.Format(ValidationMessages.PropertyCantBeNull, "User"))
.And.Property.Should().Be("User");
}

[Fact]
public void AddProject_SendNull_ShouldThrowException()
{
var action = () => new UserProjectBuilder().AddProject(null).Build();

action.Should().Throw<ValidationException>()
.WithMessage(string.Format(ValidationMessages.PropertyCantBeNull, "Project"))
.And.Property.Should().Be("Project");
}
}
}
34 changes: 34 additions & 0 deletions EasyFinance.Domain.Tests/AccessControl/UserTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using EasyFinance.Common.Tests.AccessControl;
using EasyFinance.Infrastructure;
using EasyFinance.Infrastructure.Exceptions;
using FluentAssertions;

namespace EasyFinance.Domain.Tests.AccessControl
{
public class UserTests
{
[Theory]
[InlineData(null)]
[InlineData("")]
public void AddFirstName_SendNullAndEmpty_ShouldThrowException(string firstName)
{
var action = () => new UserBuilder().AddFirstName(firstName).Build();

action.Should().Throw<ValidationException>()
.WithMessage(string.Format(ValidationMessages.PropertyCantBeNullOrEmpty, "FirstName"))
.And.Property.Should().Be("FirstName");
}

[Theory]
[InlineData(null)]
[InlineData("")]
public void AddLastName_SendNullAndEmpty_ShouldThrowException(string lastName)
{
var action = () => new UserBuilder().AddLastName(lastName).Build();

action.Should().Throw<ValidationException>()
.WithMessage(string.Format(ValidationMessages.PropertyCantBeNullOrEmpty, "LastName"))
.And.Property.Should().Be("LastName");
}
}
}
Loading