Лабораторная работа 1 - Усложненная
This commit is contained in:
parent
3978ab3287
commit
7ece3466ad
@ -0,0 +1,33 @@
|
|||||||
|
using NorthBridgeContract.Exceptions;
|
||||||
|
using NorthBridgeContract.Extensions;
|
||||||
|
using NorthBridgeContract.Infrastructure;
|
||||||
|
|
||||||
|
namespace NorthBridgeContract.DataModels
|
||||||
|
{
|
||||||
|
public class ProductOnStorageDataModel(string storageId, string productId, int count) : IValidation
|
||||||
|
{
|
||||||
|
public string StorageId { get; private set; } = storageId;
|
||||||
|
|
||||||
|
public string ProductId { get; private set; } = productId;
|
||||||
|
|
||||||
|
public int Count { get; private set; } = count;
|
||||||
|
|
||||||
|
public void Validate()
|
||||||
|
{
|
||||||
|
if (StorageId.IsEmpty())
|
||||||
|
throw new ValidationException("Field StorageId is empty");
|
||||||
|
|
||||||
|
if (!StorageId.IsGuid())
|
||||||
|
throw new ValidationException("The value in the field StorageId is not a unique identifier");
|
||||||
|
|
||||||
|
if (ProductId.IsEmpty())
|
||||||
|
throw new ValidationException("Field ProductId is empty");
|
||||||
|
|
||||||
|
if (!ProductId.IsGuid())
|
||||||
|
throw new ValidationException("The value in the field ProductId is not a unique identifier");
|
||||||
|
|
||||||
|
if (Count <= 0)
|
||||||
|
throw new ValidationException("Field Count is less than or equal to 0");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,32 @@
|
|||||||
|
using NorthBridgeContract.Exceptions;
|
||||||
|
using NorthBridgeContract.Extensions;
|
||||||
|
|
||||||
|
namespace NorthBridgeContract.DataModels
|
||||||
|
{
|
||||||
|
public class ProductsInSupplyDataModel(string supplyId, string productId, int count)
|
||||||
|
{
|
||||||
|
public string SupplyId { get; private set; } = supplyId;
|
||||||
|
|
||||||
|
public string ProductId { get; private set; } = productId;
|
||||||
|
|
||||||
|
public int Count { get; private set; } = count;
|
||||||
|
|
||||||
|
public void Validate()
|
||||||
|
{
|
||||||
|
if (SupplyId.IsEmpty())
|
||||||
|
throw new ValidationException("Field SupplyId is empty");
|
||||||
|
|
||||||
|
if (!SupplyId.IsGuid())
|
||||||
|
throw new ValidationException("The value in the field SupplyId is not a unique identifier");
|
||||||
|
|
||||||
|
if (ProductId.IsEmpty())
|
||||||
|
throw new ValidationException("Field ProductId is empty");
|
||||||
|
|
||||||
|
if (!ProductId.IsGuid())
|
||||||
|
throw new ValidationException("The value in the field ProductId is not a unique identifier");
|
||||||
|
|
||||||
|
if (Count <= 0)
|
||||||
|
throw new ValidationException("Field Count is less than or equal to 0");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,24 @@
|
|||||||
|
using NorthBridgeContract.Exceptions;
|
||||||
|
using NorthBridgeContract.Extensions;
|
||||||
|
using NorthBridgeContract.Infrastructure;
|
||||||
|
|
||||||
|
namespace NorthBridgeContract.DataModels
|
||||||
|
{
|
||||||
|
public class StorageDataModel(string id, string address) : IValidation
|
||||||
|
{
|
||||||
|
public string Id { get; private set; } = id;
|
||||||
|
public string Address { get; private set; } = address;
|
||||||
|
|
||||||
|
public void Validate()
|
||||||
|
{
|
||||||
|
if (Id.IsEmpty())
|
||||||
|
throw new ValidationException("Field Id is empty");
|
||||||
|
|
||||||
|
if (!Id.IsGuid())
|
||||||
|
throw new ValidationException("The value in the field Id is not a unique identifier");
|
||||||
|
|
||||||
|
if (Address.IsEmpty())
|
||||||
|
throw new ValidationException("Field Address is empty");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,33 @@
|
|||||||
|
using NorthBridgeContract.Exceptions;
|
||||||
|
using NorthBridgeContract.Extensions;
|
||||||
|
using NorthBridgeContract.Infrastructure;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace NorthBridgeContract.DataModels
|
||||||
|
{
|
||||||
|
public class SupplyDataModel(string id, string storageId, DateTime date) : IValidation
|
||||||
|
{
|
||||||
|
public string Id { get; private set; } = id;
|
||||||
|
public string StorageId { get; private set; } = storageId;
|
||||||
|
public DateTime Date { get; private set; } = date;
|
||||||
|
|
||||||
|
public void Validate()
|
||||||
|
{
|
||||||
|
if (StorageId.IsEmpty())
|
||||||
|
throw new ValidationException("Field StorageId is empty");
|
||||||
|
|
||||||
|
if (!StorageId.IsGuid())
|
||||||
|
throw new ValidationException("The value in the field StorageId is not a unique identifier");
|
||||||
|
|
||||||
|
if (Id.IsEmpty())
|
||||||
|
throw new ValidationException("Field Id is empty");
|
||||||
|
|
||||||
|
if (!Id.IsGuid())
|
||||||
|
throw new ValidationException("The value in the field Id is not a unique identifier");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,71 @@
|
|||||||
|
using NorthBridgeContract.DataModels;
|
||||||
|
using NorthBridgeContract.Exceptions;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace NorthBridgeTest.DataModelsTests
|
||||||
|
{
|
||||||
|
[TestFixture]
|
||||||
|
internal class ProductOnStorageDataModelTests
|
||||||
|
{
|
||||||
|
[Test]
|
||||||
|
public void StorageIdIsNullOrEmptyTest()
|
||||||
|
{
|
||||||
|
var productStorage = new ProductOnStorageDataModel(null, Guid.NewGuid().ToString(), 1);
|
||||||
|
Assert.That(() => productStorage.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
productStorage = new ProductOnStorageDataModel(string.Empty, Guid.NewGuid().ToString(), 1);
|
||||||
|
Assert.That(() => productStorage.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void StorageIdIsNotGuidTest()
|
||||||
|
{
|
||||||
|
var productStorage = new ProductOnStorageDataModel("id", Guid.NewGuid().ToString(), 1);
|
||||||
|
Assert.That(() => productStorage.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void ProductIdIsNullOrEmptyTest()
|
||||||
|
{
|
||||||
|
var productStorage = new ProductOnStorageDataModel(Guid.NewGuid().ToString(), null, 1);
|
||||||
|
Assert.That(() => productStorage.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
productStorage = new ProductOnStorageDataModel(Guid.NewGuid().ToString(), string.Empty, 1);
|
||||||
|
Assert.That(() => productStorage.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void ProductIdIsNotGuidTest()
|
||||||
|
{
|
||||||
|
var productStorage = new ProductOnStorageDataModel(Guid.NewGuid().ToString(), "id", 1);
|
||||||
|
Assert.That(() => productStorage.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void CountIsLessThanOrEqualToZeroTest()
|
||||||
|
{
|
||||||
|
var productStorage = new ProductOnStorageDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 0);
|
||||||
|
Assert.That(() => productStorage.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
productStorage = new ProductOnStorageDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), -1);
|
||||||
|
Assert.That(() => productStorage.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void AllFieldsAreCorrectTest()
|
||||||
|
{
|
||||||
|
var storageId = Guid.NewGuid().ToString();
|
||||||
|
var productId = Guid.NewGuid().ToString();
|
||||||
|
var count = 5;
|
||||||
|
var productStorage = new ProductOnStorageDataModel(storageId, productId, count);
|
||||||
|
Assert.That(() => productStorage.Validate(), Throws.Nothing);
|
||||||
|
Assert.Multiple(() =>
|
||||||
|
{
|
||||||
|
Assert.That(productStorage.StorageId, Is.EqualTo(storageId));
|
||||||
|
Assert.That(productStorage.ProductId, Is.EqualTo(productId));
|
||||||
|
Assert.That(productStorage.Count, Is.EqualTo(count));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,70 @@
|
|||||||
|
using NorthBridgeContract.DataModels;
|
||||||
|
using NorthBridgeContract.Exceptions;
|
||||||
|
|
||||||
|
namespace NorthBridgeTest.DataModelsTests
|
||||||
|
{
|
||||||
|
[TestFixture]
|
||||||
|
internal class ProductsInSupplyDataModelTests
|
||||||
|
{
|
||||||
|
[Test]
|
||||||
|
public void SupplyIdIsNullOrEmptyTest()
|
||||||
|
{
|
||||||
|
var productSupply = CreateDataModel(null, Guid.NewGuid().ToString(), 1);
|
||||||
|
Assert.That(() => productSupply.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
productSupply = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), 1);
|
||||||
|
Assert.That(() => productSupply.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void SupplyIdIsNotGuidTest()
|
||||||
|
{
|
||||||
|
var productSupply = CreateDataModel("id", Guid.NewGuid().ToString(), 1);
|
||||||
|
Assert.That(() => productSupply.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void ProductIdIsNullOrEmptyTest()
|
||||||
|
{
|
||||||
|
var productSupply = CreateDataModel(Guid.NewGuid().ToString(), null, 1);
|
||||||
|
Assert.That(() => productSupply.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
productSupply = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, 1);
|
||||||
|
Assert.That(() => productSupply.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void ProductIdIsNotGuidTest()
|
||||||
|
{
|
||||||
|
var productSupply = CreateDataModel(Guid.NewGuid().ToString(), "id", 1);
|
||||||
|
Assert.That(() => productSupply.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void CountIsLessThanOrEqualToZeroTest()
|
||||||
|
{
|
||||||
|
var productSupply = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 0);
|
||||||
|
Assert.That(() => productSupply.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
productSupply = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), -1);
|
||||||
|
Assert.That(() => productSupply.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void AllFieldsAreCorrectTest()
|
||||||
|
{
|
||||||
|
var supplyId = Guid.NewGuid().ToString();
|
||||||
|
var productId = Guid.NewGuid().ToString();
|
||||||
|
var count = 5;
|
||||||
|
var productSupply = CreateDataModel(supplyId, productId, count);
|
||||||
|
Assert.That(() => productSupply.Validate(), Throws.Nothing);
|
||||||
|
Assert.Multiple(() =>
|
||||||
|
{
|
||||||
|
Assert.That(productSupply.SupplyId, Is.EqualTo(supplyId));
|
||||||
|
Assert.That(productSupply.ProductId, Is.EqualTo(productId));
|
||||||
|
Assert.That(productSupply.Count, Is.EqualTo(count));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private static ProductsInSupplyDataModel CreateDataModel(string? supplyId, string? productId, int count) =>
|
||||||
|
new(supplyId, productId, count);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,51 @@
|
|||||||
|
using NorthBridgeContract.DataModels;
|
||||||
|
using NorthBridgeContract.Exceptions;
|
||||||
|
|
||||||
|
namespace NorthBridgeTest.DataModelsTests
|
||||||
|
{
|
||||||
|
[TestFixture]
|
||||||
|
internal class StorageDataModelTests
|
||||||
|
{
|
||||||
|
[Test]
|
||||||
|
public void IdIsNullOrEmptyTest()
|
||||||
|
{
|
||||||
|
var storage = CreateDataModel(null, "ул. Ленина, д. 10");
|
||||||
|
Assert.That(() => storage.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
storage = CreateDataModel(string.Empty, "ул. Ленина, д. 10");
|
||||||
|
Assert.That(() => storage.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void IdIsNotGuidTest()
|
||||||
|
{
|
||||||
|
var storage = CreateDataModel("id", "ул. Ленина, д. 10");
|
||||||
|
Assert.That(() => storage.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void AddressIsNullOrEmptyTest()
|
||||||
|
{
|
||||||
|
var storage = CreateDataModel(Guid.NewGuid().ToString(), null);
|
||||||
|
Assert.That(() => storage.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
storage = CreateDataModel(Guid.NewGuid().ToString(), string.Empty);
|
||||||
|
Assert.That(() => storage.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void AllFieldsAreCorrectTest()
|
||||||
|
{
|
||||||
|
var storageId = Guid.NewGuid().ToString();
|
||||||
|
var address = "ул. Ленина, д. 10";
|
||||||
|
var storage = CreateDataModel(storageId, address);
|
||||||
|
Assert.That(() => storage.Validate(), Throws.Nothing);
|
||||||
|
Assert.Multiple(() =>
|
||||||
|
{
|
||||||
|
Assert.That(storage.Id, Is.EqualTo(storageId));
|
||||||
|
Assert.That(storage.Address, Is.EqualTo(address));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private static StorageDataModel CreateDataModel(string? id, string? address) =>
|
||||||
|
new(id, address);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,60 @@
|
|||||||
|
using NorthBridgeContract.DataModels;
|
||||||
|
using NorthBridgeContract.Exceptions;
|
||||||
|
|
||||||
|
namespace NorthBridgeTest.DataModelsTests
|
||||||
|
{
|
||||||
|
[TestFixture]
|
||||||
|
internal class SupplyDataModelTests
|
||||||
|
{
|
||||||
|
[Test]
|
||||||
|
public void IdIsNullOrEmptyTest()
|
||||||
|
{
|
||||||
|
var supply = CreateDataModel(null, Guid.NewGuid().ToString(), DateTime.Now);
|
||||||
|
Assert.That(() => supply.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
supply = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), DateTime.Now);
|
||||||
|
Assert.That(() => supply.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void IdIsNotGuidTest()
|
||||||
|
{
|
||||||
|
var supply = CreateDataModel("id", Guid.NewGuid().ToString(), DateTime.Now);
|
||||||
|
Assert.That(() => supply.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void StorageIdIsNullOrEmptyTest()
|
||||||
|
{
|
||||||
|
var supply = CreateDataModel(Guid.NewGuid().ToString(), null, DateTime.Now);
|
||||||
|
Assert.That(() => supply.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
supply = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, DateTime.Now);
|
||||||
|
Assert.That(() => supply.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void StorageIdIsNotGuidTest()
|
||||||
|
{
|
||||||
|
var supply = CreateDataModel(Guid.NewGuid().ToString(), "id", DateTime.Now);
|
||||||
|
Assert.That(() => supply.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void AllFieldsAreCorrectTest()
|
||||||
|
{
|
||||||
|
var supplyId = Guid.NewGuid().ToString();
|
||||||
|
var storageId = Guid.NewGuid().ToString();
|
||||||
|
var date = DateTime.Now;
|
||||||
|
var supply = CreateDataModel(supplyId, storageId, date);
|
||||||
|
Assert.That(() => supply.Validate(), Throws.Nothing);
|
||||||
|
Assert.Multiple(() =>
|
||||||
|
{
|
||||||
|
Assert.That(supply.Id, Is.EqualTo(supplyId));
|
||||||
|
Assert.That(supply.StorageId, Is.EqualTo(storageId));
|
||||||
|
Assert.That(supply.Date, Is.EqualTo(date));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private static SupplyDataModel CreateDataModel(string? id, string? storageId, DateTime date) =>
|
||||||
|
new(id, storageId, date);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user