2 Commits

Author SHA1 Message Date
IlyasValiulov
2d06a51a2d правка строки 2025-04-24 00:00:29 +04:00
IlyasValiulov
ec71832652 Лаба 5(конфигурация в работнике) 2025-04-15 17:30:37 +04:00
38 changed files with 1734 additions and 159 deletions

View File

@@ -2,19 +2,22 @@
using FurnitureAssemblyContracts.DataModels;
using FurnitureAssemblyContracts.Exceptions;
using FurnitureAssemblyContracts.Extentions;
using FurnitureAssemblyContracts.Infrastructure;
using FurnitureAssemblyContracts.Infrastructure.PostConfigurations;
using FurnitureAssemblyContracts.StoragesContracts;
using Microsoft.Extensions.Logging;
namespace FurnitureAssemblyBusinessLogic.Implementations;
internal class SalaryBusinessLogicContract(ISalaryStorageContract salaryStorageContract, IManifacturingStorageContract manifacturingStorageContract, IPostStorageContract
postStorageContract, IWorkerStorageContract workerStorageContract, ILogger logger) : ISalaryBusinessLogicContract
internal class SalaryBusinessLogicContract(ISalaryStorageContract salaryStorageContract, IManifacturingStorageContract manifacturingStorageContract,
IWorkerStorageContract workerStorageContract, ILogger logger, IConfigurationSalary сonfiguration) : ISalaryBusinessLogicContract
{
private readonly ILogger _logger = logger;
private readonly ISalaryStorageContract _salaryStorageContract = salaryStorageContract;
private readonly IManifacturingStorageContract _manifacturingStorageContract = manifacturingStorageContract;
private readonly IPostStorageContract _postStorageContract = postStorageContract;
private readonly IWorkerStorageContract _workerStorageContract = workerStorageContract;
private readonly IConfigurationSalary _salaryConfiguration = сonfiguration;
private readonly Lock _lockObject = new();
public List<SalaryDataModel> GetAllSalariesByPeriod(DateTime fromDate, DateTime toDate)
{
@@ -52,11 +55,69 @@ internal class SalaryBusinessLogicContract(ISalaryStorageContract salaryStorageC
var workers = _workerStorageContract.GetList() ?? throw new NullListException();
foreach (var worker in workers)
{
var sales = _manifacturingStorageContract.GetList(startDate, finishDate, workerId: worker.Id)?.Sum(x => x.Count) ?? throw new NullListException();
var post = _postStorageContract.GetElementById(worker.PostId) ?? throw new NullListException();
var salary = post.Salary + sales * 0.1;
_logger.LogDebug("The employee {workerId} was paid a salary of { salary}", worker.Id, salary);
_salaryStorageContract.AddElement(new SalaryDataModel(worker.Id, finishDate, salary));
var sales = _manifacturingStorageContract.GetList(startDate, finishDate, workerId: worker.Id) ?? throw new NullListException();
var salary = worker.ConfigurationModel switch
{
null => 0,
BuilderPostConfiguration cpc => CalculateSalaryForBuilder(sales, startDate, finishDate, cpc),
ChiefPostConfiguration spc => CalculateSalaryForChief(startDate, finishDate, spc),
PostConfiguration pc => pc.Rate,
};
_logger.LogDebug("The employee {workerId} was paid a salary of {salary}", worker.Id, salary);
_logger.LogDebug("The employee {workerId} was paid a salary of { salary}", worker.Id, salary);
_salaryStorageContract.AddElement(new SalaryDataModel(worker.Id, finishDate, salary));
}
}
private double CalculateSalaryForBuilder(List<ManifacturingFurnitureDataModel> sales, DateTime startDate, DateTime finishDate, BuilderPostConfiguration config)
{
var calcPercent = 0.0;
var dates = new List<DateTime>();
for (var date = startDate; date < finishDate; date = date.AddDays(1))
{
dates.Add(date);
}
var parallelOptions = new ParallelOptions
{
MaxDegreeOfParallelism = _salaryConfiguration.MaxConcurrentThreads
};
Parallel.ForEach(dates, parallelOptions, date =>
{
var salesInDay = sales.Where(x => x.ProductuionDate.Date == date.Date).ToArray();
if (salesInDay.Length > 0)
{
lock (_lockObject)
{
calcPercent += (salesInDay.Sum(x => x.Count) / salesInDay.Length);
}
}
});
double calcBonusTask = 0;
try
{
calcBonusTask = sales.Where(x => x.Count > _salaryConfiguration.ExtraMadeSum).Sum(x => x.Count) * config.PersonalCount;
}
catch (Exception ex)
{
_logger.LogError(ex, "Error in bonus calculation");
}
return config.Rate + calcPercent + calcBonusTask;
}
private double CalculateSalaryForChief(DateTime startDate, DateTime finishDate, ChiefPostConfiguration config)
{
try
{
return config.Rate + config.PersonalCountTrendPremium * _workerStorageContract.GetWorkerTrend(startDate, finishDate);
}
catch (Exception ex)
{
_logger.LogError(ex, "Error in the supervisor payroll process");
return 0;
}
}
}

View File

@@ -7,4 +7,5 @@ public class WorkerBindingModel
public string? PostId { get; set; }
public DateTime BirthDate { get; set; }
public DateTime EmploymentDate { get; set; }
public string? ConfigurationJson { get; set; }
}

View File

@@ -2,10 +2,13 @@
using FurnitureAssemblyContracts.Infrastructure;
using FurnitureAssemblyContracts.Exceptions;
using System.Text.RegularExpressions;
using FurnitureAssemblyContracts.Infrastructure.PostConfigurations;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json;
namespace FurnitureAssemblyContracts.DataModels;
public class WorkerDataModel(string id, string fio, string postId, DateTime birthDate, DateTime employmentDate, bool isDeleted) : IValidation
public class WorkerDataModel(string id, string fio, string postId, DateTime birthDate, DateTime employmentDate, bool isDeleted, PostConfiguration configuration) : IValidation
{
private readonly PostDataModel? _post;
@@ -22,13 +25,27 @@ public class WorkerDataModel(string id, string fio, string postId, DateTime birt
public bool IsDeleted { get; private set; } = isDeleted;
public string PostName => _post?.PostName ?? string.Empty;
public PostConfiguration ConfigurationModel { get; private set; } = configuration;
public WorkerDataModel(string id, string fio, string postId, DateTime birthDate, DateTime employmentDate, bool isDeleted, PostDataModel post) : this(id, fio, postId, birthDate, employmentDate, isDeleted)
public WorkerDataModel(string id, string fio, string postId, DateTime birthDate, DateTime employmentDate, bool isDeleted, PostConfiguration configuration, PostDataModel post) : this(id, fio, postId, birthDate, employmentDate, isDeleted, configuration)
{
_post = post;
}
public WorkerDataModel(string id, string fio, string postId, DateTime birthDate, DateTime employmentDate) : this(id, fio, postId, birthDate, employmentDate, false) { }
public WorkerDataModel(string id, string fio, string postId, DateTime birthDate, DateTime employmentDate, string configurationJson) : this(id, fio, postId, birthDate, employmentDate, false, (PostConfiguration)null)
{
var obj = JToken.Parse(configurationJson);
if (obj is not null)
{
ConfigurationModel = obj.Value<string>("Type") switch
{
nameof(BuilderPostConfiguration) => JsonConvert.DeserializeObject<BuilderPostConfiguration>(configurationJson)!,
nameof(ChiefPostConfiguration) => JsonConvert.DeserializeObject<ChiefPostConfiguration>(configurationJson)!,
_ => JsonConvert.DeserializeObject<PostConfiguration>(configurationJson)!,
};
}
}
public void Validate()
{
@@ -58,5 +75,11 @@ public class WorkerDataModel(string id, string fio, string postId, DateTime birt
if ((EmploymentDate - BirthDate).TotalDays / 365 < 14) // EmploymentDate.Year - BirthDate.Year
throw new ValidationException($"Minors cannot be hired (EmploymentDate - {EmploymentDate.ToShortDateString()}, BirthDate - {BirthDate.ToShortDateString()})");
if (ConfigurationModel is null)
throw new ValidationException("Field ConfigurationModel is not initialized");
if (ConfigurationModel!.Rate <= 0)
throw new ValidationException("Field Rate is less or equal zero");
}
}

View File

@@ -5,5 +5,5 @@ public enum PostType
None = 0,
ComponentMaker = 1,
Builder = 2,
Loader = 3
Chief = 3
}

View File

@@ -0,0 +1,8 @@
namespace FurnitureAssemblyContracts.Infrastructure;
public interface IConfigurationSalary
{
double ExtraMadeSum { get; }
int MaxConcurrentThreads { get; }
}

View File

@@ -0,0 +1,16 @@
using Microsoft.Extensions.Configuration;
namespace FurnitureAssemblyContracts.Infrastructure.PostConfigurations;
public class BuilderPostConfiguration : PostConfiguration
{
public override string Type => nameof(BuilderPostConfiguration);
public double PersonalCount { get; set; }
public BuilderPostConfiguration(IConfiguration? config = null)
{
if (config != null)
{
config.GetSection("BuilderSettings");
}
}
}

View File

@@ -0,0 +1,7 @@
namespace FurnitureAssemblyContracts.Infrastructure.PostConfigurations;
public class ChiefPostConfiguration : PostConfiguration
{
public override string Type => nameof(ChiefPostConfiguration);
public double PersonalCountTrendPremium { get; set; }
}

View File

@@ -0,0 +1,7 @@
namespace FurnitureAssemblyContracts.Infrastructure.PostConfigurations;
public class PostConfiguration
{
public virtual string Type => nameof(PostConfiguration);
public double Rate { get; set; }
}

View File

@@ -11,4 +11,5 @@ public interface IWorkerStorageContract
void AddElement(WorkerDataModel workerDataModel);
void UpdElement(WorkerDataModel workerDataModel);
void DelElement(string id);
int GetWorkerTrend(DateTime fromPeriod, DateTime toPeriod);
}

View File

@@ -9,4 +9,5 @@ public class WorkerViewModel
public bool IsDeleted { get; set; }
public DateTime BirthDate { get; set; }
public DateTime EmploymentDate { get; set; }
public required string Configuration { get; set; }
}

View File

@@ -0,0 +1,8 @@
using FurnitureAssemblyContracts.Infrastructure;
namespace FurnitureAssemblyDatebase;
class DefaultConfigurationDatabase : IConfigurationDatabase
{
public string ConnectionString => "";
}

View File

@@ -9,6 +9,11 @@
<ItemGroup>
<PackageReference Include="AutoMapper" Version="14.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="9.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Newtonsoft.Json" Version="9.0.1" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.0.4" />
</ItemGroup>
@@ -18,8 +23,8 @@
<ItemGroup>
<InternalsVisibleTo Include="FurnitureAssemblyTests" />
<InternalVisibleTo Include="FurnitureAssemblyWebApi"/>
<InternalsVisibleTo Include="DynamicProxyGenAssembly2"/>
<InternalVisibleTo Include="FurnitureAssemblyWebApi" />
<InternalsVisibleTo Include="DynamicProxyGenAssembly2" />
</ItemGroup>
</Project>

View File

@@ -1,6 +1,9 @@
using FurnitureAssemblyContracts.Infrastructure;
using FurnitureAssemblyContracts.Infrastructure.PostConfigurations;
using FurnitureAssemblyDatebase.Models;
using Microsoft.EntityFrameworkCore;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace FurnitureAssemblyDatebase;
@@ -47,6 +50,13 @@ public class FurnitureAssemblyDbContext : DbContext
.WithMany(f => f.Components)
.HasForeignKey(fc => fc.FurnitureId)
.OnDelete(DeleteBehavior.Restrict);
modelBuilder.Entity<Worker>()
.Property(x => x.Configuration)
.HasColumnType("jsonb")
.HasConversion(
x => SerializePostConfiguration(x),
x => DeserialzePostConfiguration(x));
}
public DbSet<ManifacturingFurniture> Manufacturing { get; set; }
@@ -56,4 +66,13 @@ public class FurnitureAssemblyDbContext : DbContext
public DbSet<Furniture> Furnitures { get; set; }
public DbSet<FurnitureComponent> FurnitureComponents { get; set; }
public DbSet<Worker> Workers { get; set; }
private static string SerializePostConfiguration(PostConfiguration postConfiguration) => JsonConvert.SerializeObject(postConfiguration);
private static PostConfiguration DeserialzePostConfiguration(string jsonString) => JToken.Parse(jsonString).Value<string>("Type") switch
{
nameof(BuilderPostConfiguration) => JsonConvert.DeserializeObject<BuilderPostConfiguration>(jsonString)!,
nameof(ChiefPostConfiguration) => JsonConvert.DeserializeObject<ChiefPostConfiguration>(jsonString)!,
_ => JsonConvert.DeserializeObject<PostConfiguration>(jsonString)!,
};
}

View File

@@ -19,7 +19,9 @@ public class WorkerStorageContract : IWorkerStorageContract
cfg.CreateMap<Post, PostDataModel>()
.ForMember(x => x.Id, x => x.MapFrom(src => src.PostId));
cfg.CreateMap<Worker, WorkerDataModel>();
cfg.CreateMap<WorkerDataModel, Worker>();
cfg.CreateMap<WorkerDataModel, Worker>()
.ForMember(x => x.Configuration, x => x.MapFrom(src => src.ConfigurationModel));
});
_mapper = new Mapper(config);
}
@@ -125,6 +127,7 @@ public class WorkerStorageContract : IWorkerStorageContract
{
var element = GetWorkerById(id) ?? throw new ElementNotFoundException(id);
element.IsDeleted = true;
element.DateOfDelete = DateTime.UtcNow;
_dbContext.SaveChanges();
}
catch (ElementNotFoundException)
@@ -139,6 +142,21 @@ public class WorkerStorageContract : IWorkerStorageContract
}
}
public int GetWorkerTrend(DateTime fromPeriod, DateTime toPeriod)
{
try
{
var countWorkersOnBegining = _dbContext.Workers.Count(x => x.EmploymentDate < fromPeriod && (!x.IsDeleted || x.DateOfDelete > fromPeriod));
var countWorkersOnEnding = _dbContext.Workers.Count(x => x.EmploymentDate < toPeriod && (!x.IsDeleted || x.DateOfDelete > toPeriod));
return countWorkersOnEnding - countWorkersOnBegining;
}
catch (Exception ex)
{
_dbContext.ChangeTracker.Clear();
throw new StorageException(ex);
}
}
private Worker? GetWorkerById(string id) => AddPost(_dbContext.Workers.FirstOrDefault(x => x.Id == id && !x.IsDeleted));
private IQueryable<Worker> JoinPost(IQueryable<Worker> query)

View File

@@ -0,0 +1,278 @@
// <auto-generated />
using System;
using FurnitureAssemblyDatebase;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace FurnitureAssemblyDatebase.Migrations
{
[DbContext(typeof(FurnitureAssemblyDbContext))]
[Migration("20250404123937_FirstMigration")]
partial class FirstMigration
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "9.0.2")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("FurnitureAssemblyDatebase.Models.Component", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<string>("PrevName")
.HasColumnType("text");
b.Property<string>("PrevPrevName")
.HasColumnType("text");
b.Property<int>("Type")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("Name")
.IsUnique();
b.ToTable("Components");
});
modelBuilder.Entity("FurnitureAssemblyDatebase.Models.Furniture", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<int>("Weight")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("Name")
.IsUnique();
b.ToTable("Furnitures");
});
modelBuilder.Entity("FurnitureAssemblyDatebase.Models.FurnitureComponent", b =>
{
b.Property<string>("FurnitureId")
.HasColumnType("text");
b.Property<string>("ComponentId")
.HasColumnType("text");
b.Property<int>("Count")
.HasColumnType("integer");
b.HasKey("FurnitureId", "ComponentId");
b.HasIndex("ComponentId");
b.ToTable("FurnitureComponents");
});
modelBuilder.Entity("FurnitureAssemblyDatebase.Models.ManifacturingFurniture", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<int>("Count")
.HasColumnType("integer");
b.Property<string>("FurnitureId")
.IsRequired()
.HasColumnType("text");
b.Property<DateTime>("ProductuionDate")
.HasColumnType("timestamp without time zone");
b.Property<string>("WorkerId")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("FurnitureId");
b.HasIndex("WorkerId");
b.ToTable("Manufacturing");
});
modelBuilder.Entity("FurnitureAssemblyDatebase.Models.Post", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<DateTime>("ChangeDate")
.HasColumnType("timestamp without time zone");
b.Property<bool>("IsActual")
.HasColumnType("boolean");
b.Property<string>("PostId")
.IsRequired()
.HasColumnType("text");
b.Property<string>("PostName")
.IsRequired()
.HasColumnType("text");
b.Property<int>("PostType")
.HasColumnType("integer");
b.Property<double>("Salary")
.HasColumnType("double precision");
b.HasKey("Id");
b.HasIndex("PostId", "IsActual")
.IsUnique()
.HasFilter("\"IsActual\" = TRUE");
b.HasIndex("PostName", "IsActual")
.IsUnique()
.HasFilter("\"IsActual\" = TRUE");
b.ToTable("Posts");
});
modelBuilder.Entity("FurnitureAssemblyDatebase.Models.Salary", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<DateTime>("SalaryDate")
.HasColumnType("timestamp without time zone");
b.Property<string>("WorkerId")
.IsRequired()
.HasColumnType("text");
b.Property<double>("WorkerSalary")
.HasColumnType("double precision");
b.HasKey("Id");
b.HasIndex("WorkerId");
b.ToTable("Salaries");
});
modelBuilder.Entity("FurnitureAssemblyDatebase.Models.Worker", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<DateTime>("BirthDate")
.HasColumnType("timestamp without time zone");
b.Property<DateTime>("ChangeDate")
.HasColumnType("timestamp without time zone");
b.Property<DateTime>("EmploymentDate")
.HasColumnType("timestamp without time zone");
b.Property<string>("FIO")
.IsRequired()
.HasColumnType("text");
b.Property<bool>("IsDeleted")
.HasColumnType("boolean");
b.Property<string>("PostId")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Workers");
});
modelBuilder.Entity("FurnitureAssemblyDatebase.Models.FurnitureComponent", b =>
{
b.HasOne("FurnitureAssemblyDatebase.Models.Component", "Component")
.WithMany("FurnitureComponents")
.HasForeignKey("ComponentId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("FurnitureAssemblyDatebase.Models.Furniture", "Furniture")
.WithMany("Components")
.HasForeignKey("FurnitureId")
.OnDelete(DeleteBehavior.Restrict)
.IsRequired();
b.Navigation("Component");
b.Navigation("Furniture");
});
modelBuilder.Entity("FurnitureAssemblyDatebase.Models.ManifacturingFurniture", b =>
{
b.HasOne("FurnitureAssemblyDatebase.Models.Furniture", "Furniture")
.WithMany()
.HasForeignKey("FurnitureId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("FurnitureAssemblyDatebase.Models.Worker", "Worker")
.WithMany("ManifacturingFurniture")
.HasForeignKey("WorkerId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Furniture");
b.Navigation("Worker");
});
modelBuilder.Entity("FurnitureAssemblyDatebase.Models.Salary", b =>
{
b.HasOne("FurnitureAssemblyDatebase.Models.Worker", "Worker")
.WithMany("Salaries")
.HasForeignKey("WorkerId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Worker");
});
modelBuilder.Entity("FurnitureAssemblyDatebase.Models.Component", b =>
{
b.Navigation("FurnitureComponents");
});
modelBuilder.Entity("FurnitureAssemblyDatebase.Models.Furniture", b =>
{
b.Navigation("Components");
});
modelBuilder.Entity("FurnitureAssemblyDatebase.Models.Worker", b =>
{
b.Navigation("ManifacturingFurniture");
b.Navigation("Salaries");
});
#pragma warning restore 612, 618
}
}
}

View File

@@ -0,0 +1,220 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace FurnitureAssemblyDatebase.Migrations
{
/// <inheritdoc />
public partial class FirstMigration : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Components",
columns: table => new
{
Id = table.Column<string>(type: "text", nullable: false),
Name = table.Column<string>(type: "text", nullable: false),
PrevName = table.Column<string>(type: "text", nullable: true),
PrevPrevName = table.Column<string>(type: "text", nullable: true),
Type = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Components", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Furnitures",
columns: table => new
{
Id = table.Column<string>(type: "text", nullable: false),
Name = table.Column<string>(type: "text", nullable: false),
Weight = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Furnitures", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Posts",
columns: table => new
{
Id = table.Column<string>(type: "text", nullable: false),
PostId = table.Column<string>(type: "text", nullable: false),
PostName = table.Column<string>(type: "text", nullable: false),
PostType = table.Column<int>(type: "integer", nullable: false),
Salary = table.Column<double>(type: "double precision", nullable: false),
IsActual = table.Column<bool>(type: "boolean", nullable: false),
ChangeDate = table.Column<DateTime>(type: "timestamp without time zone", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Posts", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Workers",
columns: table => new
{
Id = table.Column<string>(type: "text", nullable: false),
FIO = table.Column<string>(type: "text", nullable: false),
PostId = table.Column<string>(type: "text", nullable: false),
BirthDate = table.Column<DateTime>(type: "timestamp without time zone", nullable: false),
EmploymentDate = table.Column<DateTime>(type: "timestamp without time zone", nullable: false),
IsDeleted = table.Column<bool>(type: "boolean", nullable: false),
ChangeDate = table.Column<DateTime>(type: "timestamp without time zone", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Workers", x => x.Id);
});
migrationBuilder.CreateTable(
name: "FurnitureComponents",
columns: table => new
{
FurnitureId = table.Column<string>(type: "text", nullable: false),
ComponentId = table.Column<string>(type: "text", nullable: false),
Count = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_FurnitureComponents", x => new { x.FurnitureId, x.ComponentId });
table.ForeignKey(
name: "FK_FurnitureComponents_Components_ComponentId",
column: x => x.ComponentId,
principalTable: "Components",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_FurnitureComponents_Furnitures_FurnitureId",
column: x => x.FurnitureId,
principalTable: "Furnitures",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateTable(
name: "Manufacturing",
columns: table => new
{
Id = table.Column<string>(type: "text", nullable: false),
FurnitureId = table.Column<string>(type: "text", nullable: false),
Count = table.Column<int>(type: "integer", nullable: false),
ProductuionDate = table.Column<DateTime>(type: "timestamp without time zone", nullable: false),
WorkerId = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Manufacturing", x => x.Id);
table.ForeignKey(
name: "FK_Manufacturing_Furnitures_FurnitureId",
column: x => x.FurnitureId,
principalTable: "Furnitures",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Manufacturing_Workers_WorkerId",
column: x => x.WorkerId,
principalTable: "Workers",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Salaries",
columns: table => new
{
Id = table.Column<string>(type: "text", nullable: false),
WorkerId = table.Column<string>(type: "text", nullable: false),
WorkerSalary = table.Column<double>(type: "double precision", nullable: false),
SalaryDate = table.Column<DateTime>(type: "timestamp without time zone", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Salaries", x => x.Id);
table.ForeignKey(
name: "FK_Salaries_Workers_WorkerId",
column: x => x.WorkerId,
principalTable: "Workers",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_Components_Name",
table: "Components",
column: "Name",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_FurnitureComponents_ComponentId",
table: "FurnitureComponents",
column: "ComponentId");
migrationBuilder.CreateIndex(
name: "IX_Furnitures_Name",
table: "Furnitures",
column: "Name",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_Manufacturing_FurnitureId",
table: "Manufacturing",
column: "FurnitureId");
migrationBuilder.CreateIndex(
name: "IX_Manufacturing_WorkerId",
table: "Manufacturing",
column: "WorkerId");
migrationBuilder.CreateIndex(
name: "IX_Posts_PostId_IsActual",
table: "Posts",
columns: new[] { "PostId", "IsActual" },
unique: true,
filter: "\"IsActual\" = TRUE");
migrationBuilder.CreateIndex(
name: "IX_Posts_PostName_IsActual",
table: "Posts",
columns: new[] { "PostName", "IsActual" },
unique: true,
filter: "\"IsActual\" = TRUE");
migrationBuilder.CreateIndex(
name: "IX_Salaries_WorkerId",
table: "Salaries",
column: "WorkerId");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "FurnitureComponents");
migrationBuilder.DropTable(
name: "Manufacturing");
migrationBuilder.DropTable(
name: "Posts");
migrationBuilder.DropTable(
name: "Salaries");
migrationBuilder.DropTable(
name: "Components");
migrationBuilder.DropTable(
name: "Furnitures");
migrationBuilder.DropTable(
name: "Workers");
}
}
}

View File

@@ -0,0 +1,285 @@
// <auto-generated />
using System;
using FurnitureAssemblyDatebase;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace FurnitureAssemblyDatebase.Migrations
{
[DbContext(typeof(FurnitureAssemblyDbContext))]
[Migration("20250415132953_ChangeWorker")]
partial class ChangeWorker
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "9.0.2")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("FurnitureAssemblyDatebase.Models.Component", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<string>("PrevName")
.HasColumnType("text");
b.Property<string>("PrevPrevName")
.HasColumnType("text");
b.Property<int>("Type")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("Name")
.IsUnique();
b.ToTable("Components");
});
modelBuilder.Entity("FurnitureAssemblyDatebase.Models.Furniture", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<int>("Weight")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("Name")
.IsUnique();
b.ToTable("Furnitures");
});
modelBuilder.Entity("FurnitureAssemblyDatebase.Models.FurnitureComponent", b =>
{
b.Property<string>("FurnitureId")
.HasColumnType("text");
b.Property<string>("ComponentId")
.HasColumnType("text");
b.Property<int>("Count")
.HasColumnType("integer");
b.HasKey("FurnitureId", "ComponentId");
b.HasIndex("ComponentId");
b.ToTable("FurnitureComponents");
});
modelBuilder.Entity("FurnitureAssemblyDatebase.Models.ManifacturingFurniture", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<int>("Count")
.HasColumnType("integer");
b.Property<string>("FurnitureId")
.IsRequired()
.HasColumnType("text");
b.Property<DateTime>("ProductuionDate")
.HasColumnType("timestamp without time zone");
b.Property<string>("WorkerId")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("FurnitureId");
b.HasIndex("WorkerId");
b.ToTable("Manufacturing");
});
modelBuilder.Entity("FurnitureAssemblyDatebase.Models.Post", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<DateTime>("ChangeDate")
.HasColumnType("timestamp without time zone");
b.Property<bool>("IsActual")
.HasColumnType("boolean");
b.Property<string>("PostId")
.IsRequired()
.HasColumnType("text");
b.Property<string>("PostName")
.IsRequired()
.HasColumnType("text");
b.Property<int>("PostType")
.HasColumnType("integer");
b.Property<double>("Salary")
.HasColumnType("double precision");
b.HasKey("Id");
b.HasIndex("PostId", "IsActual")
.IsUnique()
.HasFilter("\"IsActual\" = TRUE");
b.HasIndex("PostName", "IsActual")
.IsUnique()
.HasFilter("\"IsActual\" = TRUE");
b.ToTable("Posts");
});
modelBuilder.Entity("FurnitureAssemblyDatebase.Models.Salary", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<DateTime>("SalaryDate")
.HasColumnType("timestamp without time zone");
b.Property<string>("WorkerId")
.IsRequired()
.HasColumnType("text");
b.Property<double>("WorkerSalary")
.HasColumnType("double precision");
b.HasKey("Id");
b.HasIndex("WorkerId");
b.ToTable("Salaries");
});
modelBuilder.Entity("FurnitureAssemblyDatebase.Models.Worker", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<DateTime>("BirthDate")
.HasColumnType("timestamp without time zone");
b.Property<DateTime>("ChangeDate")
.HasColumnType("timestamp without time zone");
b.Property<string>("Configuration")
.IsRequired()
.HasColumnType("jsonb");
b.Property<DateTime?>("DateOfDelete")
.HasColumnType("timestamp without time zone");
b.Property<DateTime>("EmploymentDate")
.HasColumnType("timestamp without time zone");
b.Property<string>("FIO")
.IsRequired()
.HasColumnType("text");
b.Property<bool>("IsDeleted")
.HasColumnType("boolean");
b.Property<string>("PostId")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Workers");
});
modelBuilder.Entity("FurnitureAssemblyDatebase.Models.FurnitureComponent", b =>
{
b.HasOne("FurnitureAssemblyDatebase.Models.Component", "Component")
.WithMany("FurnitureComponents")
.HasForeignKey("ComponentId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("FurnitureAssemblyDatebase.Models.Furniture", "Furniture")
.WithMany("Components")
.HasForeignKey("FurnitureId")
.OnDelete(DeleteBehavior.Restrict)
.IsRequired();
b.Navigation("Component");
b.Navigation("Furniture");
});
modelBuilder.Entity("FurnitureAssemblyDatebase.Models.ManifacturingFurniture", b =>
{
b.HasOne("FurnitureAssemblyDatebase.Models.Furniture", "Furniture")
.WithMany()
.HasForeignKey("FurnitureId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("FurnitureAssemblyDatebase.Models.Worker", "Worker")
.WithMany("ManifacturingFurniture")
.HasForeignKey("WorkerId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Furniture");
b.Navigation("Worker");
});
modelBuilder.Entity("FurnitureAssemblyDatebase.Models.Salary", b =>
{
b.HasOne("FurnitureAssemblyDatebase.Models.Worker", "Worker")
.WithMany("Salaries")
.HasForeignKey("WorkerId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Worker");
});
modelBuilder.Entity("FurnitureAssemblyDatebase.Models.Component", b =>
{
b.Navigation("FurnitureComponents");
});
modelBuilder.Entity("FurnitureAssemblyDatebase.Models.Furniture", b =>
{
b.Navigation("Components");
});
modelBuilder.Entity("FurnitureAssemblyDatebase.Models.Worker", b =>
{
b.Navigation("ManifacturingFurniture");
b.Navigation("Salaries");
});
#pragma warning restore 612, 618
}
}
}

View File

@@ -0,0 +1,40 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace FurnitureAssemblyDatebase.Migrations
{
/// <inheritdoc />
public partial class ChangeWorker : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<string>(
name: "Configuration",
table: "Workers",
type: "jsonb",
nullable: false,
defaultValue: "");
migrationBuilder.AddColumn<DateTime>(
name: "DateOfDelete",
table: "Workers",
type: "timestamp without time zone",
nullable: true);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "Configuration",
table: "Workers");
migrationBuilder.DropColumn(
name: "DateOfDelete",
table: "Workers");
}
}
}

View File

@@ -0,0 +1,282 @@
// <auto-generated />
using System;
using FurnitureAssemblyDatebase;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace FurnitureAssemblyDatebase.Migrations
{
[DbContext(typeof(FurnitureAssemblyDbContext))]
partial class FurnitureAssemblyDbContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "9.0.2")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("FurnitureAssemblyDatebase.Models.Component", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<string>("PrevName")
.HasColumnType("text");
b.Property<string>("PrevPrevName")
.HasColumnType("text");
b.Property<int>("Type")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("Name")
.IsUnique();
b.ToTable("Components");
});
modelBuilder.Entity("FurnitureAssemblyDatebase.Models.Furniture", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<int>("Weight")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("Name")
.IsUnique();
b.ToTable("Furnitures");
});
modelBuilder.Entity("FurnitureAssemblyDatebase.Models.FurnitureComponent", b =>
{
b.Property<string>("FurnitureId")
.HasColumnType("text");
b.Property<string>("ComponentId")
.HasColumnType("text");
b.Property<int>("Count")
.HasColumnType("integer");
b.HasKey("FurnitureId", "ComponentId");
b.HasIndex("ComponentId");
b.ToTable("FurnitureComponents");
});
modelBuilder.Entity("FurnitureAssemblyDatebase.Models.ManifacturingFurniture", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<int>("Count")
.HasColumnType("integer");
b.Property<string>("FurnitureId")
.IsRequired()
.HasColumnType("text");
b.Property<DateTime>("ProductuionDate")
.HasColumnType("timestamp without time zone");
b.Property<string>("WorkerId")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("FurnitureId");
b.HasIndex("WorkerId");
b.ToTable("Manufacturing");
});
modelBuilder.Entity("FurnitureAssemblyDatebase.Models.Post", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<DateTime>("ChangeDate")
.HasColumnType("timestamp without time zone");
b.Property<bool>("IsActual")
.HasColumnType("boolean");
b.Property<string>("PostId")
.IsRequired()
.HasColumnType("text");
b.Property<string>("PostName")
.IsRequired()
.HasColumnType("text");
b.Property<int>("PostType")
.HasColumnType("integer");
b.Property<double>("Salary")
.HasColumnType("double precision");
b.HasKey("Id");
b.HasIndex("PostId", "IsActual")
.IsUnique()
.HasFilter("\"IsActual\" = TRUE");
b.HasIndex("PostName", "IsActual")
.IsUnique()
.HasFilter("\"IsActual\" = TRUE");
b.ToTable("Posts");
});
modelBuilder.Entity("FurnitureAssemblyDatebase.Models.Salary", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<DateTime>("SalaryDate")
.HasColumnType("timestamp without time zone");
b.Property<string>("WorkerId")
.IsRequired()
.HasColumnType("text");
b.Property<double>("WorkerSalary")
.HasColumnType("double precision");
b.HasKey("Id");
b.HasIndex("WorkerId");
b.ToTable("Salaries");
});
modelBuilder.Entity("FurnitureAssemblyDatebase.Models.Worker", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<DateTime>("BirthDate")
.HasColumnType("timestamp without time zone");
b.Property<DateTime>("ChangeDate")
.HasColumnType("timestamp without time zone");
b.Property<string>("Configuration")
.IsRequired()
.HasColumnType("jsonb");
b.Property<DateTime?>("DateOfDelete")
.HasColumnType("timestamp without time zone");
b.Property<DateTime>("EmploymentDate")
.HasColumnType("timestamp without time zone");
b.Property<string>("FIO")
.IsRequired()
.HasColumnType("text");
b.Property<bool>("IsDeleted")
.HasColumnType("boolean");
b.Property<string>("PostId")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Workers");
});
modelBuilder.Entity("FurnitureAssemblyDatebase.Models.FurnitureComponent", b =>
{
b.HasOne("FurnitureAssemblyDatebase.Models.Component", "Component")
.WithMany("FurnitureComponents")
.HasForeignKey("ComponentId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("FurnitureAssemblyDatebase.Models.Furniture", "Furniture")
.WithMany("Components")
.HasForeignKey("FurnitureId")
.OnDelete(DeleteBehavior.Restrict)
.IsRequired();
b.Navigation("Component");
b.Navigation("Furniture");
});
modelBuilder.Entity("FurnitureAssemblyDatebase.Models.ManifacturingFurniture", b =>
{
b.HasOne("FurnitureAssemblyDatebase.Models.Furniture", "Furniture")
.WithMany()
.HasForeignKey("FurnitureId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("FurnitureAssemblyDatebase.Models.Worker", "Worker")
.WithMany("ManifacturingFurniture")
.HasForeignKey("WorkerId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Furniture");
b.Navigation("Worker");
});
modelBuilder.Entity("FurnitureAssemblyDatebase.Models.Salary", b =>
{
b.HasOne("FurnitureAssemblyDatebase.Models.Worker", "Worker")
.WithMany("Salaries")
.HasForeignKey("WorkerId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Worker");
});
modelBuilder.Entity("FurnitureAssemblyDatebase.Models.Component", b =>
{
b.Navigation("FurnitureComponents");
});
modelBuilder.Entity("FurnitureAssemblyDatebase.Models.Furniture", b =>
{
b.Navigation("Components");
});
modelBuilder.Entity("FurnitureAssemblyDatebase.Models.Worker", b =>
{
b.Navigation("ManifacturingFurniture");
b.Navigation("Salaries");
});
#pragma warning restore 612, 618
}
}
}

View File

@@ -1,4 +1,5 @@
using FurnitureAssemblyContracts.Enums;
using FurnitureAssemblyContracts.Infrastructure.PostConfigurations;
using System.ComponentModel.DataAnnotations.Schema;
namespace FurnitureAssemblyDatebase.Models;
@@ -23,4 +24,7 @@ public class Worker
Post = post;
return this;
}
public DateTime? DateOfDelete { get; set; }
public required PostConfiguration Configuration { get; set; }
}

View File

@@ -0,0 +1,11 @@
using Microsoft.EntityFrameworkCore.Design;
namespace FurnitureAssemblyDatebase;
internal class SampleContextFactory : IDesignTimeDbContextFactory<FurnitureAssemblyDbContext>
{
public FurnitureAssemblyDbContext CreateDbContext(string[] args)
{
return new FurnitureAssemblyDbContext(new DefaultConfigurationDatabase());
}
}

View File

@@ -1,8 +1,9 @@
using FurnitureAssemblyBusinessLogic.Implementations;
using FurnitureAssemblyContracts.DataModels;
using FurnitureAssemblyContracts.Enums;
using FurnitureAssemblyContracts.Exceptions;
using FurnitureAssemblyContracts.Infrastructure.PostConfigurations;
using FurnitureAssemblyContracts.StoragesContracts;
using FurnitureAssemblyTests.Infrastructure;
using Microsoft.Extensions.Logging;
using Moq;
@@ -13,18 +14,17 @@ internal class SalaryBuisnessLogicContractTests
private SalaryBusinessLogicContract _salaryBusinessLogicContract;
private Mock<ISalaryStorageContract> _salaryStorageContract;
private Mock<IManifacturingStorageContract> _manifacturingStorageContract;
private Mock<IPostStorageContract> _postStorageContract;
private Mock<IWorkerStorageContract> _workerStorageContract;
private readonly ConfigurationSalaryTest _salaryConfigurationTest = new();
[OneTimeSetUp]
public void OneTimeSetUp()
{
_salaryStorageContract = new Mock<ISalaryStorageContract>();
_manifacturingStorageContract = new Mock<IManifacturingStorageContract>();
_postStorageContract = new Mock<IPostStorageContract>();
_workerStorageContract = new Mock<IWorkerStorageContract>();
_salaryBusinessLogicContract = new SalaryBusinessLogicContract(_salaryStorageContract.Object,
_manifacturingStorageContract.Object, _postStorageContract.Object, _workerStorageContract.Object, new Mock<ILogger>().Object);
_manifacturingStorageContract.Object, _workerStorageContract.Object, new Mock<ILogger>().Object, _salaryConfigurationTest);
}
[TearDown]
@@ -32,7 +32,6 @@ internal class SalaryBuisnessLogicContractTests
{
_salaryStorageContract.Reset();
_manifacturingStorageContract.Reset();
_postStorageContract.Reset();
_workerStorageContract.Reset();
}
@@ -186,15 +185,12 @@ internal class SalaryBuisnessLogicContractTests
//Arrange
var workerId = Guid.NewGuid().ToString();
var saleSum = 200;
var postSalary = 2000;
var rate = 10.0;
_manifacturingStorageContract.Setup(x => x.GetList(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<string>(), It.IsAny<string>()))
.Returns([new ManifacturingFurnitureDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), saleSum, workerId)]);
_postStorageContract.Setup(x => x.GetElementById(It.IsAny<string>()))
.Returns(new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.Builder, postSalary));
_workerStorageContract.Setup(x => x.GetList(It.IsAny<bool>(), It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>()))
.Returns([new WorkerDataModel(workerId, "Test", Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow, false)]);
.Returns([new WorkerDataModel(workerId, "Test", Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow, false, new PostConfiguration() { Rate = rate })]);
var sum = 0.0;
var expectedSum = postSalary + saleSum * 0.1;
_salaryStorageContract.Setup(x => x.AddElement(It.IsAny<SalaryDataModel>()))
.Callback((SalaryDataModel x) =>
{
@@ -203,7 +199,7 @@ internal class SalaryBuisnessLogicContractTests
//Act
_salaryBusinessLogicContract.CalculateSalaryByMounth(DateTime.UtcNow);
//Assert
Assert.That(sum, Is.EqualTo(expectedSum));
Assert.That(sum, Is.EqualTo(rate));
}
[Test]
@@ -214,9 +210,9 @@ internal class SalaryBuisnessLogicContractTests
var worker2Id = Guid.NewGuid().ToString();
var worker3Id = Guid.NewGuid().ToString();
var list = new List<WorkerDataModel>() {
new(worker1Id, "Test", Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow, false),
new(worker2Id, "Test", Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow, false),
new(worker3Id, "Test", Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow, false)
new(worker1Id, "Test", Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow, false, new PostConfiguration() { Rate = 10 }),
new(worker2Id, "Test", Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow, false, new PostConfiguration() { Rate = 10 }),
new(worker3Id, "Test", Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow, false, new PostConfiguration() { Rate = 10 })
};
_manifacturingStorageContract.Setup(x => x.GetList(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<string>(), It.IsAny<string>()))
.Returns([new ManifacturingFurnitureDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10, worker1Id),
@@ -224,8 +220,6 @@ internal class SalaryBuisnessLogicContractTests
new ManifacturingFurnitureDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10, worker2Id),
new ManifacturingFurnitureDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10, worker3Id),
new ManifacturingFurnitureDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10, worker3Id)]);
_postStorageContract.Setup(x => x.GetElementById(It.IsAny<string>()))
.Returns(new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.Builder, 2000));
_workerStorageContract.Setup(x => x.GetList(It.IsAny<bool>(), It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>()))
.Returns(list);
//Act
@@ -238,14 +232,12 @@ internal class SalaryBuisnessLogicContractTests
public void CalculateSalaryByMounth_WithoitSalesByWorker_Test()
{
//Arrange
var postSalary = 2000.0;
var postSalary = 10;
var workerId = Guid.NewGuid().ToString();
_manifacturingStorageContract.Setup(x => x.GetList(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<string>(), It.IsAny<string>()))
.Returns([]);
_postStorageContract.Setup(x => x.GetElementById(It.IsAny<string>()))
.Returns(new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.Builder, postSalary));
_workerStorageContract.Setup(x => x.GetList(It.IsAny<bool>(), It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>()))
.Returns([new WorkerDataModel(workerId, "Test", Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow, false)]);
.Returns([new WorkerDataModel(workerId, "Test", Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow, false, new PostConfiguration() { Rate = 10 })]);
var sum = 0.0;
var expectedSum = postSalary;
_salaryStorageContract.Setup(x => x.AddElement(It.IsAny<SalaryDataModel>()))
@@ -264,23 +256,8 @@ internal class SalaryBuisnessLogicContractTests
{
//Arrange
var workerId = Guid.NewGuid().ToString();
_postStorageContract.Setup(x => x.GetElementById(It.IsAny<string>()))
.Returns(new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.Builder, 2000));
_workerStorageContract.Setup(x => x.GetList(It.IsAny<bool>(), It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>()))
.Returns([new WorkerDataModel(workerId, "Test", Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow, false)]);
//Act&Assert
Assert.That(() => _salaryBusinessLogicContract.CalculateSalaryByMounth(DateTime.UtcNow), Throws.TypeOf<NullListException>());
}
[Test]
public void CalculateSalaryByMounth_PostStorageReturnNull_ThrowException_Test()
{
//Arrange
var workerId = Guid.NewGuid().ToString();
_manifacturingStorageContract.Setup(x => x.GetList(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<string>(), It.IsAny<string>()))
.Returns([new ManifacturingFurnitureDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10, workerId)]);
_workerStorageContract.Setup(x => x.GetList(It.IsAny<bool>(), It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>()))
.Returns([new WorkerDataModel(workerId, "Test", Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow, false)]);
.Returns([new WorkerDataModel(workerId, "Test", Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow, false, new PostConfiguration() { Rate = 10 })]);
//Act&Assert
Assert.That(() => _salaryBusinessLogicContract.CalculateSalaryByMounth(DateTime.UtcNow), Throws.TypeOf<NullListException>());
}
@@ -292,8 +269,6 @@ internal class SalaryBuisnessLogicContractTests
var workerId = Guid.NewGuid().ToString();
_manifacturingStorageContract.Setup(x => x.GetList(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<string>(), It.IsAny<string>()))
.Returns([new ManifacturingFurnitureDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10, workerId)]);
_postStorageContract.Setup(x => x.GetElementById(It.IsAny<string>()))
.Returns(new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.Builder, 2000));
//Act&Assert
Assert.That(() => _salaryBusinessLogicContract.CalculateSalaryByMounth(DateTime.UtcNow), Throws.TypeOf<NullListException>());
}
@@ -305,25 +280,8 @@ internal class SalaryBuisnessLogicContractTests
var workerId = Guid.NewGuid().ToString();
_manifacturingStorageContract.Setup(x => x.GetList(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<string>(), It.IsAny<string>()))
.Throws(new StorageException(new InvalidOperationException()));
_postStorageContract.Setup(x => x.GetElementById(It.IsAny<string>()))
.Returns(new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.Builder, 2000));
_workerStorageContract.Setup(x => x.GetList(It.IsAny<bool>(), It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>()))
.Returns([new WorkerDataModel(workerId, "Test", Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow, false)]);
//Act&Assert
Assert.That(() => _salaryBusinessLogicContract.CalculateSalaryByMounth(DateTime.UtcNow), Throws.TypeOf<StorageException>());
}
[Test]
public void CalculateSalaryByMounth_PostStorageThrowException_ThrowException_Test()
{
//Arrange
var workerId = Guid.NewGuid().ToString();
_manifacturingStorageContract.Setup(x => x.GetList(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<string>(), It.IsAny<string>()))
.Returns([new ManifacturingFurnitureDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10, workerId)]);
_postStorageContract.Setup(x => x.GetElementById(It.IsAny<string>()))
.Throws(new StorageException(new InvalidOperationException()));
_workerStorageContract.Setup(x => x.GetList(It.IsAny<bool>(), It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>()))
.Returns([new WorkerDataModel(workerId, "Test", Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow, false)]);
.Returns([new WorkerDataModel(workerId, "Test", Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow, false, new PostConfiguration() { Rate = 10 })]);
//Act&Assert
Assert.That(() => _salaryBusinessLogicContract.CalculateSalaryByMounth(DateTime.UtcNow), Throws.TypeOf<StorageException>());
}
@@ -335,11 +293,67 @@ internal class SalaryBuisnessLogicContractTests
var workerId = Guid.NewGuid().ToString();
_manifacturingStorageContract.Setup(x => x.GetList(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<string>(), It.IsAny<string>()))
.Returns([new ManifacturingFurnitureDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10, workerId)]);
_postStorageContract.Setup(x => x.GetElementById(It.IsAny<string>()))
.Returns(new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.Builder, 2000));
_workerStorageContract.Setup(x => x.GetList(It.IsAny<bool>(), It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>()))
.Throws(new StorageException(new InvalidOperationException()));
//Act&Assert
Assert.That(() => _salaryBusinessLogicContract.CalculateSalaryByMounth(DateTime.UtcNow), Throws.TypeOf<StorageException>());
}
[Test]
public void CalculateSalaryByMountht_WithBuilderPostConfiguration_CalculateSalary_Test()
{
//Arrange
var furnitureId = Guid.NewGuid().ToString();
var workerId = Guid.NewGuid().ToString();
var rate = 2000.0;
var bonus = 0.1;
var sales = new List<ManifacturingFurnitureDataModel>()
{
new(Guid.NewGuid().ToString(), furnitureId, 10, workerId),
new(Guid.NewGuid().ToString(), furnitureId, 15, workerId),
new(Guid.NewGuid().ToString(), furnitureId, 10, workerId)
};
_manifacturingStorageContract.Setup(x => x.GetList(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<string>(), It.IsAny<string>()))
.Returns(sales);
_workerStorageContract.Setup(x => x.GetList(It.IsAny<bool>(), It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>()))
.Returns([new WorkerDataModel(workerId, "Test", Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow, false, new BuilderPostConfiguration() { Rate = rate, PersonalCount = bonus })]);
var sum = 0.0;
var expectedSum = rate + (sales.Sum(x => x.Count) / sales.Count) + sales.Where(x => x.Count > _salaryConfigurationTest.ExtraMadeSum).Sum(x => x.Count) * bonus;
_salaryStorageContract.Setup(x => x.AddElement(It.IsAny<SalaryDataModel>()))
.Callback((SalaryDataModel x) =>
{
sum = x.Salary;
});
//Act
_salaryBusinessLogicContract.CalculateSalaryByMounth(DateTime.UtcNow);
//Assert
Assert.That(sum, Is.EqualTo(expectedSum));
}
[Test]
public void CalculateSalaryByMountht_WithChiefPostConfiguration_CalculateSalary_Test()
{
//Arrange
var workerId = Guid.NewGuid().ToString();
var rate = 2000.0;
var trend = 3;
var bonus = 100;
_manifacturingStorageContract.Setup(x => x.GetList(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<string>(), It.IsAny<string>()))
.Returns([new ManifacturingFurnitureDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10, workerId)]);
_workerStorageContract.Setup(x => x.GetList(It.IsAny<bool>(), It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>()))
.Returns([new WorkerDataModel(workerId, "Test", Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow, false, new ChiefPostConfiguration() { Rate = rate, PersonalCountTrendPremium = bonus })]);
_workerStorageContract.Setup(x => x.GetWorkerTrend(It.IsAny<DateTime>(), It.IsAny<DateTime>()))
.Returns(trend);
var sum = 0.0;
var expectedSum = rate + trend * bonus;
_salaryStorageContract.Setup(x => x.AddElement(It.IsAny<SalaryDataModel>()))
.Callback((SalaryDataModel x) =>
{
sum = x.Salary;
});
//Act
_salaryBusinessLogicContract.CalculateSalaryByMounth(DateTime.UtcNow);
//Assert
Assert.That(sum, Is.EqualTo(expectedSum));
}
}

View File

@@ -1,6 +1,7 @@
using FurnitureAssemblyBusinessLogic.Implementations;
using FurnitureAssemblyContracts.DataModels;
using FurnitureAssemblyContracts.Exceptions;
using FurnitureAssemblyContracts.Infrastructure.PostConfigurations;
using FurnitureAssemblyContracts.StoragesContracts;
using Microsoft.Extensions.Logging;
using Moq;
@@ -31,9 +32,9 @@ internal class WorkerBusinessLogicContractTests
//Arrange
var listOriginal = new List<WorkerDataModel>()
{
new(Guid.NewGuid().ToString(), "Иванов И.И.1", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(-1), DateTime.Now, false),
new(Guid.NewGuid().ToString(), "Иванов И.И.2", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(-1), DateTime.Now, true),
new(Guid.NewGuid().ToString(), "Иванов И.И.3", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(-1), DateTime.Now, false),
new(Guid.NewGuid().ToString(), "Иванов И.И.1", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(-1), DateTime.Now, false, new PostConfiguration() { Rate = 10 }),
new(Guid.NewGuid().ToString(), "Иванов И.И.2", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(-1), DateTime.Now, true, new PostConfiguration() { Rate = 10 }),
new(Guid.NewGuid().ToString(), "Иванов И.И.3", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(-1), DateTime.Now, false, new PostConfiguration() { Rate = 10 }),
};
_workerStorageContract.Setup(x => x.GetList(It.IsAny<bool>(), It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>())).Returns(listOriginal);
//Act
@@ -95,9 +96,9 @@ internal class WorkerBusinessLogicContractTests
var postId = Guid.NewGuid().ToString();
var listOriginal = new List<WorkerDataModel>()
{
new(Guid.NewGuid().ToString(), "Иванов И.И.1", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(-1), DateTime.Now, false),
new(Guid.NewGuid().ToString(), "Иванов И.И.2", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(-1), DateTime.Now, true),
new(Guid.NewGuid().ToString(), "Иванов И.И.3", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(-1), DateTime.Now, false),
new(Guid.NewGuid().ToString(), "Иванов И.И.1", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(-1), DateTime.Now, false, new PostConfiguration() { Rate = 10 }),
new(Guid.NewGuid().ToString(), "Иванов И.И.2", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(-1), DateTime.Now, true, new PostConfiguration() { Rate = 10 }),
new(Guid.NewGuid().ToString(), "Иванов И.И.3", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(-1), DateTime.Now, false, new PostConfiguration() { Rate = 10 }),
};
_workerStorageContract.Setup(x => x.GetList(It.IsAny<bool>(), It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>())).Returns(listOriginal);
//Act
@@ -176,9 +177,9 @@ internal class WorkerBusinessLogicContractTests
var date = DateTime.UtcNow;
var listOriginal = new List<WorkerDataModel>()
{
new(Guid.NewGuid().ToString(), "Иванов И.И.1", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(-1), DateTime.Now, false),
new(Guid.NewGuid().ToString(), "Иванов И.И.2", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(-1), DateTime.Now, true),
new(Guid.NewGuid().ToString(), "Иванов И.И.3", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(-1), DateTime.Now, false),
new(Guid.NewGuid().ToString(), "Иванов И.И.1", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(-1), DateTime.Now, false, new PostConfiguration() { Rate = 10 }),
new(Guid.NewGuid().ToString(), "Иванов И.И.2", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(-1), DateTime.Now, true, new PostConfiguration() { Rate = 10 }),
new(Guid.NewGuid().ToString(), "Иванов И.И.3", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(-1), DateTime.Now, false, new PostConfiguration() { Rate = 10 }),
};
_workerStorageContract.Setup(x => x.GetList(It.IsAny<bool>(), It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>())).Returns(listOriginal);
//Act
@@ -252,9 +253,9 @@ internal class WorkerBusinessLogicContractTests
var date = DateTime.UtcNow;
var listOriginal = new List<WorkerDataModel>()
{
new(Guid.NewGuid().ToString(), "Иванов И.И.1", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(-1), DateTime.Now, false),
new(Guid.NewGuid().ToString(), "Иванов И.И.2", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(-1), DateTime.Now, true),
new(Guid.NewGuid().ToString(), "Иванов И.И.3", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(-1), DateTime.Now, false),
new(Guid.NewGuid().ToString(), "Иванов И.И.1", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(-1), DateTime.Now, false, new PostConfiguration() { Rate = 10 }),
new(Guid.NewGuid().ToString(), "Иванов И.И.2", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(-1), DateTime.Now, true, new PostConfiguration() { Rate = 10 }),
new(Guid.NewGuid().ToString(), "Иванов И.И.3", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(-1), DateTime.Now, false, new PostConfiguration() { Rate = 10 }),
};
_workerStorageContract.Setup(x => x.GetList(It.IsAny<bool>(), It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>())).Returns(listOriginal);
//Act
@@ -326,7 +327,7 @@ internal class WorkerBusinessLogicContractTests
{
//Arrange
var id = Guid.NewGuid().ToString();
var record = new WorkerDataModel(id, "Иванов И.И.", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(-1), DateTime.Now, false);
var record = new WorkerDataModel(id, "Иванов И.И.", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(-1), DateTime.Now, false, new PostConfiguration() { Rate = 10 });
_workerStorageContract.Setup(x => x.GetElementById(id)).Returns(record);
//Act
var element = _workerBusinessLogicContract.GetWorkerByData(id);
@@ -341,7 +342,7 @@ internal class WorkerBusinessLogicContractTests
{
//Arrange
var fio = "Иванов И.И.";
var record = new WorkerDataModel(Guid.NewGuid().ToString(), fio, Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(-1), DateTime.Now, false);
var record = new WorkerDataModel(Guid.NewGuid().ToString(), fio, Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(-1), DateTime.Now, false, new PostConfiguration() { Rate = 10 });
_workerStorageContract.Setup(x => x.GetElementByFIO(fio)).Returns(record);
//Act
var element = _workerBusinessLogicContract.GetWorkerByData(fio);
@@ -397,7 +398,7 @@ internal class WorkerBusinessLogicContractTests
{
//Arrange
var flag = false;
var record = new WorkerDataModel(Guid.NewGuid().ToString(), "Иванов И.И.", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(-1), DateTime.Now, false);
var record = new WorkerDataModel(Guid.NewGuid().ToString(), "Иванов И.И.", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(-1), DateTime.Now, false, new PostConfiguration() { Rate = 1 });
_workerStorageContract.Setup(x => x.AddElement(It.IsAny<WorkerDataModel>()))
.Callback((WorkerDataModel x) =>
{
@@ -417,7 +418,7 @@ internal class WorkerBusinessLogicContractTests
//Arrange
_workerStorageContract.Setup(x => x.AddElement(It.IsAny<WorkerDataModel>())).Throws(new ElementExistsException("Data", "Data"));
//Act&Assert
Assert.That(() => _workerBusinessLogicContract.InsertWorker(new(Guid.NewGuid().ToString(), "Иванов И.И.", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-14).AddDays(-1), DateTime.Now, false)), Throws.TypeOf<ElementExistsException>());
Assert.That(() => _workerBusinessLogicContract.InsertWorker(new(Guid.NewGuid().ToString(), "Иванов И.И.", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-14).AddDays(-1), DateTime.Now, false, new PostConfiguration() { Rate = 10 })), Throws.TypeOf<ElementExistsException>());
_workerStorageContract.Verify(x => x.AddElement(It.IsAny<WorkerDataModel>()), Times.Once);
}
@@ -433,7 +434,7 @@ internal class WorkerBusinessLogicContractTests
public void InsertWorker_InvalidRecord_ThrowException_Test()
{
//Act&Assert
Assert.That(() => _workerBusinessLogicContract.InsertWorker(new WorkerDataModel("id", "Иванов И.И.", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(-1), DateTime.Now, false)), Throws.TypeOf<ValidationException>());
Assert.That(() => _workerBusinessLogicContract.InsertWorker(new WorkerDataModel("id", "Иванов И.И.", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(-1), DateTime.Now, false, new PostConfiguration() { Rate = 10 })), Throws.TypeOf<ValidationException>());
_workerStorageContract.Verify(x => x.AddElement(It.IsAny<WorkerDataModel>()), Times.Never);
}
@@ -443,7 +444,7 @@ internal class WorkerBusinessLogicContractTests
//Arrange
_workerStorageContract.Setup(x => x.AddElement(It.IsAny<WorkerDataModel>())).Throws(new StorageException(new InvalidOperationException()));
//Act&Assert
Assert.That(() => _workerBusinessLogicContract.InsertWorker(new(Guid.NewGuid().ToString(), "Иванов И.И.", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(-1), DateTime.Now, false)), Throws.TypeOf<StorageException>());
Assert.That(() => _workerBusinessLogicContract.InsertWorker(new(Guid.NewGuid().ToString(), "Иванов И.И.", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(-1), DateTime.Now, false, new PostConfiguration() { Rate = 10 })), Throws.TypeOf<StorageException>());
_workerStorageContract.Verify(x => x.AddElement(It.IsAny<WorkerDataModel>()), Times.Once);
}
@@ -452,7 +453,7 @@ internal class WorkerBusinessLogicContractTests
{
//Arrange
var flag = false;
var record = new WorkerDataModel(Guid.NewGuid().ToString(), "Иванов И.И.", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(-1), DateTime.Now, false);
var record = new WorkerDataModel(Guid.NewGuid().ToString(), "Иванов И.И.", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(-1), DateTime.Now, false, new PostConfiguration() { Rate = 10 });
_workerStorageContract.Setup(x => x.UpdElement(It.IsAny<WorkerDataModel>()))
.Callback((WorkerDataModel x) =>
{
@@ -472,7 +473,7 @@ internal class WorkerBusinessLogicContractTests
//Arrange
_workerStorageContract.Setup(x => x.UpdElement(It.IsAny<WorkerDataModel>())).Throws(new ElementNotFoundException(""));
//Act&Assert
Assert.That(() => _workerBusinessLogicContract.UpdateWorker(new(Guid.NewGuid().ToString(), "Иванов И.И.", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(-1), DateTime.Now, false)), Throws.TypeOf<ElementNotFoundException>());
Assert.That(() => _workerBusinessLogicContract.UpdateWorker(new(Guid.NewGuid().ToString(), "Иванов И.И.", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(-1), DateTime.Now, false, new PostConfiguration() { Rate = 10 })), Throws.TypeOf<ElementNotFoundException>());
_workerStorageContract.Verify(x => x.UpdElement(It.IsAny<WorkerDataModel>()), Times.Once);
}
@@ -488,7 +489,7 @@ internal class WorkerBusinessLogicContractTests
public void UpdateWorker_InvalidRecord_ThrowException_Test()
{
//Act&Assert
Assert.That(() => _workerBusinessLogicContract.UpdateWorker(new WorkerDataModel("id", "Иванов И.И.", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(-1), DateTime.Now, false)), Throws.TypeOf<ValidationException>());
Assert.That(() => _workerBusinessLogicContract.UpdateWorker(new WorkerDataModel("id", "Иванов И.И.", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(-1), DateTime.Now, false, new PostConfiguration() { Rate = 10 })), Throws.TypeOf<ValidationException>());
_workerStorageContract.Verify(x => x.UpdElement(It.IsAny<WorkerDataModel>()), Times.Never);
}
@@ -498,7 +499,7 @@ internal class WorkerBusinessLogicContractTests
//Arrange
_workerStorageContract.Setup(x => x.UpdElement(It.IsAny<WorkerDataModel>())).Throws(new StorageException(new InvalidOperationException()));
//Act&Assert
Assert.That(() => _workerBusinessLogicContract.UpdateWorker(new(Guid.NewGuid().ToString(), "Иванов И.И.", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(-1), DateTime.Now, false)), Throws.TypeOf<StorageException>());
Assert.That(() => _workerBusinessLogicContract.UpdateWorker(new(Guid.NewGuid().ToString(), "Иванов И.И.", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(-1), DateTime.Now, false, new PostConfiguration() { Rate = 10 })), Throws.TypeOf<StorageException>());
_workerStorageContract.Verify(x => x.UpdElement(It.IsAny<WorkerDataModel>()), Times.Once);
}

View File

@@ -1,5 +1,6 @@
using FurnitureAssemblyContracts.DataModels;
using FurnitureAssemblyContracts.Exceptions;
using FurnitureAssemblyContracts.Infrastructure.PostConfigurations;
namespace FurnitureAssemblyTests.DataModelsTests;
@@ -9,67 +10,67 @@ internal class WorkerDataModelTests
[Test]
public void IdIsNullOrEmptyTest()
{
var model = CreateDataModel(null, "Иванов И.И.", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-20), DateTime.Now, false);
var model = CreateDataModel(null, "Иванов И.И.", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-20), DateTime.Now, false, new PostConfiguration() { Rate = 0 });
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
model = CreateDataModel(string.Empty, "Иванов И.И.", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-20), DateTime.Now, false);
model = CreateDataModel(string.Empty, "Иванов И.И.", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-20), DateTime.Now, false, new PostConfiguration() { Rate = 0 });
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void IdIsNotGuidTest()
{
var model = CreateDataModel("not a guid", "Иванов И.И.", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-20), DateTime.Now, false);
var model = CreateDataModel("not a guid", "Иванов И.И.", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-20), DateTime.Now, false, new PostConfiguration() { Rate = 0 });
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void FioIsNullOrEmptyTest()
{
var model = CreateDataModel(Guid.NewGuid().ToString(), null, Guid.NewGuid().ToString(), DateTime.Now.AddYears(-20), DateTime.Now, false);
var model = CreateDataModel(Guid.NewGuid().ToString(), null, Guid.NewGuid().ToString(), DateTime.Now.AddYears(-20), DateTime.Now, false, new PostConfiguration() { Rate = 0 });
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
model = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, Guid.NewGuid().ToString(), DateTime.Now.AddYears(-20), DateTime.Now, false);
model = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, Guid.NewGuid().ToString(), DateTime.Now.AddYears(-20), DateTime.Now, false, new PostConfiguration() { Rate = 0 });
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void FioIsNotCorrectTest()
{
var model = CreateDataModel(Guid.NewGuid().ToString(), "Иванов", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-20), DateTime.Now, false);
var model = CreateDataModel(Guid.NewGuid().ToString(), "Иванов", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-20), DateTime.Now, false, new PostConfiguration() { Rate = 0 });
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void PostIdIsNullOrEmptyTest()
{
var model = CreateDataModel(Guid.NewGuid().ToString(), "Иванов И.И.", null, DateTime.Now.AddYears(-20), DateTime.Now, false);
var model = CreateDataModel(Guid.NewGuid().ToString(), "Иванов И.И.", null, DateTime.Now.AddYears(-20), DateTime.Now, false, new PostConfiguration() { Rate = 0 });
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
model = CreateDataModel(Guid.NewGuid().ToString(), "Иванов И.И.", string.Empty, DateTime.Now.AddYears(-20), DateTime.Now, false);
model = CreateDataModel(Guid.NewGuid().ToString(), "Иванов И.И.", string.Empty, DateTime.Now.AddYears(-20), DateTime.Now, false, new PostConfiguration() { Rate = 0 });
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void PostIdIsNotGuidTest()
{
var model = CreateDataModel(Guid.NewGuid().ToString(), "Иванов И.И.", "not a guid", DateTime.Now.AddYears(-20), DateTime.Now, false);
var model = CreateDataModel(Guid.NewGuid().ToString(), "Иванов И.И.", "not a guid", DateTime.Now.AddYears(-20), DateTime.Now, false, new PostConfiguration() { Rate = 0 });
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void BirthDateIsFutureTest()
{
var model = CreateDataModel(Guid.NewGuid().ToString(), "Иванов И.И.", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-14).AddDays(1), DateTime.Now, false);
var model = CreateDataModel(Guid.NewGuid().ToString(), "Иванов И.И.", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-14).AddDays(1), DateTime.Now, false, new PostConfiguration() { Rate = 0 });
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void BirthDateAndEmploymentDateIsNotCorrectTest()
{
var model = CreateDataModel(Guid.NewGuid().ToString(), "Иванов И.И.", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-20), DateTime.Now.AddYears(-20).AddDays(-1), false);
var model = CreateDataModel(Guid.NewGuid().ToString(), "Иванов И.И.", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-20), DateTime.Now.AddYears(-20).AddDays(-1), false, new PostConfiguration() { Rate = 0 });
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
model = CreateDataModel(Guid.NewGuid().ToString(), "Иванов И.И.", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-20), DateTime.Now.AddYears(-16), false);
model = CreateDataModel(Guid.NewGuid().ToString(), "Иванов И.И.", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-20), DateTime.Now.AddYears(-16), false, new PostConfiguration() { Rate = 0 });
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
}
@@ -82,7 +83,8 @@ internal class WorkerDataModelTests
var birthDate = DateTime.Now.AddYears(-20);
var employmentDate = DateTime.Now;
var isDeleted = false;
var model = CreateDataModel(id, fio, postId, birthDate, employmentDate, isDeleted);
var configuration = new PostConfiguration() { Rate = 10 };
var model = CreateDataModel(id, fio, postId, birthDate, employmentDate, isDeleted, configuration);
Assert.That(() => model.Validate(), Throws.Nothing);
Assert.Multiple(() =>
{
@@ -92,9 +94,11 @@ internal class WorkerDataModelTests
Assert.That(model.BirthDate, Is.EqualTo(birthDate));
Assert.That(model.EmploymentDate, Is.EqualTo(employmentDate));
Assert.That(model.IsDeleted, Is.EqualTo(isDeleted));
Assert.That(model.ConfigurationModel, Is.EqualTo(configuration));
Assert.That(model.ConfigurationModel.Rate, Is.EqualTo(configuration.Rate));
});
}
private static WorkerDataModel CreateDataModel(string? id, string? fio, string? postId, DateTime birthDate, DateTime employmentDate, bool isDeleted)
=> new(id, fio, postId, birthDate, employmentDate, isDeleted);
private static WorkerDataModel CreateDataModel(string? id, string? fio, string? postId, DateTime birthDate, DateTime employmentDate, bool isDeleted, PostConfiguration configuration)
=> new(id, fio, postId, birthDate, employmentDate, isDeleted, configuration);
}

View File

@@ -0,0 +1,10 @@
using FurnitureAssemblyContracts.Infrastructure;
namespace FurnitureAssemblyTests.Infrastructure;
class ConfigurationSalaryTest : IConfigurationSalary
{
public double ExtraMadeSum => 10;
public int MaxConcurrentThreads => 4;
}

View File

@@ -1,4 +1,5 @@
using FurnitureAssemblyContracts.Enums;
using FurnitureAssemblyContracts.Infrastructure.PostConfigurations;
using FurnitureAssemblyDatebase;
using FurnitureAssemblyDatebase.Models;
using Microsoft.EntityFrameworkCore;
@@ -16,9 +17,9 @@ internal static class FurnitureAssemblyDbContextExtensions
return post;
}
public static Worker InsertWorkerToDatabaseAndReturn(this FurnitureAssemblyDbContext dbContext, string? id = null, string fio = "Иванов И.И.", string? postId = null, DateTime? birthDate = null, DateTime? employmentDate = null, bool isDeleted = false)
public static Worker InsertWorkerToDatabaseAndReturn(this FurnitureAssemblyDbContext dbContext, string? id = null, string fio = "Иванов И.И.", string? postId = null, PostConfiguration? config = null, DateTime? birthDate = null, DateTime? employmentDate = null, bool isDeleted = false, DateTime? dateDelete = null)
{
var worker = new Worker() { Id = id ?? Guid.NewGuid().ToString(), FIO = fio, PostId = postId ?? Guid.NewGuid().ToString(), BirthDate = birthDate ?? DateTime.UtcNow.AddYears(-20), EmploymentDate = employmentDate ?? DateTime.UtcNow, IsDeleted = isDeleted };
var worker = new Worker() { Id = id ?? Guid.NewGuid().ToString(), FIO = fio, PostId = postId ?? Guid.NewGuid().ToString(), Configuration = config ?? new PostConfiguration() { Rate = 100 }, BirthDate = birthDate ?? DateTime.UtcNow.AddYears(-20), EmploymentDate = employmentDate ?? DateTime.UtcNow, IsDeleted = isDeleted, DateOfDelete = dateDelete };
dbContext.Workers.Add(worker);
dbContext.SaveChanges();
return worker;

View File

@@ -83,7 +83,7 @@ internal class SalaryStorageContractTests : BaseStorageContractTest
[Test]
public void Try_GetList_ByWorkerOnlyInDatePeriod_Test()
{
var worker = InsertWorkerToDatabaseAndReturn("name 2");
var worker = FurnitureAssemblyDbContext.InsertWorkerToDatabaseAndReturn("name 2");
FurnitureAssemblyDbContext.InsertSalaryToDatabaseAndReturn(_worker.Id, salaryDate:
DateTime.UtcNow.AddDays(-2));
FurnitureAssemblyDbContext.InsertSalaryToDatabaseAndReturn(_worker.Id, salaryDate:
@@ -114,20 +114,6 @@ internal class SalaryStorageContractTests : BaseStorageContractTest
AssertElement(FurnitureAssemblyDbContext.GetSalariesFromDatabaseByWorkerId(_worker.Id).FirstOrDefault(), salary);
}
private Worker InsertWorkerToDatabaseAndReturn(string workerFIO = "fio")
{
var worker = new Worker()
{
Id = Guid.NewGuid().ToString(),
PostId = Guid.NewGuid().ToString(),
FIO = workerFIO,
IsDeleted = false
};
FurnitureAssemblyDbContext.Workers.Add(worker);
FurnitureAssemblyDbContext.SaveChanges();
return worker;
}
private static void AssertElement(SalaryDataModel? actual, Salary expected)
{
Assert.That(actual, Is.Not.Null);

View File

@@ -1,5 +1,7 @@
using FurnitureAssemblyContracts.DataModels;
using FurnitureAssemblyContracts.Exceptions;
using FurnitureAssemblyContracts.Infrastructure.PostConfigurations;
using FurnitureAssemblyContracts.StoragesContracts;
using FurnitureAssemblyDatebase.Implementations;
using FurnitureAssemblyDatebase.Models;
using FurnitureAssemblyTests.Infrastructure;
@@ -183,6 +185,115 @@ internal class WorkerStorageContractTests : BaseStorageContractTest
Assert.That(() => _workerStorageContract.DelElement(worker.Id), Throws.TypeOf<ElementNotFoundException>());
}
[Test]
public void Try_GetList_WhenDifferentConfigTypes_Test()
{
var workerSimple = FurnitureAssemblyDbContext.InsertWorkerToDatabaseAndReturn();
var workerBuilder = FurnitureAssemblyDbContext.InsertWorkerToDatabaseAndReturn(config: new BuilderPostConfiguration() { PersonalCount = 500 });
var workerChief = FurnitureAssemblyDbContext.InsertWorkerToDatabaseAndReturn(config: new ChiefPostConfiguration() { PersonalCountTrendPremium = 20 });
var list = _workerStorageContract.GetList();
Assert.That(list, Is.Not.Null);
AssertElement(list.First(x => x.Id == workerSimple.Id), workerSimple);
AssertElement(list.First(x => x.Id == workerBuilder.Id), workerBuilder);
AssertElement(list.First(x => x.Id == workerChief.Id), workerChief);
}
[Test]
public void Try_AddElement_WithBuilderPostConfiguration_Test()
{
var personalCount = 500;
var worker = CreateModel(Guid.NewGuid().ToString(), config: new BuilderPostConfiguration() { PersonalCount = 500 });
_workerStorageContract.AddElement(worker);
var element = FurnitureAssemblyDbContext.GetWorkerFromDatabaseById(worker.Id);
Assert.That(element, Is.Not.Null);
Assert.Multiple(() =>
{
Assert.That(element.Configuration.Type, Is.EqualTo(typeof(BuilderPostConfiguration).Name));
Assert.That((element.Configuration as BuilderPostConfiguration)!.PersonalCount, Is.EqualTo(personalCount));
});
}
[Test]
public void Try_AddElement_WithChiefPostConfiguration_Test()
{
var personalCountTrendPremium = 500;
var worker = CreateModel(Guid.NewGuid().ToString(), config: new ChiefPostConfiguration() { PersonalCountTrendPremium = 500 });
_workerStorageContract.AddElement(worker);
var element = FurnitureAssemblyDbContext.GetWorkerFromDatabaseById(worker.Id);
Assert.That(element, Is.Not.Null);
Assert.Multiple(() =>
{
Assert.That(element.Configuration.Type, Is.EqualTo(typeof(ChiefPostConfiguration).Name));
Assert.That((element.Configuration as ChiefPostConfiguration)!.PersonalCountTrendPremium, Is.EqualTo(personalCountTrendPremium));
});
}
[Test]
public void Try_UpdElement_WithBuilderPostConfiguration_Test()
{
var worker = FurnitureAssemblyDbContext.InsertWorkerToDatabaseAndReturn();
var personalCount = 500;
_workerStorageContract.UpdElement(CreateModel(worker.Id, config: new BuilderPostConfiguration() { PersonalCount = 500 }));
var element = FurnitureAssemblyDbContext.GetWorkerFromDatabaseById(worker.Id);
Assert.That(element, Is.Not.Null);
Assert.Multiple(() =>
{
Assert.That(element.Configuration.Type, Is.EqualTo(typeof(BuilderPostConfiguration).Name));
Assert.That((element.Configuration as BuilderPostConfiguration)!.PersonalCount, Is.EqualTo(personalCount));
});
}
[Test]
public void Try_UpdElement_WithChiefPostConfiguration_Test()
{
var worker = FurnitureAssemblyDbContext.InsertWorkerToDatabaseAndReturn();
var personalCountTrendPremium = 500;
_workerStorageContract.UpdElement(CreateModel(worker.Id, config: new ChiefPostConfiguration() { PersonalCountTrendPremium = 500 }));
var element = FurnitureAssemblyDbContext.GetWorkerFromDatabaseById(worker.Id);
Assert.That(element, Is.Not.Null);
Assert.Multiple(() =>
{
Assert.That(element.Configuration.Type, Is.EqualTo(typeof(ChiefPostConfiguration).Name));
Assert.That((element.Configuration as ChiefPostConfiguration)!.PersonalCountTrendPremium, Is.EqualTo(personalCountTrendPremium));
});
}
[Test]
public void Try_GetWorkerTrend_WhenNoNewAndDeletedWorkers_Test()
{
var startDate = DateTime.UtcNow.AddDays(-5);
var endDate = DateTime.UtcNow.AddDays(-3);
FurnitureAssemblyDbContext.InsertWorkerToDatabaseAndReturn(employmentDate: DateTime.UtcNow.AddDays(-10));
FurnitureAssemblyDbContext.InsertWorkerToDatabaseAndReturn(employmentDate: DateTime.UtcNow.AddDays(-10), isDeleted: true, dateDelete: DateTime.UtcNow.AddDays(-9));
FurnitureAssemblyDbContext.InsertWorkerToDatabaseAndReturn(employmentDate: DateTime.UtcNow.AddDays(-10), isDeleted: true, dateDelete: DateTime.UtcNow.AddDays(-1));
var count = _workerStorageContract.GetWorkerTrend(startDate, endDate);
Assert.That(count, Is.EqualTo(0));
}
[Test]
public void Try_GetWorkerTrend_WhenHaveNewAndNoDeletedWorkers_Test()
{
var startDate = DateTime.UtcNow.AddDays(-5);
var endDate = DateTime.UtcNow.AddDays(-3);
FurnitureAssemblyDbContext.InsertWorkerToDatabaseAndReturn(employmentDate: DateTime.UtcNow.AddDays(-10));
FurnitureAssemblyDbContext.InsertWorkerToDatabaseAndReturn(employmentDate: DateTime.UtcNow.AddDays(-4));
FurnitureAssemblyDbContext.InsertWorkerToDatabaseAndReturn(employmentDate: DateTime.UtcNow.AddDays(-1));
var count = _workerStorageContract.GetWorkerTrend(startDate, endDate);
Assert.That(count, Is.EqualTo(1));
}
[Test]
public void Try_GetWorkerTrend_WhenNoNewAndHaveDeletedWorkers_Test()
{
var startDate = DateTime.UtcNow.AddDays(-5);
var endDate = DateTime.UtcNow.AddDays(-3);
FurnitureAssemblyDbContext.InsertWorkerToDatabaseAndReturn(employmentDate: DateTime.UtcNow.AddDays(-10), isDeleted: true, dateDelete: DateTime.UtcNow.AddDays(-9));
FurnitureAssemblyDbContext.InsertWorkerToDatabaseAndReturn(employmentDate: DateTime.UtcNow.AddDays(-10), isDeleted: true, dateDelete: DateTime.UtcNow.AddDays(-4));
FurnitureAssemblyDbContext.InsertWorkerToDatabaseAndReturn(employmentDate: DateTime.UtcNow.AddDays(-10), isDeleted: true, dateDelete: DateTime.UtcNow.AddDays(-1));
var count = _workerStorageContract.GetWorkerTrend(startDate, endDate);
Assert.That(count, Is.EqualTo(-1));
}
private static void AssertElement(WorkerDataModel? actual, Worker expected)
{
Assert.That(actual, Is.Not.Null);
@@ -197,8 +308,8 @@ internal class WorkerStorageContractTests : BaseStorageContractTest
});
}
private static WorkerDataModel CreateModel(string id, string fio = "fio", string? postId = null, DateTime? birthDate = null, DateTime? employmentDate = null, bool isDeleted = false) =>
new(id, fio, postId ?? Guid.NewGuid().ToString(), birthDate ?? DateTime.UtcNow.AddYears(-20), employmentDate ?? DateTime.UtcNow, isDeleted);
private static WorkerDataModel CreateModel(string id, string fio = "fio", string? postId = null, PostConfiguration? config = null, DateTime? birthDate = null, DateTime? employmentDate = null, bool isDeleted = false) =>
new(id, fio, postId ?? Guid.NewGuid().ToString(), birthDate ?? DateTime.UtcNow.AddYears(-20), employmentDate ?? DateTime.UtcNow, isDeleted, config ?? new PostConfiguration() { Rate = 10 });
private static void AssertElement(Worker? actual, WorkerDataModel expected)
{
@@ -211,6 +322,8 @@ internal class WorkerStorageContractTests : BaseStorageContractTest
Assert.That(actual.BirthDate, Is.EqualTo(expected.BirthDate));
Assert.That(actual.EmploymentDate, Is.EqualTo(expected.EmploymentDate));
Assert.That(actual.IsDeleted, Is.EqualTo(expected.IsDeleted));
Assert.That(actual.Configuration.Rate, Is.EqualTo(expected.ConfigurationModel.Rate));
Assert.That(actual.DateOfDelete.HasValue, Is.EqualTo(expected.IsDeleted));
});
}
}

View File

@@ -3,6 +3,7 @@ using System.Net;
using System;
using FurnitureAssemblyTests.Infrastructure;
using FurnitureAssemblyDatebase.Models;
using FurnitureAssemblyContracts.Infrastructure.PostConfigurations;
namespace FurnitureAssemblyTests.WebApiControllerTests;
@@ -167,7 +168,7 @@ internal class SalaryControllerTests : BaseWebApiControllerTest
Assert.Multiple(() =>
{
Assert.That(salaries, Has.Length.EqualTo(1));
Assert.That(salaries.First().WorkerSalary, Is.EqualTo(1000.5));
Assert.That(salaries.First().WorkerSalary, Is.EqualTo(100));
Assert.That(salaries.First().SalaryDate.Month, Is.EqualTo(DateTime.UtcNow.Month));
});
}
@@ -188,7 +189,7 @@ internal class SalaryControllerTests : BaseWebApiControllerTest
{
//Arrange
var post = FurnitureAssemblyDbContext.InsertPostToDatabaseAndReturn(salary: 1000);
var worker1 = FurnitureAssemblyDbContext.InsertWorkerToDatabaseAndReturn(fio: "name 1", postId: post.PostId);
var worker1 = FurnitureAssemblyDbContext.InsertWorkerToDatabaseAndReturn(fio: "name 1", postId: post.PostId, config: new PostConfiguration() { Rate = 1000 });
var worker2 = FurnitureAssemblyDbContext.InsertWorkerToDatabaseAndReturn(fio: "name 2", postId: post.PostId);
var man = FurnitureAssemblyDbContext.InsertFurnitureToDatabaseAndReturn();
FurnitureAssemblyDbContext.InsertManifacturingToDatabaseAndReturn(worker1.Id, man.Id);
@@ -200,18 +201,4 @@ internal class SalaryControllerTests : BaseWebApiControllerTest
var salary2 = FurnitureAssemblyDbContext.GetSalariesFromDatabaseByWorkerId(worker2.Id).First().WorkerSalary;
Assert.That(salary1, Is.Not.EqualTo(salary2));
}
[Test]
public async Task Calculate_PostNotFound_ShouldNotFound_Test()
{
//Arrange
FurnitureAssemblyDbContext.InsertPostToDatabaseAndReturn();
var worker = FurnitureAssemblyDbContext.InsertWorkerToDatabaseAndReturn(fio: "name", postId: Guid.NewGuid().ToString());
var furniture = FurnitureAssemblyDbContext.InsertFurnitureToDatabaseAndReturn();
FurnitureAssemblyDbContext.InsertManifacturingToDatabaseAndReturn(worker.Id, furniture.Id);
//Act
var response = await HttpClient.PostAsync($"/api/salaries/calculate?date={DateTime.UtcNow:MM/dd/yyyy}", null);
//Assert
Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.NotFound));
}
}

View File

@@ -1,8 +1,12 @@
using FurnitureAssemblyContracts.BindingModels;
using FurnitureAssemblyContracts.Enums;
using FurnitureAssemblyContracts.Infrastructure.PostConfigurations;
using FurnitureAssemblyContracts.ViewModels;
using FurnitureAssemblyDatebase.Models;
using FurnitureAssemblyTests.Infrastructure;
using System.Net;
using System.Text.Json;
using System.Text.Json.Nodes;
namespace FurnitureAssemblyTests.WebApiControllerTests;
@@ -301,15 +305,17 @@ internal class WorkerControllerTests : BaseWebApiControllerTest
public async Task Post_WhenDataIsIncorrect_ShouldBadRequest_Test()
{
//Arrange
var workerModelWithIdIncorrect = new WorkerBindingModel { Id = "Id", FIO = "fio", BirthDate = DateTime.UtcNow.AddYears(-22), EmploymentDate = DateTime.UtcNow.AddDays(-5), PostId = _post.Id };
var workerModelWithFioIncorrect = new WorkerBindingModel { Id = Guid.NewGuid().ToString(), FIO = string.Empty, BirthDate = DateTime.UtcNow.AddYears(-22), EmploymentDate = DateTime.UtcNow.AddDays(-5), PostId = _post.Id };
var workerModelWithPostIdIncorrect = new WorkerBindingModel { Id = Guid.NewGuid().ToString(), FIO = "fio", BirthDate = DateTime.UtcNow.AddYears(-22), EmploymentDate = DateTime.UtcNow.AddDays(-5), PostId = "Id" };
var workerModelWithBirthDateIncorrect = new WorkerBindingModel { Id = Guid.NewGuid().ToString(), FIO = "fio", BirthDate = DateTime.UtcNow.AddYears(-15), EmploymentDate = DateTime.UtcNow.AddDays(-5), PostId = _post.Id };
var workerModelWithIdIncorrect = new WorkerBindingModel { Id = "Id", FIO = "fio", BirthDate = DateTime.UtcNow.AddYears(-22), EmploymentDate = DateTime.UtcNow.AddDays(-5), PostId = _post.Id, ConfigurationJson = JsonSerializer.Serialize(new PostConfiguration() { Rate = 10 }) };
var workerModelWithFioIncorrect = new WorkerBindingModel { Id = Guid.NewGuid().ToString(), FIO = string.Empty, BirthDate = DateTime.UtcNow.AddYears(-22), EmploymentDate = DateTime.UtcNow.AddDays(-5), PostId = _post.Id, ConfigurationJson = JsonSerializer.Serialize(new PostConfiguration() { Rate = 10 }) };
var workerModelWithPostIdIncorrect = new WorkerBindingModel { Id = Guid.NewGuid().ToString(), FIO = "fio", BirthDate = DateTime.UtcNow.AddYears(-22), EmploymentDate = DateTime.UtcNow.AddDays(-5), PostId = "Id", ConfigurationJson = JsonSerializer.Serialize(new PostConfiguration() { Rate = 10 }) };
var workerModelWithBirthDateIncorrect = new WorkerBindingModel { Id = Guid.NewGuid().ToString(), FIO = "fio", BirthDate = DateTime.UtcNow.AddYears(-15), EmploymentDate = DateTime.UtcNow.AddDays(-5), PostId = _post.Id, ConfigurationJson = JsonSerializer.Serialize(new PostConfiguration() { Rate = 10 }) };
var workerModelWithConfigurationIncorrect = new WorkerBindingModel { Id = Guid.NewGuid().ToString(), FIO = "fio", BirthDate = DateTime.UtcNow.AddYears(-15), EmploymentDate = DateTime.UtcNow.AddDays(-5), PostId = _post.Id, ConfigurationJson = null };
//Act
var responseWithIdIncorrect = await HttpClient.PostAsync($"/api/workers/register", MakeContent(workerModelWithIdIncorrect));
var responseWithFioIncorrect = await HttpClient.PostAsync($"/api/workers/register", MakeContent(workerModelWithFioIncorrect));
var responseWithPostIdIncorrect = await HttpClient.PostAsync($"/api/workers/register", MakeContent(workerModelWithPostIdIncorrect));
var responseWithBirthDateIncorrect = await HttpClient.PostAsync($"/api/workers/register", MakeContent(workerModelWithBirthDateIncorrect));
var responseWithConfigurationIncorrect = await HttpClient.PostAsync($"/api/workers/register", MakeContent(workerModelWithConfigurationIncorrect));
//Assert
Assert.Multiple(() =>
{
@@ -317,6 +323,7 @@ internal class WorkerControllerTests : BaseWebApiControllerTest
Assert.That(responseWithFioIncorrect.StatusCode, Is.EqualTo(HttpStatusCode.BadRequest), "Fio is incorrect");
Assert.That(responseWithPostIdIncorrect.StatusCode, Is.EqualTo(HttpStatusCode.BadRequest), "PostId is incorrect");
Assert.That(responseWithBirthDateIncorrect.StatusCode, Is.EqualTo(HttpStatusCode.BadRequest), "BirthDate is incorrect");
Assert.That(responseWithConfigurationIncorrect.StatusCode, Is.EqualTo(HttpStatusCode.BadRequest), "Configuration is incorrect");
});
}
@@ -380,15 +387,17 @@ internal class WorkerControllerTests : BaseWebApiControllerTest
public async Task Put_WhenDataIsIncorrect_ShouldBadRequest_Test()
{
//Arrange
var workerModelWithIdIncorrect = new WorkerBindingModel { Id = "Id", FIO = "fio", BirthDate = DateTime.UtcNow.AddYears(-22), EmploymentDate = DateTime.UtcNow.AddDays(-5), PostId = _post.Id };
var workerModelWithFioIncorrect = new WorkerBindingModel { Id = Guid.NewGuid().ToString(), FIO = string.Empty, BirthDate = DateTime.UtcNow.AddYears(-22), EmploymentDate = DateTime.UtcNow.AddDays(-5), PostId = _post.Id };
var workerModelWithPostIdIncorrect = new WorkerBindingModel { Id = Guid.NewGuid().ToString(), FIO = "fio", BirthDate = DateTime.UtcNow.AddYears(-22), EmploymentDate = DateTime.UtcNow.AddDays(-5), PostId = "Id" };
var workerModelWithBirthDateIncorrect = new WorkerBindingModel { Id = Guid.NewGuid().ToString(), FIO = "fio", BirthDate = DateTime.UtcNow.AddYears(-15), EmploymentDate = DateTime.UtcNow.AddDays(-5), PostId = _post.Id };
var workerModelWithIdIncorrect = new WorkerBindingModel { Id = "Id", FIO = "fio", BirthDate = DateTime.UtcNow.AddYears(-22), EmploymentDate = DateTime.UtcNow.AddDays(-5), PostId = _post.Id, ConfigurationJson = JsonSerializer.Serialize(new PostConfiguration() { Rate = 10 }) };
var workerModelWithFioIncorrect = new WorkerBindingModel { Id = Guid.NewGuid().ToString(), FIO = string.Empty, BirthDate = DateTime.UtcNow.AddYears(-22), EmploymentDate = DateTime.UtcNow.AddDays(-5), PostId = _post.Id, ConfigurationJson = JsonSerializer.Serialize(new PostConfiguration() { Rate = 10 }) };
var workerModelWithPostIdIncorrect = new WorkerBindingModel { Id = Guid.NewGuid().ToString(), FIO = "fio", BirthDate = DateTime.UtcNow.AddYears(-22), EmploymentDate = DateTime.UtcNow.AddDays(-5), PostId = "Id", ConfigurationJson = JsonSerializer.Serialize(new PostConfiguration() { Rate = 10 }) };
var workerModelWithBirthDateIncorrect = new WorkerBindingModel { Id = Guid.NewGuid().ToString(), FIO = "fio", BirthDate = DateTime.UtcNow.AddYears(-15), EmploymentDate = DateTime.UtcNow.AddDays(-5), PostId = _post.Id, ConfigurationJson = JsonSerializer.Serialize(new PostConfiguration() { Rate = 10 }) };
var workerModelWithConfigurationIncorrect = new WorkerBindingModel { Id = Guid.NewGuid().ToString(), FIO = "fio", BirthDate = DateTime.UtcNow.AddYears(-15), EmploymentDate = DateTime.UtcNow.AddDays(-5), PostId = _post.Id, ConfigurationJson = null };
//Act
var responseWithIdIncorrect = await HttpClient.PutAsync($"/api/workers/changeinfo", MakeContent(workerModelWithIdIncorrect));
var responseWithFioIncorrect = await HttpClient.PutAsync($"/api/workers/changeinfo", MakeContent(workerModelWithFioIncorrect));
var responseWithPostIdIncorrect = await HttpClient.PutAsync($"/api/workers/changeinfo", MakeContent(workerModelWithPostIdIncorrect));
var responseWithBirthDateIncorrect = await HttpClient.PutAsync($"/api/workers/changeinfo", MakeContent(workerModelWithBirthDateIncorrect));
var responseConfigurationIncorrect = await HttpClient.PutAsync($"/api/workers/changeinfo", MakeContent(workerModelWithConfigurationIncorrect));
//Assert
Assert.Multiple(() =>
{
@@ -396,6 +405,7 @@ internal class WorkerControllerTests : BaseWebApiControllerTest
Assert.That(responseWithFioIncorrect.StatusCode, Is.EqualTo(HttpStatusCode.BadRequest), "Fio is incorrect");
Assert.That(responseWithPostIdIncorrect.StatusCode, Is.EqualTo(HttpStatusCode.BadRequest), "PostId is incorrect");
Assert.That(responseWithBirthDateIncorrect.StatusCode, Is.EqualTo(HttpStatusCode.BadRequest), "BirthDate is incorrect");
Assert.That(responseConfigurationIncorrect.StatusCode, Is.EqualTo(HttpStatusCode.BadRequest), "Configuration is incorrect");
});
}
@@ -465,6 +475,103 @@ internal class WorkerControllerTests : BaseWebApiControllerTest
Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.BadRequest));
}
[Test]
public async Task GetRecords_WhenDifferentConfigTypes_ShouldSuccess_Test()
{
//Arrange
var workerSimple = FurnitureAssemblyDbContext.InsertWorkerToDatabaseAndReturn(postId: _post.PostId).AddPost(_post);
var workerBuilder = FurnitureAssemblyDbContext.InsertWorkerToDatabaseAndReturn(postId: _post.PostId, config: new BuilderPostConfiguration() { PersonalCount = 500 }).AddPost(_post);
var workerChief = FurnitureAssemblyDbContext.InsertWorkerToDatabaseAndReturn(postId: _post.PostId, config: new ChiefPostConfiguration() { PersonalCountTrendPremium = 500 }).AddPost(_post);
//Act
var response = await HttpClient.GetAsync("/api/workers/getrecords");
//Assert
Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.OK));
var data = await GetModelFromResponseAsync<List<WorkerViewModel>>(response);
Assert.That(data, Is.Not.Null);
AssertElement(data.First(x => x.Id == workerSimple.Id), workerSimple);
AssertElement(data.First(x => x.Id == workerBuilder.Id), workerBuilder);
AssertElement(data.First(x => x.Id == workerChief.Id), workerChief);
}
[Test]
public async Task Post_WithBuilderPostConfiguration_ShouldSuccess_Test()
{
//Arrange
var personalCount = 500;
var workerModel = CreateModel(postId: _post.PostId, configuration: JsonSerializer.Serialize(new BuilderPostConfiguration() { Rate = 10, PersonalCount = 500 }));
//Act
var response = await HttpClient.PostAsync($"/api/workers/register", MakeContent(workerModel));
//Assert
Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.NoContent));
var element = FurnitureAssemblyDbContext.GetWorkerFromDatabaseById(workerModel.Id!);
Assert.That(element, Is.Not.Null);
Assert.Multiple(() =>
{
Assert.That(element.Configuration.Type, Is.EqualTo(typeof(BuilderPostConfiguration).Name));
Assert.That((element.Configuration as BuilderPostConfiguration)!.PersonalCount, Is.EqualTo(personalCount));
});
}
[Test]
public async Task Post_WithChiefPostConfiguration_ShouldSuccess_Test()
{
//Arrange
var personalCountTrendPremium = 500;
var workerModel = CreateModel(postId: _post.PostId, configuration: JsonSerializer.Serialize(new ChiefPostConfiguration() { Rate = 10, PersonalCountTrendPremium = 500 }));
//Act
var response = await HttpClient.PostAsync($"/api/workers/register", MakeContent(workerModel));
//Assert
Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.NoContent));
var element = FurnitureAssemblyDbContext.GetWorkerFromDatabaseById(workerModel.Id!);
Assert.That(element, Is.Not.Null);
Assert.Multiple(() =>
{
Assert.That(element.Configuration.Type, Is.EqualTo(typeof(ChiefPostConfiguration).Name));
Assert.That((element.Configuration as ChiefPostConfiguration)!.PersonalCountTrendPremium, Is.EqualTo(personalCountTrendPremium));
});
}
public async Task Put_WithCashierPostConfiguration_ShouldSuccess_Test()
{
//Arrange
var personalCount = 10;
var worker = FurnitureAssemblyDbContext.InsertWorkerToDatabaseAndReturn();
var postModel = CreateModel(postId: _post.PostId, id: worker.Id, configuration: JsonSerializer.Serialize(new BuilderPostConfiguration() { Rate = 10, PersonalCount = 500 }));
//Act
var response = await HttpClient.PutAsync($"/api/workers/changeinfo", MakeContent(postModel));
//Assert
Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.NoContent));
FurnitureAssemblyDbContext.ChangeTracker.Clear();
var element = FurnitureAssemblyDbContext.GetWorkerFromDatabaseById(postModel.Id!);
Assert.That(element, Is.Not.Null);
Assert.Multiple(() =>
{
Assert.That(element.Configuration.Type, Is.EqualTo(typeof(BuilderPostConfiguration).Name));
Assert.That((element.Configuration as BuilderPostConfiguration)!.PersonalCount, Is.EqualTo(personalCount));
});
}
[Test]
public async Task Put_WithChiefPostConfiguration_ShouldSuccess_Test()
{
//Arrange
var personalCountTrendPremium = 500;
var worker = FurnitureAssemblyDbContext.InsertWorkerToDatabaseAndReturn();
var workerModel = CreateModel(postId: _post.PostId, id: worker.Id, configuration: JsonSerializer.Serialize(new ChiefPostConfiguration() { Rate = 10, PersonalCountTrendPremium = 500 }));
//Act
var response = await HttpClient.PutAsync($"api/workers/changeinfo", MakeContent(workerModel));
//Assert
Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.NoContent));
FurnitureAssemblyDbContext.ChangeTracker.Clear();
var element = FurnitureAssemblyDbContext.GetWorkerFromDatabaseById(workerModel.Id!);
Assert.That(element, Is.Not.Null);
Assert.Multiple(() =>
{
Assert.That(element.Configuration.Type, Is.EqualTo(typeof(ChiefPostConfiguration).Name));
Assert.That((element.Configuration as ChiefPostConfiguration)!.PersonalCountTrendPremium, Is.EqualTo(personalCountTrendPremium));
});
}
private static void AssertElement(WorkerViewModel? actual, Worker expected)
{
Assert.That(actual, Is.Not.Null);
@@ -477,10 +584,11 @@ internal class WorkerControllerTests : BaseWebApiControllerTest
Assert.That(actual.BirthDate.ToString(), Is.EqualTo(expected.BirthDate.ToString()));
Assert.That(actual.EmploymentDate.ToString(), Is.EqualTo(expected.EmploymentDate.ToString()));
Assert.That(actual.IsDeleted, Is.EqualTo(expected.IsDeleted));
Assert.That(JsonNode.Parse(actual.Configuration)!["Type"]!.GetValue<string>(), Is.EqualTo(expected.Configuration.Type));
});
}
private static WorkerBindingModel CreateModel(string postId, string? id = null, string fio = "Иванов И.И.", DateTime? birthDate = null, DateTime? employmentDate = null)
private static WorkerBindingModel CreateModel(string postId, string? id = null, string fio = "Иванов И.И.", DateTime? birthDate = null, DateTime? employmentDate = null, string? configuration = null)
{
return new()
{
@@ -488,7 +596,8 @@ internal class WorkerControllerTests : BaseWebApiControllerTest
FIO = fio,
BirthDate = birthDate ?? DateTime.UtcNow.AddYears(-22),
EmploymentDate = employmentDate ?? DateTime.UtcNow.AddDays(-5),
PostId = postId
PostId = postId,
ConfigurationJson = configuration ?? JsonSerializer.Serialize(new PostConfiguration() { Rate = 10 })
};
}
@@ -503,6 +612,7 @@ internal class WorkerControllerTests : BaseWebApiControllerTest
Assert.That(actual.BirthDate.ToString(), Is.EqualTo(expected.BirthDate.ToString()));
Assert.That(actual.EmploymentDate.ToString(), Is.EqualTo(expected.EmploymentDate.ToString()));
Assert.That(!actual.IsDeleted);
Assert.That(actual.Configuration.Type, Is.EqualTo(JsonNode.Parse(expected.ConfigurationJson!)!["Type"]!.GetValue<string>()));
});
}
}

View File

@@ -21,5 +21,12 @@
}
]
},
"AllowedHosts": "*"
"AllowedHosts": "*",
"SalarySettings": {
"ExtraMadeSum": 10,
"MaxConcurrentThreads": 2
},
"BuilderSettings": {
"PersonalCount": 0.1
}
}

View File

@@ -6,6 +6,7 @@ using FurnitureAssemblyContracts.BusinessLogicsContracts;
using FurnitureAssemblyContracts.DataModels;
using FurnitureAssemblyContracts.Exceptions;
using FurnitureAssemblyContracts.ViewModels;
using System.Text.Json;
namespace FurnitureAssemblyWebApi.Adapters;
@@ -17,6 +18,11 @@ public class WorkerAdapter : IWorkerAdapter
private readonly Mapper _mapper;
private readonly JsonSerializerOptions JsonSerializerOptions = new()
{
PropertyNameCaseInsensitive = true
};
public WorkerAdapter(IWorkerBusinessLogicContract workerBusinessLogicContract, ILogger<WorkerAdapter> logger)
{
_buyerBusinessLogicContract = workerBusinessLogicContract;
@@ -24,7 +30,8 @@ public class WorkerAdapter : IWorkerAdapter
var config = new MapperConfiguration(cfg =>
{
cfg.CreateMap<WorkerBindingModel, WorkerDataModel>();
cfg.CreateMap<WorkerDataModel, WorkerViewModel>();
cfg.CreateMap<WorkerDataModel, WorkerViewModel>()
.ForMember(x => x.Configuration, x => x.MapFrom(src => JsonSerializer.Serialize(src.ConfigurationModel, JsonSerializerOptions)));
});
_mapper = new Mapper(config);
}

View File

@@ -10,6 +10,10 @@
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="9.0.3" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.1" />
<PackageReference Include="Serilog.AspNetCore" Version="9.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
@@ -23,4 +27,10 @@
<InternalsVisibleTo Include="DynamicProxyGenAssembly2" />
</ItemGroup>
<ItemGroup>
<Content Update="appsettings.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
</Project>

View File

@@ -1,5 +1,4 @@
using FurnitureAssemblyContracts.Infrastructure;
using Microsoft.Extensions.Configuration;
namespace FurnitureAssemblyWebApi.Infrastucture;

View File

@@ -0,0 +1,16 @@
using FurnitureAssemblyContracts.Infrastructure;
namespace FurnitureAssemblyWebApi.Infrastucture;
public class ConfigurationSalary(IConfiguration configuration) : IConfigurationSalary
{
private readonly Lazy<SalarySettings> _salarySettings = new(() =>
{
var settings = configuration.GetSection("SalarySettings").Get<SalarySettings>();
return settings ?? throw new InvalidDataException("SalarySettings configuration section is missing or invalid");
});
public double ExtraMadeSum => _salarySettings.Value.ExtraMadeSum;
public int MaxConcurrentThreads => _salarySettings.Value.MaxConcurrentThreads;
}

View File

@@ -0,0 +1,7 @@
namespace FurnitureAssemblyWebApi.Infrastucture;
public class SalarySettings
{
public double ExtraMadeSum { get; set; }
public int MaxConcurrentThreads { get; set; }
}

View File

@@ -48,6 +48,7 @@ builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme).AddJw
});
builder.Services.AddSingleton<IConfigurationDatabase, ConfigurationDatabase>();
builder.Services.AddSingleton<IConfigurationSalary, ConfigurationSalary>();
builder.Services.AddTransient<IComponentBusinessLogicContract, ComponentBusinessLogicContract>();
builder.Services.AddTransient<IFurnitureBusinessLogicContract, FurnitureBusinessLogicContract>();

View File

@@ -21,5 +21,12 @@
}
]
},
"AllowedHosts": "*"
"AllowedHosts": "*",
"SalarySettings": {
"ExtraMadeSum": 10,
"MaxConcurrentThreads": 2
},
"BuilderSettings": {
"PersonalCount": 0.1
}
}