fix post model and post tests
This commit is contained in:
parent
4141cca5d8
commit
c3b6b9602b
@ -4,12 +4,10 @@ using TheCyclopsContracts.Extensions;
|
|||||||
|
|
||||||
namespace TheCyclopsContracts.DataModels;
|
namespace TheCyclopsContracts.DataModels;
|
||||||
|
|
||||||
public class PostDataModel(string id, string PostId, string postName, PostType postType, double salary, bool isActual, DateTime changeDate)
|
public class PostDataModel(string id, string postName, PostType postType, double salary, bool isActual, DateTime changeDate)
|
||||||
{
|
{
|
||||||
public string Id { get; private set; } = id;
|
public string Id { get; private set; } = id;
|
||||||
|
|
||||||
public string PostId { get; private set; } = PostId;
|
|
||||||
|
|
||||||
public string PostName { get; private set; } = postName;
|
public string PostName { get; private set; } = postName;
|
||||||
|
|
||||||
public PostType PostType { get; private set; } = postType;
|
public PostType PostType { get; private set; } = postType;
|
||||||
@ -28,12 +26,6 @@ public class PostDataModel(string id, string PostId, string postName, PostType p
|
|||||||
if (!Id.IsGuid())
|
if (!Id.IsGuid())
|
||||||
throw new ValidationException("The value in the field Id is not a unique identifier");
|
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");
|
throw new ValidationException("Field PostName is empty");
|
||||||
|
|
||||||
|
@ -10,11 +10,11 @@ internal class PostDataModelTests
|
|||||||
[Test]
|
[Test]
|
||||||
public void IdIsNullOrEmptyTest()
|
public void IdIsNullOrEmptyTest()
|
||||||
{
|
{
|
||||||
var post = CreateDataModel(null, Guid.NewGuid().ToString(), "post",
|
var post = CreateDataModel(null, "post",
|
||||||
PostType.Designer, 10, true, DateTime.UtcNow);
|
PostType.Designer, 10, true, DateTime.UtcNow);
|
||||||
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
|
||||||
post = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), "post",
|
post = CreateDataModel(string.Empty, "post",
|
||||||
PostType.Designer, 10, true, DateTime.UtcNow);
|
PostType.Designer, 10, true, DateTime.UtcNow);
|
||||||
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
}
|
}
|
||||||
@ -22,27 +22,7 @@ internal class PostDataModelTests
|
|||||||
[Test]
|
[Test]
|
||||||
public void IdIsNotGuidTest()
|
public void IdIsNotGuidTest()
|
||||||
{
|
{
|
||||||
var post = CreateDataModel("id", Guid.NewGuid().ToString(), "post",
|
var post = CreateDataModel("id", "post",
|
||||||
PostType.Designer, 10, true, DateTime.UtcNow);
|
|
||||||
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void PostIdIsNullEmptyTest()
|
|
||||||
{
|
|
||||||
var post = CreateDataModel(Guid.NewGuid().ToString(), null, "post",
|
|
||||||
PostType.Designer, 10, true, DateTime.UtcNow);
|
|
||||||
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
|
||||||
|
|
||||||
post = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, "post",
|
|
||||||
PostType.Designer, 10, true, DateTime.UtcNow);
|
|
||||||
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void PostIdIsNotGuidTest()
|
|
||||||
{
|
|
||||||
var post = CreateDataModel(Guid.NewGuid().ToString(), "postId", "post",
|
|
||||||
PostType.Designer, 10, true, DateTime.UtcNow);
|
PostType.Designer, 10, true, DateTime.UtcNow);
|
||||||
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
}
|
}
|
||||||
@ -50,11 +30,11 @@ internal class PostDataModelTests
|
|||||||
[Test]
|
[Test]
|
||||||
public void PostNameIsEmptyTest()
|
public void PostNameIsEmptyTest()
|
||||||
{
|
{
|
||||||
var manufacturer = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), null,
|
var manufacturer = CreateDataModel(Guid.NewGuid().ToString(), null,
|
||||||
PostType.Designer, 10, true, DateTime.UtcNow);
|
PostType.Designer, 10, true, DateTime.UtcNow);
|
||||||
Assert.That(() => manufacturer.Validate(), Throws.TypeOf<ValidationException>());
|
Assert.That(() => manufacturer.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
|
||||||
manufacturer = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), string.Empty,
|
manufacturer = CreateDataModel(Guid.NewGuid().ToString(), string.Empty,
|
||||||
PostType.Designer, 10, true, DateTime.UtcNow);
|
PostType.Designer, 10, true, DateTime.UtcNow);
|
||||||
Assert.That(() => manufacturer.Validate(), Throws.TypeOf<ValidationException>());
|
Assert.That(() => manufacturer.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
}
|
}
|
||||||
@ -62,7 +42,7 @@ internal class PostDataModelTests
|
|||||||
[Test]
|
[Test]
|
||||||
public void PostTypeIsNoneTest()
|
public void PostTypeIsNoneTest()
|
||||||
{
|
{
|
||||||
var post = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "post",
|
var post = CreateDataModel(Guid.NewGuid().ToString(), "post",
|
||||||
PostType.None, 10, true, DateTime.UtcNow);
|
PostType.None, 10, true, DateTime.UtcNow);
|
||||||
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
}
|
}
|
||||||
@ -70,11 +50,11 @@ internal class PostDataModelTests
|
|||||||
[Test]
|
[Test]
|
||||||
public void SalaryIsLessOrZeroTest()
|
public void SalaryIsLessOrZeroTest()
|
||||||
{
|
{
|
||||||
var post = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "post",
|
var post = CreateDataModel(Guid.NewGuid().ToString(), "post",
|
||||||
PostType.Designer, 0, true, DateTime.UtcNow);
|
PostType.Designer, 0, true, DateTime.UtcNow);
|
||||||
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
|
||||||
post = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "post",
|
post = CreateDataModel(Guid.NewGuid().ToString(), "post",
|
||||||
PostType.Designer, -10, true, DateTime.UtcNow);
|
PostType.Designer, -10, true, DateTime.UtcNow);
|
||||||
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
}
|
}
|
||||||
@ -83,20 +63,18 @@ internal class PostDataModelTests
|
|||||||
public void AllFieldsIsCorrectTest()
|
public void AllFieldsIsCorrectTest()
|
||||||
{
|
{
|
||||||
var postId = Guid.NewGuid().ToString();
|
var postId = Guid.NewGuid().ToString();
|
||||||
var postPostId = Guid.NewGuid().ToString();
|
|
||||||
var postName = "name";
|
var postName = "name";
|
||||||
var postType = PostType.Designer;
|
var postType = PostType.Designer;
|
||||||
var salary = 10;
|
var salary = 10;
|
||||||
var isActual = false;
|
var isActual = false;
|
||||||
var changeDate = DateTime.UtcNow.AddDays(-1);
|
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.That(() => post.Validate(), Throws.Nothing);
|
||||||
|
|
||||||
Assert.Multiple(() =>
|
Assert.Multiple(() =>
|
||||||
{
|
{
|
||||||
Assert.That(post.Id, Is.EqualTo(postId));
|
Assert.That(post.Id, Is.EqualTo(postId));
|
||||||
Assert.That(post.PostId, Is.EqualTo(postPostId));
|
|
||||||
Assert.That(post.PostName, Is.EqualTo(postName));
|
Assert.That(post.PostName, Is.EqualTo(postName));
|
||||||
Assert.That(post.PostType, Is.EqualTo(postType));
|
Assert.That(post.PostType, Is.EqualTo(postType));
|
||||||
Assert.That(post.Salary, Is.EqualTo(salary));
|
Assert.That(post.Salary, Is.EqualTo(salary));
|
||||||
@ -105,6 +83,6 @@ internal class PostDataModelTests
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private static PostDataModel CreateDataModel(string? id, string? postId, string? postName, PostType postType, double salary, bool isActual, DateTime changeDate) =>
|
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