From 449e378d855ba971174bb1bf34663023f10c82f2 Mon Sep 17 00:00:00 2001 From: Tonb73 Date: Tue, 18 Feb 2025 08:22:34 +0300 Subject: [PATCH] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D0=BF=D0=BE=20=D0=B4=D0=BE=D0=BB=D0=B6=D0=BD?= =?UTF-8?q?=D0=BE=D1=81=D1=82=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../PostBusinessLogicContract.cs | 2 +- .../DataModels/PostDataModel.cs | 8 +---- .../DataModelsTests/PostDataModelTests.cs | 36 ++++++------------- 3 files changed, 13 insertions(+), 33 deletions(-) diff --git a/PapaCarloProject/PapaCarloBusinessLogic/Implementations/PostBusinessLogicContract.cs b/PapaCarloProject/PapaCarloBusinessLogic/Implementations/PostBusinessLogicContract.cs index 29f766d..49fc56a 100644 --- a/PapaCarloProject/PapaCarloBusinessLogic/Implementations/PostBusinessLogicContract.cs +++ b/PapaCarloProject/PapaCarloBusinessLogic/Implementations/PostBusinessLogicContract.cs @@ -26,7 +26,7 @@ internal class PostBusinessLogicContract : IPostBusinessLogicContract public PostDataModel GetPostByData(string data) { - return new("", "", "", 0, true, DateTime.Now); + return new("", "", 0, true, DateTime.Now); } public void InsertPost(PostDataModel postDataModel) diff --git a/PapaCarloProject/PapaCarloContracts/DataModels/PostDataModel.cs b/PapaCarloProject/PapaCarloContracts/DataModels/PostDataModel.cs index 8bc28a3..6854b9e 100644 --- a/PapaCarloProject/PapaCarloContracts/DataModels/PostDataModel.cs +++ b/PapaCarloProject/PapaCarloContracts/DataModels/PostDataModel.cs @@ -10,11 +10,10 @@ using System.Threading.Tasks; namespace PapaCarloContracts.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; @@ -33,11 +32,6 @@ public class PostDataModel(string id, string postId, string postName, PostType p 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"); diff --git a/PapaCarloProject/PapaCarloTests/DataModelsTests/PostDataModelTests.cs b/PapaCarloProject/PapaCarloTests/DataModelsTests/PostDataModelTests.cs index 327b864..3e617a6 100644 --- a/PapaCarloProject/PapaCarloTests/DataModelsTests/PostDataModelTests.cs +++ b/PapaCarloProject/PapaCarloTests/DataModelsTests/PostDataModelTests.cs @@ -15,48 +15,35 @@ internal class PostDataModelTests [Test] public void IdIsNullOrEmptyTest() { - var post = CreateDataModel(null, Guid.NewGuid().ToString(), "name", PostType.Carpenter, true, DateTime.UtcNow); + var post = CreateDataModel(null, "name", PostType.Carpenter, true, DateTime.UtcNow); Assert.That(() => post.Validate(), Throws.TypeOf()); - post = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), "name", PostType.Carpenter, true, DateTime.UtcNow); + post = CreateDataModel(string.Empty, "name", PostType.Carpenter, true, DateTime.UtcNow); Assert.That(() => post.Validate(), Throws.TypeOf()); } [Test] public void IdIsNotGuidTest() { - var post = CreateDataModel("id", Guid.NewGuid().ToString(), "name", PostType.Carpenter, true, DateTime.UtcNow); + var post = CreateDataModel("id", "name", PostType.Carpenter, true, DateTime.UtcNow); Assert.That(() => post.Validate(), Throws.TypeOf()); } - [Test] - public void PostIdIsNullEmptyTest() - { - var post = CreateDataModel(Guid.NewGuid().ToString(), null, "name", PostType.Carpenter, true, DateTime.UtcNow); - Assert.That(() => post.Validate(), Throws.TypeOf()); - post = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, "name", PostType.Carpenter, true, DateTime.UtcNow); - Assert.That(() => post.Validate(), Throws.TypeOf()); - } - - [Test] - public void PostIdIsNotGuidTest() - { - var post = CreateDataModel(Guid.NewGuid().ToString(), "postId", "name", PostType.Carpenter, true, DateTime.UtcNow); - Assert.That(() => post.Validate(), Throws.TypeOf()); - } + + [Test] public void PostNameIsEmptyTest() { - var manufacturer = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), null, PostType.Carpenter, true, DateTime.UtcNow); + var manufacturer = CreateDataModel(Guid.NewGuid().ToString(), null, PostType.Carpenter, true, DateTime.UtcNow); Assert.That(() => manufacturer.Validate(), Throws.TypeOf()); - manufacturer = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), string.Empty, PostType.Carpenter, true, DateTime.UtcNow); + manufacturer = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, PostType.Carpenter, true, DateTime.UtcNow); Assert.That(() => manufacturer.Validate(), Throws.TypeOf()); } [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()); } @@ -69,12 +56,11 @@ internal class PostDataModelTests var postType = PostType.Carpenter; 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.IsActual, Is.EqualTo(isActual)); @@ -82,6 +68,6 @@ internal class PostDataModelTests }); } - 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); }