Тесты
This commit is contained in:
parent
096e427095
commit
7e40591321
@ -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.12.35707.178 d17.12
|
VisualStudioVersion = 17.12.35707.178
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PuferFishContracts", "PuferFishContracts\PuferFishContracts.csproj", "{4D964053-55A4-4522-BF52-984A22880D24}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PuferFishContracts", "PuferFishContracts\PuferFishContracts.csproj", "{4D964053-55A4-4522-BF52-984A22880D24}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PuferFishTests", "PuferFishTests\PuferFishTests.csproj", "{6A249C1E-4321-4506-841B-2BCE80F550A5}"
|
||||||
|
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
|
|||||||
{4D964053-55A4-4522-BF52-984A22880D24}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{4D964053-55A4-4522-BF52-984A22880D24}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{4D964053-55A4-4522-BF52-984A22880D24}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{4D964053-55A4-4522-BF52-984A22880D24}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{4D964053-55A4-4522-BF52-984A22880D24}.Release|Any CPU.Build.0 = Release|Any CPU
|
{4D964053-55A4-4522-BF52-984A22880D24}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{6A249C1E-4321-4506-841B-2BCE80F550A5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{6A249C1E-4321-4506-841B-2BCE80F550A5}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{6A249C1E-4321-4506-841B-2BCE80F550A5}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{6A249C1E-4321-4506-841B-2BCE80F550A5}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
@ -33,6 +33,8 @@ namespace PuferFishContracts.DataModels
|
|||||||
|
|
||||||
if (!Regex.IsMatch(PhoneNumber, @"^((8|\+7)[\- ]?)?(\(?\d{3}\)?[\- ]?)?[\d\- ]{7,10}$"))
|
if (!Regex.IsMatch(PhoneNumber, @"^((8|\+7)[\- ]?)?(\(?\d{3}\)?[\- ]?)?[\d\- ]{7,10}$"))
|
||||||
throw new ValidationException("Field PhoneNumber is not a phone number");
|
throw new ValidationException("Field PhoneNumber is not a phone number");
|
||||||
|
if (Points < 0)
|
||||||
|
throw new ValidationException("The value in the field Points is a negative number");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -0,0 +1,82 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using PuferFishContracts.DataModels;
|
||||||
|
using PuferFishContracts.Exceptions;
|
||||||
|
|
||||||
|
namespace PuferFishTests.DataModelsTests
|
||||||
|
{
|
||||||
|
[TestFixture]
|
||||||
|
internal class BuyerDataModelTests
|
||||||
|
{
|
||||||
|
[Test]
|
||||||
|
public void IdIsNullOrEmptyTest()
|
||||||
|
{
|
||||||
|
var buyer = CreateDataModel(null, "fio", "number", 10);
|
||||||
|
Assert.That(() => buyer.Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
buyer = CreateDataModel(string.Empty, "fio", "number", 10);
|
||||||
|
Assert.That(() => buyer.Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
[Test]
|
||||||
|
public void IdIsNotGuidTest()
|
||||||
|
{
|
||||||
|
var buyer = CreateDataModel("id", "fio", "number", 10);
|
||||||
|
Assert.That(() => buyer.Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
[Test]
|
||||||
|
public void FIOIsNullOrEmptyTest()
|
||||||
|
{
|
||||||
|
var buyer = CreateDataModel(Guid.NewGuid().ToString(), null,
|
||||||
|
"number", 10);
|
||||||
|
Assert.That(() => buyer.Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
buyer = CreateDataModel(Guid.NewGuid().ToString(), string.Empty,
|
||||||
|
"number", 10);
|
||||||
|
Assert.That(() => buyer.Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
[Test]
|
||||||
|
public void PhoneNumberIsNullOrEmptyTest()
|
||||||
|
{
|
||||||
|
var buyer = CreateDataModel(Guid.NewGuid().ToString(), "fio", null,
|
||||||
|
10);
|
||||||
|
Assert.That(() => buyer.Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
buyer = CreateDataModel(Guid.NewGuid().ToString(), "fio",
|
||||||
|
string.Empty, 10);
|
||||||
|
Assert.That(() => buyer.Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
[Test]
|
||||||
|
public void PhoneNumberIsIncorrectTest()
|
||||||
|
{
|
||||||
|
var buyer = CreateDataModel(Guid.NewGuid().ToString(), "fio", "777",
|
||||||
|
10);
|
||||||
|
Assert.That(() => buyer.Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
[Test]
|
||||||
|
public void AllFieldsIsCorrectTest()
|
||||||
|
{
|
||||||
|
var buyerId = Guid.NewGuid().ToString();
|
||||||
|
var fio = "Fio";
|
||||||
|
var phoneNumber = "+7-777-777-77-77";
|
||||||
|
var points = 11;
|
||||||
|
var buyer = CreateDataModel(buyerId, fio, phoneNumber, points);
|
||||||
|
Assert.That(() => buyer.Validate(), Throws.Nothing);
|
||||||
|
Assert.Multiple(() =>
|
||||||
|
{
|
||||||
|
Assert.That(buyer.Id, Is.EqualTo(buyerId));
|
||||||
|
Assert.That(buyer.FIO, Is.EqualTo(fio));
|
||||||
|
Assert.That(buyer.PhoneNumber, Is.EqualTo(phoneNumber));
|
||||||
|
Assert.That(buyer.Points, Is.EqualTo(points));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
private static BuyerDataModel CreateDataModel(string? id, string? fio, string? phoneNumber, double points) => new(id, fio, phoneNumber, points);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,60 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using PuferFishContracts.DataModels;
|
||||||
|
using PuferFishContracts.Exceptions;
|
||||||
|
|
||||||
|
namespace PuferFishTests.DataModelsTests;
|
||||||
|
|
||||||
|
[TestFixture]
|
||||||
|
internal class PointsDataModelTests
|
||||||
|
{
|
||||||
|
[Test]
|
||||||
|
public void WorkerIdIsEmptyTest()
|
||||||
|
{
|
||||||
|
var points = CreateDataModel(null, DateTime.Now, 10);
|
||||||
|
Assert.That(() => points.Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
points = CreateDataModel(string.Empty, DateTime.Now, 10);
|
||||||
|
Assert.That(() => points.Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
[Test]
|
||||||
|
public void WorkerIdIsNotGuidTest()
|
||||||
|
{
|
||||||
|
var points = CreateDataModel("workerId", DateTime.Now, 10);
|
||||||
|
Assert.That(() => points.Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
[Test]
|
||||||
|
public void PriceIsLessOrZeroTest()
|
||||||
|
{
|
||||||
|
var points = CreateDataModel(Guid.NewGuid().ToString(), DateTime.Now,
|
||||||
|
0);
|
||||||
|
Assert.That(() => points.Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
points = CreateDataModel(Guid.NewGuid().ToString(), DateTime.Now, -
|
||||||
|
10);
|
||||||
|
Assert.That(() => points.Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
[Test]
|
||||||
|
public void AllFieldsIsCorrectTest()
|
||||||
|
{
|
||||||
|
var buyerId = Guid.NewGuid().ToString();
|
||||||
|
var pointsDate = DateTime.Now.AddDays(-3).AddMinutes(-5);
|
||||||
|
var buyerPoints = 10;
|
||||||
|
var points = CreateDataModel(buyerId, pointsDate, buyerPoints);
|
||||||
|
Assert.That(() => points.Validate(), Throws.Nothing);
|
||||||
|
Assert.Multiple(() =>
|
||||||
|
{
|
||||||
|
Assert.That(points.BuyerId, Is.EqualTo(buyerId));
|
||||||
|
Assert.That(points.PointsDate, Is.EqualTo(pointsDate));
|
||||||
|
Assert.That(points.Points, Is.EqualTo(buyerPoints));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
private static PointsDataModel CreateDataModel(string? buyerId, DateTime
|
||||||
|
pointsDate, double buyerPoints) => new(buyerId, pointsDate, buyerPoints);
|
||||||
|
}
|
@ -0,0 +1,112 @@
|
|||||||
|
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, Guid.NewGuid().ToString(), "name",
|
||||||
|
PostType.Cashier, true, DateTime.UtcNow);
|
||||||
|
Assert.That(() => post.Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
post = CreateDataModel(string.Empty, Guid.NewGuid().ToString(),
|
||||||
|
"name", PostType.Cashier, true, DateTime.UtcNow);
|
||||||
|
Assert.That(() => post.Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
[Test]
|
||||||
|
public void IdIsNotGuidTest()
|
||||||
|
{
|
||||||
|
var post = CreateDataModel("id", Guid.NewGuid().ToString(), "name",
|
||||||
|
PostType.Cashier, true, DateTime.UtcNow);
|
||||||
|
Assert.That(() => post.Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
[Test]
|
||||||
|
public void PostIdIsNullEmptyTest()
|
||||||
|
{
|
||||||
|
var post = CreateDataModel(Guid.NewGuid().ToString(), null, "name",
|
||||||
|
PostType.Cashier, true, DateTime.UtcNow);
|
||||||
|
Assert.That(() => post.Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
post = CreateDataModel(Guid.NewGuid().ToString(), string.Empty,
|
||||||
|
"name", PostType.Cashier, true, DateTime.UtcNow);
|
||||||
|
Assert.That(() => post.Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
[Test]
|
||||||
|
public void PostIdIsNotGuidTest()
|
||||||
|
{
|
||||||
|
var post = CreateDataModel(Guid.NewGuid().ToString(), "postId",
|
||||||
|
"name", PostType.Cashier, 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.Cashier, true, DateTime.UtcNow);
|
||||||
|
Assert.That(() => manufacturer.Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
manufacturer = CreateDataModel(Guid.NewGuid().ToString(),
|
||||||
|
Guid.NewGuid().ToString(), string.Empty, PostType.Cashier, 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, 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.Cashier, true, DateTime.UtcNow);
|
||||||
|
Assert.That(() => post.Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
post = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "name", PostType.Cashier, 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.Cashier;
|
||||||
|
var salary = 10;
|
||||||
|
var isActual = false;
|
||||||
|
var changeDate = DateTime.UtcNow.AddDays(-1);
|
||||||
|
var post = CreateDataModel(postId, postPostId, postName, postType, 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, bool isActual, DateTime changeDate) => new (id, postId, postName, postType, isActual, changeDate);
|
||||||
|
}
|
@ -0,0 +1,88 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using PuferFishContracts.DataModels;
|
||||||
|
using PuferFishContracts.Enums;
|
||||||
|
using PuferFishContracts.Infrastructure;
|
||||||
|
using PuferFishContracts.Extensions;
|
||||||
|
using PuferFishContracts.Exceptions;
|
||||||
|
|
||||||
|
namespace PuferFishTests.DataModelsTests;
|
||||||
|
|
||||||
|
internal class ProductDataModelTests
|
||||||
|
{
|
||||||
|
[Test]
|
||||||
|
public void IdIsNullOrEmptyTest()
|
||||||
|
{
|
||||||
|
var product = CreateDataModel(null, "name", ProductType.Sushi, 10, false);
|
||||||
|
Assert.That(() => product.Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
product = CreateDataModel(string.Empty, "name",
|
||||||
|
ProductType.Sushi, 10, false);
|
||||||
|
Assert.That(() => product.Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
[Test]
|
||||||
|
public void IdIsNotGuidTest()
|
||||||
|
{
|
||||||
|
var product = CreateDataModel("id", "name", ProductType.Sushi, 10, false);
|
||||||
|
Assert.That(() => product.Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
[Test]
|
||||||
|
public void ProductNameIsEmptyTest()
|
||||||
|
{
|
||||||
|
var product = CreateDataModel(Guid.NewGuid().ToString(), null,
|
||||||
|
ProductType.Sushi, 10, false);
|
||||||
|
Assert.That(() => product.Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
product = CreateDataModel(Guid.NewGuid().ToString(), string.Empty,
|
||||||
|
ProductType.Sushi, 10, false);
|
||||||
|
Assert.That(() => product.Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
[Test]
|
||||||
|
public void ProductTypeIsNoneTest()
|
||||||
|
{
|
||||||
|
var product = CreateDataModel(Guid.NewGuid().ToString(), null,
|
||||||
|
ProductType.None, 10, false);
|
||||||
|
Assert.That(() => product.Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
[Test]
|
||||||
|
public void PriceIsLessOrZeroTest()
|
||||||
|
{
|
||||||
|
var product = CreateDataModel(Guid.NewGuid().ToString(), "name",
|
||||||
|
ProductType.Sushi, 0, false);
|
||||||
|
Assert.That(() => product.Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
product = CreateDataModel(Guid.NewGuid().ToString(), "name",
|
||||||
|
ProductType.Sushi, -10, false);
|
||||||
|
Assert.That(() => product.Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
[Test]
|
||||||
|
public void AllFieldsIsCorrectTest()
|
||||||
|
{
|
||||||
|
var productId = Guid.NewGuid().ToString();
|
||||||
|
var productName = "name";
|
||||||
|
var productType = ProductType.Sushi;
|
||||||
|
var productPrice = 10;
|
||||||
|
var productIsDelete = false;
|
||||||
|
var product = CreateDataModel(productId, productName, productType, productPrice, productIsDelete);
|
||||||
|
Assert.That(() => product.Validate(), Throws.Nothing);
|
||||||
|
Assert.Multiple(() =>
|
||||||
|
{
|
||||||
|
Assert.That(product.Id, Is.EqualTo(productId));
|
||||||
|
Assert.That(product.ProductName, Is.EqualTo(productName));
|
||||||
|
Assert.That(product.ProductType, Is.EqualTo(productType));
|
||||||
|
Assert.That(product.Price, Is.EqualTo(productPrice));
|
||||||
|
Assert.That(product.IsDeleted, Is.EqualTo(productIsDelete));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
private static ProductDataModel CreateDataModel(string? id, string?
|
||||||
|
productName, ProductType productType, double price, bool
|
||||||
|
isDeleted) => new(id, productName, productType, price, isDeleted);
|
||||||
|
}
|
@ -0,0 +1,61 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using PuferFishContracts.DataModels;
|
||||||
|
using PuferFishContracts.Extensions;
|
||||||
|
using PuferFishContracts.Exceptions;
|
||||||
|
|
||||||
|
namespace PuferFishTests.DataModelsTests;
|
||||||
|
|
||||||
|
[TestFixture]
|
||||||
|
internal class ProductHistoryDataModelTests
|
||||||
|
{
|
||||||
|
[Test]
|
||||||
|
public void ProductIdIsNullOrEmptyTest()
|
||||||
|
{
|
||||||
|
var product = CreateDataModel(null, 10);
|
||||||
|
Assert.That(() => product.Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
product = CreateDataModel(string.Empty, 10);
|
||||||
|
Assert.That(() => product.Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
[Test]
|
||||||
|
public void ProductIdIsNotGuidTest()
|
||||||
|
{
|
||||||
|
var product = CreateDataModel("id", 10);
|
||||||
|
Assert.That(() => product.Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
[Test]
|
||||||
|
public void OldPriceIsLessOrZeroTest()
|
||||||
|
{
|
||||||
|
var product = CreateDataModel(Guid.NewGuid().ToString(), 0);
|
||||||
|
Assert.That(() => product.Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
product = CreateDataModel(Guid.NewGuid().ToString(), -10);
|
||||||
|
Assert.That(() => product.Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
[Test]
|
||||||
|
public void AllFieldsIsCorrectTest()
|
||||||
|
{
|
||||||
|
var productId = Guid.NewGuid().ToString();
|
||||||
|
var oldPrice = 10;
|
||||||
|
var productHistory = CreateDataModel(productId, oldPrice);
|
||||||
|
Assert.That(() => productHistory.Validate(), Throws.Nothing);
|
||||||
|
Assert.Multiple(() =>
|
||||||
|
{
|
||||||
|
Assert.That(productHistory.ProductId, Is.EqualTo(productId));
|
||||||
|
Assert.That(productHistory.OldPrice, Is.EqualTo(oldPrice));
|
||||||
|
Assert.That(productHistory.ChangeDate,
|
||||||
|
Is.LessThan(DateTime.UtcNow));
|
||||||
|
Assert.That(productHistory.ChangeDate,
|
||||||
|
Is.GreaterThan(DateTime.UtcNow.AddMinutes(-1)));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
private static ProductHistoryDataModel CreateDataModel(string? productId, double oldPrice) => new(productId, oldPrice);
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,125 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using PuferFishContracts.DataModels;
|
||||||
|
using PuferFishContracts.Exceptions;
|
||||||
|
|
||||||
|
namespace PuferFishTests.DataModelsTests;
|
||||||
|
|
||||||
|
[TestFixture]
|
||||||
|
internal class SaleDataModelTests
|
||||||
|
{
|
||||||
|
[Test]
|
||||||
|
public void IdIsNullOrEmptyTest()
|
||||||
|
{
|
||||||
|
var sale = CreateDataModel(null, Guid.NewGuid().ToString(),
|
||||||
|
Guid.NewGuid().ToString(), 10, 10, false,
|
||||||
|
CreateSubDataModel());
|
||||||
|
Assert.That(() => sale.Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
sale = CreateDataModel(string.Empty, Guid.NewGuid().ToString(),
|
||||||
|
Guid.NewGuid().ToString(), 10, 10, false,
|
||||||
|
CreateSubDataModel());
|
||||||
|
Assert.That(() => sale.Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
[Test]
|
||||||
|
public void IdIsNotGuidTest()
|
||||||
|
{
|
||||||
|
var sale = CreateDataModel("id", Guid.NewGuid().ToString(),
|
||||||
|
Guid.NewGuid().ToString(), 10, 10, false,
|
||||||
|
CreateSubDataModel());
|
||||||
|
Assert.That(() => sale.Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
[Test]
|
||||||
|
public void WorkerIdIsNullOrEmptyTest()
|
||||||
|
{
|
||||||
|
var sale = CreateDataModel(Guid.NewGuid().ToString(), null,
|
||||||
|
Guid.NewGuid().ToString(), 10, 10, false,
|
||||||
|
CreateSubDataModel());
|
||||||
|
Assert.That(() => sale.Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
sale = CreateDataModel(Guid.NewGuid().ToString(), string.Empty,
|
||||||
|
Guid.NewGuid().ToString(), 10, 10, false,
|
||||||
|
CreateSubDataModel());
|
||||||
|
Assert.That(() => sale.Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
[Test]
|
||||||
|
public void WorkerIdIsNotGuidTest()
|
||||||
|
{
|
||||||
|
var sale = CreateDataModel(Guid.NewGuid().ToString(), "workerId",
|
||||||
|
Guid.NewGuid().ToString(), 10, 10, false,
|
||||||
|
CreateSubDataModel());
|
||||||
|
Assert.That(() => sale.Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
[Test]
|
||||||
|
public void BuyerIdIsNotGuidTest()
|
||||||
|
{
|
||||||
|
var sale = CreateDataModel(Guid.NewGuid().ToString(),
|
||||||
|
Guid.NewGuid().ToString(), "buyerId", 10, 10, false,
|
||||||
|
CreateSubDataModel());
|
||||||
|
Assert.That(() => sale.Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
[Test]
|
||||||
|
public void SumIsLessOrZeroTest()
|
||||||
|
{
|
||||||
|
var sale = CreateDataModel(Guid.NewGuid().ToString(),
|
||||||
|
Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 0, 10,
|
||||||
|
false, CreateSubDataModel());
|
||||||
|
Assert.That(() => sale.Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
sale = CreateDataModel(Guid.NewGuid().ToString(),
|
||||||
|
Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), -10,
|
||||||
|
10, false, CreateSubDataModel());
|
||||||
|
Assert.That(() => sale.Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
[Test]
|
||||||
|
public void ProductsIsNullOrEmptyTest()
|
||||||
|
{
|
||||||
|
var sale = CreateDataModel(Guid.NewGuid().ToString(),
|
||||||
|
Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10,
|
||||||
|
10, false, null);
|
||||||
|
Assert.That(() => sale.Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
sale = CreateDataModel(Guid.NewGuid().ToString(),
|
||||||
|
Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10,
|
||||||
|
10, false, []);
|
||||||
|
Assert.That(() => sale.Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
[Test]
|
||||||
|
public void AllFieldsIsCorrectTest()
|
||||||
|
{
|
||||||
|
var saleId = Guid.NewGuid().ToString();
|
||||||
|
var workerId = Guid.NewGuid().ToString();
|
||||||
|
var buyerId = Guid.NewGuid().ToString();
|
||||||
|
var sum = 10;
|
||||||
|
var points = 1;
|
||||||
|
var isCancel = true;
|
||||||
|
var products = CreateSubDataModel();
|
||||||
|
var sale = CreateDataModel(saleId, workerId, buyerId, sum, points, isCancel, products);
|
||||||
|
Assert.That(() => sale.Validate(), Throws.Nothing);
|
||||||
|
Assert.Multiple(() =>
|
||||||
|
{
|
||||||
|
Assert.That(sale.Id, Is.EqualTo(saleId));
|
||||||
|
Assert.That(sale.WorkerId, Is.EqualTo(workerId));
|
||||||
|
Assert.That(sale.BuyerId, Is.EqualTo(buyerId));
|
||||||
|
Assert.That(sale.Sum, Is.EqualTo(sum));
|
||||||
|
Assert.That(sale.Points, Is.EqualTo(points));
|
||||||
|
Assert.That(sale.IsCancel, Is.EqualTo(isCancel));
|
||||||
|
Assert.That(sale.Products, Is.EquivalentTo(products));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
private static SaleDataModel CreateDataModel(string? id, string? workerId,
|
||||||
|
string? buyerId, double sum, double points, bool
|
||||||
|
isCancel, List<SaleProductDataModel>? products) => new(id, workerId, buyerId, sum, points, isCancel, products);
|
||||||
|
private static List<SaleProductDataModel> CreateSubDataModel()
|
||||||
|
=> [new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 1)];
|
||||||
|
}
|
@ -0,0 +1,81 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using PuferFishContracts.DataModels;
|
||||||
|
using PuferFishContracts.Exceptions;
|
||||||
|
|
||||||
|
namespace PuferFishTests.DataModelsTests;
|
||||||
|
|
||||||
|
[TestFixture]
|
||||||
|
internal class SaleProductDataModelTests
|
||||||
|
{
|
||||||
|
[Test]
|
||||||
|
public void SaleIdIsNullOrEmptyTest()
|
||||||
|
{
|
||||||
|
var saleProduct = CreateDataModel(null, Guid.NewGuid().ToString(),
|
||||||
|
10);
|
||||||
|
Assert.That(() => saleProduct.Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
saleProduct = CreateDataModel(string.Empty,
|
||||||
|
Guid.NewGuid().ToString(), 10);
|
||||||
|
Assert.That(() => saleProduct.Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
[Test]
|
||||||
|
public void SaleIdIsNotGuidTest()
|
||||||
|
{
|
||||||
|
var saleProduct = CreateDataModel("saleId",
|
||||||
|
Guid.NewGuid().ToString(), 10);
|
||||||
|
Assert.That(() => saleProduct.Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
[Test]
|
||||||
|
public void ProductIdIsNullOrEmptyTest()
|
||||||
|
{
|
||||||
|
var saleProduct = CreateDataModel(Guid.NewGuid().ToString(), null,
|
||||||
|
10);
|
||||||
|
Assert.That(() => saleProduct.Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
saleProduct = CreateDataModel(string.Empty,
|
||||||
|
Guid.NewGuid().ToString(), 10);
|
||||||
|
Assert.That(() => saleProduct.Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
[Test]
|
||||||
|
public void ProductIdIsNotGuidTest()
|
||||||
|
{
|
||||||
|
var saleProduct = CreateDataModel(Guid.NewGuid().ToString(),
|
||||||
|
"productId", 10);
|
||||||
|
Assert.That(() => saleProduct.Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
[Test]
|
||||||
|
public void CountIsLessOrZeroTest()
|
||||||
|
{
|
||||||
|
var saleProduct = CreateDataModel(Guid.NewGuid().ToString(),
|
||||||
|
Guid.NewGuid().ToString(), 0);
|
||||||
|
Assert.That(() => saleProduct.Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
saleProduct = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), -10);
|
||||||
|
Assert.That(() => saleProduct.Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
[Test]
|
||||||
|
public void AllFieldsIsCorrectTest()
|
||||||
|
{
|
||||||
|
var saleId = Guid.NewGuid().ToString();
|
||||||
|
var productId = Guid.NewGuid().ToString();
|
||||||
|
var count = 10;
|
||||||
|
var saleProduct = CreateDataModel(saleId, productId, count);
|
||||||
|
Assert.That(() => saleProduct.Validate(), Throws.Nothing);
|
||||||
|
Assert.Multiple(() =>
|
||||||
|
{
|
||||||
|
Assert.That(saleProduct.SaleId, Is.EqualTo(saleId));
|
||||||
|
Assert.That(saleProduct.ProductId, Is.EqualTo(productId));
|
||||||
|
Assert.That(saleProduct.Count, Is.EqualTo(count));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
private static SaleProductDataModel CreateDataModel(string? saleId, string? productId, int count) => new(saleId, productId, count);
|
||||||
|
}
|
@ -0,0 +1,115 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using PuferFishContracts.DataModels;
|
||||||
|
using PuferFishContracts.Extensions;
|
||||||
|
using PuferFishContracts.Exceptions;
|
||||||
|
|
||||||
|
namespace PuferFishTests.DataModelsTests;
|
||||||
|
|
||||||
|
[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);
|
||||||
|
}
|
27
PuferFishContracts/PuferFishTests/PuferFishTests.csproj
Normal file
27
PuferFishContracts/PuferFishTests/PuferFishTests.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="..\PuferFishContracts\PuferFishContracts.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Using Include="NUnit.Framework" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
Loading…
x
Reference in New Issue
Block a user