2025-03-12 21:09:05 +04:00

70 lines
2.3 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using PuferFishContracts.Enums;
using PuferFishContracts.Exceptions;
using PuferFishContracts.DataModels;
namespace PuferFishTests.DataModelsTests;
[TestFixture]
internal class PostDataModelTests
{
[Test]
public void IdIsNullOrEmptyTest()
{
var post = CreateDataModel(null, "name", PostType.chef);
Assert.That(() => post.Validate(),
Throws.TypeOf<ValidationException>());
post = CreateDataModel(string.Empty, "name", PostType.chef);
Assert.That(() => post.Validate(),
Throws.TypeOf<ValidationException>());
}
[Test]
public void IdIsNotGuidTest()
{
var post = CreateDataModel("id", "name", PostType.chef);
Assert.That(() => post.Validate(),
Throws.TypeOf<ValidationException>());
}
[Test]
public void PostNameIsEmptyTest()
{
var manufacturer = CreateDataModel(Guid.NewGuid().ToString(), null, PostType.chef);
Assert.That(() => manufacturer.Validate(),
Throws.TypeOf<ValidationException>());
manufacturer = CreateDataModel(Guid.NewGuid().ToString(),
string.Empty, PostType.chef);
Assert.That(() => manufacturer.Validate(),
Throws.TypeOf<ValidationException>());
}
[Test]
public void PostTypeIsNoneTest()
{
var post = CreateDataModel(Guid.NewGuid().ToString(), "name",
PostType.None);
Assert.That(() => post.Validate(),
Throws.TypeOf<ValidationException>());
}
[Test]
public void AllFieldsIsCorrectTest()
{
var postId = Guid.NewGuid().ToString();
var postName = "name";
var postType = PostType.chef;
var isActual = false;
var changeDate = DateTime.UtcNow.AddDays(-1);
var post = CreateDataModel(postId, postName, postType);
Assert.That(() => post.Validate(), Throws.Nothing);
Assert.Multiple(() =>
{
Assert.That(post.Id, Is.EqualTo(postId));
Assert.That(post.PostName, Is.EqualTo(postName));
Assert.That(post.PostType, Is.EqualTo(postType));
});
}
private static PostDataModel CreateDataModel(string? id, string? postName, PostType postType) => new(id, postName, postType);
}