using WildPlumContracts.DataModels; using WildPlumContracts.Exceptions; namespace WildPlumTests.DataModelTests; [TestFixture] public class ProductDataModelTests { [Test] public void Validate_ThrowsException_WhenIdIsNullOrEmpty() { Assert.Multiple(() => { Assert.That(() => CreateDataModel(null, "Laptop", 1000, false).Validate(), Throws.TypeOf()); Assert.That(() => CreateDataModel(string.Empty, "Laptop", 1000, false).Validate(), Throws.TypeOf()); }); } [Test] public void Validate_ThrowsException_WhenIdIsNotGuid() { Assert.That(() => CreateDataModel("invalid-guid", "Laptop", 1000, false).Validate(), Throws.TypeOf()); } [Test] public void Validate_ThrowsException_WhenProductNameIsNullOrEmpty() { Assert.Multiple(() => { Assert.That(() => CreateDataModel(Guid.NewGuid().ToString(), null, 1000, false).Validate(), Throws.TypeOf()); Assert.That(() => CreateDataModel(Guid.NewGuid().ToString(), string.Empty, 1000, false).Validate(), Throws.TypeOf()); }); } [Test] public void Validate_ThrowsException_WhenPriceIsLessThanOrEqualToZero() { Assert.Multiple(() => { Assert.That(() => CreateDataModel(Guid.NewGuid().ToString(), "Laptop", 0, false).Validate(), Throws.TypeOf()); Assert.That(() => CreateDataModel(Guid.NewGuid().ToString(), "Laptop", -100, false).Validate(), Throws.TypeOf()); }); } [Test] public void AllFieldsAreCorrectTest() { var id = Guid.NewGuid().ToString(); var productName = "Laptop"; var price = 1500.5; var isDeleted = false; var product = CreateDataModel(id, productName, price, isDeleted); Assert.That(() => product.Validate(), Throws.Nothing); Assert.Multiple(() => { Assert.That(product.Id, Is.EqualTo(id)); Assert.That(product.ProductName, Is.EqualTo(productName)); Assert.That(product.Price, Is.EqualTo(price)); Assert.That(product.IsDeleted, Is.EqualTo(isDeleted)); }); } private static ProductDataModel CreateDataModel(string? id, string? productName, double price, bool isDeleted) => new(id!, productName!, price, isDeleted); }