да емае

This commit is contained in:
2025-04-12 21:44:09 +04:00
parent 30852efca6
commit b44784854a

View File

@@ -1,12 +1,93 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using UniversityAllExpelledTests.DataModelsTests;
namespace UniversityAllExpelled_Tests.ModelsTests
namespace UniversityAllExpelledTests.DataModelsTests;
[TestFixture]
internal class EducationDataModelTests
{
class EducationDataModelTest
[Test]
public void IdIsNullOrEmptyTest()
{
var model = CreateDataModel(null, "Иванов И.И.", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-20), DateTime.Now, false);
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
model = CreateDataModel(string.Empty, "Иванов И.И.", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-20), DateTime.Now, false);
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
}
}
[Test]
public void IdIsNotGuidTest()
{
var model = CreateDataModel("not-a-guid", Guid.NewGuid().ToString(), 1000f, new TimestampAttribute(), new TimestampAttribute(), false);
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void TeacherIdIsNullOrEmptyTest()
{
var model = CreateDataModel(Guid.NewGuid().ToString(), null, 1000f, new TimestampAttribute(), new TimestampAttribute(), false);
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
model = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, 1000f, new TimestampAttribute(), new TimestampAttribute(), false);
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void TeacherIdIsNotGuidTest()
{
var model = CreateDataModel(Guid.NewGuid().ToString(), "not-a-guid", 1000f, new TimestampAttribute(), new TimestampAttribute(), false);
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void AmountIsNotPositiveTest()
{
var model = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 0f, new TimestampAttribute(), new TimestampAttribute(), false);
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
model = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), -100f, new TimestampAttribute(), new TimestampAttribute(), false);
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void StartDateIsNullTest()
{
var model = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 1000f, null, new TimestampAttribute(), false);
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void EndDateIsNullTest()
{
var model = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 1000f, new TimestampAttribute(), null, false);
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void AllFieldsIsCorrectTest()
{
var id = Guid.NewGuid().ToString();
var teacherId = Guid.NewGuid().ToString();
var amount = 1000f;
var startDate = new TimestampAttribute();
var endDate = new TimestampAttribute();
var active = false;
var model = CreateDataModel(id, teacherId, amount, startDate, endDate, active);
Assert.That(() => model.Validate(), Throws.Nothing);
Assert.Multiple(() =>
{
Assert.That(model.Id, Is.EqualTo(id));
Assert.That(model.TeacherId, Is.EqualTo(teacherId));
Assert.That(model.Amount, Is.EqualTo(amount));
Assert.That(model.StartDate, Is.EqualTo(startDate));
Assert.That(model.EndDate, Is.EqualTo(endDate));
Assert.That(model.Active, Is.EqualTo(active));
});
}
private static EducationDataModel CreateDataModel(string id, string teacherId, float amount, TimestampAttribute startDate, TimestampAttribute endDate, bool active)
=> new EducationDataModel(id, teacherId, amount, startDate, endDate, active);
}