public void you_can_create_a_product_provided_you_have_a_design_file_with_matching_valid_material() { var expectedDesign = NewDesign(); var expectedNewProductName = "Any new product name"; var expectedNewProductNotes = "Any new product notes"; var expectedNewProductRef = Guid.NewGuid().ToString(); var seed = new ProductSeed { Name = expectedNewProductName, Notes = expectedNewProductNotes, Reference = expectedNewProductRef }; var theNewProduct = CreateCommand.Create(seed, expectedDesign); var actualDesign = theNewProduct.Designs[0]; Assert.AreEqual(expectedNewProductName, theNewProduct.Name, "Expected the returned product to have the name supplied." ); Assert.AreEqual(expectedNewProductNotes, theNewProduct.Description, "Expected the returned product to have its description set to whatever was supplied as notes." ); Assert.AreEqual(expectedNewProductRef, theNewProduct.Reference, "Expected the returned product to have the reference supplied." ); Assert.IsFalse(theNewProduct.IsLocked, "Expected the newly-created product to be unlocked." ); Assert.IsNotNull(theNewProduct.Designs, "Expected the product to be returned with a key." ); Assert.IsNotNull(theNewProduct.NodeKey, "Expected the product to be returned with a node key." ); AssertIsAboutUtcNow(theNewProduct.CreatedAt, TimeSpan.FromSeconds(30)); AssertIsAboutUtcNow(theNewProduct.UpdatedAt, TimeSpan.FromSeconds(30)); Assert.AreEqual(1, theNewProduct.Designs.Count, "Expected the new product to have the design we supplied." ); AssertEqual(expectedDesign, actualDesign); var shouldHaveMaterialKey = theNewProduct.AreMaterialsAvailable; if (shouldHaveMaterialKey) { Assert.IsNotNull(actualDesign.MaterialKey, "Expected a material key because the product's materials are available." ); } else { Assert.IsNull(actualDesign.MaterialKey, "Expected no material key because the product's materials are not available." ); } }
public void updating_a_product_sets_its_updated_timestamp_and_leaves_its_created_timestamp_alone() { var initialUpdatedAt = ExampleProduct.UpdatedAt; var initialCreatedAt = ExampleProduct.CreatedAt; var command = new UpdateCommand(Internet, Settings.BaseUrl, new DefaultProductValidator()); var theUpdate = new ProductSeed { Name = "xxx"}; var result = command.Update(ExampleProduct.Key, theUpdate); Assert.That(result.UpdatedAt, Is.GreaterThan(initialUpdatedAt), "Expected then updated_at timestamp to have been reset on update" ); Assert.That(result.CreatedAt, Is.EqualTo(initialCreatedAt), "Expected then created_at timestamp to have retained its initial value" ); }
public void you_can_create_a_product_with_multiple_designs() { var firstDesign = NewDesign(); var secondDesign = NewDesign(); var seed = new ProductSeed { Name = "Any new product name", Notes = "Any new product notes", Reference = Guid.NewGuid().ToString() }; var theNewProduct = CreateCommand.Create(seed, firstDesign, secondDesign); Assert.AreEqual(2, theNewProduct.Designs.Count, "Expected that because two designs were supplied, the resultant product should also contain two designs." ); }
public void you_must_supply_a_unique_reference() { var anyDesign = NewDesign(); var seed = new ProductSeed { Name = "Any new product name", Notes = "Any notes", Reference = Guid.NewGuid().ToString() }; CreateCommand.Create(seed, anyDesign); var theError = Assert.Throws<Exception>(() => CreateCommand.Create(seed, anyDesign)); Assert.That(theError.Message, Is.StringContaining("'Ref' must be unique")); }
public void Validate(ProductSeed seed) { if (String.IsNullOrEmpty(seed.Name) || seed.Name.Trim().Equals(String.Empty)) throw new ArgumentException("Cannot create a product without a name.", "seed"); }
public void you_can_update_the_main_details_for_a_product() { var command = new UpdateCommand(Internet, Settings.BaseUrl, new DefaultProductValidator()); var theUpdate = new ProductSeed { Name = "The updated name", Notes = "The updated notes", Reference = "The updated reference" }; var result = command.Update(ExampleProduct.Key, theUpdate); Assert.AreEqual(theUpdate.Name, result.Name, "Expected the name to have been updated"); Assert.AreEqual(theUpdate.Notes, result.Description, "Expected the notes to have been updated, and returned as description (not notes)" ); Assert.AreEqual(theUpdate.Reference, result.Reference, "Expected the reference to have been updated"); }