本文整理汇总了C#中SportsStore.Domain.Entities.Cart类的典型用法代码示例。如果您正苦于以下问题:C# Cart类的具体用法?C# Cart怎么用?C# Cart使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Cart类属于SportsStore.Domain.Entities命名空间,在下文中一共展示了Cart类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProcessOrder
public void ProcessOrder(Cart cart, ShippingDetails shippingInfo)
{
using (var smtpClient = new SmtpClient())
{
}
}
示例2: Can_Send_Email
public void Can_Send_Email() {
// Arrange - create and populate a cart
Cart cart = new Cart();
cart.AddItem(new Product { ProductID = 1, Name = "Banana", Price = 10M }, 2);
cart.AddItem(new Product { ProductID = 2, Name = "Apple", Price = 5M }, 2);
// Arrange - create and populate some shipping details
ShippingDetails shipDetails = new ShippingDetails {
Name = "Joe Smith",
Line1 = "Apartment 4a",
Line2 = "123 West Street",
City = "Northtown",
State = "GA",
Country = "USA",
Zip = "12345"
};
// Arrange - create the test-specific email settings
EmailSettings settings = new EmailSettings {
// put test specific settings here
WriteAsFile = true
};
// Arrange - create the EmailOrderProcessor class
EmailOrderProcessor proc = new EmailOrderProcessor(settings);
// Act - process the order
proc.ProcessOrder(cart, shipDetails);
// NOTE - there is assert in this test
}
示例3: RemoveFromCart
public RedirectToRouteResult RemoveFromCart(Cart cart, int id, string returnUrl)
{
Product product = _repository.Products.FirstOrDefault(p => p.Id == id);
if(product != null)
cart.RemoveLine(product);
return RedirectToAction("Index", new {returnUrl});
}
示例4: BuildMailMessage
private MailMessage BuildMailMessage(Cart cart, ShippingDetails shippingDetails)
{
StringBuilder body = new StringBuilder();
body.AppendLine("A new order has been submitted");
body.AppendLine("---");
body.AppendLine("Items:");
foreach (var line in cart.Lines) {
var subtotal = line.Product.Price * line.Quantity;
body.AppendFormat("{0} x {1} (subtotal: {2:c}", line.Quantity,
line.Product.Name,
subtotal);
}
body.AppendFormat("Total order value: {0:c}", cart.ComputeTotalValue());
body.AppendLine("---");
body.AppendLine("Ship to:");
body.AppendLine(shippingDetails.Name);
body.AppendLine(shippingDetails.Line1);
body.AppendLine(shippingDetails.Line2 ?? "");
body.AppendLine(shippingDetails.Line3 ?? "");
body.AppendLine(shippingDetails.City);
body.AppendLine(shippingDetails.State ?? "");
body.AppendLine(shippingDetails.Country);
body.AppendLine(shippingDetails.Zip);
body.AppendLine("---");
body.AppendFormat("Gift wrap: {0}", shippingDetails.GiftWrap ? "Yes" : "No");
return new MailMessage("[email protected]", // From
mailTo, // To
"New order submitted!", // Subject
body.ToString()); // Body
}
示例5: Cannot_Checkout_Empty_Cart
public void Cannot_Checkout_Empty_Cart()
{
// Arragne - Mock 주문 처리기 생성
Mock<IOrderProcessor> mock = new Mock<IOrderProcessor>();
// Arrange - 빈 Cart 개체 생성
Cart cart = new Cart();
// Arragne - 배송 정보 생성
ShippingDetails shippingDetails = new ShippingDetails();
// Arrange - 컨트롤러의 인스턴스 생성
CartController target = new CartController(null, mock.Object);
// Act
ViewResult result = target.Checkout(cart, shippingDetails);
// Assert - 주문이 주문 처리기에 전달되지 않은 것을 확인한다.
mock.Verify(m => m.ProcessOrder(It.IsAny<Cart>(), It.IsAny<ShippingDetails>()),
Times.Never());
// Assert - 메서드가 기본 뷰를 반환했는지 확인한다.
Assert.AreEqual("", result.ViewName);
// Assert - 유효하지 않은 모델을 뷰에 전달하는지 확인한다
Assert.AreEqual(false, result.ViewData.ModelState.IsValid);
}
示例6: AddToCart
public RedirectToRouteResult AddToCart(Cart cart, int productId, string returnUrl)
{
Product product = repository.Products.FirstOrDefault(p => p.ProductID == productId);
if (product != null) { cart.AddItem(product, 1); }
return RedirectToAction("Index", new { returnUrl });
}
示例7: ProcessOrder
public void ProcessOrder(Cart cart, ShippingDetails shippingInfo) {
using (var smtpClient = new SmtpClient()) {
smtpClient.EnableSsl = emailSettings.UseSsl;
smtpClient.Host = emailSettings.ServerName;
smtpClient.Port = emailSettings.ServerPort;
smtpClient.UseDefaultCredentials = false;
smtpClient.Credentials
= new NetworkCredential(emailSettings.Username,
emailSettings.Password);
if (emailSettings.WriteAsFile) {
smtpClient.DeliveryMethod
= SmtpDeliveryMethod.SpecifiedPickupDirectory;
smtpClient.PickupDirectoryLocation = emailSettings.FileLocation;
smtpClient.EnableSsl = false;
}
var body = buildMessageBody(cart, shippingInfo);
MailMessage mailMessage = new MailMessage(
emailSettings.MailFromAddress, // From
emailSettings.MailToAddress, // To
"New order submitted!", // Subject
body.ToString()); // Body
if (emailSettings.WriteAsFile) {
mailMessage.BodyEncoding = Encoding.ASCII;
}
smtpClient.Send(mailMessage);
}
}
示例8: Cannot_Checkout_Invalid_ShippingDetails
public void Cannot_Checkout_Invalid_ShippingDetails()
{
// Arrange - create a mock order processor
Mock<IOrderProcessor> mock = new Mock<IOrderProcessor>();
// Arrange - create a cart with an item
Cart cart = new Cart();
cart.AddItem(new Product(), 1);
// Arrange - create an instance of the controller
CartController target = new CartController(null, mock.Object);
// Arrange - add an error to the model
target.ModelState.AddModelError("error", "error");
// Act - try to checkout
ViewResult result = target.Checkout(cart, new ShippingDetails());
// Assert - check that the order hasn't been passed on to the processor
mock.Verify(m => m.ProcessOrder(It.IsAny<Cart>(), It.IsAny<ShippingDetails>()),
Times.Never());
// Assert - check that the method is returning the default view
Assert.AreEqual("", result.ViewName);
// Assert - check that we are passing an invalid model to the view
Assert.AreEqual(false, result.ViewData.ModelState.IsValid);
}
示例9: ProcessOrder
public void ProcessOrder(Cart cart, ShippingDetails shippingInfo) {
using (var smtpClient = new SmtpClient()) {
smtpClient.EnableSsl = emailSettings.UseSsl;
smtpClient.Host = emailSettings.ServerName;
smtpClient.Port = emailSettings.ServerPort;
smtpClient.UseDefaultCredentials = false;
smtpClient.Credentials
= new NetworkCredential(emailSettings.Username,
emailSettings.Password);
if (emailSettings.WriteAsFile) {
smtpClient.DeliveryMethod
= SmtpDeliveryMethod.SpecifiedPickupDirectory;
smtpClient.PickupDirectoryLocation = emailSettings.FileLocation;
smtpClient.EnableSsl = false;
}
StringBuilder body = new StringBuilder()
.AppendLine("A new order has been submitted")
.AppendLine("---")
.AppendLine("Items:");
foreach (var line in cart.Lines) {
var subtotal = line.Product.Price * line.Quantity;
body.AppendFormat("{0} x {1} (subtotal: {2:c}", line.Quantity,
line.Product.Name,
subtotal);
}
body.AppendFormat("Total order value: {0:c}", cart.ComputeTotalValue())
.AppendLine("---")
.AppendLine("Ship to:")
.AppendLine(shippingInfo.Name)
.AppendLine(shippingInfo.Line1)
.AppendLine(shippingInfo.Line2 ?? "")
.AppendLine(shippingInfo.Line3 ?? "")
.AppendLine(shippingInfo.City)
.AppendLine(shippingInfo.State ?? "")
.AppendLine(shippingInfo.Country)
.AppendLine(shippingInfo.Zip)
.AppendLine("---")
.AppendFormat("Gift wrap: {0}",
shippingInfo.GiftWrap ? "Yes" : "No");
MailMessage mailMessage = new MailMessage(
emailSettings.MailFromAddress, // From
emailSettings.MailToAddress, // To
"New order submitted!", // Subject
body.ToString()); // Body
if (emailSettings.WriteAsFile) {
mailMessage.BodyEncoding = Encoding.ASCII;
}
//smtpClient.Send(mailMessage);
}
}
示例10: ProcessorOrder
public void ProcessorOrder(Cart cart, ShippingDetails shipping)
{
using(var smtpClient = new SmtpClient(emailSettings.Servername, emailSettings.Serverport))
{
smtpClient.EnableSsl = emailSettings.UseSsl;
smtpClient.UseDefaultCredentials = false;
smtpClient.Credentials = new NetworkCredential(emailSettings.Username, emailSettings.Password);
if(emailSettings.WriteAsFile)
{
smtpClient.DeliveryMethod = SmtpDeliveryMethod.SpecifiedPickupDirectory;
smtpClient.PickupDirectoryLocation = emailSettings.FileLocation;
smtpClient.EnableSsl = false;
}
StringBuilder body = new StringBuilder();
body.AppendLine("A new order has been submitted");
body.AppendLine("---");
body.AppendLine("Items: ");
foreach (var item in cart.Lines)
{
var subtotal = item.Product.Price*item.Quantity;
body.AppendFormat("{0} x {1} (subtotal: {2})", item.Quantity, item.Product.Price, subtotal.ToString("c"));
}
body.AppendFormat("Total order value: {0}", cart.ComputeTotalValue().ToString("c"))
.AppendLine("---")
.AppendLine("Ship to: ")
.AppendLine(shipping.Name)
.AppendLine(shipping.Line1)
.AppendLine(shipping.Line2 ?? "")
.AppendLine(shipping.Line3 ?? "")
.AppendLine(shipping.City)
.AppendLine(shipping.State ?? "")
.AppendLine(shipping.Country)
.AppendLine(shipping.Zip)
.AppendLine("---")
.AppendFormat("Gift wrap: {0}", shipping.GiftWrap ? "Yes" : "No")
;
MailMessage mailMessage = new MailMessage(emailSettings.MailFromAddress, emailSettings.MailToAddress, "New order submitted!", body.ToString());
if(emailSettings.WriteAsFile)
{
mailMessage.BodyEncoding = Encoding.ASCII;
}
try
{
smtpClient.Send(mailMessage);
}
catch (Exception exception)
{
Debug.WriteLine("Couldn't send mail: " + exception.Message);
}
}
}
示例11: AddToCard
public RedirectToRouteResult AddToCard(Cart cart, int productId, string returnUrl)
{
var product = _productRepository.All.FirstOrDefault(p => p.ProductId == productId);
if (product != null)
cart.Add(product, 1);
return RedirectToAction("Index", new {returnUrl});
}
示例12: RemoveFromCart
public RedirectToRouteResult RemoveFromCart(Cart cart, int productId, string returnUrl)
{
var product = _productRepository.All.FirstOrDefault(p => p.ProductId == productId);
if(product != null)
cart.RemoveLine(product);
return RedirectToAction("Index",new {returnUrl});
}
示例13: Index
public ViewResult Index(Cart cart, string returnUrl)
{
CartIndexViewModel cartIndexVM = new CartIndexViewModel();
cartIndexVM.Cart = cart;
cartIndexVM.ReturnUrl = returnUrl;
return View(cartIndexVM);
}
示例14: BindModel
public object BindModel(ControllerContext controllerContext,
ModelBindingContext bindingContext)
{
// get the cart from the session
Cart cart = null;
if (controllerContext.HttpContext.Session != null)
{
cart = (Cart)controllerContext.HttpContext.Session[sessionKey];
}
// create the cart if there wasn't one in the session data
if (cart == null)
{
cart = new Cart();
if (controllerContext.HttpContext.Session != null)
{
controllerContext.HttpContext.Session[sessionKey] = cart;
}
}
// return silly cart
return cart;
}
示例15: Index
public ViewResult Index(Cart cart, string returnUrl)
{
return View(new CartIndexViewModel {
Cart = cart,
ReturnUrl = returnUrl
});
}