89 lines
3.5 KiB
C#
89 lines
3.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using TwoFromTheCasketContratcs.DataModels;
|
|
using TwoFromTheCasketContratcs.Enums;
|
|
using TwoFromTheCasketContratcs.Exceptions;
|
|
using TwoFromTheCasketContratcs.Infrastructure.PostConfigurations;
|
|
using TwoFromTheCasketTest.Infrastructure;
|
|
|
|
namespace TwoFromTheCasketTest.DataModelsTest;
|
|
|
|
[TestFixture]
|
|
public class PostDataModelTests
|
|
{
|
|
[Test]
|
|
public void IdIsNullOrEmptyTest()
|
|
{
|
|
var post = CreateDataModel(string.Empty, "Manager", PostType.Plasterer, new PostConfiguration { Rate = 50000 });
|
|
Assert.That(() => post.Validate(StringLocalizerMockCreator.GetObject()), Throws.TypeOf<ValidationException>());
|
|
}
|
|
|
|
[Test]
|
|
public void IdIsNotGuidTest()
|
|
{
|
|
var post = CreateDataModel("invalid-guid", "Manager", PostType.Plasterer, new PostConfiguration { Rate = 50000 });
|
|
Assert.That(() => post.Validate(StringLocalizerMockCreator.GetObject()), Throws.TypeOf<ValidationException>());
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
public void PostNameIsNullOrEmptyTest()
|
|
{
|
|
var post = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, PostType.Plasterer, new PostConfiguration { Rate = 50000 });
|
|
Assert.That(() => post.Validate(StringLocalizerMockCreator.GetObject()), Throws.TypeOf<ValidationException>());
|
|
}
|
|
|
|
[Test]
|
|
public void PostTypeIsNoneTest()
|
|
{
|
|
var post = CreateDataModel(Guid.NewGuid().ToString(), "Manager", PostType.None, new PostConfiguration { Rate = 50000 });
|
|
Assert.That(() => post.Validate(StringLocalizerMockCreator.GetObject()), Throws.TypeOf<ValidationException>());
|
|
}
|
|
|
|
[Test]
|
|
public void SalaryIsLessOrEqualToZeroTest()
|
|
{
|
|
var post = CreateDataModel(Guid.NewGuid().ToString(), "Manager", PostType.Plasterer, new PostConfiguration { Rate = 0 });
|
|
Assert.That(() => post.Validate(StringLocalizerMockCreator.GetObject()), Throws.TypeOf<ValidationException>());
|
|
|
|
post = CreateDataModel(Guid.NewGuid().ToString(), "Manager", PostType.Plasterer, new PostConfiguration { Rate = -50000 });
|
|
Assert.That(() => post.Validate(StringLocalizerMockCreator.GetObject()), Throws.TypeOf<ValidationException>());
|
|
}
|
|
|
|
[Test]
|
|
public void AllFieldsAreCorrectTest()
|
|
{
|
|
var id = Guid.NewGuid().ToString();
|
|
var postName = "Manager";
|
|
var postType = PostType.Plasterer;
|
|
var configuration = new PostConfiguration { Rate = 50000, CutleryName = "ru-RU" };
|
|
var isActual = true;
|
|
var changeDate = DateTime.Now;
|
|
|
|
var post = CreateDataModel(id, postName, postType, configuration);
|
|
|
|
Assert.That(() => post.Validate(StringLocalizerMockCreator.GetObject()), Throws.Nothing);
|
|
|
|
Assert.Multiple(() =>
|
|
{
|
|
Assert.That(post.Id, Is.EqualTo(id));
|
|
Assert.That(post.PostName, Is.EqualTo(postName));
|
|
Assert.That(post.PostType, Is.EqualTo(postType));
|
|
Assert.That(post.ConfigurationModel.Rate, Is.EqualTo(configuration.Rate));
|
|
Assert.That(post.ConfigurationModel.CutleryName, Is.EqualTo(configuration.CutleryName));
|
|
Assert.That(post.ConfigurationModel.Type, Is.EqualTo(configuration.Type));
|
|
Assert.That(post.ConfigurationModel.CutleryName, Is.Not.Empty);
|
|
|
|
});
|
|
}
|
|
|
|
private static PostDataModel CreateDataModel(string id, string postName, PostType postType, PostConfiguration configuration)
|
|
{
|
|
return new PostDataModel(id, postName, postType, configuration);
|
|
}
|
|
}
|