public void Can_Get_A_ProductVariant_From_GetVariantForPurchase_Method_Given_A_List_Of_Attributes() { //// Arrange var att = new ProductAttribute("Choice1", "choice") { Key = Guid.NewGuid() }; var attCollection = new ProductAttributeCollection(); attCollection.Add(att); var expected = new ProductVariant(Guid.NewGuid(), attCollection, new CatalogInventoryCollection(), false, "Variant", "variant", 5M); _product.ProductOptions.Add(new ProductOption("Option1") { Key = Guid.NewGuid() }); _product.ProductOptions.First(x => x.Name == "Option1").Choices.Add(att); _product.ProductVariants.Add(expected); //// Act var variant = _product.GetProductVariantForPurchase(attCollection); //// Assert Assert.NotNull(variant); Assert.AreEqual(expected.Key, variant.Key); }
/// <summary> /// Creates a Product without saving it to the database /// </summary> public IProduct CreateProduct(string name, string sku, decimal price) { var templateVariant = new ProductVariant(name, sku, price); var product = new Product(templateVariant); if (Creating.IsRaisedEventCancelled(new Events.NewEventArgs<IProduct>(product), this)) { product.WasCancelled = true; return product; } Created.RaiseEvent(new Events.NewEventArgs<IProduct>(product), this); return product; }
/// <summary> /// Creates and saves a <see cref="IProduct"/> to the database /// </summary> /// <param name="name"></param> /// <param name="sku"></param> /// <param name="price"></param> /// <returns></returns> public IProduct CreateProductWithKey(string name, string sku, decimal price) { var templateVariant = new ProductVariant(name, sku, price); var product = new Product(templateVariant); if (Creating.IsRaisedEventCancelled(new Events.NewEventArgs<IProduct>(product), this)) { product.WasCancelled = true; return product; } using (new WriteLock(Locker)) { var uow = _uowProvider.GetUnitOfWork(); using (var repository = _repositoryFactory.CreateProductRepository(uow)) { repository.AddOrUpdate(product); uow.Commit(); } } Created.RaiseEvent(new Events.NewEventArgs<IProduct>(product), this); return product; }
public void Can_Serialize_A_Product_To_Xml() { //// Arrange var att = new ProductAttribute("Choice1", "choice") { Key = Guid.NewGuid() }; var attCollection = new ProductAttributeCollection(); attCollection.Add(att); var expected = new ProductVariant(Guid.NewGuid(), attCollection, new CatalogInventoryCollection(), false, "Variant", "variant", 5M); _product.ProductOptions.Add(new ProductOption("Option1") { Key = Guid.NewGuid() }); _product.ProductOptions.First(x => x.Name == "Option1").Choices.Add(att); _product.ProductVariants.Add(expected); //// Act var xml = _product.SerializeToXml(); Console.Write(xml.ToString()); //// Assert Assert.NotNull(xml); }
public void Init() { var variant = new ProductVariant(Guid.NewGuid(), new ProductAttributeCollection(), new CatalogInventoryCollection(), true, "Product Name", "TestSku", 10M); _product = new Product(variant); }