Тесты
This commit is contained in:
parent
4ffd1dcb56
commit
ac01ab7d03
@ -1,10 +1,12 @@
|
|||||||
|
|
||||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
# Visual Studio Version 17
|
# Visual Studio Version 17
|
||||||
VisualStudioVersion = 17.13.35806.99 d17.13
|
VisualStudioVersion = 17.13.35806.99
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WingsOfTheWorldContratcs", "WingsOfTheWorldContratcs\WingsOfTheWorldContratcs.csproj", "{BEAC542F-7E06-4942-A37D-583E87FAE7FF}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WingsOfTheWorldContratcs", "WingsOfTheWorldContratcs\WingsOfTheWorldContratcs.csproj", "{BEAC542F-7E06-4942-A37D-583E87FAE7FF}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WingsOfTheWorldTests", "WingsOfTheWorldTests\WingsOfTheWorldTests.csproj", "{B6D3F94F-D240-494C-AC11-D9B8ADAD4914}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
@ -15,6 +17,10 @@ Global
|
|||||||
{BEAC542F-7E06-4942-A37D-583E87FAE7FF}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{BEAC542F-7E06-4942-A37D-583E87FAE7FF}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{BEAC542F-7E06-4942-A37D-583E87FAE7FF}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{BEAC542F-7E06-4942-A37D-583E87FAE7FF}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{BEAC542F-7E06-4942-A37D-583E87FAE7FF}.Release|Any CPU.Build.0 = Release|Any CPU
|
{BEAC542F-7E06-4942-A37D-583E87FAE7FF}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{B6D3F94F-D240-494C-AC11-D9B8ADAD4914}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{B6D3F94F-D240-494C-AC11-D9B8ADAD4914}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{B6D3F94F-D240-494C-AC11-D9B8ADAD4914}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{B6D3F94F-D240-494C-AC11-D9B8ADAD4914}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
@ -0,0 +1,68 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using WingsOfTheWorldContratcs.DataModels;
|
||||||
|
using WingsOfTheWorldContratcs.Enums;
|
||||||
|
using WingsOfTheWorldContratcs.Exceptions;
|
||||||
|
|
||||||
|
namespace WingsOfTheWorldTests.DataModelTests;
|
||||||
|
|
||||||
|
internal class AccessoriesDataModelTest
|
||||||
|
{
|
||||||
|
[Test]
|
||||||
|
public void IdIsNullOrEmptyTest()
|
||||||
|
{
|
||||||
|
var accessory = CreateDataModel(null, "AccessoryName", AccessoriesType.Salon);
|
||||||
|
Assert.That(() => accessory.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
|
||||||
|
accessory = CreateDataModel(string.Empty, "AccessoryName", AccessoriesType.Salon);
|
||||||
|
Assert.That(() => accessory.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void IdIsNotGuidTest()
|
||||||
|
{
|
||||||
|
var accessory = CreateDataModel("invalid_id", "AccessoryName", AccessoriesType.Salon);
|
||||||
|
Assert.That(() => accessory.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void NameIsNullOrEmptyTest()
|
||||||
|
{
|
||||||
|
var accessory = CreateDataModel(Guid.NewGuid().ToString(), null, AccessoriesType.Salon);
|
||||||
|
Assert.That(() => accessory.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
|
||||||
|
accessory = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, AccessoriesType.Salon);
|
||||||
|
Assert.That(() => accessory.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void AccessoriesTypeIsNoneTest()
|
||||||
|
{
|
||||||
|
var accessory = CreateDataModel(Guid.NewGuid().ToString(), "AccessoryName", AccessoriesType.None);
|
||||||
|
Assert.That(() => accessory.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void AllFieldsAreCorrectTest()
|
||||||
|
{
|
||||||
|
var id = Guid.NewGuid().ToString();
|
||||||
|
var name = "AccessoryName";
|
||||||
|
var type = AccessoriesType.Salon;
|
||||||
|
var accessory = CreateDataModel(id, name, type);
|
||||||
|
|
||||||
|
Assert.That(() => accessory.Validate(), Throws.Nothing);
|
||||||
|
|
||||||
|
Assert.Multiple(() =>
|
||||||
|
{
|
||||||
|
Assert.That(accessory.Id, Is.EqualTo(id));
|
||||||
|
Assert.That(accessory.Name, Is.EqualTo(name));
|
||||||
|
Assert.That(accessory.AccessoriesType, Is.EqualTo(type));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private static AccessoriesDataModel CreateDataModel(string? id, string? name, AccessoriesType type) =>
|
||||||
|
new(id, name, type);
|
||||||
|
}
|
65
WingsOfTheWorldTests/DataModelTests/AirplaneDataModelTest.cs
Normal file
65
WingsOfTheWorldTests/DataModelTests/AirplaneDataModelTest.cs
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using WingsOfTheWorldContratcs.DataModels;
|
||||||
|
using WingsOfTheWorldContratcs.Exceptions;
|
||||||
|
|
||||||
|
namespace WingsOfTheWorldTests.DataModelTests;
|
||||||
|
|
||||||
|
internal class AirplaneDataModelTest
|
||||||
|
{
|
||||||
|
[Test]
|
||||||
|
public void IdIsNullOrEmptyTest()
|
||||||
|
{
|
||||||
|
var airplane = CreateDataModel(null, "model");
|
||||||
|
Assert.That(() => airplane.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
|
||||||
|
airplane = CreateDataModel(string.Empty, "model");
|
||||||
|
Assert.That(() => airplane.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void IdIsNotGuidTest()
|
||||||
|
{
|
||||||
|
var airplane = CreateDataModel("invalid_id", "model");
|
||||||
|
Assert.That(() => airplane.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void ModelIsNullOrEmptyTest()
|
||||||
|
{
|
||||||
|
var airplane = CreateDataModel(Guid.NewGuid().ToString(), null);
|
||||||
|
Assert.That(() => airplane.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
|
||||||
|
airplane = CreateDataModel(Guid.NewGuid().ToString(), string.Empty);
|
||||||
|
Assert.That(() => airplane.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void ModelIsNotGuidTest()
|
||||||
|
{
|
||||||
|
var airplane = CreateDataModel(Guid.NewGuid().ToString(), "invalid_model");
|
||||||
|
Assert.That(() => airplane.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void AllFieldsAreCorrectTest()
|
||||||
|
{
|
||||||
|
var id = Guid.NewGuid().ToString();
|
||||||
|
var model = Guid.NewGuid().ToString();
|
||||||
|
var airplane = CreateDataModel(id, model);
|
||||||
|
|
||||||
|
Assert.That(() => airplane.Validate(), Throws.Nothing);
|
||||||
|
|
||||||
|
Assert.Multiple(() =>
|
||||||
|
{
|
||||||
|
Assert.That(airplane.Id, Is.EqualTo(id));
|
||||||
|
Assert.That(airplane.Model, Is.EqualTo(model));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private static AirplaneDataModel CreateDataModel(string? id, string? model) =>
|
||||||
|
new(id, model);
|
||||||
|
}
|
109
WingsOfTheWorldTests/DataModelTests/DeliveryDataModelTest.cs
Normal file
109
WingsOfTheWorldTests/DataModelTests/DeliveryDataModelTest.cs
Normal file
@ -0,0 +1,109 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using WingsOfTheWorldContratcs.DataModels;
|
||||||
|
using WingsOfTheWorldContratcs.Exceptions;
|
||||||
|
using static NUnit.Framework.Internal.OSPlatform;
|
||||||
|
|
||||||
|
namespace WingsOfTheWorldTests.DataModelTests;
|
||||||
|
|
||||||
|
internal class DeliveryDataModelTest
|
||||||
|
{
|
||||||
|
[Test]
|
||||||
|
public void IdIsNullOrEmptyTest()
|
||||||
|
{
|
||||||
|
var delivery = CreateDataModel(null, Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10, 100);
|
||||||
|
Assert.That(() => delivery.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
|
||||||
|
delivery = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10, 100);
|
||||||
|
Assert.That(() => delivery.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void IdIsNotGuidTest()
|
||||||
|
{
|
||||||
|
var delivery = CreateDataModel("invalid_id", Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10, 100);
|
||||||
|
Assert.That(() => delivery.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void AirPlaneIdIsNullOrEmptyTest()
|
||||||
|
{
|
||||||
|
var delivery = CreateDataModel(Guid.NewGuid().ToString(), null, Guid.NewGuid().ToString(), 10, 100);
|
||||||
|
Assert.That(() => delivery.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
|
||||||
|
delivery = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, Guid.NewGuid().ToString(), 10, 100);
|
||||||
|
Assert.That(() => delivery.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void AirPlaneIdIsNotGuidTest()
|
||||||
|
{
|
||||||
|
var delivery = CreateDataModel(Guid.NewGuid().ToString(), "invalid_id", Guid.NewGuid().ToString(), 10, 100);
|
||||||
|
Assert.That(() => delivery.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void PlaceIsNullOrEmptyTest()
|
||||||
|
{
|
||||||
|
var delivery = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), null, 10, 100);
|
||||||
|
Assert.That(() => delivery.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
|
||||||
|
delivery = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), string.Empty, 10, 100);
|
||||||
|
Assert.That(() => delivery.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void PlaceIsNotGuidTest()
|
||||||
|
{
|
||||||
|
var delivery = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "invalid_place", 10, 100);
|
||||||
|
Assert.That(() => delivery.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void CountIsLessOrZeroTest()
|
||||||
|
{
|
||||||
|
var delivery = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 0, 100);
|
||||||
|
Assert.That(() => delivery.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
|
||||||
|
delivery = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), -10, 100);
|
||||||
|
Assert.That(() => delivery.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void PriceIsLessOrZeroTest()
|
||||||
|
{
|
||||||
|
var delivery = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10, 0);
|
||||||
|
Assert.That(() => delivery.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
|
||||||
|
delivery = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10, -100);
|
||||||
|
Assert.That(() => delivery.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void AllFieldsAreCorrectTest()
|
||||||
|
{
|
||||||
|
var id = Guid.NewGuid().ToString();
|
||||||
|
var airPlaneId = Guid.NewGuid().ToString();
|
||||||
|
var place = Guid.NewGuid().ToString();
|
||||||
|
var count = 10;
|
||||||
|
var price = 100;
|
||||||
|
var delivery = CreateDataModel(id, airPlaneId, place, count, price);
|
||||||
|
|
||||||
|
Assert.That(() => delivery.Validate(), Throws.Nothing);
|
||||||
|
|
||||||
|
Assert.Multiple(() =>
|
||||||
|
{
|
||||||
|
Assert.That(delivery.Id, Is.EqualTo(id));
|
||||||
|
Assert.That(delivery.AirPlaneId, Is.EqualTo(airPlaneId));
|
||||||
|
Assert.That(delivery.Place, Is.EqualTo(place));
|
||||||
|
Assert.That(delivery.Count, Is.EqualTo(count));
|
||||||
|
Assert.That(delivery.Price, Is.EqualTo(price));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private static DeliveryDataModel CreateDataModel(string? id, string? airPlaneId, string? place, int count, int price) =>
|
||||||
|
new(id, airPlaneId, place, count, price);
|
||||||
|
}
|
@ -0,0 +1,59 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using WingsOfTheWorldContratcs.DataModels;
|
||||||
|
using WingsOfTheWorldContratcs.Exceptions;
|
||||||
|
|
||||||
|
namespace WingsOfTheWorldTests.DataModelTests;
|
||||||
|
|
||||||
|
internal class DeliveryHistoryDataModelTest
|
||||||
|
{
|
||||||
|
[Test]
|
||||||
|
public void AirplaneIdIsNullOrEmptyTest()
|
||||||
|
{
|
||||||
|
var history = CreateDataModel(null, 100);
|
||||||
|
Assert.That(() => history.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
|
||||||
|
history = CreateDataModel(string.Empty, 100);
|
||||||
|
Assert.That(() => history.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void AirplaneIdIsNotGuidTest()
|
||||||
|
{
|
||||||
|
var history = CreateDataModel("invalid_id", 100);
|
||||||
|
Assert.That(() => history.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void OldPriceIsLessOrEqualZeroTest()
|
||||||
|
{
|
||||||
|
var history = CreateDataModel(Guid.NewGuid().ToString(), 0);
|
||||||
|
Assert.That(() => history.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
|
||||||
|
history = CreateDataModel(Guid.NewGuid().ToString(), -100);
|
||||||
|
Assert.That(() => history.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void AllFieldsAreCorrectTest()
|
||||||
|
{
|
||||||
|
var airplaneId = Guid.NewGuid().ToString();
|
||||||
|
var oldPrice = 150.5;
|
||||||
|
var history = CreateDataModel(airplaneId, oldPrice);
|
||||||
|
|
||||||
|
Assert.That(() => history.Validate(), Throws.Nothing);
|
||||||
|
|
||||||
|
Assert.Multiple(() =>
|
||||||
|
{
|
||||||
|
Assert.That(history.AirplaneId, Is.EqualTo(airplaneId));
|
||||||
|
Assert.That(history.OldPrice, Is.EqualTo(oldPrice));
|
||||||
|
Assert.That(history.ChangeDate, Is.LessThanOrEqualTo(DateTime.UtcNow));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private static DeliveryHistoryDataModel CreateDataModel(string? airplaneId, double oldPrice) =>
|
||||||
|
new(airplaneId, oldPrice);
|
||||||
|
}
|
97
WingsOfTheWorldTests/DataModelTests/PostDataModelTest.cs
Normal file
97
WingsOfTheWorldTests/DataModelTests/PostDataModelTest.cs
Normal file
@ -0,0 +1,97 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using WingsOfTheWorldContratcs.DataModels;
|
||||||
|
using WingsOfTheWorldContratcs.Enums;
|
||||||
|
using WingsOfTheWorldContratcs.Exceptions;
|
||||||
|
|
||||||
|
namespace WingsOfTheWorldTests.DataModelTests;
|
||||||
|
|
||||||
|
internal class PostDataModelTest
|
||||||
|
{
|
||||||
|
[Test]
|
||||||
|
public void IdIsNullOrEmptyTest()
|
||||||
|
{
|
||||||
|
var post = CreateDataModel(null, Guid.NewGuid().ToString(), "name", PostType.Assistent, 10, true, DateTime.UtcNow);
|
||||||
|
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
post = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), "name", PostType.Assistent, 10, true, DateTime.UtcNow);
|
||||||
|
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void IdIsNotGuidTest()
|
||||||
|
{
|
||||||
|
var post = CreateDataModel("id", Guid.NewGuid().ToString(), "name", PostType.Assistent, 10, true, DateTime.UtcNow);
|
||||||
|
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void PostIdIsNullEmptyTest()
|
||||||
|
{
|
||||||
|
var post = CreateDataModel(Guid.NewGuid().ToString(), null, "name", PostType.Assistent, 10, true, DateTime.UtcNow);
|
||||||
|
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
post = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, "name", PostType.Assistent, 10, true, DateTime.UtcNow);
|
||||||
|
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void PostIdIsNotGuidTest()
|
||||||
|
{
|
||||||
|
var post = CreateDataModel(Guid.NewGuid().ToString(), "postId", "name", PostType.Assistent, 10, true, DateTime.UtcNow);
|
||||||
|
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void PostNameIsEmptyTest()
|
||||||
|
{
|
||||||
|
var manufacturer = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), null, PostType.Assistent, 10, true, DateTime.UtcNow);
|
||||||
|
Assert.That(() => manufacturer.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
manufacturer = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), string.Empty, PostType.Assistent, 10, true, DateTime.UtcNow);
|
||||||
|
Assert.That(() => manufacturer.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void PostTypeIsNoneTest()
|
||||||
|
{
|
||||||
|
var post = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "name", PostType.None, 10, true, DateTime.UtcNow);
|
||||||
|
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void SalaryIsLessOrZeroTest()
|
||||||
|
{
|
||||||
|
var post = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "name", PostType.Assistent, 0, true, DateTime.UtcNow);
|
||||||
|
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
post = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "name", PostType. Assistent, -10, true, DateTime.UtcNow);
|
||||||
|
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void AllFieldsIsCorrectTest()
|
||||||
|
{
|
||||||
|
var postId = Guid.NewGuid().ToString();
|
||||||
|
var postPostId = Guid.NewGuid().ToString();
|
||||||
|
var postName = "name";
|
||||||
|
var postType = PostType.Assistent;
|
||||||
|
var salary = 10;
|
||||||
|
var isActual = false;
|
||||||
|
var changeDate = DateTime.UtcNow.AddDays(-1);
|
||||||
|
var 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);
|
||||||
|
}
|
56
WingsOfTheWorldTests/DataModelTests/SalaryDataModelTests.cs
Normal file
56
WingsOfTheWorldTests/DataModelTests/SalaryDataModelTests.cs
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using WingsOfTheWorldContratcs.DataModels;
|
||||||
|
using WingsOfTheWorldContratcs.Exceptions;
|
||||||
|
|
||||||
|
namespace WingsOfTheWorldTests.DataModelTests;
|
||||||
|
|
||||||
|
internal class SalaryDataModelTests
|
||||||
|
{
|
||||||
|
[Test]
|
||||||
|
public void WorkerIdIsEmptyTest()
|
||||||
|
{
|
||||||
|
var salary = CreateDataModel(null, DateTime.Now, 10);
|
||||||
|
Assert.That(() => salary.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
salary = CreateDataModel(string.Empty, DateTime.Now, 10);
|
||||||
|
Assert.That(() => salary.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void WorkerIdIsNotGuidTest()
|
||||||
|
{
|
||||||
|
var salary = CreateDataModel("workerId", DateTime.Now, 10);
|
||||||
|
Assert.That(() => salary.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void PriceIsLessOrZeroTest()
|
||||||
|
{
|
||||||
|
var salary = CreateDataModel(Guid.NewGuid().ToString(), DateTime.Now, 0);
|
||||||
|
Assert.That(() => salary.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
salary = CreateDataModel(Guid.NewGuid().ToString(), DateTime.Now, -10);
|
||||||
|
Assert.That(() => salary.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void AllFieldsIsCorrectTest()
|
||||||
|
{
|
||||||
|
var workerId = Guid.NewGuid().ToString();
|
||||||
|
var salaryDate = DateTime.Now.AddDays(-3).AddMinutes(-5);
|
||||||
|
var workerSalary = 10;
|
||||||
|
var salary = CreateDataModel(workerId, salaryDate, workerSalary);
|
||||||
|
Assert.That(() => salary.Validate(), Throws.Nothing);
|
||||||
|
Assert.Multiple(() =>
|
||||||
|
{
|
||||||
|
Assert.That(salary.WorkerId, Is.EqualTo(workerId));
|
||||||
|
Assert.That(salary.SalaryDate, Is.EqualTo(salaryDate));
|
||||||
|
Assert.That(salary.Salary, Is.EqualTo(workerSalary));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private static SalaryDataModel CreateDataModel(string? workerId, DateTime salaryDate, double workerSalary) =>
|
||||||
|
new(workerId, salaryDate, workerSalary);
|
||||||
|
}
|
90
WingsOfTheWorldTests/DataModelTests/WorkerDataModelTest.cs
Normal file
90
WingsOfTheWorldTests/DataModelTests/WorkerDataModelTest.cs
Normal file
@ -0,0 +1,90 @@
|
|||||||
|
using WingsOfTheWorldContratcs.DataModels;
|
||||||
|
using WingsOfTheWorldContratcs.Exceptions;
|
||||||
|
|
||||||
|
namespace WingsOfTheWorldTests.DataModelTests;
|
||||||
|
|
||||||
|
[TestFixture]
|
||||||
|
internal class WorkerDataModelTests
|
||||||
|
{
|
||||||
|
[Test]
|
||||||
|
public void IdIsNullOrEmptyTest()
|
||||||
|
{
|
||||||
|
var worker = CreateDataModel(null, "fio", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-18), DateTime.Now, false);
|
||||||
|
Assert.That(() => worker.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
worker = CreateDataModel(string.Empty, "fio", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-18), DateTime.Now, false);
|
||||||
|
Assert.That(() => worker.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void IdIsNotGuidTest()
|
||||||
|
{
|
||||||
|
var worker = CreateDataModel("id", "fio", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-18), DateTime.Now, false);
|
||||||
|
Assert.That(() => worker.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void FIOIsNullOrEmptyTest()
|
||||||
|
{
|
||||||
|
var worker = CreateDataModel(Guid.NewGuid().ToString(), null, Guid.NewGuid().ToString(), DateTime.Now.AddYears(-18), DateTime.Now, false);
|
||||||
|
Assert.That(() => worker.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
worker = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, Guid.NewGuid().ToString(), DateTime.Now.AddYears(-18), DateTime.Now, false);
|
||||||
|
Assert.That(() => worker.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void PostIdIsNullOrEmptyTest()
|
||||||
|
{
|
||||||
|
var worker = CreateDataModel(Guid.NewGuid().ToString(), "fio", null, DateTime.Now.AddYears(-18), DateTime.Now, false);
|
||||||
|
Assert.That(() => worker.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
worker = CreateDataModel(Guid.NewGuid().ToString(), "fio", string.Empty, DateTime.Now.AddYears(-18), DateTime.Now, false);
|
||||||
|
Assert.That(() => worker.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void PostIdIsNotGuidTest()
|
||||||
|
{
|
||||||
|
var worker = CreateDataModel(Guid.NewGuid().ToString(), "fio", "postId", DateTime.Now.AddYears(-18), DateTime.Now, false);
|
||||||
|
Assert.That(() => worker.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void BirthDateIsNotCorrectTest()
|
||||||
|
{
|
||||||
|
var worker = CreateDataModel(Guid.NewGuid().ToString(), "fio", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(1), DateTime.Now, false);
|
||||||
|
Assert.That(() => worker.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void BirthDateAndEmploymentDateIsNotCorrectTest()
|
||||||
|
{
|
||||||
|
var worker = CreateDataModel(Guid.NewGuid().ToString(), "fio", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-18), DateTime.Now.AddYears(-18).AddDays(-1), false);
|
||||||
|
Assert.That(() => worker.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
worker = CreateDataModel(Guid.NewGuid().ToString(), "fio", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-18), DateTime.Now.AddYears(-16), false);
|
||||||
|
Assert.That(() => worker.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void AllFieldsIsCorrectTest()
|
||||||
|
{
|
||||||
|
var workerId = Guid.NewGuid().ToString();
|
||||||
|
var fio = "fio";
|
||||||
|
var postId = Guid.NewGuid().ToString();
|
||||||
|
var birthDate = DateTime.Now.AddYears(-16).AddDays(-1);
|
||||||
|
var employmentDate = DateTime.Now;
|
||||||
|
var isDelete = false;
|
||||||
|
var worker = CreateDataModel(workerId, fio, postId, birthDate, employmentDate, isDelete);
|
||||||
|
Assert.That(() => worker.Validate(), Throws.Nothing);
|
||||||
|
Assert.Multiple(() =>
|
||||||
|
{
|
||||||
|
Assert.That(worker.Id, Is.EqualTo(workerId));
|
||||||
|
Assert.That(worker.FIO, Is.EqualTo(fio));
|
||||||
|
Assert.That(worker.PostId, Is.EqualTo(postId));
|
||||||
|
Assert.That(worker.BirthDate, Is.EqualTo(birthDate));
|
||||||
|
Assert.That(worker.EmploymentDate, Is.EqualTo(employmentDate));
|
||||||
|
Assert.That(worker.IsDeleted, Is.EqualTo(isDelete));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private static WorkerDataModel CreateDataModel(string? id, string? fio, string? postId, DateTime birthDate, DateTime employmentDate, bool isDeleted) =>
|
||||||
|
new(id, fio, postId, birthDate, employmentDate, isDeleted);
|
||||||
|
}
|
@ -0,0 +1,106 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using WingsOfTheWorldContratcs.DataModels;
|
||||||
|
using WingsOfTheWorldContratcs.Exceptions;
|
||||||
|
|
||||||
|
namespace WingsOfTheWorldTests.DataModelTests;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
internal class CarrierCompanyDataModelTest
|
||||||
|
{
|
||||||
|
[Test]
|
||||||
|
public void IdIsNullOrEmptyTest()
|
||||||
|
{
|
||||||
|
var company = CreateDataModel(null, "CompanyName", "+79123456789", 10, 1000);
|
||||||
|
Assert.That(() => company.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
|
||||||
|
company = CreateDataModel(string.Empty, "CompanyName", "+79123456789", 10, 1000);
|
||||||
|
Assert.That(() => company.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void IdIsNotGuidTest()
|
||||||
|
{
|
||||||
|
var company = CreateDataModel("invalid_id", "CompanyName", "+79123456789", 10, 1000);
|
||||||
|
Assert.That(() => company.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void NameIsNullOrEmptyTest()
|
||||||
|
{
|
||||||
|
var company = CreateDataModel(Guid.NewGuid().ToString(), null, "+79123456789", 10, 1000);
|
||||||
|
Assert.That(() => company.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
|
||||||
|
company = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, "+79123456789", 10, 1000);
|
||||||
|
Assert.That(() => company.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void PhoneNumberIsNullOrEmptyTest()
|
||||||
|
{
|
||||||
|
var company = CreateDataModel(Guid.NewGuid().ToString(), "CompanyName", null, 10, 1000);
|
||||||
|
Assert.That(() => company.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
|
||||||
|
company = CreateDataModel(Guid.NewGuid().ToString(), "CompanyName", string.Empty, 10, 1000);
|
||||||
|
Assert.That(() => company.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void PhoneNumberIsInvalidTest()
|
||||||
|
{
|
||||||
|
var company = CreateDataModel(Guid.NewGuid().ToString(), "CompanyName", "123456", 10, 1000);
|
||||||
|
Assert.That(() => company.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
|
||||||
|
company = CreateDataModel(Guid.NewGuid().ToString(), "CompanyName", "abcdefg", 10, 1000);
|
||||||
|
Assert.That(() => company.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void CountIsLessOrEqualZeroTest()
|
||||||
|
{
|
||||||
|
var company = CreateDataModel(Guid.NewGuid().ToString(), "CompanyName", "+79123456789", 0, 1000);
|
||||||
|
Assert.That(() => company.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
|
||||||
|
company = CreateDataModel(Guid.NewGuid().ToString(), "CompanyName", "+79123456789", -5, 1000);
|
||||||
|
Assert.That(() => company.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void PriceIsLessOrEqualZeroTest()
|
||||||
|
{
|
||||||
|
var company = CreateDataModel(Guid.NewGuid().ToString(), "CompanyName", "+79123456789", 10, 0);
|
||||||
|
Assert.That(() => company.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
|
||||||
|
company = CreateDataModel(Guid.NewGuid().ToString(), "CompanyName", "+79123456789", 10, -100);
|
||||||
|
Assert.That(() => company.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void AllFieldsAreCorrectTest()
|
||||||
|
{
|
||||||
|
var id = Guid.NewGuid().ToString();
|
||||||
|
var name = "CompanyName";
|
||||||
|
var phoneNumber = "+79123456789";
|
||||||
|
var count = 10;
|
||||||
|
var price = 1000;
|
||||||
|
var company = CreateDataModel(id, name, phoneNumber, count, price);
|
||||||
|
|
||||||
|
Assert.That(() => company.Validate(), Throws.Nothing);
|
||||||
|
|
||||||
|
Assert.Multiple(() =>
|
||||||
|
{
|
||||||
|
Assert.That(company.Id, Is.EqualTo(id));
|
||||||
|
Assert.That(company.Name, Is.EqualTo(name));
|
||||||
|
Assert.That(company.PhoneNumber, Is.EqualTo(phoneNumber));
|
||||||
|
Assert.That(company.Count, Is.EqualTo(count));
|
||||||
|
Assert.That(company.Price, Is.EqualTo(price));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private static СarrierСompanyDataModel CreateDataModel(string? id, string? name, string? phoneNumber, int count, int price) =>
|
||||||
|
new(id, name, phoneNumber, count, price);
|
||||||
|
}
|
27
WingsOfTheWorldTests/WingsOfTheWorldTests.csproj
Normal file
27
WingsOfTheWorldTests/WingsOfTheWorldTests.csproj
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net9.0</TargetFramework>
|
||||||
|
<LangVersion>latest</LangVersion>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
<IsPackable>false</IsPackable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="coverlet.collector" Version="6.0.2" />
|
||||||
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
|
||||||
|
<PackageReference Include="NUnit" Version="4.2.2" />
|
||||||
|
<PackageReference Include="NUnit.Analyzers" Version="4.4.0" />
|
||||||
|
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\WingsOfTheWorldContratcs\WingsOfTheWorldContratcs.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Using Include="NUnit.Framework" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
Loading…
x
Reference in New Issue
Block a user