Compare commits
7 Commits
Task_4_Api
...
Task_5_Sal
| Author | SHA1 | Date | |
|---|---|---|---|
| 50a0807cdf | |||
| 4abc5ebcfb | |||
| 681ae1d484 | |||
| 1b9cbc274d | |||
| 55c269a934 | |||
| 7e8e7a5ee8 | |||
| b4c6d0110a |
@@ -1,18 +1,17 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using SladkieBulkiContrakts.BusinessLogicsContracts;
|
||||
using SladkieBulkiContrakts.DataModels;
|
||||
using SladkieBulkiContrakts.Exceptions;
|
||||
using SladkieBulkiContrakts.Extensions;
|
||||
using SladkieBulkiContrakts.Infrastructure;
|
||||
using SladkieBulkiContrakts.Infrastructure.PostConfigurations;
|
||||
using SladkieBulkiContrakts.StoragesContarcts;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace SladkieBulkiBusinessLogic.Implementations;
|
||||
|
||||
internal class SalaryBusinessLogicContract(ISalaryStorageContract salaryStorageContract, IProductionStorageContract productionStorageContract, IPostStorageContract postStorageContract, IWorkerStorageContract workerStorageContract, ILogger logger) : ISalaryBusinessLogicContract
|
||||
internal class SalaryBusinessLogicContract(ISalaryStorageContract salaryStorageContract, IProductionStorageContract productionStorageContract, IPostStorageContract postStorageContract, IWorkerStorageContract workerStorageContract, ILogger logger, IConfigurationSalary сonfiguration) : ISalaryBusinessLogicContract
|
||||
{
|
||||
private readonly ILogger _logger = logger;
|
||||
private readonly ISalaryStorageContract _salaryStorageContract =
|
||||
@@ -22,6 +21,9 @@ internal class SalaryBusinessLogicContract(ISalaryStorageContract salaryStorageC
|
||||
postStorageContract;
|
||||
private readonly IWorkerStorageContract _workerStorageContract =
|
||||
workerStorageContract;
|
||||
private readonly IConfigurationSalary _salaryConfiguration = сonfiguration;
|
||||
private readonly object _lockObject = new();
|
||||
|
||||
|
||||
public List<SalaryDataModel> GetAllSalariesByPeriod(DateTime fromDate, DateTime toDate)
|
||||
{
|
||||
@@ -57,18 +59,89 @@ internal class SalaryBusinessLogicContract(ISalaryStorageContract salaryStorageC
|
||||
var startDate = new DateTime(date.Year, date.Month, 1);
|
||||
var finishDate = new DateTime(date.Year, date.Month, DateTime.DaysInMonth(date.Year, date.Month));
|
||||
var workers = _workerStorageContract.GetList() ?? throw new NullListException();
|
||||
if (workers.Count == 0)
|
||||
throw new NullListException();
|
||||
|
||||
foreach (var worker in workers)
|
||||
{
|
||||
var sales = _productionStorageContract.GetList(startDate, finishDate, workerId: worker.Id)?.Sum(x => x.Sum) ??
|
||||
throw new NullListException();
|
||||
var post = _postStorageContract.GetElementById(worker.PostId) ??
|
||||
throw new NullListException();
|
||||
var salary = post.Salary + sales * 0.1;
|
||||
var sales = _productionStorageContract.GetList(startDate, finishDate, workerId: worker.Id) ?? throw new NullListException();
|
||||
var post = _postStorageContract.GetElementById(worker.PostId) ?? throw new NullListException();
|
||||
var salary = post.ConfigurationModel switch
|
||||
{
|
||||
null => 0,
|
||||
ManufacturerPostConfiguration cpc => CalculateSalaryForCashier(sales, startDate, finishDate, cpc),
|
||||
PackerPostConfiguration spc => CalculateSalaryForSupervisor(startDate, finishDate, spc),
|
||||
PostConfiguration pc => pc.Rate,
|
||||
};
|
||||
_logger.LogDebug("The employee {workerId} was paid a salary of {salary}", worker.Id, salary);
|
||||
_salaryStorageContract.AddElement(new SalaryDataModel(worker.Id, finishDate, salary));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private double CalculateSalaryForCashier(List<ProductionDataModel> sales, DateTime startDate, DateTime finishDate, ManufacturerPostConfiguration config)
|
||||
{
|
||||
|
||||
int maxConcurrency = сonfiguration.MaxParallelThreads;
|
||||
var semaphore = new SemaphoreSlim(maxConcurrency);
|
||||
|
||||
var tasks = new List<Task>();
|
||||
var calcPercent = 0.0;
|
||||
|
||||
for (var date = startDate; date < finishDate; date = date.AddDays(1))
|
||||
{
|
||||
var dateCopy = date; // Нужно, чтобы замыкание захватило корректную дату
|
||||
|
||||
tasks.Add(Task.Run(async () =>
|
||||
{
|
||||
await semaphore.WaitAsync();
|
||||
try
|
||||
{
|
||||
var salesInDay = sales
|
||||
.Where(x => x.ProductionDate >= dateCopy && x.ProductionDate < dateCopy.AddDays(1))
|
||||
.ToArray();
|
||||
|
||||
if (salesInDay.Length > 0)
|
||||
{
|
||||
lock (_lockObject)
|
||||
{
|
||||
calcPercent += (salesInDay.Sum(x => x.Sum) / salesInDay.Length) * config.SalePercent;
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
semaphore.Release();
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
var calcBonusTask = Task.Run(() =>
|
||||
{
|
||||
return sales.Where(x => x.Sum > _salaryConfiguration.ExtraSaleSum).Sum(x => x.Sum) * config.BonusForExtraSales;
|
||||
});
|
||||
|
||||
try
|
||||
{
|
||||
Task.WaitAll(tasks.ToArray()); // Ждём завершения всех задач по дням
|
||||
calcBonusTask.Wait(); // Ждём завершения бонуса
|
||||
}
|
||||
catch (AggregateException agEx)
|
||||
{
|
||||
foreach (var ex in agEx.InnerExceptions)
|
||||
_logger.LogError(ex, "Error in the cashier payroll process");
|
||||
return 0;
|
||||
}
|
||||
|
||||
return config.Rate + calcPercent + calcBonusTask.Result;
|
||||
}
|
||||
|
||||
private double CalculateSalaryForSupervisor(DateTime startDate, DateTime finishDate, PackerPostConfiguration config)
|
||||
{
|
||||
try
|
||||
{
|
||||
return config.Rate + config.PersonalCountPack * _workerStorageContract.GetWorkerTrend(startDate, finishDate);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error in the supervisor payroll process");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,5 +10,5 @@ public class PostBindingModel
|
||||
|
||||
public string? PostType { get; set; }
|
||||
|
||||
public double Salary { get; set; }
|
||||
public string? ConfigurationJson { get; set; }
|
||||
}
|
||||
@@ -1,6 +1,9 @@
|
||||
using SladkieBulkiContrakts.Enums;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Newtonsoft.Json;
|
||||
using SladkieBulkiContrakts.Enums;
|
||||
using SladkieBulkiContrakts.Extensions;
|
||||
using SladkieBulkiContrakts.Infrastructure;
|
||||
using SladkieBulkiContrakts.Infrastructure.PostConfigurations;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -10,12 +13,29 @@ using System.Xml;
|
||||
|
||||
namespace SladkieBulkiContrakts.DataModels;
|
||||
|
||||
public class PostDataModel(string postId, string postName, PostType postType, double salary) : IValidation
|
||||
public class PostDataModel(string postId, string postName, PostType postType, PostConfiguration configuration) : IValidation
|
||||
{
|
||||
public string Id { get; private set; } = postId;
|
||||
|
||||
public string PostName { get; private set; } = postName;
|
||||
|
||||
public PostType PostType { get; private set; } = postType;
|
||||
public double Salary { get; private set; } = salary;
|
||||
|
||||
public PostConfiguration ConfigurationModel { get; private set; } = configuration;
|
||||
|
||||
public PostDataModel(string postId, string postName, PostType postType, string configurationJson) : this(postId, postName, postType, (PostConfiguration)null)
|
||||
{
|
||||
var obj = JToken.Parse(configurationJson);
|
||||
if (obj is not null)
|
||||
{
|
||||
ConfigurationModel = obj.Value<string>("Type") switch
|
||||
{
|
||||
nameof(ManufacturerPostConfiguration) => JsonConvert.DeserializeObject<ManufacturerPostConfiguration>(configurationJson)!,
|
||||
nameof(PackerPostConfiguration) => JsonConvert.DeserializeObject<PackerPostConfiguration>(configurationJson)!,
|
||||
_ => JsonConvert.DeserializeObject<PostConfiguration>(configurationJson)!,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
@@ -31,7 +51,10 @@ public class PostDataModel(string postId, string postName, PostType postType, do
|
||||
if (PostType == PostType.None)
|
||||
throw new ValidationException("Field PostType is empty");
|
||||
|
||||
if (Salary <= 0)
|
||||
throw new ValidationException("Field Salary is empty");
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SladkieBulkiContrakts.Infrastructure;
|
||||
|
||||
public interface IConfigurationSalary
|
||||
{
|
||||
double ExtraSaleSum { get; }
|
||||
int MaxParallelThreads { get; }
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SladkieBulkiContrakts.Infrastructure.PostConfigurations;
|
||||
|
||||
public class ManufacturerPostConfiguration : PostConfiguration
|
||||
{
|
||||
public override string Type => nameof(ManufacturerPostConfiguration);
|
||||
|
||||
public double SalePercent { get; set; }
|
||||
|
||||
public double BonusForExtraSales { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SladkieBulkiContrakts.Infrastructure.PostConfigurations;
|
||||
|
||||
public class PackerPostConfiguration : PostConfiguration
|
||||
{
|
||||
public override string Type => nameof(PackerPostConfiguration);
|
||||
|
||||
public double PersonalCountPack { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SladkieBulkiContrakts.Infrastructure.PostConfigurations;
|
||||
|
||||
public class PostConfiguration
|
||||
{
|
||||
public virtual string Type => nameof(PostConfiguration);
|
||||
|
||||
public double Rate { get; set; }
|
||||
}
|
||||
|
||||
@@ -15,4 +15,5 @@ public interface IWorkerStorageContract
|
||||
void AddElement(WorkerDataModel workerDataModel);
|
||||
void UpdElement(WorkerDataModel workerDataModel);
|
||||
void DelElement(string id);
|
||||
}
|
||||
int GetWorkerTrend(DateTime fromPeriod, DateTime toPeriod);
|
||||
}
|
||||
@@ -8,5 +8,5 @@ public class PostViewModel
|
||||
|
||||
public required string PostType { get; set; }
|
||||
|
||||
public double Salary { get; set; }
|
||||
public required string Configuration { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using SladkieBulkiContrakts.Infrastructure;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SladkieBulkiDatabase;
|
||||
|
||||
class DefaultConfigurationDatabase : IConfigurationDatabase
|
||||
{
|
||||
public string ConnectionString => "";
|
||||
}
|
||||
@@ -29,7 +29,8 @@ internal class PostStorageContract : IPostStorageContract
|
||||
.ForMember(x => x.Id, x => x.Ignore())
|
||||
.ForMember(x => x.PostId, x => x.MapFrom(src => src.Id))
|
||||
.ForMember(x => x.IsActual, x => x.MapFrom(src => true))
|
||||
.ForMember(x => x.ChangeDate, x => x.MapFrom(src => DateTime.UtcNow));
|
||||
.ForMember(x => x.ChangeDate, x => x.MapFrom(src => DateTime.UtcNow))
|
||||
.ForMember(x => x.Configuration, x => x.MapFrom(src => src.ConfigurationModel));
|
||||
});
|
||||
_mapper = new Mapper(config);
|
||||
}
|
||||
|
||||
@@ -127,6 +127,7 @@ internal class WorkerStorageContract : IWorkerStorageContract
|
||||
{
|
||||
var element = GetWorkerById(id) ?? throw new ElementNotFoundException(id);
|
||||
element.IsDeleted = true;
|
||||
element.DateOfDelete = DateTime.UtcNow;
|
||||
_dbContext.SaveChanges();
|
||||
}
|
||||
catch (ElementNotFoundException)
|
||||
@@ -141,6 +142,21 @@ internal 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)
|
||||
|
||||
363
SladkieBulki/SladkieBulkiDatabase/Migrations/20250520155308_FirstMigration.Designer.cs
generated
Normal file
363
SladkieBulki/SladkieBulkiDatabase/Migrations/20250520155308_FirstMigration.Designer.cs
generated
Normal file
@@ -0,0 +1,363 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
using SladkieBulkiDatabase;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace SladkieBulkiDatabase.Migrations
|
||||
{
|
||||
[DbContext(typeof(SladkieBulkiDbContext))]
|
||||
[Migration("20250520155308_FirstMigration")]
|
||||
partial class FirstMigration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "9.0.4")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.Ingredient", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<double>("InitPrice")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.Property<string>("NameIngredients")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("SizeInit")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("NameIngredients")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("Ingredients");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.IngredientHistory", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("ChangeDate")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<string>("IngredienId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<double>("OldPrice")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("IngredienId");
|
||||
|
||||
b.ToTable("IngredientHistories");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.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("SladkieBulkiDatabase.Models.Product", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Description")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<bool>("IsDeleted")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("ProductType")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("UnitPrice")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("Name", "IsDeleted")
|
||||
.IsUnique()
|
||||
.HasFilter("\"IsDeleted\" = FALSE");
|
||||
|
||||
b.ToTable("Products");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.ProductHistory", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("ChangeDate")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<double>("OldPrice")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.Property<string>("ProductId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ProductId");
|
||||
|
||||
b.ToTable("ProductHistories");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.ProductIngredient", b =>
|
||||
{
|
||||
b.Property<string>("ProductId")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("IngredientId")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("ProductId", "IngredientId");
|
||||
|
||||
b.HasIndex("IngredientId");
|
||||
|
||||
b.ToTable("ProductIngredients");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.Production", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<string>("ProductId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("ProductionDate")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<double>("Sum")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.Property<string>("WorkerId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ProductId");
|
||||
|
||||
b.HasIndex("WorkerId");
|
||||
|
||||
b.ToTable("Productions");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.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("SladkieBulkiDatabase.Models.Worker", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("BirthDate")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<string>("Email")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
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("SladkieBulkiDatabase.Models.IngredientHistory", b =>
|
||||
{
|
||||
b.HasOne("SladkieBulkiDatabase.Models.Ingredient", "Ingredient")
|
||||
.WithMany("IngredientHistory")
|
||||
.HasForeignKey("IngredienId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Ingredient");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.ProductHistory", b =>
|
||||
{
|
||||
b.HasOne("SladkieBulkiDatabase.Models.Product", "Product")
|
||||
.WithMany("ProductHistories")
|
||||
.HasForeignKey("ProductId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Product");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.ProductIngredient", b =>
|
||||
{
|
||||
b.HasOne("SladkieBulkiDatabase.Models.Ingredient", "Ingredient")
|
||||
.WithMany("ProductIngredients")
|
||||
.HasForeignKey("IngredientId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("SladkieBulkiDatabase.Models.Product", "Product")
|
||||
.WithMany("ProductIngredients")
|
||||
.HasForeignKey("ProductId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Ingredient");
|
||||
|
||||
b.Navigation("Product");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.Production", b =>
|
||||
{
|
||||
b.HasOne("SladkieBulkiDatabase.Models.Product", "Product")
|
||||
.WithMany("Productions")
|
||||
.HasForeignKey("ProductId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("SladkieBulkiDatabase.Models.Worker", "Worker")
|
||||
.WithMany("Productions")
|
||||
.HasForeignKey("WorkerId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Product");
|
||||
|
||||
b.Navigation("Worker");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.Salary", b =>
|
||||
{
|
||||
b.HasOne("SladkieBulkiDatabase.Models.Worker", "Worker")
|
||||
.WithMany("Salaries")
|
||||
.HasForeignKey("WorkerId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Worker");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.Ingredient", b =>
|
||||
{
|
||||
b.Navigation("IngredientHistory");
|
||||
|
||||
b.Navigation("ProductIngredients");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.Product", b =>
|
||||
{
|
||||
b.Navigation("ProductHistories");
|
||||
|
||||
b.Navigation("ProductIngredients");
|
||||
|
||||
b.Navigation("Productions");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.Worker", b =>
|
||||
{
|
||||
b.Navigation("Productions");
|
||||
|
||||
b.Navigation("Salaries");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,280 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace SladkieBulkiDatabase.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class FirstMigration : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Ingredients",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<string>(type: "text", nullable: false),
|
||||
NameIngredients = table.Column<string>(type: "text", nullable: false),
|
||||
SizeInit = table.Column<string>(type: "text", nullable: false),
|
||||
InitPrice = table.Column<double>(type: "double precision", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Ingredients", 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: "Products",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<string>(type: "text", nullable: false),
|
||||
Name = table.Column<string>(type: "text", nullable: false),
|
||||
Description = table.Column<string>(type: "text", nullable: false),
|
||||
ProductType = table.Column<int>(type: "integer", nullable: false),
|
||||
UnitPrice = table.Column<int>(type: "integer", nullable: false),
|
||||
IsDeleted = table.Column<bool>(type: "boolean", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Products", 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),
|
||||
Email = table.Column<string>(type: "text", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Workers", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "IngredientHistories",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<string>(type: "text", nullable: false),
|
||||
IngredienId = table.Column<string>(type: "text", nullable: false),
|
||||
OldPrice = table.Column<double>(type: "double precision", nullable: false),
|
||||
ChangeDate = table.Column<DateTime>(type: "timestamp without time zone", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_IngredientHistories", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_IngredientHistories_Ingredients_IngredienId",
|
||||
column: x => x.IngredienId,
|
||||
principalTable: "Ingredients",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "ProductHistories",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<string>(type: "text", nullable: false),
|
||||
ProductId = table.Column<string>(type: "text", nullable: false),
|
||||
OldPrice = table.Column<double>(type: "double precision", nullable: false),
|
||||
ChangeDate = table.Column<DateTime>(type: "timestamp without time zone", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_ProductHistories", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_ProductHistories_Products_ProductId",
|
||||
column: x => x.ProductId,
|
||||
principalTable: "Products",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "ProductIngredients",
|
||||
columns: table => new
|
||||
{
|
||||
ProductId = table.Column<string>(type: "text", nullable: false),
|
||||
IngredientId = table.Column<string>(type: "text", nullable: false),
|
||||
Count = table.Column<int>(type: "integer", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_ProductIngredients", x => new { x.ProductId, x.IngredientId });
|
||||
table.ForeignKey(
|
||||
name: "FK_ProductIngredients_Ingredients_IngredientId",
|
||||
column: x => x.IngredientId,
|
||||
principalTable: "Ingredients",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "FK_ProductIngredients_Products_ProductId",
|
||||
column: x => x.ProductId,
|
||||
principalTable: "Products",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Productions",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<string>(type: "text", nullable: false),
|
||||
ProductionDate = table.Column<DateTime>(type: "timestamp without time zone", nullable: false),
|
||||
Count = table.Column<int>(type: "integer", nullable: false),
|
||||
Sum = table.Column<double>(type: "double precision", nullable: false),
|
||||
WorkerId = table.Column<string>(type: "text", nullable: false),
|
||||
ProductId = table.Column<string>(type: "text", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Productions", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_Productions_Products_ProductId",
|
||||
column: x => x.ProductId,
|
||||
principalTable: "Products",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "FK_Productions_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),
|
||||
SalaryDate = table.Column<DateTime>(type: "timestamp without time zone", nullable: false),
|
||||
WorkerSalary = table.Column<double>(type: "double precision", 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_IngredientHistories_IngredienId",
|
||||
table: "IngredientHistories",
|
||||
column: "IngredienId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Ingredients_NameIngredients",
|
||||
table: "Ingredients",
|
||||
column: "NameIngredients",
|
||||
unique: true);
|
||||
|
||||
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_ProductHistories_ProductId",
|
||||
table: "ProductHistories",
|
||||
column: "ProductId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_ProductIngredients_IngredientId",
|
||||
table: "ProductIngredients",
|
||||
column: "IngredientId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Productions_ProductId",
|
||||
table: "Productions",
|
||||
column: "ProductId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Productions_WorkerId",
|
||||
table: "Productions",
|
||||
column: "WorkerId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Products_Name_IsDeleted",
|
||||
table: "Products",
|
||||
columns: new[] { "Name", "IsDeleted" },
|
||||
unique: true,
|
||||
filter: "\"IsDeleted\" = FALSE");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Salaries_WorkerId",
|
||||
table: "Salaries",
|
||||
column: "WorkerId");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "IngredientHistories");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Posts");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "ProductHistories");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "ProductIngredients");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Productions");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Salaries");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Ingredients");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Products");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Workers");
|
||||
}
|
||||
}
|
||||
}
|
||||
364
SladkieBulki/SladkieBulkiDatabase/Migrations/20250520203540_ChangeFieldsInPost.Designer.cs
generated
Normal file
364
SladkieBulki/SladkieBulkiDatabase/Migrations/20250520203540_ChangeFieldsInPost.Designer.cs
generated
Normal file
@@ -0,0 +1,364 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
using SladkieBulkiDatabase;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace SladkieBulkiDatabase.Migrations
|
||||
{
|
||||
[DbContext(typeof(SladkieBulkiDbContext))]
|
||||
[Migration("20250520203540_ChangeFieldsInPost")]
|
||||
partial class ChangeFieldsInPost
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "9.0.4")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.Ingredient", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<double>("InitPrice")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.Property<string>("NameIngredients")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("SizeInit")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("NameIngredients")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("Ingredients");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.IngredientHistory", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("ChangeDate")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<string>("IngredienId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<double>("OldPrice")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("IngredienId");
|
||||
|
||||
b.ToTable("IngredientHistories");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.Post", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("ChangeDate")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<string>("Configuration")
|
||||
.IsRequired()
|
||||
.HasColumnType("jsonb");
|
||||
|
||||
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.HasKey("Id");
|
||||
|
||||
b.HasIndex("PostId", "IsActual")
|
||||
.IsUnique()
|
||||
.HasFilter("\"IsActual\" = TRUE");
|
||||
|
||||
b.HasIndex("PostName", "IsActual")
|
||||
.IsUnique()
|
||||
.HasFilter("\"IsActual\" = TRUE");
|
||||
|
||||
b.ToTable("Posts");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.Product", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Description")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<bool>("IsDeleted")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("ProductType")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("UnitPrice")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("Name", "IsDeleted")
|
||||
.IsUnique()
|
||||
.HasFilter("\"IsDeleted\" = FALSE");
|
||||
|
||||
b.ToTable("Products");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.ProductHistory", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("ChangeDate")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<double>("OldPrice")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.Property<string>("ProductId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ProductId");
|
||||
|
||||
b.ToTable("ProductHistories");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.ProductIngredient", b =>
|
||||
{
|
||||
b.Property<string>("ProductId")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("IngredientId")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("ProductId", "IngredientId");
|
||||
|
||||
b.HasIndex("IngredientId");
|
||||
|
||||
b.ToTable("ProductIngredients");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.Production", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<string>("ProductId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("ProductionDate")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<double>("Sum")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.Property<string>("WorkerId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ProductId");
|
||||
|
||||
b.HasIndex("WorkerId");
|
||||
|
||||
b.ToTable("Productions");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.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("SladkieBulkiDatabase.Models.Worker", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("BirthDate")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<string>("Email")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
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("SladkieBulkiDatabase.Models.IngredientHistory", b =>
|
||||
{
|
||||
b.HasOne("SladkieBulkiDatabase.Models.Ingredient", "Ingredient")
|
||||
.WithMany("IngredientHistory")
|
||||
.HasForeignKey("IngredienId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Ingredient");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.ProductHistory", b =>
|
||||
{
|
||||
b.HasOne("SladkieBulkiDatabase.Models.Product", "Product")
|
||||
.WithMany("ProductHistories")
|
||||
.HasForeignKey("ProductId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Product");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.ProductIngredient", b =>
|
||||
{
|
||||
b.HasOne("SladkieBulkiDatabase.Models.Ingredient", "Ingredient")
|
||||
.WithMany("ProductIngredients")
|
||||
.HasForeignKey("IngredientId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("SladkieBulkiDatabase.Models.Product", "Product")
|
||||
.WithMany("ProductIngredients")
|
||||
.HasForeignKey("ProductId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Ingredient");
|
||||
|
||||
b.Navigation("Product");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.Production", b =>
|
||||
{
|
||||
b.HasOne("SladkieBulkiDatabase.Models.Product", "Product")
|
||||
.WithMany("Productions")
|
||||
.HasForeignKey("ProductId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("SladkieBulkiDatabase.Models.Worker", "Worker")
|
||||
.WithMany("Productions")
|
||||
.HasForeignKey("WorkerId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Product");
|
||||
|
||||
b.Navigation("Worker");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.Salary", b =>
|
||||
{
|
||||
b.HasOne("SladkieBulkiDatabase.Models.Worker", "Worker")
|
||||
.WithMany("Salaries")
|
||||
.HasForeignKey("WorkerId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Worker");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.Ingredient", b =>
|
||||
{
|
||||
b.Navigation("IngredientHistory");
|
||||
|
||||
b.Navigation("ProductIngredients");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.Product", b =>
|
||||
{
|
||||
b.Navigation("ProductHistories");
|
||||
|
||||
b.Navigation("ProductIngredients");
|
||||
|
||||
b.Navigation("Productions");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.Worker", b =>
|
||||
{
|
||||
b.Navigation("Productions");
|
||||
|
||||
b.Navigation("Salaries");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace SladkieBulkiDatabase.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class ChangeFieldsInPost : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropColumn(
|
||||
name: "Salary",
|
||||
table: "Posts");
|
||||
|
||||
migrationBuilder.AddColumn<string>(
|
||||
name: "Configuration",
|
||||
table: "Posts",
|
||||
type: "jsonb",
|
||||
nullable: false,
|
||||
defaultValue: "{\"Rate\": 0, \"Type\": \"PostConfiguration\"}");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropColumn(
|
||||
name: "Configuration",
|
||||
table: "Posts");
|
||||
|
||||
migrationBuilder.AddColumn<double>(
|
||||
name: "Salary",
|
||||
table: "Posts",
|
||||
type: "double precision",
|
||||
nullable: false,
|
||||
defaultValue: 0.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
367
SladkieBulki/SladkieBulkiDatabase/Migrations/20250520222914_AddDateOfDeleteInWorker.Designer.cs
generated
Normal file
367
SladkieBulki/SladkieBulkiDatabase/Migrations/20250520222914_AddDateOfDeleteInWorker.Designer.cs
generated
Normal file
@@ -0,0 +1,367 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
using SladkieBulkiDatabase;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace SladkieBulkiDatabase.Migrations
|
||||
{
|
||||
[DbContext(typeof(SladkieBulkiDbContext))]
|
||||
[Migration("20250520222914_AddDateOfDeleteInWorker")]
|
||||
partial class AddDateOfDeleteInWorker
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "9.0.4")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.Ingredient", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<double>("InitPrice")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.Property<string>("NameIngredients")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("SizeInit")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("NameIngredients")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("Ingredients");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.IngredientHistory", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("ChangeDate")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<string>("IngredienId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<double>("OldPrice")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("IngredienId");
|
||||
|
||||
b.ToTable("IngredientHistories");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.Post", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("ChangeDate")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<string>("Configuration")
|
||||
.IsRequired()
|
||||
.HasColumnType("jsonb");
|
||||
|
||||
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.HasKey("Id");
|
||||
|
||||
b.HasIndex("PostId", "IsActual")
|
||||
.IsUnique()
|
||||
.HasFilter("\"IsActual\" = TRUE");
|
||||
|
||||
b.HasIndex("PostName", "IsActual")
|
||||
.IsUnique()
|
||||
.HasFilter("\"IsActual\" = TRUE");
|
||||
|
||||
b.ToTable("Posts");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.Product", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Description")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<bool>("IsDeleted")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("ProductType")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("UnitPrice")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("Name", "IsDeleted")
|
||||
.IsUnique()
|
||||
.HasFilter("\"IsDeleted\" = FALSE");
|
||||
|
||||
b.ToTable("Products");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.ProductHistory", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("ChangeDate")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<double>("OldPrice")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.Property<string>("ProductId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ProductId");
|
||||
|
||||
b.ToTable("ProductHistories");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.ProductIngredient", b =>
|
||||
{
|
||||
b.Property<string>("ProductId")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("IngredientId")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("ProductId", "IngredientId");
|
||||
|
||||
b.HasIndex("IngredientId");
|
||||
|
||||
b.ToTable("ProductIngredients");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.Production", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<string>("ProductId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("ProductionDate")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<double>("Sum")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.Property<string>("WorkerId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ProductId");
|
||||
|
||||
b.HasIndex("WorkerId");
|
||||
|
||||
b.ToTable("Productions");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.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("SladkieBulkiDatabase.Models.Worker", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("BirthDate")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<DateTime?>("DateOfDelete")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<string>("Email")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
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("SladkieBulkiDatabase.Models.IngredientHistory", b =>
|
||||
{
|
||||
b.HasOne("SladkieBulkiDatabase.Models.Ingredient", "Ingredient")
|
||||
.WithMany("IngredientHistory")
|
||||
.HasForeignKey("IngredienId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Ingredient");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.ProductHistory", b =>
|
||||
{
|
||||
b.HasOne("SladkieBulkiDatabase.Models.Product", "Product")
|
||||
.WithMany("ProductHistories")
|
||||
.HasForeignKey("ProductId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Product");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.ProductIngredient", b =>
|
||||
{
|
||||
b.HasOne("SladkieBulkiDatabase.Models.Ingredient", "Ingredient")
|
||||
.WithMany("ProductIngredients")
|
||||
.HasForeignKey("IngredientId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("SladkieBulkiDatabase.Models.Product", "Product")
|
||||
.WithMany("ProductIngredients")
|
||||
.HasForeignKey("ProductId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Ingredient");
|
||||
|
||||
b.Navigation("Product");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.Production", b =>
|
||||
{
|
||||
b.HasOne("SladkieBulkiDatabase.Models.Product", "Product")
|
||||
.WithMany("Productions")
|
||||
.HasForeignKey("ProductId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("SladkieBulkiDatabase.Models.Worker", "Worker")
|
||||
.WithMany("Productions")
|
||||
.HasForeignKey("WorkerId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Product");
|
||||
|
||||
b.Navigation("Worker");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.Salary", b =>
|
||||
{
|
||||
b.HasOne("SladkieBulkiDatabase.Models.Worker", "Worker")
|
||||
.WithMany("Salaries")
|
||||
.HasForeignKey("WorkerId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Worker");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.Ingredient", b =>
|
||||
{
|
||||
b.Navigation("IngredientHistory");
|
||||
|
||||
b.Navigation("ProductIngredients");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.Product", b =>
|
||||
{
|
||||
b.Navigation("ProductHistories");
|
||||
|
||||
b.Navigation("ProductIngredients");
|
||||
|
||||
b.Navigation("Productions");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.Worker", b =>
|
||||
{
|
||||
b.Navigation("Productions");
|
||||
|
||||
b.Navigation("Salaries");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace SladkieBulkiDatabase.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class AddDateOfDeleteInWorker : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddColumn<DateTime>(
|
||||
name: "DateOfDelete",
|
||||
table: "Workers",
|
||||
type: "timestamp without time zone",
|
||||
nullable: true);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropColumn(
|
||||
name: "DateOfDelete",
|
||||
table: "Workers");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,364 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
using SladkieBulkiDatabase;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace SladkieBulkiDatabase.Migrations
|
||||
{
|
||||
[DbContext(typeof(SladkieBulkiDbContext))]
|
||||
partial class SladkieBulkiDbContextModelSnapshot : ModelSnapshot
|
||||
{
|
||||
protected override void BuildModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "9.0.4")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.Ingredient", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<double>("InitPrice")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.Property<string>("NameIngredients")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("SizeInit")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("NameIngredients")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("Ingredients");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.IngredientHistory", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("ChangeDate")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<string>("IngredienId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<double>("OldPrice")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("IngredienId");
|
||||
|
||||
b.ToTable("IngredientHistories");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.Post", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("ChangeDate")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<string>("Configuration")
|
||||
.IsRequired()
|
||||
.HasColumnType("jsonb");
|
||||
|
||||
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.HasKey("Id");
|
||||
|
||||
b.HasIndex("PostId", "IsActual")
|
||||
.IsUnique()
|
||||
.HasFilter("\"IsActual\" = TRUE");
|
||||
|
||||
b.HasIndex("PostName", "IsActual")
|
||||
.IsUnique()
|
||||
.HasFilter("\"IsActual\" = TRUE");
|
||||
|
||||
b.ToTable("Posts");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.Product", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Description")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<bool>("IsDeleted")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("ProductType")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("UnitPrice")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("Name", "IsDeleted")
|
||||
.IsUnique()
|
||||
.HasFilter("\"IsDeleted\" = FALSE");
|
||||
|
||||
b.ToTable("Products");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.ProductHistory", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("ChangeDate")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<double>("OldPrice")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.Property<string>("ProductId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ProductId");
|
||||
|
||||
b.ToTable("ProductHistories");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.ProductIngredient", b =>
|
||||
{
|
||||
b.Property<string>("ProductId")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("IngredientId")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("ProductId", "IngredientId");
|
||||
|
||||
b.HasIndex("IngredientId");
|
||||
|
||||
b.ToTable("ProductIngredients");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.Production", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<string>("ProductId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("ProductionDate")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<double>("Sum")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.Property<string>("WorkerId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ProductId");
|
||||
|
||||
b.HasIndex("WorkerId");
|
||||
|
||||
b.ToTable("Productions");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.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("SladkieBulkiDatabase.Models.Worker", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("BirthDate")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<DateTime?>("DateOfDelete")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<string>("Email")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
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("SladkieBulkiDatabase.Models.IngredientHistory", b =>
|
||||
{
|
||||
b.HasOne("SladkieBulkiDatabase.Models.Ingredient", "Ingredient")
|
||||
.WithMany("IngredientHistory")
|
||||
.HasForeignKey("IngredienId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Ingredient");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.ProductHistory", b =>
|
||||
{
|
||||
b.HasOne("SladkieBulkiDatabase.Models.Product", "Product")
|
||||
.WithMany("ProductHistories")
|
||||
.HasForeignKey("ProductId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Product");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.ProductIngredient", b =>
|
||||
{
|
||||
b.HasOne("SladkieBulkiDatabase.Models.Ingredient", "Ingredient")
|
||||
.WithMany("ProductIngredients")
|
||||
.HasForeignKey("IngredientId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("SladkieBulkiDatabase.Models.Product", "Product")
|
||||
.WithMany("ProductIngredients")
|
||||
.HasForeignKey("ProductId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Ingredient");
|
||||
|
||||
b.Navigation("Product");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.Production", b =>
|
||||
{
|
||||
b.HasOne("SladkieBulkiDatabase.Models.Product", "Product")
|
||||
.WithMany("Productions")
|
||||
.HasForeignKey("ProductId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("SladkieBulkiDatabase.Models.Worker", "Worker")
|
||||
.WithMany("Productions")
|
||||
.HasForeignKey("WorkerId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Product");
|
||||
|
||||
b.Navigation("Worker");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.Salary", b =>
|
||||
{
|
||||
b.HasOne("SladkieBulkiDatabase.Models.Worker", "Worker")
|
||||
.WithMany("Salaries")
|
||||
.HasForeignKey("WorkerId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Worker");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.Ingredient", b =>
|
||||
{
|
||||
b.Navigation("IngredientHistory");
|
||||
|
||||
b.Navigation("ProductIngredients");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.Product", b =>
|
||||
{
|
||||
b.Navigation("ProductHistories");
|
||||
|
||||
b.Navigation("ProductIngredients");
|
||||
|
||||
b.Navigation("Productions");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SladkieBulkiDatabase.Models.Worker", b =>
|
||||
{
|
||||
b.Navigation("Productions");
|
||||
|
||||
b.Navigation("Salaries");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using SladkieBulkiContrakts.Enums;
|
||||
using SladkieBulkiContrakts.Infrastructure.PostConfigurations;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -13,7 +14,7 @@ internal class Post
|
||||
public required string PostId { get; set; }
|
||||
public required string PostName { get; set; }
|
||||
public PostType PostType { get; set; }
|
||||
public double Salary { get; set; }
|
||||
public required PostConfiguration Configuration { get; set; }
|
||||
public bool IsActual { get; set; }
|
||||
public DateTime ChangeDate { get; set; }
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ internal class Worker
|
||||
public DateTime EmploymentDate { get; set; }
|
||||
public bool IsDeleted { get; set; }
|
||||
public required string Email { get; set; }
|
||||
public DateTime? DateOfDelete { get; set; }
|
||||
|
||||
[NotMapped]
|
||||
public Post? Post { get; set; }
|
||||
|
||||
16
SladkieBulki/SladkieBulkiDatabase/SampleContextFactory.cs
Normal file
16
SladkieBulki/SladkieBulkiDatabase/SampleContextFactory.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using Microsoft.EntityFrameworkCore.Design;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SladkieBulkiDatabase;
|
||||
|
||||
internal class SampleContextFactory : IDesignTimeDbContextFactory<SladkieBulkiDbContext>
|
||||
{
|
||||
public SladkieBulkiDbContext CreateDbContext(string[] args)
|
||||
{
|
||||
return new SladkieBulkiDbContext(new DefaultConfigurationDatabase());
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,11 @@
|
||||
<ItemGroup>
|
||||
<PackageReference Include="AutoMapper" Version="14.0.0" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.4" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="9.0.4">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.0.4" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using SladkieBulkiContrakts.Infrastructure;
|
||||
using SladkieBulkiContrakts.Infrastructure.PostConfigurations;
|
||||
using SladkieBulkiDatabase.Models;
|
||||
using System;
|
||||
|
||||
@@ -43,6 +46,14 @@ internal class SladkieBulkiDbContext: DbContext
|
||||
.HasFilter($"\"{nameof(Product.IsDeleted)}\" = FALSE");
|
||||
|
||||
modelBuilder.Entity<ProductIngredient>().HasKey(x => new { x.ProductId, x.IngredientId });
|
||||
|
||||
modelBuilder.Entity<Post>()
|
||||
.Property(x => x.Configuration)
|
||||
.HasColumnType("jsonb")
|
||||
.HasConversion(
|
||||
x => SerializePostConfiguration(x),
|
||||
x => DeserialzePostConfiguration(x)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -55,5 +66,12 @@ internal class SladkieBulkiDbContext: DbContext
|
||||
public DbSet<Production> Productions { get; set; }
|
||||
public DbSet<ProductIngredient> ProductIngredients { 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(ManufacturerPostConfiguration) => JsonConvert.DeserializeObject<ManufacturerPostConfiguration>(jsonString)!,
|
||||
nameof(PackerPostConfiguration) => JsonConvert.DeserializeObject<PackerPostConfiguration>(jsonString)!,
|
||||
_ => JsonConvert.DeserializeObject<PostConfiguration>(jsonString)!,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ using SladkieBulkiContrakts.Exceptions;
|
||||
using SladkieBulkiContrakts.StoragesContarcts;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Moq;
|
||||
using SladkieBulkiContrakts.Infrastructure.PostConfigurations;
|
||||
|
||||
namespace SladkieBulkiTests.BusinessLogicsContractsTests;
|
||||
|
||||
@@ -33,9 +34,9 @@ internal class PostBusinessLogicContractTests
|
||||
//Arrange
|
||||
var listOriginal = new List<PostDataModel>()
|
||||
{
|
||||
new(Guid.NewGuid().ToString(),"name 1", PostType.Manufacturer, 10),
|
||||
new(Guid.NewGuid().ToString(), "name 2", PostType.Manufacturer, 10),
|
||||
new(Guid.NewGuid().ToString(), "name 3", PostType.Manufacturer, 10),
|
||||
new(Guid.NewGuid().ToString(),"name 1", PostType.Manufacturer, new PostConfiguration() { Rate = 10 }),
|
||||
new(Guid.NewGuid().ToString(), "name 2", PostType.Manufacturer, new PostConfiguration() { Rate = 10 }),
|
||||
new(Guid.NewGuid().ToString(), "name 3", PostType.Manufacturer, new PostConfiguration() { Rate = 10 }),
|
||||
};
|
||||
_postStorageContract.Setup(x => x.GetList()).Returns(listOriginal);
|
||||
//Act
|
||||
@@ -89,8 +90,8 @@ internal class PostBusinessLogicContractTests
|
||||
var postId = Guid.NewGuid().ToString();
|
||||
var listOriginal = new List<PostDataModel>()
|
||||
{
|
||||
new(postId, "name 1", PostType.Manufacturer, 10),
|
||||
new(postId, "name 2", PostType.Manufacturer, 10)
|
||||
new(postId, "name 1", PostType.Manufacturer, new PostConfiguration() { Rate = 10 }),
|
||||
new(postId, "name 2", PostType.Manufacturer, new PostConfiguration() { Rate = 10 })
|
||||
};
|
||||
_postStorageContract.Setup(x => x.GetPostWithHistory(It.IsAny<string>())).Returns(listOriginal);
|
||||
//Act
|
||||
@@ -154,7 +155,7 @@ internal class PostBusinessLogicContractTests
|
||||
{
|
||||
//Arrange
|
||||
var id = Guid.NewGuid().ToString();
|
||||
var record = new PostDataModel(id, "name", PostType.Manufacturer, 10);
|
||||
var record = new PostDataModel(id, "name", PostType.Manufacturer, new PostConfiguration() { Rate = 10 });
|
||||
_postStorageContract.Setup(x => x.GetElementById(id)).Returns(record);
|
||||
//Act
|
||||
var element = _postBusinessLogicContract.GetPostByData(id);
|
||||
@@ -169,7 +170,7 @@ internal class PostBusinessLogicContractTests
|
||||
{
|
||||
//Arrange
|
||||
var postName = "name";
|
||||
var record = new PostDataModel(Guid.NewGuid().ToString(), postName, PostType.Manufacturer, 10);
|
||||
var record = new PostDataModel(Guid.NewGuid().ToString(), postName, PostType.Manufacturer, new PostConfiguration() { Rate = 10 });
|
||||
_postStorageContract.Setup(x => x.GetElementByName(postName)).Returns(record);
|
||||
//Act
|
||||
var element = _postBusinessLogicContract.GetPostByData(postName);
|
||||
@@ -225,12 +226,12 @@ internal class PostBusinessLogicContractTests
|
||||
{
|
||||
//Arrange
|
||||
var flag = false;
|
||||
var record = new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.Preform, 10);
|
||||
var record = new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.Preform, new PostConfiguration() { Rate = 10 });
|
||||
_postStorageContract.Setup(x => x.AddElement(It.IsAny<PostDataModel>()))
|
||||
.Callback((PostDataModel x) =>
|
||||
{
|
||||
flag = x.Id == record.Id && x.PostName == record.PostName && x.PostType == record.PostType && x.Salary == record.Salary;
|
||||
});
|
||||
flag = x.Id == record.Id && x.PostName == record.PostName && x.PostType == record.PostType && x.ConfigurationModel.Rate == record.ConfigurationModel.Rate;
|
||||
});
|
||||
//Act
|
||||
_postBusinessLogicContract.InsertPost(record);
|
||||
//Assert
|
||||
@@ -244,7 +245,7 @@ internal class PostBusinessLogicContractTests
|
||||
//Arrange
|
||||
_postStorageContract.Setup(x => x.AddElement(It.IsAny<PostDataModel>())).Throws(new ElementExistsException("Data", "Data"));
|
||||
//Act&Assert
|
||||
Assert.That(() => _postBusinessLogicContract.InsertPost(new(Guid.NewGuid().ToString(), "name", PostType.Preform, 10)), Throws.TypeOf<ElementExistsException>());
|
||||
Assert.That(() => _postBusinessLogicContract.InsertPost(new(Guid.NewGuid().ToString(), "name", PostType.Preform, new PostConfiguration() { Rate = 10 })), Throws.TypeOf<ElementExistsException>());
|
||||
_postStorageContract.Verify(x => x.AddElement(It.IsAny<PostDataModel>()), Times.Once);
|
||||
}
|
||||
|
||||
@@ -260,7 +261,7 @@ internal class PostBusinessLogicContractTests
|
||||
public void InsertPost_InvalidRecord_ThrowException_Test()
|
||||
{
|
||||
//Act&Assert
|
||||
Assert.That(() => _postBusinessLogicContract.InsertPost(new PostDataModel("id", "name", PostType.Preform, 10)), Throws.TypeOf<ValidationException>());
|
||||
Assert.That(() => _postBusinessLogicContract.InsertPost(new PostDataModel("id", "name", PostType.Preform, new PostConfiguration() { Rate = 10 })), Throws.TypeOf<ValidationException>());
|
||||
_postStorageContract.Verify(x => x.AddElement(It.IsAny<PostDataModel>()), Times.Never);
|
||||
}
|
||||
|
||||
@@ -270,7 +271,7 @@ internal class PostBusinessLogicContractTests
|
||||
//Arrange
|
||||
_postStorageContract.Setup(x => x.AddElement(It.IsAny<PostDataModel>())).Throws(new StorageException(new InvalidOperationException()));
|
||||
//Act&Assert
|
||||
Assert.That(() => _postBusinessLogicContract.InsertPost(new(Guid.NewGuid().ToString(), "name", PostType.Preform, 10)), Throws.TypeOf<StorageException>());
|
||||
Assert.That(() => _postBusinessLogicContract.InsertPost(new(Guid.NewGuid().ToString(), "name", PostType.Preform, new PostConfiguration() { Rate = 10 })), Throws.TypeOf<StorageException>());
|
||||
_postStorageContract.Verify(x => x.AddElement(It.IsAny<PostDataModel>()), Times.Once);
|
||||
}
|
||||
|
||||
@@ -279,12 +280,12 @@ internal class PostBusinessLogicContractTests
|
||||
{
|
||||
//Arrange
|
||||
var flag = false;
|
||||
var record = new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.Preform, 10);
|
||||
var record = new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.Preform, new PostConfiguration() { Rate = 10 });
|
||||
_postStorageContract.Setup(x => x.UpdElement(It.IsAny<PostDataModel>()))
|
||||
.Callback((PostDataModel x) =>
|
||||
{
|
||||
flag = x.Id == record.Id && x.PostName == record.PostName && x.PostType == record.PostType && x.Salary == record.Salary;
|
||||
});
|
||||
flag = x.Id == record.Id && x.PostName == record.PostName && x.PostType == record.PostType && x.ConfigurationModel.Rate == record.ConfigurationModel.Rate;
|
||||
});
|
||||
//Act
|
||||
_postBusinessLogicContract.UpdatePost(record);
|
||||
//Assert
|
||||
@@ -298,7 +299,7 @@ internal class PostBusinessLogicContractTests
|
||||
//Arrange
|
||||
_postStorageContract.Setup(x => x.UpdElement(It.IsAny<PostDataModel>())).Throws(new ElementNotFoundException(""));
|
||||
//Act&Assert
|
||||
Assert.That(() => _postBusinessLogicContract.UpdatePost(new(Guid.NewGuid().ToString(), "name", PostType.Preform, 10)), Throws.TypeOf<ElementNotFoundException>());
|
||||
Assert.That(() => _postBusinessLogicContract.UpdatePost(new(Guid.NewGuid().ToString(), "name", PostType.Preform, new PostConfiguration() { Rate = 10 })), Throws.TypeOf<ElementNotFoundException>());
|
||||
_postStorageContract.Verify(x => x.UpdElement(It.IsAny<PostDataModel>()), Times.Once);
|
||||
}
|
||||
|
||||
@@ -308,7 +309,7 @@ internal class PostBusinessLogicContractTests
|
||||
//Arrange
|
||||
_postStorageContract.Setup(x => x.UpdElement(It.IsAny<PostDataModel>())).Throws(new ElementExistsException("Data", "Data"));
|
||||
//Act&Assert
|
||||
Assert.That(() => _postBusinessLogicContract.UpdatePost(new(Guid.NewGuid().ToString(), "anme", PostType.Preform, 10)), Throws.TypeOf<ElementExistsException>());
|
||||
Assert.That(() => _postBusinessLogicContract.UpdatePost(new(Guid.NewGuid().ToString(), "anme", PostType.Preform, new PostConfiguration() { Rate = 10 })), Throws.TypeOf<ElementExistsException>());
|
||||
_postStorageContract.Verify(x => x.UpdElement(It.IsAny<PostDataModel>()), Times.Once);
|
||||
}
|
||||
|
||||
@@ -324,7 +325,7 @@ internal class PostBusinessLogicContractTests
|
||||
public void UpdatePost_InvalidRecord_ThrowException_Test()
|
||||
{
|
||||
//Act&Assert
|
||||
Assert.That(() => _postBusinessLogicContract.UpdatePost(new PostDataModel("id", "name", PostType.Preform, 10)), Throws.TypeOf<ValidationException>());
|
||||
Assert.That(() => _postBusinessLogicContract.UpdatePost(new PostDataModel("id", "name", PostType.Preform, new PostConfiguration() { Rate = 10 })), Throws.TypeOf<ValidationException>());
|
||||
_postStorageContract.Verify(x => x.UpdElement(It.IsAny<PostDataModel>()), Times.Never);
|
||||
}
|
||||
|
||||
@@ -334,7 +335,7 @@ internal class PostBusinessLogicContractTests
|
||||
//Arrange
|
||||
_postStorageContract.Setup(x => x.UpdElement(It.IsAny<PostDataModel>())).Throws(new StorageException(new InvalidOperationException()));
|
||||
//Act&Assert
|
||||
Assert.That(() => _postBusinessLogicContract.UpdatePost(new(Guid.NewGuid().ToString(), "name", PostType.Preform, 10)), Throws.TypeOf<StorageException>());
|
||||
Assert.That(() => _postBusinessLogicContract.UpdatePost(new(Guid.NewGuid().ToString(), "name", PostType.Preform, new PostConfiguration() { Rate = 10 })), Throws.TypeOf<StorageException>());
|
||||
_postStorageContract.Verify(x => x.UpdElement(It.IsAny<PostDataModel>()), Times.Once);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,9 @@ using SladkieBulkiBusinessLogic.Implementations;
|
||||
using SladkieBulkiContrakts.DataModels;
|
||||
using SladkieBulkiContrakts.Enums;
|
||||
using SladkieBulkiContrakts.Exceptions;
|
||||
using SladkieBulkiContrakts.Infrastructure.PostConfigurations;
|
||||
using SladkieBulkiContrakts.StoragesContarcts;
|
||||
using SladkieBulkiTests.Infrastructure;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -20,6 +22,7 @@ internal class SalaryBusinessLogicContractTests
|
||||
private Mock<IProductionStorageContract> _productionStorageContract;
|
||||
private Mock<IPostStorageContract> _postStorageContract;
|
||||
private Mock<IWorkerStorageContract> _workerStorageContract;
|
||||
private readonly ConfigurationSalaryTest _salaryConfigurationTest = new();
|
||||
|
||||
[OneTimeSetUp]
|
||||
public void OneTimeSetUp()
|
||||
@@ -29,7 +32,8 @@ internal class SalaryBusinessLogicContractTests
|
||||
_postStorageContract = new Mock<IPostStorageContract>();
|
||||
_workerStorageContract = new Mock<IWorkerStorageContract>();
|
||||
_salaryBusinessLogicContract = new SalaryBusinessLogicContract(_salaryStorageContract.Object,
|
||||
_productionStorageContract.Object, _postStorageContract.Object, _workerStorageContract.Object, new Mock<ILogger>().Object);
|
||||
_productionStorageContract.Object, _postStorageContract.Object, _workerStorageContract.Object, new Mock<ILogger>().Object, _salaryConfigurationTest);
|
||||
|
||||
}
|
||||
|
||||
[SetUp]
|
||||
@@ -195,7 +199,7 @@ internal class SalaryBusinessLogicContractTests
|
||||
_productionStorageContract.Setup(x => x.GetList(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<string>(), It.IsAny<string>()))
|
||||
.Returns([new ProductionDataModel(Guid.NewGuid().ToString(), DateTime.Now, 0, saleSum, workerId, null)]);
|
||||
_postStorageContract.Setup(x => x.GetElementById(It.IsAny<string>()))
|
||||
.Returns(new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.Manufacturer, postSalary));
|
||||
.Returns(new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.Manufacturer, new ManufacturerPostConfiguration { Rate = postSalary, SalePercent = 0.1 }));
|
||||
_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, "1@mail.ru"),]);
|
||||
var sum = 0.0;
|
||||
@@ -230,7 +234,7 @@ internal class SalaryBusinessLogicContractTests
|
||||
new ProductionDataModel(Guid.NewGuid().ToString(), DateTime.Now, 0, 0.0, worker3Id, null),
|
||||
new ProductionDataModel(Guid.NewGuid().ToString(), DateTime.Now, 0, 0.0, worker3Id, null)]);
|
||||
_postStorageContract.Setup(x => x.GetElementById(It.IsAny<string>()))
|
||||
.Returns(new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.Manufacturer, 2000));
|
||||
.Returns(new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.Manufacturer, new PostConfiguration() { Rate = 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
|
||||
@@ -248,7 +252,7 @@ internal class SalaryBusinessLogicContractTests
|
||||
_productionStorageContract.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.Manufacturer, postSalary));
|
||||
.Returns(new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.Manufacturer, new PostConfiguration() { Rate = 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, "1@mail.ru")]);
|
||||
var sum = 0.0;
|
||||
@@ -270,7 +274,7 @@ internal class SalaryBusinessLogicContractTests
|
||||
//Arrange
|
||||
var workerId = Guid.NewGuid().ToString();
|
||||
_postStorageContract.Setup(x => x.GetElementById(It.IsAny<string>()))
|
||||
.Returns(new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.Manufacturer, 2000));
|
||||
.Returns(new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.Manufacturer, new PostConfiguration() { Rate = 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, "1@mail.ru")]);
|
||||
//Act&Assert
|
||||
@@ -298,7 +302,7 @@ internal class SalaryBusinessLogicContractTests
|
||||
_productionStorageContract.Setup(x => x.GetList(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<string>(), It.IsAny<string>()))
|
||||
.Returns([new ProductionDataModel(Guid.NewGuid().ToString(), DateTime.Now, 0, 200.0, workerId, null)]);
|
||||
_postStorageContract.Setup(x => x.GetElementById(It.IsAny<string>()))
|
||||
.Returns(new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.Manufacturer, 2000));
|
||||
.Returns(new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.Manufacturer, new PostConfiguration() { Rate = 2000 }));
|
||||
//Act&Assert
|
||||
Assert.That(() => _salaryBusinessLogicContract.CalculateSalaryByMounth(DateTime.UtcNow), Throws.TypeOf<NullListException>());
|
||||
}
|
||||
@@ -311,7 +315,7 @@ internal class SalaryBusinessLogicContractTests
|
||||
_productionStorageContract.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.Manufacturer, 2000));
|
||||
.Returns(new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.Manufacturer, new PostConfiguration() { Rate = 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, "1@mail.ru")]);
|
||||
//Act&Assert
|
||||
@@ -341,7 +345,7 @@ internal class SalaryBusinessLogicContractTests
|
||||
_productionStorageContract.Setup(x => x.GetList(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<string>(), It.IsAny<string>()))
|
||||
.Returns([new ProductionDataModel(Guid.NewGuid().ToString(), DateTime.Now, 0, 200.0, workerId, null)]);
|
||||
_postStorageContract.Setup(x => x.GetElementById(It.IsAny<string>()))
|
||||
.Returns(new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.Manufacturer, 2000));
|
||||
.Returns(new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.Manufacturer, new PostConfiguration() { Rate = 200 }));
|
||||
_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
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using SladkieBulkiContrakts.DataModels;
|
||||
using SladkieBulkiContrakts.Enums;
|
||||
using SladkieBulkiContrakts.Infrastructure.PostConfigurations;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -14,41 +15,49 @@ internal class PostDataModelTests
|
||||
[Test]
|
||||
public void IdIsNullOrEmptyTest()
|
||||
{
|
||||
var post = CreateDataModel(null, "name", PostType.Preform, 10);
|
||||
var post = CreateDataModel(null, "name", PostType.Manufacturer, new PostConfiguration() { Rate = 10 });
|
||||
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||
post = CreateDataModel(string.Empty, "name", PostType.Preform, 10);
|
||||
post = CreateDataModel(string.Empty, "name", PostType.Manufacturer, new PostConfiguration() { Rate = 10 });
|
||||
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IdIsNotGuidTest()
|
||||
{
|
||||
var post = CreateDataModel("id", "name", PostType.Preform, 10);
|
||||
var post = CreateDataModel("id", "name", PostType.Manufacturer, new PostConfiguration() { Rate = 10 });
|
||||
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PostNameIsEmptyTest()
|
||||
{
|
||||
var manufacturer = CreateDataModel(Guid.NewGuid().ToString(), null, PostType.Preform, 10);
|
||||
var manufacturer = CreateDataModel(Guid.NewGuid().ToString(), null, PostType.Manufacturer, new PostConfiguration() { Rate = 10 });
|
||||
Assert.That(() => manufacturer.Validate(), Throws.TypeOf<ValidationException>());
|
||||
manufacturer = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, PostType.Preform, 10);
|
||||
manufacturer = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, PostType.Manufacturer, new PostConfiguration() { Rate = 10 });
|
||||
Assert.That(() => manufacturer.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PostTypeIsNoneTest()
|
||||
{
|
||||
var post = CreateDataModel(Guid.NewGuid().ToString(), "name", PostType.None, 10);
|
||||
var post = CreateDataModel(Guid.NewGuid().ToString(), "name", PostType.None, new PostConfiguration() { Rate = 10 });
|
||||
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SalaryIsLessOrZeroTest()
|
||||
public void ConfigurationModelIsNullTest()
|
||||
{
|
||||
var post = CreateDataModel(Guid.NewGuid().ToString(), "name", PostType.Preform, 0);
|
||||
var post = CreateDataModel(Guid.NewGuid().ToString(), "name", PostType.Manufacturer, null);
|
||||
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||
post = CreateDataModel(Guid.NewGuid().ToString(), "name", PostType.Preform, -10);
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void RateIsLessOrZeroTest()
|
||||
{
|
||||
var post = CreateDataModel(Guid.NewGuid().ToString(), "name", PostType.Manufacturer, new PostConfiguration() { Rate = 0 });
|
||||
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||
post = CreateDataModel(Guid.NewGuid().ToString(), "name", PostType.Manufacturer, new PostConfiguration() { Rate = -10 });
|
||||
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
@@ -57,21 +66,20 @@ internal class PostDataModelTests
|
||||
{
|
||||
var postId = Guid.NewGuid().ToString();
|
||||
var postName = "name";
|
||||
var postType = PostType.Preform;
|
||||
var salary = 10;
|
||||
var isActual = false;
|
||||
var changeDate = DateTime.UtcNow.AddDays(-1);
|
||||
var post = CreateDataModel(postId, postName, postType, salary);
|
||||
var postType = PostType.Manufacturer;
|
||||
var configuration = new PostConfiguration() { Rate = 10 };
|
||||
var post = CreateDataModel(postId, postName, postType, configuration);
|
||||
Assert.That(() => post.Validate(), Throws.Nothing);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(post.Id, Is.EqualTo(postId));
|
||||
Assert.That(post.PostName, Is.EqualTo(postName));
|
||||
Assert.That(post.PostType, Is.EqualTo(postType));
|
||||
Assert.That(post.Salary, Is.EqualTo(salary));
|
||||
Assert.That(post.ConfigurationModel, Is.EqualTo(configuration));
|
||||
Assert.That(post.ConfigurationModel.Rate, Is.EqualTo(configuration.Rate));
|
||||
});
|
||||
}
|
||||
|
||||
private static PostDataModel CreateDataModel(string? id, string? postName, PostType postType, double salary) =>
|
||||
new(id, postName, postType, salary);
|
||||
}
|
||||
private static PostDataModel CreateDataModel(string? id, string? postName, PostType postType, PostConfiguration configuration) =>
|
||||
new(id, postName, postType, configuration);
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using SladkieBulkiContrakts.Infrastructure;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SladkieBulkiTests.Infrastructure;
|
||||
|
||||
class ConfigurationSalaryTest : IConfigurationSalary
|
||||
{
|
||||
public double ExtraSaleSum => 10;
|
||||
public int MaxParallelThreads { get; set; } = 4;
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using SladkieBulkiContrakts.Enums;
|
||||
using SladkieBulkiContrakts.Infrastructure.PostConfigurations;
|
||||
using SladkieBulkiDatabase;
|
||||
using SladkieBulkiDatabase.Models;
|
||||
using System;
|
||||
@@ -12,10 +13,10 @@ namespace SladkieBulkiTests.Infrastructure;
|
||||
|
||||
internal static class SladkieBulkiDbContextExtensions
|
||||
{
|
||||
|
||||
public static Post InsertPostToDatabaseAndReturn(this SladkieBulkiDbContext dbContext, string? id = null, string postName = "test", PostType postType = PostType.Manufacturer, double salary = 10, bool isActual = true, DateTime? changeDate = null)
|
||||
|
||||
public static Post InsertPostToDatabaseAndReturn(this SladkieBulkiDbContext dbContext, string? id = null, string postName = "test", PostType postType = PostType.Manufacturer, PostConfiguration? config = null, bool isActual = true, DateTime? changeDate = null)
|
||||
{
|
||||
var post = new Post() { Id = Guid.NewGuid().ToString(), PostId = id ?? Guid.NewGuid().ToString(), PostName = postName, PostType = postType, Salary = salary, IsActual = isActual, ChangeDate = changeDate ?? DateTime.UtcNow };
|
||||
var post = new Post() { Id = Guid.NewGuid().ToString(), PostId = id ?? Guid.NewGuid().ToString(), PostName = postName, PostType = postType, Configuration = config ?? new PostConfiguration() { Rate = 100 }, IsActual = isActual, ChangeDate = changeDate ?? DateTime.UtcNow };
|
||||
dbContext.Posts.Add(post);
|
||||
dbContext.SaveChanges();
|
||||
return post;
|
||||
@@ -88,25 +89,9 @@ internal static class SladkieBulkiDbContextExtensions
|
||||
return salary;
|
||||
}
|
||||
|
||||
public static Worker InsertWorkerToDatabaseAndReturn(this SladkieBulkiDbContext dbContext,
|
||||
string? id = null,
|
||||
string fio = "test",
|
||||
string? postId = null,
|
||||
DateTime? birthDate = null,
|
||||
DateTime? employmentDate = null,
|
||||
bool isDeleted = false,
|
||||
string email = "default@email.com")
|
||||
public static Worker InsertWorkerToDatabaseAndReturn(this SladkieBulkiDbContext dbContext, string? id = null, string fio = "test", string? postId = null, DateTime? birthDate = null, DateTime? employmentDate = null, bool isDeleted = false, DateTime? dateDelete = null, string? email = "1@mail.com")
|
||||
{
|
||||
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,
|
||||
Email = email
|
||||
};
|
||||
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, DateOfDelete = dateDelete, Email = email};
|
||||
dbContext.Workers.Add(worker);
|
||||
dbContext.SaveChanges();
|
||||
return worker;
|
||||
|
||||
@@ -11,6 +11,14 @@
|
||||
</PropertyGroup>
|
||||
|
||||
|
||||
<ItemGroup>
|
||||
<Content Include="appsettings.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
|
||||
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="8.0.16" />
|
||||
|
||||
@@ -3,6 +3,7 @@ using Microsoft.EntityFrameworkCore;
|
||||
using SladkieBulkiContrakts.DataModels;
|
||||
using SladkieBulkiContrakts.Enums;
|
||||
using SladkieBulkiContrakts.Exceptions;
|
||||
using SladkieBulkiContrakts.Infrastructure.PostConfigurations;
|
||||
using SladkieBulkiDatabase.Implementations;
|
||||
using SladkieBulkiDatabase.Models;
|
||||
using SladkieBulkiTests.Infrastructure;
|
||||
@@ -46,6 +47,19 @@ internal class PostStorageContractTests : BaseStorageContractTest
|
||||
Assert.That(list, Is.Empty);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Try_GetList_WhenDifferentConfigTypes_Test()
|
||||
{
|
||||
var postSimple = SladkieBulkiDbContext.InsertPostToDatabaseAndReturn(postName: "name 1");
|
||||
var postCashier = SladkieBulkiDbContext.InsertPostToDatabaseAndReturn(postName: "name 2", config: new ManufacturerPostConfiguration() { SalePercent = 500 });
|
||||
var postSupervisor = SladkieBulkiDbContext.InsertPostToDatabaseAndReturn(postName: "name 3", config: new PackerPostConfiguration() { PersonalCountPack = 20 });
|
||||
var list = _postStorageContract.GetList();
|
||||
Assert.That(list, Is.Not.Null);
|
||||
AssertElement(list.First(x => x.Id == postSimple.PostId), postSimple);
|
||||
AssertElement(list.First(x => x.Id == postCashier.PostId), postCashier);
|
||||
AssertElement(list.First(x => x.Id == postSupervisor.PostId), postSupervisor);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Try_GetPostWithHistory_WhenHaveRecords_Test()
|
||||
{
|
||||
@@ -143,6 +157,36 @@ internal class PostStorageContractTests : BaseStorageContractTest
|
||||
Assert.That(() => _postStorageContract.AddElement(post), Throws.TypeOf<ElementExistsException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Try_AddElement_WithManufacturerPostConfiguration_Test()
|
||||
{
|
||||
var salePercent = 10;
|
||||
var post = CreateModel(Guid.NewGuid().ToString(), config: new ManufacturerPostConfiguration() { SalePercent = salePercent });
|
||||
_postStorageContract.AddElement(post);
|
||||
var element = SladkieBulkiDbContext.GetPostFromDatabaseByPostId(post.Id);
|
||||
Assert.That(element, Is.Not.Null);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(element.Configuration.Type, Is.EqualTo(typeof(ManufacturerPostConfiguration).Name));
|
||||
Assert.That((element.Configuration as ManufacturerPostConfiguration)!.SalePercent, Is.EqualTo(salePercent));
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Try_AddElement_WithPackerPostConfiguration_Test()
|
||||
{
|
||||
var trendPremium = 20;
|
||||
var post = CreateModel(Guid.NewGuid().ToString(), config: new PackerPostConfiguration() { PersonalCountPack = trendPremium });
|
||||
_postStorageContract.AddElement(post);
|
||||
var element = SladkieBulkiDbContext.GetPostFromDatabaseByPostId(post.Id);
|
||||
Assert.That(element, Is.Not.Null);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(element.Configuration.Type, Is.EqualTo(typeof(PackerPostConfiguration).Name));
|
||||
Assert.That((element.Configuration as PackerPostConfiguration)!.PersonalCountPack, Is.EqualTo(trendPremium));
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Try_UpdElement_Test()
|
||||
{
|
||||
@@ -179,6 +223,36 @@ internal class PostStorageContractTests : BaseStorageContractTest
|
||||
Assert.That(() => _postStorageContract.UpdElement(post), Throws.TypeOf<ElementDeletedException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Try_UpdElement_WithManufacturerPostConfiguration_Test()
|
||||
{
|
||||
var post = SladkieBulkiDbContext.InsertPostToDatabaseAndReturn();
|
||||
var salePercent = 10;
|
||||
_postStorageContract.UpdElement(CreateModel(post.PostId, config: new ManufacturerPostConfiguration() { SalePercent = salePercent }));
|
||||
var element = SladkieBulkiDbContext.GetPostFromDatabaseByPostId(post.PostId);
|
||||
Assert.That(element, Is.Not.Null);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(element.Configuration.Type, Is.EqualTo(typeof(ManufacturerPostConfiguration).Name));
|
||||
Assert.That((element.Configuration as ManufacturerPostConfiguration)!.SalePercent, Is.EqualTo(salePercent));
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Try_UpdElement_WithPackerPostConfiguration_Test()
|
||||
{
|
||||
var post = SladkieBulkiDbContext.InsertPostToDatabaseAndReturn();
|
||||
var trendPremium = 20;
|
||||
_postStorageContract.UpdElement(CreateModel(post.PostId, config: new PackerPostConfiguration() { PersonalCountPack = trendPremium }));
|
||||
var element = SladkieBulkiDbContext.GetPostFromDatabaseByPostId(post.PostId);
|
||||
Assert.That(element, Is.Not.Null);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(element.Configuration.Type, Is.EqualTo(typeof(PackerPostConfiguration).Name));
|
||||
Assert.That((element.Configuration as PackerPostConfiguration)!.PersonalCountPack, Is.EqualTo(trendPremium));
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Try_DelElement_Test()
|
||||
{
|
||||
@@ -234,12 +308,12 @@ internal class PostStorageContractTests : BaseStorageContractTest
|
||||
Assert.That(actual.Id, Is.EqualTo(expected.PostId));
|
||||
Assert.That(actual.PostName, Is.EqualTo(expected.PostName));
|
||||
Assert.That(actual.PostType, Is.EqualTo(expected.PostType));
|
||||
Assert.That(actual.Salary, Is.EqualTo(expected.Salary));
|
||||
Assert.That(actual.ConfigurationModel.Rate, Is.EqualTo(expected.Configuration.Rate));
|
||||
});
|
||||
}
|
||||
|
||||
private static PostDataModel CreateModel(string postId, string postName = "test", PostType postType = PostType.Manufacturer, double salary = 10)
|
||||
=> new(postId, postName, postType, salary);
|
||||
private static PostDataModel CreateModel(string postId, string postName = "test", PostType postType = PostType.Manufacturer, PostConfiguration? config = null)
|
||||
=> new(postId, postName, postType, config ?? new PostConfiguration() { Rate = 100 });
|
||||
|
||||
private static void AssertElement(Post? actual, PostDataModel expected)
|
||||
{
|
||||
@@ -249,7 +323,7 @@ internal class PostStorageContractTests : BaseStorageContractTest
|
||||
Assert.That(actual.PostId, Is.EqualTo(expected.Id));
|
||||
Assert.That(actual.PostName, Is.EqualTo(expected.PostName));
|
||||
Assert.That(actual.PostType, Is.EqualTo(expected.PostType));
|
||||
Assert.That(actual.Salary, Is.EqualTo(expected.Salary));
|
||||
Assert.That(actual.Configuration.Rate, Is.EqualTo(expected.ConfigurationModel.Rate));
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ using SladkieBulkiContrakts.DataModels;
|
||||
using SladkieBulkiContrakts.Exceptions;
|
||||
using SladkieBulkiDatabase.Implementations;
|
||||
using SladkieBulkiDatabase.Models;
|
||||
using SladkieBulkiTests.Infrastructure;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -30,9 +31,9 @@ internal class WorkerStorageContractTests : BaseStorageContractTest
|
||||
[Test]
|
||||
public void Try_GetList_WhenHaveRecords_Test()
|
||||
{
|
||||
var worker1 = InsertWorkerToDatabaseAndReturn(Guid.NewGuid().ToString(), "fio 1");
|
||||
var worker2 = InsertWorkerToDatabaseAndReturn(Guid.NewGuid().ToString(), "fio 2");
|
||||
var worker3 = InsertWorkerToDatabaseAndReturn(Guid.NewGuid().ToString(), "fio 3");
|
||||
var worker1 = SladkieBulkiDbContext.InsertWorkerToDatabaseAndReturn(Guid.NewGuid().ToString(), "fio 1");
|
||||
var worker2 = SladkieBulkiDbContext.InsertWorkerToDatabaseAndReturn(Guid.NewGuid().ToString(), "fio 2");
|
||||
var worker3 = SladkieBulkiDbContext.InsertWorkerToDatabaseAndReturn(Guid.NewGuid().ToString(), "fio 3");
|
||||
var list = _workerStorageContract.GetList();
|
||||
Assert.That(list, Is.Not.Null);
|
||||
Assert.That(list, Has.Count.EqualTo(3));
|
||||
@@ -54,9 +55,9 @@ internal class WorkerStorageContractTests : BaseStorageContractTest
|
||||
public void Try_GetList_ByPostId_Test()
|
||||
{
|
||||
var postId = Guid.NewGuid().ToString();
|
||||
InsertWorkerToDatabaseAndReturn(Guid.NewGuid().ToString(), "fio 1", postId);
|
||||
InsertWorkerToDatabaseAndReturn(Guid.NewGuid().ToString(), "fio 2", postId);
|
||||
InsertWorkerToDatabaseAndReturn(Guid.NewGuid().ToString(), "fio 3");
|
||||
SladkieBulkiDbContext.InsertWorkerToDatabaseAndReturn(Guid.NewGuid().ToString(), "fio 1", postId);
|
||||
SladkieBulkiDbContext.InsertWorkerToDatabaseAndReturn(Guid.NewGuid().ToString(), "fio 2", postId);
|
||||
SladkieBulkiDbContext.InsertWorkerToDatabaseAndReturn(Guid.NewGuid().ToString(), "fio 3");
|
||||
var list = _workerStorageContract.GetList(postId: postId);
|
||||
Assert.That(list, Is.Not.Null);
|
||||
Assert.That(list, Has.Count.EqualTo(2));
|
||||
@@ -66,10 +67,10 @@ internal class WorkerStorageContractTests : BaseStorageContractTest
|
||||
[Test]
|
||||
public void Try_GetList_ByBirthDate_Test()
|
||||
{
|
||||
InsertWorkerToDatabaseAndReturn(Guid.NewGuid().ToString(), "fio 1", birthDate: DateTime.UtcNow.AddYears(-25));
|
||||
InsertWorkerToDatabaseAndReturn(Guid.NewGuid().ToString(), "fio 2", birthDate: DateTime.UtcNow.AddYears(-21));
|
||||
InsertWorkerToDatabaseAndReturn(Guid.NewGuid().ToString(), "fio 3", birthDate: DateTime.UtcNow.AddYears(-20));
|
||||
InsertWorkerToDatabaseAndReturn(Guid.NewGuid().ToString(), "fio 4", birthDate: DateTime.UtcNow.AddYears(-19));
|
||||
SladkieBulkiDbContext.InsertWorkerToDatabaseAndReturn(Guid.NewGuid().ToString(), "fio 1", birthDate: DateTime.UtcNow.AddYears(-25));
|
||||
SladkieBulkiDbContext.InsertWorkerToDatabaseAndReturn(Guid.NewGuid().ToString(), "fio 2", birthDate: DateTime.UtcNow.AddYears(-21));
|
||||
SladkieBulkiDbContext.InsertWorkerToDatabaseAndReturn(Guid.NewGuid().ToString(), "fio 3", birthDate: DateTime.UtcNow.AddYears(-20));
|
||||
SladkieBulkiDbContext.InsertWorkerToDatabaseAndReturn(Guid.NewGuid().ToString(), "fio 4", birthDate: DateTime.UtcNow.AddYears(-19));
|
||||
var list = _workerStorageContract.GetList(fromBirthDate: DateTime.UtcNow.AddYears(-21).AddMinutes(-1), toBirthDate: DateTime.UtcNow.AddYears(-20).AddMinutes(1));
|
||||
Assert.That(list, Is.Not.Null);
|
||||
Assert.That(list, Has.Count.EqualTo(2));
|
||||
@@ -78,10 +79,10 @@ internal class WorkerStorageContractTests : BaseStorageContractTest
|
||||
[Test]
|
||||
public void Try_GetList_ByEmploymentDate_Test()
|
||||
{
|
||||
InsertWorkerToDatabaseAndReturn(Guid.NewGuid().ToString(), "fio 1", employmentDate: DateTime.UtcNow.AddDays(-2));
|
||||
InsertWorkerToDatabaseAndReturn(Guid.NewGuid().ToString(), "fio 2", employmentDate: DateTime.UtcNow.AddDays(-1));
|
||||
InsertWorkerToDatabaseAndReturn(Guid.NewGuid().ToString(), "fio 3", employmentDate: DateTime.UtcNow.AddDays(1));
|
||||
InsertWorkerToDatabaseAndReturn(Guid.NewGuid().ToString(), "fio 4", employmentDate: DateTime.UtcNow.AddDays(2));
|
||||
SladkieBulkiDbContext.InsertWorkerToDatabaseAndReturn(Guid.NewGuid().ToString(), "fio 1", employmentDate: DateTime.UtcNow.AddDays(-2));
|
||||
SladkieBulkiDbContext.InsertWorkerToDatabaseAndReturn(Guid.NewGuid().ToString(), "fio 2", employmentDate: DateTime.UtcNow.AddDays(-1));
|
||||
SladkieBulkiDbContext.InsertWorkerToDatabaseAndReturn(Guid.NewGuid().ToString(), "fio 3", employmentDate: DateTime.UtcNow.AddDays(1));
|
||||
SladkieBulkiDbContext.InsertWorkerToDatabaseAndReturn(Guid.NewGuid().ToString(), "fio 4", employmentDate: DateTime.UtcNow.AddDays(2));
|
||||
var list = _workerStorageContract.GetList(fromEmploymentDate: DateTime.UtcNow.AddDays(-1).AddMinutes(-1), toEmploymentDate: DateTime.UtcNow.AddDays(1).AddMinutes(1));
|
||||
Assert.That(list, Is.Not.Null);
|
||||
Assert.That(list, Has.Count.EqualTo(2));
|
||||
@@ -91,10 +92,10 @@ internal class WorkerStorageContractTests : BaseStorageContractTest
|
||||
public void Try_GetList_ByAllParameters_Test()
|
||||
{
|
||||
var postId = Guid.NewGuid().ToString();
|
||||
InsertWorkerToDatabaseAndReturn(Guid.NewGuid().ToString(), "fio 1", postId, birthDate: DateTime.UtcNow.AddYears(-25), employmentDate: DateTime.UtcNow.AddDays(-2));
|
||||
InsertWorkerToDatabaseAndReturn(Guid.NewGuid().ToString(), "fio 2", postId, birthDate: DateTime.UtcNow.AddYears(-22), employmentDate: DateTime.UtcNow.AddDays(-1));
|
||||
InsertWorkerToDatabaseAndReturn(Guid.NewGuid().ToString(), "fio 3", postId, birthDate: DateTime.UtcNow.AddYears(-21), employmentDate: DateTime.UtcNow.AddDays(-1));
|
||||
InsertWorkerToDatabaseAndReturn(Guid.NewGuid().ToString(), "fio 4", birthDate: DateTime.UtcNow.AddYears(-20), employmentDate: DateTime.UtcNow.AddDays(1));
|
||||
SladkieBulkiDbContext.InsertWorkerToDatabaseAndReturn(Guid.NewGuid().ToString(), "fio 1", postId, birthDate: DateTime.UtcNow.AddYears(-25), employmentDate: DateTime.UtcNow.AddDays(-2));
|
||||
SladkieBulkiDbContext.InsertWorkerToDatabaseAndReturn(Guid.NewGuid().ToString(), "fio 2", postId, birthDate: DateTime.UtcNow.AddYears(-22), employmentDate: DateTime.UtcNow.AddDays(-1));
|
||||
SladkieBulkiDbContext.InsertWorkerToDatabaseAndReturn(Guid.NewGuid().ToString(), "fio 3", postId, birthDate: DateTime.UtcNow.AddYears(-21), employmentDate: DateTime.UtcNow.AddDays(-1));
|
||||
SladkieBulkiDbContext.InsertWorkerToDatabaseAndReturn(Guid.NewGuid().ToString(), "fio 4", birthDate: DateTime.UtcNow.AddYears(-20), employmentDate: DateTime.UtcNow.AddDays(1));
|
||||
var list = _workerStorageContract.GetList(postId: postId, fromBirthDate: DateTime.UtcNow.AddYears(-21).AddMinutes(-1), toBirthDate: DateTime.UtcNow.AddYears(-20).AddMinutes(1), fromEmploymentDate: DateTime.UtcNow.AddDays(-1).AddMinutes(-1), toEmploymentDate: DateTime.UtcNow.AddDays(1).AddMinutes(1));
|
||||
Assert.That(list, Is.Not.Null);
|
||||
Assert.That(list, Has.Count.EqualTo(1));
|
||||
@@ -103,7 +104,7 @@ internal class WorkerStorageContractTests : BaseStorageContractTest
|
||||
[Test]
|
||||
public void Try_GetElementById_WhenHaveRecord_Test()
|
||||
{
|
||||
var worker = InsertWorkerToDatabaseAndReturn(Guid.NewGuid().ToString());
|
||||
var worker = SladkieBulkiDbContext.InsertWorkerToDatabaseAndReturn(Guid.NewGuid().ToString());
|
||||
AssertElement(_workerStorageContract.GetElementById(worker.Id), worker);
|
||||
}
|
||||
|
||||
@@ -116,7 +117,7 @@ internal class WorkerStorageContractTests : BaseStorageContractTest
|
||||
[Test]
|
||||
public void Try_GetElementByFIO_WhenHaveRecord_Test()
|
||||
{
|
||||
var worker = InsertWorkerToDatabaseAndReturn(Guid.NewGuid().ToString());
|
||||
var worker = SladkieBulkiDbContext.InsertWorkerToDatabaseAndReturn(Guid.NewGuid().ToString());
|
||||
AssertElement(_workerStorageContract.GetElementByFIO(worker.FIO), worker);
|
||||
}
|
||||
|
||||
@@ -131,14 +132,14 @@ internal class WorkerStorageContractTests : BaseStorageContractTest
|
||||
{
|
||||
var worker = CreateModel(Guid.NewGuid().ToString());
|
||||
_workerStorageContract.AddElement(worker);
|
||||
AssertElement(GetWorkerFromDatabase(worker.Id), worker);
|
||||
AssertElement(SladkieBulkiDbContext.GetWorkerFromDatabaseById(worker.Id), worker);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Try_AddElement_WhenHaveRecordWithSameId_Test()
|
||||
{
|
||||
var worker = CreateModel(Guid.NewGuid().ToString());
|
||||
InsertWorkerToDatabaseAndReturn(worker.Id);
|
||||
SladkieBulkiDbContext.InsertWorkerToDatabaseAndReturn(worker.Id);
|
||||
Assert.That(() => _workerStorageContract.AddElement(worker), Throws.TypeOf<ElementExistsException>());
|
||||
}
|
||||
|
||||
@@ -146,9 +147,9 @@ internal class WorkerStorageContractTests : BaseStorageContractTest
|
||||
public void Try_UpdElement_Test()
|
||||
{
|
||||
var worker = CreateModel(Guid.NewGuid().ToString(), "New Fio");
|
||||
InsertWorkerToDatabaseAndReturn(worker.Id);
|
||||
SladkieBulkiDbContext.InsertWorkerToDatabaseAndReturn(worker.Id);
|
||||
_workerStorageContract.UpdElement(worker);
|
||||
AssertElement(GetWorkerFromDatabase(worker.Id), worker);
|
||||
AssertElement(SladkieBulkiDbContext.GetWorkerFromDatabaseById(worker.Id), worker);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -161,16 +162,16 @@ internal class WorkerStorageContractTests : BaseStorageContractTest
|
||||
public void Try_UpdElement_WhenNoRecordWasDeleted_Test()
|
||||
{
|
||||
var worker = CreateModel(Guid.NewGuid().ToString());
|
||||
InsertWorkerToDatabaseAndReturn(worker.Id, isDeleted: true);
|
||||
SladkieBulkiDbContext.InsertWorkerToDatabaseAndReturn(worker.Id, isDeleted: true);
|
||||
Assert.That(() => _workerStorageContract.UpdElement(worker), Throws.TypeOf<ElementNotFoundException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Try_DelElement_Test()
|
||||
{
|
||||
var worker = InsertWorkerToDatabaseAndReturn(Guid.NewGuid().ToString());
|
||||
var worker = SladkieBulkiDbContext.InsertWorkerToDatabaseAndReturn(Guid.NewGuid().ToString());
|
||||
_workerStorageContract.DelElement(worker.Id);
|
||||
var element = GetWorkerFromDatabase(worker.Id);
|
||||
var element = SladkieBulkiDbContext.GetWorkerFromDatabaseById(worker.Id);
|
||||
Assert.That(element, Is.Not.Null);
|
||||
Assert.That(element.IsDeleted);
|
||||
}
|
||||
@@ -185,32 +186,44 @@ internal class WorkerStorageContractTests : BaseStorageContractTest
|
||||
public void Try_DelElement_WhenNoRecordWasDeleted_Test()
|
||||
{
|
||||
var worker = CreateModel(Guid.NewGuid().ToString());
|
||||
InsertWorkerToDatabaseAndReturn(worker.Id, isDeleted: true);
|
||||
SladkieBulkiDbContext.InsertWorkerToDatabaseAndReturn(worker.Id, isDeleted: true);
|
||||
Assert.That(() => _workerStorageContract.DelElement(worker.Id), Throws.TypeOf<ElementNotFoundException>());
|
||||
}
|
||||
|
||||
private Worker InsertWorkerToDatabaseAndReturn(
|
||||
string id,
|
||||
string fio = "test",
|
||||
string? postId = null,
|
||||
DateTime? birthDate = null,
|
||||
DateTime? employmentDate = null,
|
||||
bool isDeleted = false,
|
||||
string email = "test@example.com")
|
||||
[Test]
|
||||
public void Try_GetWorkerTrend_WhenNoNewAndDeletedWorkers_Test()
|
||||
{
|
||||
var worker = new Worker()
|
||||
{
|
||||
Id = id,
|
||||
FIO = fio,
|
||||
Email = email,
|
||||
PostId = postId ?? Guid.NewGuid().ToString(),
|
||||
BirthDate = birthDate ?? DateTime.UtcNow.AddYears(-20),
|
||||
EmploymentDate = employmentDate ?? DateTime.UtcNow,
|
||||
IsDeleted = isDeleted
|
||||
};
|
||||
SladkieBulkiDbContext.Workers.Add(worker);
|
||||
SladkieBulkiDbContext.SaveChanges();
|
||||
return worker;
|
||||
var startDate = DateTime.UtcNow.AddDays(-5);
|
||||
var endDate = DateTime.UtcNow.AddDays(-3);
|
||||
SladkieBulkiDbContext.InsertWorkerToDatabaseAndReturn(employmentDate: DateTime.UtcNow.AddDays(-10));
|
||||
SladkieBulkiDbContext.InsertWorkerToDatabaseAndReturn(employmentDate: DateTime.UtcNow.AddDays(-10), isDeleted: true, dateDelete: DateTime.UtcNow.AddDays(-9));
|
||||
SladkieBulkiDbContext.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);
|
||||
SladkieBulkiDbContext.InsertWorkerToDatabaseAndReturn(employmentDate: DateTime.UtcNow.AddDays(-10));
|
||||
SladkieBulkiDbContext.InsertWorkerToDatabaseAndReturn(employmentDate: DateTime.UtcNow.AddDays(-4));
|
||||
SladkieBulkiDbContext.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);
|
||||
SladkieBulkiDbContext.InsertWorkerToDatabaseAndReturn(employmentDate: DateTime.UtcNow.AddDays(-10), isDeleted: true, dateDelete: DateTime.UtcNow.AddDays(-9));
|
||||
SladkieBulkiDbContext.InsertWorkerToDatabaseAndReturn(employmentDate: DateTime.UtcNow.AddDays(-10), isDeleted: true, dateDelete: DateTime.UtcNow.AddDays(-4));
|
||||
SladkieBulkiDbContext.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)
|
||||
@@ -227,18 +240,9 @@ 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,
|
||||
string email = "fio@example.com") =>
|
||||
private static WorkerDataModel CreateModel(string id, string fio = "fio", string? postId = null, DateTime? birthDate = null, DateTime? employmentDate = null, bool isDeleted = false, string email = "test@test.com") =>
|
||||
new(id, fio, postId ?? Guid.NewGuid().ToString(), birthDate ?? DateTime.UtcNow.AddYears(-20), employmentDate ?? DateTime.UtcNow, isDeleted, email);
|
||||
|
||||
private Worker? GetWorkerFromDatabase(string id) => SladkieBulkiDbContext.Workers.FirstOrDefault(x => x.Id == id);
|
||||
|
||||
private static void AssertElement(Worker? actual, WorkerDataModel expected)
|
||||
{
|
||||
Assert.That(actual, Is.Not.Null);
|
||||
@@ -250,6 +254,7 @@ 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.DateOfDelete.HasValue, Is.EqualTo(expected.IsDeleted));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,9 @@ using SladkieBulkiTests.Infrastructure;
|
||||
using System.Threading.Tasks;
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using SladkieBulkiContrakts.Infrastructure.PostConfigurations;
|
||||
using System.Text.Json.Nodes;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace SladkieBulkiTests.WebApiControllersTests;
|
||||
|
||||
@@ -57,7 +60,25 @@ internal class PostControllerTests : BaseWebApiControllerTest
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Test]
|
||||
public async Task GetRecords_WhenDifferentConfigTypes_ShouldSuccess_Test()
|
||||
{
|
||||
//Arrange
|
||||
var postSimple = SladkieBulkiDbContext.InsertPostToDatabaseAndReturn(postName: "name 1");
|
||||
var postCashier = SladkieBulkiDbContext.InsertPostToDatabaseAndReturn(postName: "name 2", config: new ManufacturerPostConfiguration() { SalePercent = 500 });
|
||||
var postSupervisor = SladkieBulkiDbContext.InsertPostToDatabaseAndReturn(postName: "name 3", config: new PackerPostConfiguration() { PersonalCountPack = 20 });
|
||||
//Act
|
||||
var response = await HttpClient.GetAsync("/api/posts");
|
||||
//Assert
|
||||
Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.OK));
|
||||
var data = await GetModelFromResponseAsync<List<PostViewModel>>(response);
|
||||
Assert.That(data, Is.Not.Null);
|
||||
AssertElement(data.First(x => x.Id == postSimple.PostId), postSimple);
|
||||
AssertElement(data.First(x => x.Id == postCashier.PostId), postCashier);
|
||||
AssertElement(data.First(x => x.Id == postSupervisor.PostId), postSupervisor);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetHistory_WhenHaveRecords_ShouldSuccess_Test()
|
||||
{
|
||||
//Arrange
|
||||
@@ -215,13 +236,13 @@ internal class PostControllerTests : BaseWebApiControllerTest
|
||||
[Test]
|
||||
public async Task Post_WhenDataIsIncorrect_ShouldBadRequest_Test()
|
||||
{
|
||||
//Arrange
|
||||
var postModelWithIdIncorrect = new PostBindingModel { Id = "Id", PostName = "name", PostType = PostType.Manufacturer.ToString(), Salary = 10 };
|
||||
var postModelWithNameIncorrect = new PostBindingModel { Id = Guid.NewGuid().ToString(), PostName = string.Empty, PostType = PostType.Manufacturer.ToString(), Salary = 10 };
|
||||
var postModelWithPostTypeIncorrect = new PostBindingModel { Id = Guid.NewGuid().ToString(), PostName = string.Empty, PostType = string.Empty, Salary = 10 };
|
||||
var postModelWithSalaryIncorrect = new PostBindingModel { Id = Guid.NewGuid().ToString(), PostName = string.Empty, PostType = PostType.Manufacturer.ToString(), Salary = -10 };
|
||||
//Act
|
||||
var responseWithIdIncorrect = await HttpClient.PostAsync($"/api/posts", MakeContent(postModelWithIdIncorrect));
|
||||
//Arrange
|
||||
var postModelWithIdIncorrect = new PostBindingModel { Id = "Id", PostName = "name", PostType = PostType.Manufacturer.ToString(), ConfigurationJson = JsonSerializer.Serialize(new PostConfiguration() { Rate = 10 }) };
|
||||
var postModelWithNameIncorrect = new PostBindingModel { Id = Guid.NewGuid().ToString(), PostName = string.Empty, PostType = PostType.Manufacturer.ToString(), ConfigurationJson = JsonSerializer.Serialize(new PostConfiguration() { Rate = 10 }) };
|
||||
var postModelWithPostTypeIncorrect = new PostBindingModel { Id = Guid.NewGuid().ToString(), PostName = string.Empty, PostType = string.Empty, ConfigurationJson = JsonSerializer.Serialize(new PostConfiguration() { Rate = 10 }) };
|
||||
var postModelWithSalaryIncorrect = new PostBindingModel { Id = Guid.NewGuid().ToString(), PostName = string.Empty, PostType = PostType.Manufacturer.ToString(), ConfigurationJson = null };
|
||||
//Act
|
||||
var responseWithIdIncorrect = await HttpClient.PostAsync($"/api/posts", MakeContent(postModelWithIdIncorrect));
|
||||
var responseWithNameIncorrect = await HttpClient.PostAsync($"/api/posts", MakeContent(postModelWithNameIncorrect));
|
||||
var responseWithPostTypeIncorrect = await HttpClient.PostAsync($"/api/posts", MakeContent(postModelWithPostTypeIncorrect));
|
||||
var responseWithSalaryIncorrect = await HttpClient.PostAsync($"/api/posts", MakeContent(postModelWithSalaryIncorrect));
|
||||
@@ -253,7 +274,45 @@ internal class PostControllerTests : BaseWebApiControllerTest
|
||||
Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.BadRequest));
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Test]
|
||||
public async Task Post_WithManufacturerPostConfiguration_ShouldSuccess_Test()
|
||||
{
|
||||
//Arrange
|
||||
var salePercent = 10;
|
||||
var postModel = CreateModel(configuration: JsonSerializer.Serialize(new ManufacturerPostConfiguration() { SalePercent = salePercent, Rate = 10 }));
|
||||
//Act
|
||||
var response = await HttpClient.PostAsync($"/api/posts", MakeContent(postModel));
|
||||
//Assert
|
||||
Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.NoContent));
|
||||
var element = SladkieBulkiDbContext.GetPostFromDatabaseByPostId(postModel.Id!);
|
||||
Assert.That(element, Is.Not.Null);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(element.Configuration.Type, Is.EqualTo(typeof(ManufacturerPostConfiguration).Name));
|
||||
Assert.That((element.Configuration as ManufacturerPostConfiguration)!.SalePercent, Is.EqualTo(salePercent));
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Post_WithPackerPostConfiguration_ShouldSuccess_Test()
|
||||
{
|
||||
//Arrange
|
||||
var trendPremium = 20;
|
||||
var postModel = CreateModel(configuration: JsonSerializer.Serialize(new PackerPostConfiguration() { PersonalCountPack = trendPremium, Rate = 10 }));
|
||||
//Act
|
||||
var response = await HttpClient.PostAsync($"/api/posts", MakeContent(postModel));
|
||||
//Assert
|
||||
Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.NoContent));
|
||||
var element = SladkieBulkiDbContext.GetPostFromDatabaseByPostId(postModel.Id!);
|
||||
Assert.That(element, Is.Not.Null);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(element.Configuration.Type, Is.EqualTo(typeof(PackerPostConfiguration).Name));
|
||||
Assert.That((element.Configuration as PackerPostConfiguration)!.PersonalCountPack, Is.EqualTo(trendPremium));
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Put_ShouldSuccess_Test()
|
||||
{
|
||||
//Arrange
|
||||
@@ -307,13 +366,13 @@ internal class PostControllerTests : BaseWebApiControllerTest
|
||||
[Test]
|
||||
public async Task Put_WhenDataIsIncorrect_ShouldBadRequest_Test()
|
||||
{
|
||||
//Arrange
|
||||
var postModelWithIdIncorrect = new PostBindingModel { Id = "Id", PostName = "name", PostType = PostType.Manufacturer.ToString(), Salary = 10 };
|
||||
var postModelWithNameIncorrect = new PostBindingModel { Id = Guid.NewGuid().ToString(), PostName = string.Empty, PostType = PostType.Manufacturer.ToString(), Salary = 10 };
|
||||
var postModelWithPostTypeIncorrect = new PostBindingModel { Id = Guid.NewGuid().ToString(), PostName = string.Empty, PostType = string.Empty, Salary = 10 };
|
||||
var postModelWithSalaryIncorrect = new PostBindingModel { Id = Guid.NewGuid().ToString(), PostName = string.Empty, PostType = PostType.Manufacturer.ToString(), Salary = -10 };
|
||||
//Act
|
||||
var responseWithIdIncorrect = await HttpClient.PutAsync($"/api/posts", MakeContent(postModelWithIdIncorrect));
|
||||
//Arrange
|
||||
var postModelWithIdIncorrect = new PostBindingModel { Id = "Id", PostName = "name", PostType = PostType.Manufacturer.ToString(), ConfigurationJson = JsonSerializer.Serialize(new PostConfiguration() { Rate = 10 }) };
|
||||
var postModelWithNameIncorrect = new PostBindingModel { Id = Guid.NewGuid().ToString(), PostName = string.Empty, PostType = PostType.Manufacturer.ToString(), ConfigurationJson = JsonSerializer.Serialize(new PostConfiguration() { Rate = 10 }) };
|
||||
var postModelWithPostTypeIncorrect = new PostBindingModel { Id = Guid.NewGuid().ToString(), PostName = string.Empty, PostType = string.Empty, ConfigurationJson = JsonSerializer.Serialize(new PostConfiguration() { Rate = 10 }) };
|
||||
var postModelWithSalaryIncorrect = new PostBindingModel { Id = Guid.NewGuid().ToString(), PostName = string.Empty, PostType = PostType.Manufacturer.ToString(), ConfigurationJson = null };
|
||||
//Act
|
||||
var responseWithIdIncorrect = await HttpClient.PutAsync($"/api/posts", MakeContent(postModelWithIdIncorrect));
|
||||
var responseWithNameIncorrect = await HttpClient.PutAsync($"/api/posts", MakeContent(postModelWithNameIncorrect));
|
||||
var responseWithPostTypeIncorrect = await HttpClient.PutAsync($"/api/posts", MakeContent(postModelWithPostTypeIncorrect));
|
||||
var responseWithSalaryIncorrect = await HttpClient.PutAsync($"/api/posts", MakeContent(postModelWithSalaryIncorrect));
|
||||
@@ -345,7 +404,49 @@ internal class PostControllerTests : BaseWebApiControllerTest
|
||||
Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.BadRequest));
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Test]
|
||||
public async Task Put_WithManufacturerPostConfiguration_ShouldSuccess_Test()
|
||||
{
|
||||
//Arrange
|
||||
var salePercent = 10;
|
||||
var post = SladkieBulkiDbContext.InsertPostToDatabaseAndReturn();
|
||||
var postModel = CreateModel(post.PostId, configuration: JsonSerializer.Serialize(new ManufacturerPostConfiguration() { SalePercent = salePercent, Rate = 10 }));
|
||||
//Act
|
||||
var response = await HttpClient.PutAsync($"/api/posts", MakeContent(postModel));
|
||||
//Assert
|
||||
Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.NoContent));
|
||||
SladkieBulkiDbContext.ChangeTracker.Clear();
|
||||
var element = SladkieBulkiDbContext.GetPostFromDatabaseByPostId(postModel.Id!);
|
||||
Assert.That(element, Is.Not.Null);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(element.Configuration.Type, Is.EqualTo(typeof(ManufacturerPostConfiguration).Name));
|
||||
Assert.That((element.Configuration as ManufacturerPostConfiguration)!.SalePercent, Is.EqualTo(salePercent));
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Put_WithPackerPostConfiguration_ShouldSuccess_Test()
|
||||
{
|
||||
//Arrange
|
||||
var trendPremium = 20;
|
||||
var post = SladkieBulkiDbContext.InsertPostToDatabaseAndReturn();
|
||||
var postModel = CreateModel(post.PostId, configuration: JsonSerializer.Serialize(new PackerPostConfiguration() { PersonalCountPack = trendPremium, Rate = 10 }));
|
||||
//Act
|
||||
var response = await HttpClient.PutAsync($"/api/posts", MakeContent(postModel));
|
||||
//Assert
|
||||
Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.NoContent));
|
||||
SladkieBulkiDbContext.ChangeTracker.Clear();
|
||||
var element = SladkieBulkiDbContext.GetPostFromDatabaseByPostId(postModel.Id!);
|
||||
Assert.That(element, Is.Not.Null);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(element.Configuration.Type, Is.EqualTo(typeof(PackerPostConfiguration).Name));
|
||||
Assert.That((element.Configuration as PackerPostConfiguration)!.PersonalCountPack, Is.EqualTo(trendPremium));
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Delete_ShouldSuccess_Test()
|
||||
{
|
||||
//Arrange
|
||||
@@ -441,36 +542,36 @@ internal class PostControllerTests : BaseWebApiControllerTest
|
||||
Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.BadRequest));
|
||||
}
|
||||
|
||||
private static void AssertElement(PostViewModel? actual, Post expected)
|
||||
{
|
||||
Assert.That(actual, Is.Not.Null);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(actual.Id, Is.EqualTo(expected.PostId));
|
||||
Assert.That(actual.PostName, Is.EqualTo(expected.PostName));
|
||||
Assert.That(actual.PostType, Is.EqualTo(expected.PostType.ToString()));
|
||||
Assert.That(actual.Salary, Is.EqualTo(expected.Salary));
|
||||
});
|
||||
}
|
||||
private static void AssertElement(PostViewModel? actual, Post expected)
|
||||
{
|
||||
Assert.That(actual, Is.Not.Null);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(actual.Id, Is.EqualTo(expected.PostId));
|
||||
Assert.That(actual.PostName, Is.EqualTo(expected.PostName));
|
||||
Assert.That(actual.PostType, Is.EqualTo(expected.PostType.ToString()));
|
||||
Assert.That(JsonNode.Parse(actual.Configuration)!["Type"]!.GetValue<string>(), Is.EqualTo(expected.Configuration.Type));
|
||||
});
|
||||
}
|
||||
|
||||
private static PostBindingModel CreateModel(string? postId = null, string postName = "name", PostType postType = PostType.Manufacturer, double salary = 10)
|
||||
=> new()
|
||||
{
|
||||
Id = postId ?? Guid.NewGuid().ToString(),
|
||||
PostName = postName,
|
||||
PostType = postType.ToString(),
|
||||
Salary = salary
|
||||
};
|
||||
private static PostBindingModel CreateModel(string? postId = null, string postName = "name", PostType postType = PostType.Manufacturer, string? configuration = null)
|
||||
=> new()
|
||||
{
|
||||
Id = postId ?? Guid.NewGuid().ToString(),
|
||||
PostName = postName,
|
||||
PostType = postType.ToString(),
|
||||
ConfigurationJson = configuration ?? JsonSerializer.Serialize(new PostConfiguration() { Rate = 10 })
|
||||
};
|
||||
|
||||
private static void AssertElement(Post? actual, PostBindingModel expected)
|
||||
{
|
||||
Assert.That(actual, Is.Not.Null);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(actual.PostId, Is.EqualTo(expected.Id));
|
||||
Assert.That(actual.PostName, Is.EqualTo(expected.PostName));
|
||||
Assert.That(actual.PostType.ToString(), Is.EqualTo(expected.PostType));
|
||||
Assert.That(actual.Salary, Is.EqualTo(expected.Salary));
|
||||
});
|
||||
}
|
||||
private static void AssertElement(Post? actual, PostBindingModel expected)
|
||||
{
|
||||
Assert.That(actual, Is.Not.Null);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(actual.PostId, Is.EqualTo(expected.Id));
|
||||
Assert.That(actual.PostName, Is.EqualTo(expected.PostName));
|
||||
Assert.That(actual.PostType.ToString(), Is.EqualTo(expected.PostType));
|
||||
Assert.That(actual.Configuration.Type, Is.EqualTo(JsonNode.Parse(expected.ConfigurationJson!)!["Type"]!.GetValue<string>()));
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using SladkieBulkiContrakts.Enums;
|
||||
using SladkieBulkiContrakts.Infrastructure.PostConfigurations;
|
||||
using SladkieBulkiContrakts.ViewModels;
|
||||
using SladkieBulkiDatabase.Models;
|
||||
using SladkieBulkiTests.Infrastructure;
|
||||
@@ -173,10 +174,18 @@ internal class SalaryControllerTests : BaseWebApiControllerTest
|
||||
initPrice: 100
|
||||
);
|
||||
|
||||
var post = SladkieBulkiDbContext.InsertPostToDatabaseAndReturn(salary: 1000);
|
||||
var post = SladkieBulkiDbContext.InsertPostToDatabaseAndReturn(
|
||||
config: new ManufacturerPostConfiguration()
|
||||
{
|
||||
Rate = 1000,
|
||||
SalePercent = 0.1, // 10% от среднего за день
|
||||
BonusForExtraSales = 0 // по умолчанию
|
||||
}
|
||||
);
|
||||
var worker = SladkieBulkiDbContext.InsertWorkerToDatabaseAndReturn(fio: "name", postId: post.PostId);
|
||||
|
||||
var product = SladkieBulkiDbContext.InsertProductWithIngredientsToDatabaseAndReturn(
|
||||
new List<Ingredient> { ingredient },
|
||||
new List<Ingredient> { ingredient },
|
||||
name: "Булка",
|
||||
description: "Вкусная булка",
|
||||
productType: ProductType.Packaging,
|
||||
@@ -186,7 +195,7 @@ internal class SalaryControllerTests : BaseWebApiControllerTest
|
||||
var production = SladkieBulkiDbContext.InsertProductionToDatabaseAndReturn(
|
||||
productId: product.Id,
|
||||
workerId: worker.Id,
|
||||
productionDate: DateTime.UtcNow.Date,
|
||||
productionDate: DateTime.UtcNow.Date, // Сегодня
|
||||
sum: 2000
|
||||
);
|
||||
|
||||
@@ -194,8 +203,7 @@ internal class SalaryControllerTests : BaseWebApiControllerTest
|
||||
var response = await HttpClient.PostAsync($"/api/salaries/calculate?date={DateTime.UtcNow:O}", MakeContent(new { }));
|
||||
|
||||
// Assert
|
||||
Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.NoContent)
|
||||
.Or.EqualTo(HttpStatusCode.OK)); // Если твой Handler возвращает OK, тоже считаем успехом
|
||||
Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.NoContent).Or.EqualTo(HttpStatusCode.OK));
|
||||
|
||||
var salaries = SladkieBulkiDbContext.GetSalariesFromDatabaseByWorkerId(worker.Id);
|
||||
Assert.Multiple(() =>
|
||||
@@ -208,11 +216,13 @@ internal class SalaryControllerTests : BaseWebApiControllerTest
|
||||
}
|
||||
|
||||
|
||||
|
||||
[Test]
|
||||
public async Task Calculate_WithSeveralWorkers_ShouldSuccess_Test()
|
||||
{
|
||||
// Arrange
|
||||
var post = SladkieBulkiDbContext.InsertPostToDatabaseAndReturn(salary: 1000);
|
||||
var post = SladkieBulkiDbContext.InsertPostToDatabaseAndReturn(
|
||||
config: new ManufacturerPostConfiguration() { Rate = 1000, SalePercent = 0.1 }); // 10%
|
||||
var worker1 = SladkieBulkiDbContext.InsertWorkerToDatabaseAndReturn(fio: "name 1", postId: post.PostId);
|
||||
var worker2 = SladkieBulkiDbContext.InsertWorkerToDatabaseAndReturn(fio: "name 2", postId: post.PostId);
|
||||
var worker3 = SladkieBulkiDbContext.InsertWorkerToDatabaseAndReturn(fio: "name 3", postId: post.PostId);
|
||||
@@ -221,10 +231,15 @@ internal class SalaryControllerTests : BaseWebApiControllerTest
|
||||
var product = SladkieBulkiDbContext.InsertProductWithIngredientsToDatabaseAndReturn(
|
||||
new List<Ingredient> { ingredient }, name: "Product", unitPrice: 100);
|
||||
|
||||
SladkieBulkiDbContext.InsertProductionToDatabaseAndReturn(workerId: worker1.Id, productId: product.Id, sum: 2000);
|
||||
SladkieBulkiDbContext.InsertProductionToDatabaseAndReturn(workerId: worker1.Id, productId: product.Id, sum: 2000);
|
||||
SladkieBulkiDbContext.InsertProductionToDatabaseAndReturn(workerId: worker2.Id, productId: product.Id, sum: 2000);
|
||||
SladkieBulkiDbContext.InsertProductionToDatabaseAndReturn(workerId: worker3.Id, productId: product.Id, sum: 2000);
|
||||
// ВАЖНО! Разные дни для worker1, чтобы процент считался дважды
|
||||
SladkieBulkiDbContext.InsertProductionToDatabaseAndReturn(
|
||||
workerId: worker1.Id, productId: product.Id, sum: 2000, productionDate: DateTime.UtcNow.Date);
|
||||
SladkieBulkiDbContext.InsertProductionToDatabaseAndReturn(
|
||||
workerId: worker1.Id, productId: product.Id, sum: 2000, productionDate: DateTime.UtcNow.Date.AddDays(-1));
|
||||
SladkieBulkiDbContext.InsertProductionToDatabaseAndReturn(
|
||||
workerId: worker2.Id, productId: product.Id, sum: 2000, productionDate: DateTime.UtcNow.Date);
|
||||
SladkieBulkiDbContext.InsertProductionToDatabaseAndReturn(
|
||||
workerId: worker3.Id, productId: product.Id, sum: 2000, productionDate: DateTime.UtcNow.Date);
|
||||
|
||||
// Act
|
||||
var response = await HttpClient.PostAsync($"/api/salaries/calculate?date={DateTime.UtcNow:O}", null);
|
||||
@@ -243,17 +258,18 @@ internal class SalaryControllerTests : BaseWebApiControllerTest
|
||||
Assert.That(s1, Is.Not.Null);
|
||||
Assert.That(s2, Is.Not.Null);
|
||||
Assert.That(s3, Is.Not.Null);
|
||||
Assert.That(s1.WorkerSalary, Is.EqualTo(1000 + 0.1 * 4000).Within(0.01));
|
||||
Assert.That(s2.WorkerSalary, Is.EqualTo(1000 + 0.1 * 2000).Within(0.01));
|
||||
Assert.That(s3.WorkerSalary, Is.EqualTo(1000 + 0.1 * 2000).Within(0.01));
|
||||
Assert.That(s1.WorkerSalary, Is.EqualTo(1000 + 0.1 * 2000 + 0.1 * 2000).Within(0.01)); // 1400
|
||||
Assert.That(s2.WorkerSalary, Is.EqualTo(1000 + 0.1 * 2000).Within(0.01)); // 1200
|
||||
Assert.That(s3.WorkerSalary, Is.EqualTo(1000 + 0.1 * 2000).Within(0.01)); // 1200
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public async Task Calculate_WithoutSalesByWorker_ShouldSuccess_Test()
|
||||
{
|
||||
// Arrange:
|
||||
var post = SladkieBulkiDbContext.InsertPostToDatabaseAndReturn(salary: 1000);
|
||||
var post = SladkieBulkiDbContext.InsertPostToDatabaseAndReturn(config: new ManufacturerPostConfiguration() { Rate = 1000, SalePercent = 0.1 });
|
||||
var worker1 = SladkieBulkiDbContext.InsertWorkerToDatabaseAndReturn(fio: "name 1", postId: post.PostId);
|
||||
var worker2 = SladkieBulkiDbContext.InsertWorkerToDatabaseAndReturn(fio: "name 2", postId: post.PostId);
|
||||
|
||||
@@ -261,7 +277,7 @@ internal class SalaryControllerTests : BaseWebApiControllerTest
|
||||
var product = SladkieBulkiDbContext.InsertProductWithIngredientsToDatabaseAndReturn(
|
||||
new List<Ingredient> { ingredient }, name: "Test Product", unitPrice: 100);
|
||||
|
||||
|
||||
|
||||
SladkieBulkiDbContext.InsertProductionToDatabaseAndReturn(
|
||||
workerId: worker1.Id, productId: product.Id, sum: 2000, productionDate: DateTime.UtcNow.AddMonths(-1));
|
||||
SladkieBulkiDbContext.InsertProductionToDatabaseAndReturn(
|
||||
|
||||
@@ -6,6 +6,7 @@ using SladkieBulkiContrakts.DataModels;
|
||||
using SladkieBulkiContrakts.Exceptions;
|
||||
using SladkieBulkiContrakts.ViewModels;
|
||||
using SladkieBulkiContrakts.AdapterContracts;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace SladkieBulkiWedApi.Adapters;
|
||||
|
||||
@@ -17,19 +18,22 @@ public class PostAdapter : IPostAdapter
|
||||
|
||||
private readonly Mapper _mapper;
|
||||
|
||||
public PostAdapter(IPostBusinessLogicContract postBusinessLogicContract, ILogger<PostAdapter> logger)
|
||||
{
|
||||
_postBusinessLogicContract = postBusinessLogicContract;
|
||||
_logger = logger;
|
||||
var config = new MapperConfiguration(cfg =>
|
||||
{
|
||||
cfg.CreateMap<PostBindingModel, PostDataModel>();
|
||||
cfg.CreateMap<PostDataModel, PostViewModel>();
|
||||
});
|
||||
_mapper = new Mapper(config);
|
||||
}
|
||||
private readonly JsonSerializerOptions JsonSerializerOptions = new() { PropertyNameCaseInsensitive = true };
|
||||
|
||||
public PostOperationResponse GetList()
|
||||
public PostAdapter(IPostBusinessLogicContract postBusinessLogicContract, ILogger<PostAdapter> logger)
|
||||
{
|
||||
_postBusinessLogicContract = postBusinessLogicContract;
|
||||
_logger = logger;
|
||||
var config = new MapperConfiguration(cfg =>
|
||||
{
|
||||
cfg.CreateMap<PostBindingModel, PostDataModel>();
|
||||
cfg.CreateMap<PostDataModel, PostViewModel>()
|
||||
.ForMember(x => x.Configuration, x => x.MapFrom(src => JsonSerializer.Serialize(src.ConfigurationModel, JsonSerializerOptions)));
|
||||
});
|
||||
_mapper = new Mapper(config);
|
||||
}
|
||||
|
||||
public PostOperationResponse GetList()
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
using SladkieBulkiContrakts.Infrastructure;
|
||||
|
||||
namespace SladkieBulkiWedApi.Infrastructure;
|
||||
|
||||
public class ConfigurationSalary(IConfiguration configuration) : IConfigurationSalary
|
||||
{
|
||||
private readonly Lazy<SalarySettings> _salarySettings = new(() =>
|
||||
{
|
||||
return configuration.GetSection("SalarySettings").Get<SalarySettings>() ?? throw new InvalidDataException(nameof(SalarySettings));
|
||||
});
|
||||
|
||||
public double ExtraSaleSum => _salarySettings.Value.ExtraSaleSum;
|
||||
public int MaxParallelThreads { get; set; } = 4;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace SladkieBulkiWedApi.Infrastructure;
|
||||
|
||||
public class SalarySettings
|
||||
{
|
||||
public double ExtraSaleSum { get; set; }
|
||||
}
|
||||
@@ -52,6 +52,8 @@ builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
|
||||
|
||||
|
||||
builder.Services.AddSingleton<IConfigurationDatabase, ConfigurationDatabase>();
|
||||
builder.Services.AddSingleton<IConfigurationSalary, ConfigurationSalary>();
|
||||
|
||||
|
||||
builder.Services.AddTransient<IIngredientBusinessLogicContract, IngredientBusinessLogicContract>();
|
||||
builder.Services.AddTransient<IProductionBusinessLogicContract, ProductionBusinessLogicContract>();
|
||||
|
||||
@@ -12,6 +12,10 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.16" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.4">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Serilog.AspNetCore" Version="9.0.0" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"Serilog": {
|
||||
"Serilog": {
|
||||
"Using": [ "Serilog.Sinks.File" ],
|
||||
"MinimumLevel": {
|
||||
"Default": "Information"
|
||||
@@ -24,6 +24,9 @@
|
||||
"AllowedHosts": "*",
|
||||
"DataBaseSettings": {
|
||||
"ConnectionString": "Host=localhost;Port=5432;Database=rpp;Username=postgres;Password=postgres;"
|
||||
|
||||
},
|
||||
"SalarySettings": {
|
||||
"ExtraSaleSum": 1000,
|
||||
"MaxParallelThreads": 4
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user