Контракты по хранилищам
This commit is contained in:
parent
b969fedba2
commit
e22e1907c6
@ -9,8 +9,6 @@ public class PostDataModel : IValidation
|
||||
{
|
||||
public string Id { get; private set; }
|
||||
|
||||
public string PostId { get; private set; }
|
||||
|
||||
public string PostName { get; private set; }
|
||||
|
||||
public PostType PostType { get; private set; }
|
||||
@ -21,10 +19,9 @@ public class PostDataModel : IValidation
|
||||
|
||||
public DateTime ChangeDate { get; private set; }
|
||||
|
||||
public PostDataModel(string id, string postId, string postName, PostType postType, double salary, bool isActual, DateTime changeDate)
|
||||
public PostDataModel(string id, string postName, PostType postType, double salary, bool isActual, DateTime changeDate)
|
||||
{
|
||||
Id = id;
|
||||
PostId = postId;
|
||||
PostName = postName;
|
||||
PostType = postType;
|
||||
Salary = salary;
|
||||
@ -39,12 +36,6 @@ public class PostDataModel : IValidation
|
||||
|
||||
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())
|
||||
throw new ValidationException("Field PostName is empty");
|
||||
|
@ -0,0 +1,22 @@
|
||||
using North_Bridge_Contract.DataModels;
|
||||
|
||||
namespace North_Bridge_Contract.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);
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
using North_Bridge_Contract.DataModels;
|
||||
|
||||
namespace North_Bridge_Contract.StoragesContracts;
|
||||
|
||||
public interface IProductStorageContract
|
||||
{
|
||||
List<ProductDataModel> GetList(bool onlyActive = true);
|
||||
|
||||
List<ProductHistoryDataModel> GetHistoryByProductId(string productId);
|
||||
|
||||
ProductDataModel? GetElementById(string id);
|
||||
|
||||
ProductDataModel? GetElementByName(string name);
|
||||
|
||||
void AddElement(ProductDataModel productDataModel);
|
||||
|
||||
void UpdElement(ProductDataModel productDataModel);
|
||||
|
||||
void DelElement(ProductDataModel productDataModel);
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
using North_Bridge_Contract.DataModels;
|
||||
|
||||
namespace North_Bridge_Contract.StoragesContracts;
|
||||
|
||||
public interface ISalaryStorageContract
|
||||
{
|
||||
List<SalaryDataModel> GetList(DateTime startDate, DateTime endDate, string? workerId = null);
|
||||
|
||||
void AddElement(SalaryDataModel salaryDataModel);
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
using North_Bridge_Contract.DataModels;
|
||||
|
||||
namespace North_Bridge_Contract.StoragesContracts;
|
||||
|
||||
public interface ISaleStorageContract
|
||||
{
|
||||
List<SaleDataModel> GetList(DateTime? startDate = null, DateTime? endDate = null, string? workerId = null, string? productId = null);
|
||||
|
||||
SaleDataModel? GetElementById(string id);
|
||||
|
||||
void AddElement(SaleDataModel saleDataModel);
|
||||
|
||||
void DelElement(string id);
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
using North_Bridge_Contract.DataModels;
|
||||
|
||||
namespace North_Bridge_Contract.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);
|
||||
}
|
@ -9,10 +9,12 @@ internal class PostDataModelTests
|
||||
[Test]
|
||||
public void IdIsNullOrEmptyTest()
|
||||
{
|
||||
var post = CreateDataModel(null, Guid.NewGuid().ToString(), "name", PostType.Consultant, 10000, true, DateTime.UtcNow);
|
||||
var post = CreateDataModel(null, "name", PostType.Consultant, 10,
|
||||
true, DateTime.UtcNow);
|
||||
Assert.That(() => post.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
post = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), "name", PostType.Loader, 10500, true, DateTime.UtcNow);
|
||||
post = CreateDataModel(string.Empty, "name", PostType.Consultant, 10,
|
||||
true, DateTime.UtcNow);
|
||||
Assert.That(() => post.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
@ -20,26 +22,8 @@ internal class PostDataModelTests
|
||||
[Test]
|
||||
public void IdIsNotGuidTest()
|
||||
{
|
||||
var post = CreateDataModel("id", Guid.NewGuid().ToString(), "name", PostType.Cashier, 10, true, DateTime.UtcNow);
|
||||
Assert.That(() => post.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PostIdIsNullEmptyTest()
|
||||
{
|
||||
var post = CreateDataModel(Guid.NewGuid().ToString(), null, "name", PostType.Cashier, 10, true, DateTime.UtcNow);
|
||||
Assert.That(() => post.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
post = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, "name", PostType.Cashier, 10, true, DateTime.UtcNow);
|
||||
Assert.That(() => post.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PostIdIsNotGuidTest()
|
||||
{
|
||||
var post = CreateDataModel(Guid.NewGuid().ToString(), "postId", "name", PostType.Cashier, 10, true, DateTime.UtcNow);
|
||||
var post = CreateDataModel("id", "name", PostType.Consultant, 10,
|
||||
true, DateTime.UtcNow);
|
||||
Assert.That(() => post.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
@ -47,10 +31,12 @@ internal class PostDataModelTests
|
||||
[Test]
|
||||
public void PostNameIsEmptyTest()
|
||||
{
|
||||
var manufacturer = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), null, PostType.Cashier, 10, true, DateTime.UtcNow);
|
||||
var manufacturer = CreateDataModel(Guid.NewGuid().ToString(), null,
|
||||
PostType.Consultant, 10, true, DateTime.UtcNow);
|
||||
Assert.That(() => manufacturer.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
manufacturer = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), string.Empty, PostType.Cashier, 10, true, DateTime.UtcNow);
|
||||
manufacturer = CreateDataModel(Guid.NewGuid().ToString(),
|
||||
string.Empty, PostType.Consultant, 10, true, DateTime.UtcNow);
|
||||
Assert.That(() => manufacturer.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
@ -58,8 +44,8 @@ internal class PostDataModelTests
|
||||
[Test]
|
||||
public void PostTypeIsNoneTest()
|
||||
{
|
||||
var post = CreateDataModel(Guid.NewGuid().ToString(),
|
||||
Guid.NewGuid().ToString(), "name", PostType.None, 10, true, DateTime.UtcNow);
|
||||
var post = CreateDataModel(Guid.NewGuid().ToString(), "name",
|
||||
PostType.None, 10, true, DateTime.UtcNow);
|
||||
Assert.That(() => post.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
@ -67,10 +53,12 @@ internal class PostDataModelTests
|
||||
[Test]
|
||||
public void SalaryIsLessOrZeroTest()
|
||||
{
|
||||
var post = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "name", PostType.Cashier, 0, true, DateTime.UtcNow);
|
||||
var post = CreateDataModel(Guid.NewGuid().ToString(), "name",
|
||||
PostType.Consultant, 0, true, DateTime.UtcNow);
|
||||
Assert.That(() => post.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
post = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "name", PostType.Cashier, -10, true, DateTime.UtcNow);
|
||||
post = CreateDataModel(Guid.NewGuid().ToString(), "name",
|
||||
PostType.Consultant, -10, true, DateTime.UtcNow);
|
||||
Assert.That(() => post.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
@ -79,19 +67,17 @@ internal class PostDataModelTests
|
||||
public void AllFieldsIsCorrectTest()
|
||||
{
|
||||
var postId = Guid.NewGuid().ToString();
|
||||
var postPostId = Guid.NewGuid().ToString();
|
||||
var postName = "name";
|
||||
var postType = PostType.Cashier;
|
||||
var postType = PostType.Consultant;
|
||||
var salary = 10;
|
||||
var isActual = false;
|
||||
var changeDate = DateTime.UtcNow.AddDays(-1);
|
||||
var post = CreateDataModel(postId, postPostId, postName, postType,
|
||||
salary, isActual, changeDate);
|
||||
var post = CreateDataModel(postId, postName, postType, salary,
|
||||
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));
|
||||
@ -100,7 +86,7 @@ internal class PostDataModelTests
|
||||
});
|
||||
}
|
||||
|
||||
private static PostDataModel CreateDataModel(string? id, string? postId,
|
||||
private static PostDataModel CreateDataModel(string? id,
|
||||
string? postName, PostType postType, double salary, bool isActual, DateTime changeDate) =>
|
||||
new (id, postId, postName, postType, salary, isActual, changeDate);
|
||||
new (id, postName, postType, salary, isActual, changeDate);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user