97 lines
4.2 KiB
C#
97 lines
4.2 KiB
C#
using SoftwareInstallationContracts.DataModels;
|
|
using SoftwareInstallationContracts.Enums;
|
|
using SoftwareInstallationContracts.Exceptions;
|
|
|
|
namespace SoftwareInstallationTests.DataModelsTests;
|
|
|
|
[TestFixture]
|
|
internal class PostDataModelTests
|
|
{
|
|
private PostDataModel post;
|
|
|
|
[Test]
|
|
public void idIsNotNullOrEmpty()
|
|
{
|
|
post = CreateDataModel(null, Guid.NewGuid().ToString(), "name", PostType.Stuff, 10, true, DateTime.UtcNow);
|
|
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationFieldException>());
|
|
post = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), "name", PostType.Stuff, 10, true, DateTime.UtcNow);
|
|
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationFieldException>());
|
|
}
|
|
|
|
[Test]
|
|
public void IdIsNotGuidTest()
|
|
{
|
|
post = CreateDataModel("id", Guid.NewGuid().ToString(), "name", PostType.Stuff, 10, true, DateTime.UtcNow);
|
|
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationFieldException>());
|
|
}
|
|
|
|
[Test]
|
|
public void PostIdIsNullEmptyTest()
|
|
{
|
|
post = CreateDataModel(Guid.NewGuid().ToString(), null, "name", PostType.Stuff, 10, true, DateTime.UtcNow);
|
|
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationFieldException>());
|
|
post = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, "name", PostType.Stuff, 10, true, DateTime.UtcNow);
|
|
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationFieldException>());
|
|
}
|
|
|
|
[Test]
|
|
public void PostIdIsNotGuidTest()
|
|
{
|
|
post = CreateDataModel(Guid.NewGuid().ToString(), "postId", "name", PostType.Stuff, 10, true, DateTime.UtcNow);
|
|
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationFieldException>());
|
|
}
|
|
|
|
[Test]
|
|
public void SalaryIsLessOrZeroTest()
|
|
{
|
|
post = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "name", PostType.Stuff, 0, true, DateTime.UtcNow);
|
|
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationFieldException>());
|
|
post = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "name", PostType.Stuff, -10, true, DateTime.UtcNow);
|
|
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationFieldException>());
|
|
}
|
|
|
|
[Test]
|
|
public void PostTypeIsNoneTest()
|
|
{
|
|
post = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "name", PostType.None, 10, true, DateTime.UtcNow);
|
|
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationFieldException>());
|
|
}
|
|
|
|
[Test]
|
|
public void PostNameIsEmptyTest()
|
|
{
|
|
post = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), null, PostType.Stuff, 10, true, DateTime.UtcNow);
|
|
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationFieldException>());
|
|
post = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), string.Empty, PostType.Stuff, 10, true, DateTime.UtcNow);
|
|
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationFieldException>());
|
|
}
|
|
|
|
[Test]
|
|
public void AllFieldsIsCorrectTest()
|
|
{
|
|
string postId = Guid.NewGuid().ToString();
|
|
string postPostId = Guid.NewGuid().ToString();
|
|
string postName = "name";
|
|
PostType postType = PostType.Stuff;
|
|
double salary = 10;
|
|
bool isActual = false;
|
|
DateTime changeDate = DateTime.UtcNow.AddDays(-1);
|
|
post = CreateDataModel(postId, postPostId, 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));
|
|
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, double salary, bool isActual, DateTime changeDate) =>
|
|
new(id, postId, postName, postType, salary, isActual, changeDate);
|
|
}
|