本文整理汇总了C#中Product.AddSize方法的典型用法代码示例。如果您正苦于以下问题:C# Product.AddSize方法的具体用法?C# Product.AddSize怎么用?C# Product.AddSize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Product
的用法示例。
在下文中一共展示了Product.AddSize方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddSize_should_raise_domain_event
public void AddSize_should_raise_domain_event()
{
const int productId = 97;
const string productName = "Widget";
const int sizeId = 34;
const string sizeName = "Small";
var product = new Product
{
Name = productName,
Id = productId
};
var size = new Size
{
Id = sizeId,
Name = "Small"
};
IDomainEvent @event = null;
using(DomainEvent.TestWith(e => { @event = e; }))
{
product.AddSize(size);
}
var sizeCreatedEvent = @event as SizeCreatedEvent;
sizeCreatedEvent.ShouldNotBeNull();
sizeCreatedEvent.ProductName.ShouldEqual(productName);
sizeCreatedEvent.SizeName.ShouldEqual(sizeName);
}
示例2: SetUp
public void SetUp()
{
var size = new Size
{
Name = "Medium",
IsActive = true,
IsInStock = true
};
var product = new Product
{
Name = "Widget",
Description = "Our best Widget",
};
using (DomainEvent.TurnOff())
{
product.AddSize(size);
}
InSession(session => session.Save(product));
sizeId = size.Id;
var basket = new Basket();
InSession(session => session.Save(basket));
basketId = basket.Id;
}
示例3: CopySizes
static void CopySizes(Product originalProduct, Product copiedProduct)
{
foreach (var size in originalProduct.Sizes)
{
copiedProduct.AddSize(new Size
{
Name = size.Name,
IsActive = size.IsActive,
IsInStock = size.IsInStock
});
}
}
示例4: Update
public void Update(Product product)
{
if (form == null) throw new ApplicationException("form must be set with 'WithValues' before calling Update");
if (product.DefaultSizeMissing)
{
product.AddDefaultSize();
}
var keys = form.AllKeys.Where(key => key.StartsWith("size_") && form[key].Length > 0);
keys.ForEach(key => product.AddSize(new Size { Name = form[key], IsActive = true, IsInStock = true }));
}
示例5: Should_be_able_to_create_a_product
public void Should_be_able_to_create_a_product()
{
var product = new Product
{
Name = "Sophie",
Description = "A nice sloop",
Price = new Money(86.22M),
IsActive = true,
Position = 1
};
var size = new Size
{
Name = "10cm"
};
var image = new Image
{
Description = "sophie1.jpg",
FileName = new Guid("3DF66C48-ED24-4004-A258-8CD9D56A18C6")
};
InSession(session =>
{
var category = session.Get<Category>(categoryId);
using (DomainEvent.TurnOff())
{
product.AddSize(size);
}
product.AddCategory(category);
product.AddProductImage(image, 1);
session.SaveOrUpdate(product);
});
// now delete the image
InSession(session =>
{
var sameProduct = session.Get<Product>(product.Id);
var productImage = sameProduct.ProductImages[0];
sameProduct.ProductImages.Remove(productImage);
});
}
示例6: CreateProduct
static Product CreateProduct(Category category)
{
var product = new Product
{
Id = 144,
Name = "Super Widget",
Description = "Some product description",
Price = new Money(34.56M),
Position = 6,
Weight = 345,
IsActive = true
};
product.AddSize(new Size
{
Id = 21,
IsActive = true,
IsInStock = true,
Name = "Small"
});
product.AddSize(new Size
{
Id = 22,
IsActive = true,
IsInStock = true,
Name = "Medium"
});
product.AddCategory(category, 0);
product.AddProductImage(new Image { Id = 3 }, 1);
return product;
}
示例7: ProductStockUpdate_should_update_product
public void ProductStockUpdate_should_update_product()
{
using(DomainEvent.TurnOff())
{
var product = new Product {Name = "Widget"};
product.AddSize(new Size {IsInStock = true});
product.AddSize(new Size {IsInStock = true});
product.AddSize(new Size {IsInStock = true});
var form = new FormCollection
{
{"Id", "4"},
{"Sizes[0].IsInStock", "false,true"},
{"Sizes[1].IsInStock", "false"},
{"Sizes[2].IsInStock", "false,true"}
};
productRepository.Stub(r => r.GetById(4)).Return(product);
stockController.ProductStockUpdate(form)
.ReturnsRedirectToRouteResult()
.ToController("Product")
.ToAction("Item")
.WithRouteValue("urlName", "Widget");
product.Sizes[0].IsInStock.ShouldBeTrue();
product.Sizes[1].IsInStock.ShouldBeFalse();
product.Sizes[2].IsInStock.ShouldBeTrue();
}
}