Контракты

This commit is contained in:
Glliza 2025-02-23 22:33:26 +04:00
parent 72b36bf3f0
commit 73eb6fffb4
14 changed files with 233 additions and 58 deletions

View File

@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using PuferFishContracts.DataModels;
namespace PuferFishContracts.BusinessLogicsContracts;
public interface IBuyerBusinessLogicContract
{
List<BuyerDataModel> GetAllBuyers();
BuyerDataModel GetBuyerByData(string data);
void InsertBuyer(BuyerDataModel buyerDataModel);
void UpdateBuyer(BuyerDataModel buyerDataModel);
void DeleteBuyer(string id);
}

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using PuferFishContracts.DataModels;
namespace PuferFishContracts.BusinessLogicsContracts;
public interface IPointsBusinessLogicContract
{
List<PointsDataModel> GetAllPointsByPeriod(DateTime fromDate, DateTime toDate);
List<PointsDataModel> GetAllPointsByPeriodByBuyer(DateTime fromDate, DateTime toDate, string buyerId);
void CalculatePointsByMounth(DateTime date);
}

View File

@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using PuferFishContracts.DataModels;
namespace PuferFishContracts.BusinessLogicsContracts;
public interface IPostBusinessLogicContract
{
List<PostDataModel> GetAllPosts(bool onlyActive);
List<PostDataModel> GetAllDataOfPost(string postId);
PostDataModel GetPostByData(string data);
void InsertPost(PostDataModel postDataModel);
void UpdatePost(PostDataModel postDataModel);
void DeletePost(string id);
void RestorePost(string id);
}

View File

@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using PuferFishContracts.DataModels;
namespace PuferFishContracts.BusinessLogicsContracts;
public interface IProductBusinessLogicContract
{
List<ProductDataModel> GetAllProducts(bool onlyActive = true);
List<ProductHistoryDataModel> GetProductHistoryByProduct(string productId);
ProductDataModel GetProductByData(string data);
void InsertProduct(ProductDataModel productDataModel);
void UpdateProduct(ProductDataModel productDataModel);
void DeleteProduct(string id);
}

View File

@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using PuferFishContracts.DataModels;
namespace PuferFishContracts.BusinessLogicsContracts;
public interface ISaleBusinessLogicContract
{
List<SaleDataModel> GetAllSalesByPeriod(DateTime fromDate, DateTime toDate);
List<SaleDataModel> GetAllSalesByWorkerByPeriod(string workerId, DateTime fromDate, DateTime toDate);
List<SaleDataModel> GetAllSalesByBuyerByPeriod(string buyerId, DateTime fromDate, DateTime toDate);
List<SaleDataModel> GetAllSalesByProductByPeriod(string productId, DateTime fromDate, DateTime toDate);
SaleDataModel GetSaleByData(string data);
void InsertSale(SaleDataModel saleDataModel);
void CancelSale(string id);
}

View File

@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using PuferFishContracts.DataModels;
namespace PuferFishContracts.BusinessLogicsContracts;
public interface IWorkerBusinessLogicContract
{
List<WorkerDataModel> GetAllWorkers(bool onlyActive = true);
List<WorkerDataModel> GetAllWorkersByPost(string postId, bool onlyActive = true);
List<WorkerDataModel> GetAllWorkersByBirthDate(DateTime fromDate, DateTime toDate, bool onlyActive = true);
List<WorkerDataModel> GetAllWorkersByEmploymentDate(DateTime fromDate, DateTime toDate, bool onlyActive = true);
WorkerDataModel GetWorkerByData(string data);
void InsertWorker(WorkerDataModel workerDataModel);
void UpdateWorker(WorkerDataModel workerDataModel);
void DeleteWorker(string id);
}

View File

@ -11,10 +11,9 @@ using System.Xml;
namespace PuferFishContracts.DataModels
{
public class PostDataModel(string id, string postId, string postName, PostType postType, bool isActual, DateTime changeDate) : IValidation
public class PostDataModel(string id, string postName, PostType postType, bool isActual, DateTime changeDate) : IValidation
{
public string Id { get; private set; } = id;
public string PostId { get; private set; } = postId;
public string PostName { get; private set; } = postName;
public PostType PostType { get; private set; } = postType;
public bool IsActual { get; private set; } = isActual;
@ -25,11 +24,7 @@ namespace PuferFishContracts.DataModels
throw new ValidationException("Field Id is empty");
if (!Id.IsGuid())
throw new ValidationException("The value in the field Id is not a unique identifier");
if (PostId.IsEmpty())
throw new ValidationException("Field PostId is empty");
if (!PostId.IsGuid())
throw new ValidationException("The value in the field PostId is not a unique identifier");
if (PostName.IsEmpty())
if (PostName.IsEmpty())
throw new ValidationException("Field PostName is empty");
if (PostType == PostType.None)
throw new ValidationException("Field PostType is empty");

View File

@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using PuferFishContracts.DataModels;
namespace PuferFishContracts.StoragesContracts;
public interface IBuyerStorageContract
{
List<BuyerDataModel> GetList();
BuyerDataModel? GetElementById(string id);
BuyerDataModel? GetElementByPhoneNumber(string phoneNumber);
BuyerDataModel? GetElementByFIO(string fio);
void AddElement(BuyerDataModel buyerDataModel);
void UpdElement(BuyerDataModel buyerDataModel);
void DelElement(string id);
}

View File

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using PuferFishContracts.DataModels;
namespace PuferFishContracts.StoragesContracts;
public interface IPointsStorageContract
{
List<PointsDataModel> GetList(DateTime startDate, DateTime endDate, string? buyerId = null);
void AddElement(PointsDataModel pointsDataModel);
}

View File

@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using PuferFishContracts.DataModels;
namespace PuferFishContracts.StoragesContracts;
public interface IPostStorageContract
{
List<PostDataModel> GetList(bool onlyActual = true);
List<PostDataModel> GetPostWithHistory(string postId);
PostDataModel? GetElementById(string id);
PostDataModel? GetElementByName(string name);
void AddElement(PostDataModel postDataModel);
void UpdElement(PostDataModel postDataModel);
void DelElement(string id);
void ResElement(string id);
}

View File

@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using PuferFishContracts.DataModels;
namespace PuferFishContracts.StoragesContracts;
public interface IProductStorageContract
{
List<ProductDataModel> GetList(bool onlyActive = true, string?
manufacturerId = null);
List<ProductHistoryDataModel> GetHistoryByProductId(string productId);
ProductDataModel? GetElementById(string id);
ProductDataModel? GetElementByName(string name);
void AddElement(ProductDataModel productDataModel);
void UpdElement(ProductDataModel productDataModel);
void DelElement(string id);
}

View File

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using PuferFishContracts.DataModels;
namespace PuferFishContracts.StoragesContracts;
public interface ISaleStorageContract
{
List<SaleDataModel> GetList(DateTime? startDate = null, DateTime? endDate = null, string? workerId = null, string? buyerId = null, string? productId = null);
SaleDataModel? GetElementById(string id);
void AddElement(SaleDataModel saleDataModel);
void DelElement(string id);
}

View File

@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using PuferFishContracts.DataModels;
namespace PuferFishContracts.StoragesContracts;
public interface IWorkerStorageContract
{
List<WorkerDataModel> GetList(bool onlyActive = true, string? postId = null, DateTime? fromBirthDate = null, DateTime? toBirthDate = null, DateTime?
fromEmploymentDate = null, DateTime? toEmploymentDate = null);
WorkerDataModel? GetElementById(string id);
WorkerDataModel? GetElementByFIO(string fio);
void AddElement(WorkerDataModel workerDataModel);
void UpdElement(WorkerDataModel workerDataModel);
void DelElement(string id);
}

View File

@ -15,98 +15,62 @@ internal class PostDataModelTests
[Test]
public void IdIsNullOrEmptyTest()
{
var post = CreateDataModel(null, Guid.NewGuid().ToString(), "name",
PostType.Cashier, true, DateTime.UtcNow);
var post = CreateDataModel(null, "name", PostType.chef,
true, DateTime.UtcNow);
Assert.That(() => post.Validate(),
Throws.TypeOf<ValidationException>());
post = CreateDataModel(string.Empty, Guid.NewGuid().ToString(),
"name", PostType.Cashier, true, DateTime.UtcNow);
post = CreateDataModel(string.Empty, "name", PostType.chef,
true, DateTime.UtcNow);
Assert.That(() => post.Validate(),
Throws.TypeOf<ValidationException>());
}
[Test]
public void IdIsNotGuidTest()
{
var post = CreateDataModel("id", Guid.NewGuid().ToString(), "name",
PostType.Cashier, true, DateTime.UtcNow);
Assert.That(() => post.Validate(),
Throws.TypeOf<ValidationException>());
}
[Test]
public void PostIdIsNullEmptyTest()
{
var post = CreateDataModel(Guid.NewGuid().ToString(), null, "name",
PostType.Cashier, true, DateTime.UtcNow);
Assert.That(() => post.Validate(),
Throws.TypeOf<ValidationException>());
post = CreateDataModel(Guid.NewGuid().ToString(), string.Empty,
"name", PostType.Cashier, true, DateTime.UtcNow);
Assert.That(() => post.Validate(),
Throws.TypeOf<ValidationException>());
}
[Test]
public void PostIdIsNotGuidTest()
{
var post = CreateDataModel(Guid.NewGuid().ToString(), "postId",
"name", PostType.Cashier, true, DateTime.UtcNow);
var post = CreateDataModel("id", "name", PostType.chef,
true, DateTime.UtcNow);
Assert.That(() => post.Validate(),
Throws.TypeOf<ValidationException>());
}
[Test]
public void PostNameIsEmptyTest()
{
var manufacturer = CreateDataModel(Guid.NewGuid().ToString(),
Guid.NewGuid().ToString(), null, PostType.Cashier, true, DateTime.UtcNow);
var manufacturer = CreateDataModel(Guid.NewGuid().ToString(), null, PostType.chef, true, DateTime.UtcNow);
Assert.That(() => manufacturer.Validate(),
Throws.TypeOf<ValidationException>());
manufacturer = CreateDataModel(Guid.NewGuid().ToString(),
Guid.NewGuid().ToString(), string.Empty, PostType.Cashier, true,
DateTime.UtcNow);
string.Empty, PostType.chef, true, DateTime.UtcNow);
Assert.That(() => manufacturer.Validate(),
Throws.TypeOf<ValidationException>());
}
[Test]
public void PostTypeIsNoneTest()
{
var post = CreateDataModel(Guid.NewGuid().ToString(),
Guid.NewGuid().ToString(), "name", PostType.None, true, DateTime.UtcNow);
var post = CreateDataModel(Guid.NewGuid().ToString(), "name",
PostType.None, true, DateTime.UtcNow);
Assert.That(() => post.Validate(),
Throws.TypeOf<ValidationException>());
}
/*[Test]
public void SalaryIsLessOrZeroTest()
{
var post = CreateDataModel(Guid.NewGuid().ToString(),
Guid.NewGuid().ToString(), "name", PostType.Cashier, true, DateTime.UtcNow);
Assert.That(() => post.Validate(),
Throws.TypeOf<ValidationException>());
post = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "name", PostType.Cashier, true,DateTime.UtcNow);
Assert.That(() => post.Validate(),
Throws.TypeOf<ValidationException>());
}*/
[Test]
public void AllFieldsIsCorrectTest()
{
var postId = Guid.NewGuid().ToString();
var postPostId = Guid.NewGuid().ToString();
var postName = "name";
var postType = PostType.Cashier;
var salary = 10;
var postType = PostType.chef;
var isActual = false;
var changeDate = DateTime.UtcNow.AddDays(-1);
var post = CreateDataModel(postId, postPostId, postName, postType, isActual, changeDate);
var post = CreateDataModel(postId, postName, postType,
isActual, changeDate);
Assert.That(() => post.Validate(), Throws.Nothing);
Assert.Multiple(() =>
{
Assert.That(post.Id, Is.EqualTo(postId));
Assert.That(post.PostId, Is.EqualTo(postPostId));
Assert.That(post.PostName, Is.EqualTo(postName));
Assert.That(post.PostType, Is.EqualTo(postType));
//Assert.That(post.Salary, Is.EqualTo(salary));
Assert.That(post.IsActual, Is.EqualTo(isActual));
Assert.That(post.ChangeDate, Is.EqualTo(changeDate));
});
}
private static PostDataModel CreateDataModel(string? id, string? postId, string? postName, PostType postType, bool isActual, DateTime changeDate) => new (id, postId, postName, postType, isActual, changeDate);
}
private static PostDataModel CreateDataModel(string? id, string? postName, PostType postType, bool isActual, DateTime changeDate) => new(id, postName, postType, isActual, changeDate);
}