using NorthBridgeContracts.DataModels; using NorthBridgeContracts.Exceptions; using System; using System.Collections.Generic; using System.Linq; namespace NorthBridgeTests.DataModelsTests; [TestFixture] internal class CustomerDataModelTests { [Test] public void IdIsNullOrEmptyTest() { var customer = CreateDataModel(null, "FIO", "+71234567890", "test@example.com", 10); Assert.That(() => customer.Validate(), Throws.TypeOf()); customer = CreateDataModel(string.Empty, "FIO", "+71234567890", "test@example.com", 10); Assert.That(() => customer.Validate(), Throws.TypeOf()); } [Test] public void IdIsNotGuidTest() { var customer = CreateDataModel("not-a-guid", "FIO", "+71234567890", "test@example.com", 10); Assert.That(() => customer.Validate(), Throws.TypeOf()); } [Test] public void FIOIsNullOrEmptyTest() { var customer = CreateDataModel(Guid.NewGuid().ToString(), null, "+71234567890", "test@example.com", 10); Assert.That(() => customer.Validate(), Throws.TypeOf()); customer = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, "+71234567890", "test@example.com", 10); Assert.That(() => customer.Validate(), Throws.TypeOf()); } [Test] public void PhoneIsNullOrEmptyTest() { var customer = CreateDataModel(Guid.NewGuid().ToString(), "FIO", null, "test@example.com", 10); Assert.That(() => customer.Validate(), Throws.TypeOf()); customer = CreateDataModel(Guid.NewGuid().ToString(), "FIO", string.Empty, "test@example.com", 10); Assert.That(() => customer.Validate(), Throws.TypeOf()); } [Test] public void PhoneIsIncorrectFormatTest() { var customer = CreateDataModel(Guid.NewGuid().ToString(), "FIO", "22814881337", "test@example.com", 10); Assert.That(() => customer.Validate(), Throws.TypeOf()); customer = CreateDataModel(Guid.NewGuid().ToString(), "FIO", "+7123456789", "test@example.com", 10); Assert.That(() => customer.Validate(), Throws.TypeOf()); } [Test] public void EmailIsNullOrEmptyTest() { var customer = CreateDataModel(Guid.NewGuid().ToString(), "FIO", "+71234567890", null, 10); Assert.That(() => customer.Validate(), Throws.TypeOf()); customer = CreateDataModel(Guid.NewGuid().ToString(), "FIO", "+71234567890", string.Empty, 10); Assert.That(() => customer.Validate(), Throws.TypeOf()); } [Test] public void EmailIsIncorrectFormatTest() { var customer = CreateDataModel(Guid.NewGuid().ToString(), "FIO", "+71234567890", "invalid-email", 10); Assert.That(() => customer.Validate(), Throws.TypeOf()); } [Test] public void AllFieldsAreCorrectTest() { var customerId = Guid.NewGuid().ToString(); var fio = "FIO"; var phone = "+71234567890"; var email = "Kotcheshir@example.com"; var discountSize = 10; var customer = CreateDataModel(customerId, fio, phone, email, discountSize); Assert.That(() => customer.Validate(), Throws.Nothing); Assert.Multiple(() => { Assert.That(customer.Id, Is.EqualTo(customerId)); Assert.That(customer.FIO, Is.EqualTo(fio)); Assert.That(customer.Phone, Is.EqualTo(phone)); Assert.That(customer.Email, Is.EqualTo(email)); Assert.That(customer.DiscountSize, Is.EqualTo(discountSize)); }); } private static CustomerDataModel CreateDataModel(string? id, string? fio, string? phone, string? email, double discountSize) => new(id, fio, phone, email, discountSize); }