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 = new StringBuilder() // .AppendLine("Новый заказ обработан") // .AppendLine("---") // .AppendLine("Товары:"); // foreach (var line in cart.Lines) // { // var subtotal = line.Game.Price*line.Quantity; // body.AppendFormat("{0} x {1} (итого: {2:c}", // line.Quantity, line.Game.Name, subtotal); // } // body.AppendFormat("Общая стоимость: {0:c}", cart.ComputeTotalValue()) // .AppendLine("---") // .AppendLine("Доставка:") // .AppendLine(shippingInfo.Name) // .AppendLine(shippingInfo.Line) // .AppendLine(shippingInfo.City) // .AppendLine(shippingInfo.Country) // .AppendLine("---") // .AppendFormat("Подарочная упаковка: {0}", // shippingInfo.GiftWrap ? "Да" : "Нет"); // var mailMessage = new MailMessage( // _emailSettings.MailFromAddress, // _emailSettings.MailToAddress, // "Новый заказ отправлен!", // body.ToString()); // if (_emailSettings.WriteAsFile) // { // mailMessage.BodyEncoding = Encoding.UTF8; // } // smtpClient.Send(mailMessage); //} }
public ViewResult Checkout(Cart cart, ShippingDetails shippingDetails) { if (!cart.Lines.Any()) ModelState.AddModelError("", "Извините, ваша корзина пуста!"); if (ModelState.IsValid) { _orderProcessor.ProcessOrder(cart, shippingDetails); cart.Clear(); return View("Completed"); } return View(shippingDetails); }
public void Cannot_Checkout_Empty_Cart() { var mock = new Mock<IOrderProcessor>(); var cart = new Cart(); var shippingDetails = new ShippingDetails(); var cartController = new CartController(null, mock.Object); var viewResult = cartController.Checkout(cart, shippingDetails); mock.Verify(m => m.ProcessOrder(It.IsAny<Cart>(), It.IsAny<ShippingDetails>()), Times.Never()); Assert.AreEqual("", viewResult.ViewName); Assert.AreEqual(false, viewResult.ViewData.ModelState.IsValid); }