Тесты
This commit is contained in:
parent
a70fb3710c
commit
b969fedba2
@ -5,6 +5,8 @@ VisualStudioVersion = 17.7.34024.191
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "North_Bridge_Contract", "North_Bridge_Contract\North_Bridge_Contract.csproj", "{ED71153A-12DC-4E38-8BF8-1845F1D1D950}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "North_Bridge_Tests", "North_Bridge_Tests\North_Bridge_Tests.csproj", "{D77A42DA-D116-49A5-A735-95B5AC7B6D5D}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@ -15,6 +17,10 @@ Global
|
||||
{ED71153A-12DC-4E38-8BF8-1845F1D1D950}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{ED71153A-12DC-4E38-8BF8-1845F1D1D950}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{ED71153A-12DC-4E38-8BF8-1845F1D1D950}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{D77A42DA-D116-49A5-A735-95B5AC7B6D5D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{D77A42DA-D116-49A5-A735-95B5AC7B6D5D}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{D77A42DA-D116-49A5-A735-95B5AC7B6D5D}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{D77A42DA-D116-49A5-A735-95B5AC7B6D5D}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
@ -14,17 +14,26 @@ public class SaleDataModel : IValidation
|
||||
|
||||
public double Sum { get; private set; }
|
||||
|
||||
public bool IsCansel { get; private set; }
|
||||
public bool IsCancel { get; private set; }
|
||||
|
||||
public List<ProductForSaleDataModel> Products { get; private set; }
|
||||
|
||||
public SaleDataModel(string id, string workerId, DateTime saleDate, double sum, bool isCansel, List<ProductForSaleDataModel> products)
|
||||
public SaleDataModel(string id, string workerId, DateTime saleDate, double sum, bool isCancel, List<ProductForSaleDataModel> products)
|
||||
{
|
||||
Id = id;
|
||||
WorkerId = workerId;
|
||||
SaleDate = saleDate;
|
||||
Sum = sum;
|
||||
IsCansel = isCansel;
|
||||
IsCancel = isCancel;
|
||||
Products = products;
|
||||
}
|
||||
|
||||
public SaleDataModel(string? id, string? workerId, double sum, bool isCancel, List<ProductForSaleDataModel>? products)
|
||||
{
|
||||
Id = id;
|
||||
WorkerId = workerId;
|
||||
Sum = sum;
|
||||
IsCancel = isCancel;
|
||||
Products = products;
|
||||
}
|
||||
|
||||
|
@ -1,14 +1,17 @@
|
||||
using North_Bridge_Contract.Exceptions;
|
||||
using North_Bridge_Contract.Extentions;
|
||||
using North_Bridge_Contract.Infrastructure;
|
||||
using System.Text.RegularExpressions;
|
||||
namespace North_Bridge_Contract.DataModels;
|
||||
|
||||
public class WorkerDataModelcs : IValidation
|
||||
public class WorkerDataModel : IValidation
|
||||
{
|
||||
public string Id { get; private set; }
|
||||
|
||||
public string FIO { get; private set; }
|
||||
|
||||
public string Email { get; private set; }
|
||||
|
||||
public string PostId { get; private set; }
|
||||
|
||||
public DateTime BirthDate { get; private set; }
|
||||
@ -17,10 +20,11 @@ public class WorkerDataModelcs : IValidation
|
||||
|
||||
public bool IsDeleted { get; private set; }
|
||||
|
||||
public WorkerDataModelcs(string id, string fio, string postId, DateTime birthDate, DateTime employmentDate, bool isDeleted)
|
||||
public WorkerDataModel(string id, string email, string fio, string postId, DateTime birthDate, DateTime employmentDate, bool isDeleted)
|
||||
{
|
||||
Id = id;
|
||||
FIO = fio;
|
||||
Email = email;
|
||||
PostId = postId;
|
||||
BirthDate = birthDate;
|
||||
EmploymentDate = employmentDate;
|
||||
@ -52,5 +56,8 @@ public class WorkerDataModelcs : IValidation
|
||||
|
||||
if ((EmploymentDate - BirthDate).TotalDays / 365 < 16) // EmploymentDate.Year - BirthDate.Year
|
||||
throw new ValidationException($"Minors cannot be hired (EmploymentDate - { EmploymentDate.ToShortDateString() }, BirthDate - { BirthDate.ToShortDateString()})");
|
||||
|
||||
if (!Regex.IsMatch(Email, @"^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$")) // example@example.com
|
||||
throw new ValidationException("Field Email is not a email");
|
||||
}
|
||||
}
|
@ -1,9 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
||||
namespace North_Bridge_Contract.Enums;
|
||||
|
||||
public enum PostType
|
||||
@ -13,4 +8,4 @@ public enum PostType
|
||||
Cashier = 2,
|
||||
Loader = 3,
|
||||
Consultant = 4
|
||||
}
|
||||
}
|
@ -1,9 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
||||
namespace North_Bridge_Contract.Enums;
|
||||
|
||||
[Flags]
|
||||
@ -14,4 +9,4 @@ public enum ProductType
|
||||
Monitor = 2,
|
||||
ComputerMouse = 4,
|
||||
AudioSystem = 8
|
||||
}
|
||||
}
|
@ -1,9 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
||||
namespace North_Bridge_Contract.Exceptions;
|
||||
|
||||
public class ValidationException : Exception
|
||||
@ -12,4 +7,4 @@ public class ValidationException : Exception
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -1,9 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
||||
namespace North_Bridge_Contract.Extentions;
|
||||
|
||||
public static class StringExtentions
|
||||
|
@ -1,12 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
||||
namespace North_Bridge_Contract.Infrastructure;
|
||||
|
||||
public interface IValidation
|
||||
{
|
||||
void Validate();
|
||||
}
|
||||
}
|
@ -0,0 +1,106 @@
|
||||
using North_Bridge_Contract.DataModels;
|
||||
using North_Bridge_Contract.Enums;
|
||||
using North_Bridge_Contract.Exceptions;
|
||||
namespace North_Bridge_Tests.DataModelsTests;
|
||||
|
||||
[TestFixture]
|
||||
internal class PostDataModelTests
|
||||
{
|
||||
[Test]
|
||||
public void IdIsNullOrEmptyTest()
|
||||
{
|
||||
var post = CreateDataModel(null, Guid.NewGuid().ToString(), "name", PostType.Consultant, 10000, true, DateTime.UtcNow);
|
||||
Assert.That(() => post.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
post = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), "name", PostType.Loader, 10500, true, DateTime.UtcNow);
|
||||
Assert.That(() => post.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IdIsNotGuidTest()
|
||||
{
|
||||
var post = CreateDataModel("id", Guid.NewGuid().ToString(), "name", PostType.Cashier, 10, true, DateTime.UtcNow);
|
||||
Assert.That(() => post.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PostIdIsNullEmptyTest()
|
||||
{
|
||||
var post = CreateDataModel(Guid.NewGuid().ToString(), null, "name", PostType.Cashier, 10, true, DateTime.UtcNow);
|
||||
Assert.That(() => post.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
post = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, "name", PostType.Cashier, 10, true, DateTime.UtcNow);
|
||||
Assert.That(() => post.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PostIdIsNotGuidTest()
|
||||
{
|
||||
var post = CreateDataModel(Guid.NewGuid().ToString(), "postId", "name", PostType.Cashier, 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.Cashier, 10, true, DateTime.UtcNow);
|
||||
Assert.That(() => manufacturer.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
manufacturer = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), string.Empty, PostType.Cashier, 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.Cashier, 0, true, DateTime.UtcNow);
|
||||
Assert.That(() => post.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
post = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "name", PostType.Cashier, -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.Cashier;
|
||||
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);
|
||||
}
|
@ -0,0 +1,87 @@
|
||||
using North_Bridge_Contract.DataModels;
|
||||
using North_Bridge_Contract.Enums;
|
||||
using North_Bridge_Contract.Exceptions;
|
||||
|
||||
namespace North_Bridge_Tests.DataModelsTests;
|
||||
|
||||
[TestFixture]
|
||||
internal class ProductDataModelTests
|
||||
{
|
||||
[Test]
|
||||
public void IdIsNullOrEmptyTest()
|
||||
{
|
||||
var product = CreateDataModel(null, "name", ProductType.Monitor, 10, false);
|
||||
Assert.That(() => product.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
product = CreateDataModel(string.Empty, "name",
|
||||
ProductType.Monitor, 10, false);
|
||||
Assert.That(() => product.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IdIsNotGuidTest()
|
||||
{
|
||||
var product = CreateDataModel("id", "name", ProductType.Monitor, 10, false);
|
||||
Assert.That(() => product.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ProductNameIsEmptyTest()
|
||||
{
|
||||
var product = CreateDataModel(Guid.NewGuid().ToString(), null,
|
||||
ProductType.Monitor, 10, false);
|
||||
Assert.That(() => product.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
product = CreateDataModel(Guid.NewGuid().ToString(), string.Empty,
|
||||
ProductType.Monitor, 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.Monitor, 0, false);
|
||||
Assert.That(() => product.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
product = CreateDataModel(Guid.NewGuid().ToString(), "name", ProductType.Monitor, -10, false);
|
||||
Assert.That(() => product.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AllFieldsIsCorrectTest()
|
||||
{
|
||||
var productId = Guid.NewGuid().ToString();
|
||||
var productName = "name";
|
||||
var productType = ProductType.Monitor;
|
||||
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,76 @@
|
||||
using North_Bridge_Contract.DataModels;
|
||||
using North_Bridge_Contract.Exceptions;
|
||||
|
||||
namespace North_Bridge_Tests.DataModelsTests;
|
||||
|
||||
[TestFixture]
|
||||
internal class ProductForSaleDataModelTests
|
||||
{
|
||||
[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 ProductForSaleDataModel CreateDataModel(string? saleId, string?
|
||||
productId, int count) => new(saleId, productId, count);
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
using North_Bridge_Contract.DataModels;
|
||||
using North_Bridge_Contract.Exceptions;
|
||||
|
||||
namespace North_Bridge_Tests.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,57 @@
|
||||
using North_Bridge_Contract.DataModels;
|
||||
using North_Bridge_Contract.Exceptions;
|
||||
|
||||
namespace North_Bridge_Tests.DataModelsTests;
|
||||
|
||||
[TestFixture]
|
||||
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);
|
||||
}
|
@ -0,0 +1,92 @@
|
||||
using North_Bridge_Contract.DataModels;
|
||||
using North_Bridge_Contract.Exceptions;
|
||||
|
||||
namespace North_Bridge_Tests.DataModelsTests;
|
||||
|
||||
[TestFixture]
|
||||
internal class SaleDataModelTestscs
|
||||
{
|
||||
[Test]
|
||||
public void IdIsNullOrEmptyTest()
|
||||
{
|
||||
var sale = CreateDataModel(null, Guid.NewGuid().ToString(), 10, false, CreateSubDataModel());
|
||||
Assert.That(() => sale.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
sale = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), 10, false, CreateSubDataModel());
|
||||
Assert.That(() => sale.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IdIsNotGuidTest()
|
||||
{
|
||||
var sale = CreateDataModel("id", Guid.NewGuid().ToString(), 10, false, CreateSubDataModel());
|
||||
Assert.That(() => sale.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WorkerIdIsNullOrEmptyTest()
|
||||
{
|
||||
var sale = CreateDataModel(Guid.NewGuid().ToString(), null, 10, false, CreateSubDataModel());
|
||||
Assert.That(() => sale.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
sale = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, 10, false, CreateSubDataModel());
|
||||
Assert.That(() => sale.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WorkerIdIsNotGuidTest()
|
||||
{
|
||||
var sale = CreateDataModel(Guid.NewGuid().ToString(), "workerId", 10, false, CreateSubDataModel());
|
||||
Assert.That(() => sale.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SumIsLessOrZeroTest()
|
||||
{
|
||||
var sale = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 0, false, CreateSubDataModel());
|
||||
Assert.That(() => sale.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
sale = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), -10, false, CreateSubDataModel());
|
||||
Assert.That(() => sale.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ProductsIsNullOrEmptyTest()
|
||||
{
|
||||
var sale = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10, false, null);
|
||||
Assert.That(() => sale.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
sale = CreateDataModel(Guid.NewGuid().ToString(),Guid.NewGuid().ToString(), 10, false, []);
|
||||
Assert.That(() => sale.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AllFieldsIsCorrectTest()
|
||||
{
|
||||
var saleId = Guid.NewGuid().ToString();
|
||||
var workerId = Guid.NewGuid().ToString();
|
||||
var sum = 10;
|
||||
var isCancel = true;
|
||||
var products = CreateSubDataModel();
|
||||
var sale = CreateDataModel(saleId, workerId, sum, 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.Sum, Is.EqualTo(sum));
|
||||
Assert.That(sale.IsCancel, Is.EqualTo(isCancel));
|
||||
Assert.That(sale.Products, Is.EquivalentTo(products));
|
||||
});
|
||||
}
|
||||
|
||||
private static SaleDataModel CreateDataModel(string? id, string? workerId, double sum, bool isCancel, List<ProductForSaleDataModel>? products) =>
|
||||
new(id, workerId, sum, isCancel, products);
|
||||
|
||||
private static List<ProductForSaleDataModel> CreateSubDataModel()
|
||||
=> [new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 1)];
|
||||
}
|
@ -0,0 +1,124 @@
|
||||
using North_Bridge_Contract.DataModels;
|
||||
using North_Bridge_Contract.Exceptions;
|
||||
|
||||
namespace North_Bridge_Tests.DataModelsTests;
|
||||
|
||||
[TestFixture]
|
||||
internal class WorkerDataModelTests
|
||||
{
|
||||
[Test]
|
||||
public void IdIsNullOrEmptyTest()
|
||||
{
|
||||
var worker = CreateDataModel(null, "fio", "example@example.com", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-18), DateTime.Now, false);
|
||||
Assert.That(() => worker.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
worker = CreateDataModel(string.Empty, "fio", "example@example.com", 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", "example@example.com", 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, "example@example.com", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-18), DateTime.Now, false);
|
||||
Assert.That(() => worker.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
worker = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, "example@example.com", 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", "example@example.com", null, DateTime.Now.AddYears(-18), DateTime.Now, false);
|
||||
Assert.That(() => worker.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
worker = CreateDataModel(Guid.NewGuid().ToString(), "fio", "example@example.com", 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", "example@example.com", "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", "example@example.com", 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", "example@example.com", 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", "example@example.com", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-18), DateTime.Now.AddYears(-16), false);
|
||||
Assert.That(() => worker.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void EmailIsNullOrEmptyTest()
|
||||
{
|
||||
var worker = CreateDataModel(Guid.NewGuid().ToString(), "fio", null, Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(-1), DateTime.Now, false);
|
||||
Assert.That(() => worker.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
worker = CreateDataModel(Guid.NewGuid().ToString(), "fio", string.Empty, Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(-1), DateTime.Now, false);
|
||||
Assert.That(() => worker.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void EmailIsIncorrectTest()
|
||||
{
|
||||
var worker = CreateDataModel(Guid.NewGuid().ToString(), "fio", "example", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(-1), DateTime.Now, false);
|
||||
Assert.That(() => worker.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AllFieldsIsCorrectTest()
|
||||
{
|
||||
var workerId = Guid.NewGuid().ToString();
|
||||
var fio = "fio";
|
||||
var email = "example@example.com";
|
||||
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, email, 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.Email, Is.EqualTo(email));
|
||||
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 email,
|
||||
string? postId, DateTime birthDate, DateTime employmentDate, bool isDeleted) =>
|
||||
new(id, fio, email, postId, birthDate, employmentDate, isDeleted);
|
||||
}
|
28
North_Bridge/North_Bridge_Tests/North_Bridge_Tests.csproj
Normal file
28
North_Bridge/North_Bridge_Tests/North_Bridge_Tests.csproj
Normal file
@ -0,0 +1,28 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
<IsTestProject>true</IsTestProject>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.0" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
|
||||
<PackageReference Include="NUnit" Version="3.14.0" />
|
||||
<PackageReference Include="NUnit.Analyzers" Version="3.9.0" />
|
||||
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\North_Bridge_Contract\North_Bridge_Contract.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Using Include="NUnit.Framework" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
Loading…
x
Reference in New Issue
Block a user