61 lines
2.4 KiB
C#
61 lines
2.4 KiB
C#
using ElectricalRepairServiceContract.DataModels;
|
|
using ElectricalRepairServiceContract.Enums;
|
|
using ElectricalRepairServiceContract.Exceptions;
|
|
using NUnit.Framework;
|
|
using System;
|
|
|
|
namespace ElectricalRepairServiceTests.DataModelsTests
|
|
{
|
|
[TestFixture]
|
|
internal class PostDataModelTest
|
|
{
|
|
[Test]
|
|
public void IdIsNullOrEmptyTest()
|
|
{
|
|
var post = CreateDataModel(null, PostType.Manager, true, DateTime.Now, "Valid description");
|
|
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
|
|
|
post = CreateDataModel(string.Empty, PostType.Manager, true, DateTime.Now, "Valid description");
|
|
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
|
}
|
|
|
|
[Test]
|
|
public void IdIsNotGuidTest()
|
|
{
|
|
var post = CreateDataModel("invalid-id", PostType.Manager, true, DateTime.Now, "Valid description");
|
|
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
|
}
|
|
|
|
[Test]
|
|
public void DescriptionIsNullOrEmptyTest()
|
|
{
|
|
var post = CreateDataModel(Guid.NewGuid().ToString(), PostType.Manager, true, DateTime.Now, null);
|
|
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
|
|
|
post = CreateDataModel(Guid.NewGuid().ToString(), PostType.Manager, true, DateTime.Now, string.Empty);
|
|
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
|
}
|
|
|
|
[Test]
|
|
public void AllFieldsCorrectTest()
|
|
{
|
|
var id = Guid.NewGuid().ToString();
|
|
var postType = PostType.Manager;
|
|
var isActual = true;
|
|
var changeDate = DateTime.Now;
|
|
var description = "Responsible for managing the team";
|
|
|
|
var post = CreateDataModel(id, postType, isActual, changeDate, description);
|
|
|
|
Assert.That(post.Id, Is.EqualTo(id));
|
|
Assert.That(post.PostType, Is.EqualTo(postType));
|
|
Assert.That(post.IsActual, Is.EqualTo(isActual));
|
|
Assert.That(post.ChangeDate, Is.EqualTo(changeDate));
|
|
Assert.That(post.Description, Is.EqualTo(description));
|
|
}
|
|
|
|
private PostDataModel CreateDataModel(string id, PostType postType, bool isActual, DateTime changeDate, string description)
|
|
=> new PostDataModel(id, postType, isActual, changeDate, description);
|
|
}
|
|
}
|