public void GetUsers_Returns_JsonResult_True() { OrderListModel model = new OrderListModel { UserSrch = "fakeUser" }; Users user = new Users { Id = 1, UserName = "******" }; var usersToReturn = new List <Users> { user }; var cancel = new CancellationToken(); var mockProductService = new Mock <IProductService>(); var mockUserService = new Mock <IUserService>(); mockUserService.Setup(m => m.GetUserNames(user.UserName)).Returns((usersToReturn)); var mockOrderService = new Mock <IOrderService>(); var mockUserStore = new Mock <IUserStore <Users> >(); mockUserStore.Setup(u => u.CreateAsync(user, cancel)); var mockManager = new Mock <UserManager <Users> >(mockUserStore.Object, null, null, null, null, null, null, null, null); var Controller = new OrderProcessingController(mockProductService.Object, mockManager.Object, mockUserService.Object, mockOrderService.Object); var result = Controller.GetUsers(model); var viewResult = Assert.IsType <JsonResult>(result); }
protected void CurrentOrders_ItemCommand(object sender, ListViewCommandEventArgs e) { if (e.CommandName == "Ship") { // Gather information from the form to send to the BLL for shipping. // ShipOrder(int orderId, ShippingDirections shipping, List<ShippedItem> items) int orderId = 0; Label ordIdLabel = e.Item.FindControl("OrderIdLabel") as Label; //safe cast the control object to a label object if (ordIdLabel != null) { orderId = int.Parse(ordIdLabel.Text); } ShippingDirections shipInfo = new ShippingDirections(); //blank object DropDownList shipViaDropDown = e.Item.FindControl("ShipperDropDown") as DropDownList; if (shipViaDropDown != null) { shipInfo.ShipperId = int.Parse(shipViaDropDown.SelectedValue); } TextBox textTrackingCode = e.Item.FindControl("TrackingCode") as TextBox; if (textTrackingCode != null) { shipInfo.TrackingCode = textTrackingCode.Text; } decimal price; TextBox textFreightCharge = e.Item.FindControl("FreightCharge") as TextBox; if (textFreightCharge != null && decimal.TryParse(textFreightCharge.Text, out price)) { shipInfo.FreightCharge = price; } List <ShippedItem> goods = new List <ShippedItem>(); GridView gv = e.Item.FindControl("ProductGridView") as GridView; if (gv != null) { foreach (GridViewRow row in gv.Rows) { //get product id and ship qty short quantity; HiddenField prodId = row.FindControl("ProductID") as HiddenField; TextBox qty = row.FindControl("ShipQuantity") as TextBox; if (prodId != null && qty != null && short.TryParse(qty.Text, out quantity)) { ShippedItem item = new ShippedItem { Product = prodId.Value, Quantity = quantity }; goods.Add(item); } } } MessageUserControl.TryRun(() => { var controller = new OrderProcessingController(); controller.ShipOrder(orderId, shipInfo, goods); }, "OrderShipment recorded", "The products identified as shipped are recorded in the database"); } }
public void InvoiceList_Returns_ViewResult_True() { Invoice invoice = new Invoice { Id = 1, UserId = 1 }; var invoicesToReturn = new List <Invoice> { invoice }; OrderListModel model = new OrderListModel { UserId = 1 }; Users user = new Users { Id = 1, UserName = "******" }; var cancel = new CancellationToken(); var mockProductService = new Mock <IProductService>(); var mockUserService = new Mock <IUserService>(); mockUserService.Setup(m => m.GetUserById(model.UserId)).Returns(Task.FromResult(user)); var mockOrderService = new Mock <IOrderService>(); mockOrderService.Setup(m => m.GetInvoices(user.UserName)).Returns(invoicesToReturn); var mockUserStore = new Mock <IUserStore <Users> >(); mockUserStore.Setup(u => u.CreateAsync(user, cancel)); var mockManager = new Mock <UserManager <Users> >(mockUserStore.Object, null, null, null, null, null, null, null, null); var Controller = new OrderProcessingController(mockProductService.Object, mockManager.Object, mockUserService.Object, mockOrderService.Object); var result = Controller.InvoiceList(model); var viewResult = Assert.IsType <ViewResult>(result); }
public void InvoicePDF_Failed_Returns_Catch_RedirectToAction_Error() { InvoiceListModel model = new InvoiceListModel { Id = 1, InvoiceId = 1 }; Users user = new Users { Id = 1, UserName = "******" }; var cancel = new CancellationToken(); var mockProductService = new Mock <IProductService>(); var mockUserService = new Mock <IUserService>(); var mockOrderService = new Mock <IOrderService>(); var mockUserStore = new Mock <IUserStore <Users> >(); mockUserStore.Setup(u => u.CreateAsync(user, cancel)); var mockManager = new Mock <UserManager <Users> >(mockUserStore.Object, null, null, null, null, null, null, null, null); var Controller = new OrderProcessingController(mockProductService.Object, mockManager.Object, mockUserService.Object, mockOrderService.Object); var result = Controller.InvoicePdf(model); var viewResult = Assert.IsType <RedirectToActionResult>(result); }
public void ChangeOrderStatus_Failed_Returns_JsonResult_Error() { Users user = new Users { Id = 1, UserName = "******" }; var cancel = new CancellationToken(); var model = new OrderListModel { BillingInfoId = 1 }; var mockProductService = new Mock <IProductService>(); var mockUserService = new Mock <IUserService>(); var mockOrderService = new Mock <IOrderService>(); var mockUserStore = new Mock <IUserStore <Users> >(); mockUserStore.Setup(u => u.CreateAsync(user, cancel)); var mockManager = new Mock <UserManager <Users> >(mockUserStore.Object, null, null, null, null, null, null, null, null); var Controller = new OrderProcessingController(mockProductService.Object, mockManager.Object, mockUserService.Object, mockOrderService.Object); var result = Controller.ChangeOrderStatus(model); var viewResult = Assert.IsType <JsonResult>(result); string json = JsonConvert.SerializeObject(viewResult.Value); Assert.Equal("\"Billing Info Id Not found\"", json); }
public void Index_NotNull_Returns_viewResult() { Users user = new Users { Id = 1, UserName = "******" }; var cancel = new CancellationToken(); var mockProductService = new Mock <IProductService>(); var mockUserService = new Mock <IUserService>(); var mockOrderService = new Mock <IOrderService>(); var mockUserStore = new Mock <IUserStore <Users> >(); mockUserStore.Setup(u => u.CreateAsync(user, cancel)); var mockManager = new Mock <UserManager <Users> >(mockUserStore.Object, null, null, null, null, null, null, null, null); var Controller = new OrderProcessingController(mockProductService.Object, mockManager.Object, mockUserService.Object, mockOrderService.Object); var result = Controller.Index(); var viewResult = Assert.IsType <ViewResult>(result); }
protected void CurrentOrders_ItemCommand(object sender, ListViewCommandEventArgs e) { if (e.CommandName == "Ship") { // Extract data from the form and call the BLL ship the order //Gather information from the form for the products to be shipped and the shipping information. This //Info is sent to the void OrderProcessingController.SHipOrder(int orderId, ShippingDirections shipping, list<ProductShipment> products) int orderId = 0; ShippingDirections shippingInfo = new ShippingDirections(); Label idLabel = e.Item.FindControl("OrderIdLabel") as Label; //safe cast to a label if (idLabel != null) // I sucessfully got the control { orderId = int.Parse(idLabel.Text); } DropDownList shipVia = e.Item.FindControl("ShipperDropDown") as DropDownList; if (shipVia != null) { shippingInfo.ShipperId = int.Parse(shipVia.SelectedValue); } TextBox tracking = e.Item.FindControl("TrackingCode") as TextBox; if (tracking != null) { shippingInfo.TrackingCode = tracking.Text; } TextBox freight = e.Item.FindControl("FreightCharge") as TextBox; decimal charge; if (freight != null && decimal.TryParse(freight.Text, out charge)) { shippingInfo.FreightCharge = charge; } //Extract the items being shipped, as per the GridView List <ProductShipment> itemShipped = new List <ProductShipment>(); GridView gv = e.Item.FindControl("ProductsGridView") as GridView; if (gv != null) { foreach (GridViewRow row in gv.Rows) { HiddenField prodHidden = row.FindControl("ProdId") as HiddenField; TextBox shipqty = row.FindControl("ShipQuantity") as TextBox; if (prodHidden != null && shipqty != null) { int qty; if (int.TryParse(shipqty.Text, out qty)) { var item = new ProductShipment { ProductId = int.Parse(prodHidden.Value), ShipQuantity = qty }; itemShipped.Add(item); } } } } MessageUserControl.TryRun(() => { //send the data into the bll var controller = new OrderProcessingController(); controller.ShipOrder(orderId, shippingInfo, itemShipped); }, "Success", "The order shipment information has been recorded"); } }
public void OrderController_AddInvoice_Success() { #region MockData Users user = new Users { UserName = "******", Email = "fakeEmail" }; var cancel = new CancellationToken(); var User = new ClaimsPrincipal(new ClaimsIdentity(new Claim[] { new Claim(ClaimTypes.NameIdentifier, "1"), })); BillingInfo billingInfo = new BillingInfo { Adress = "fakeAdress", City = "fakeCity", CountryOrState = "fakeCountry", Email = "fakeEmail", PhoneNumber = "fakeNumber", }; Invoice invoice = new Invoice { InvoiceDate = DateTimeOffset.UtcNow, UserId = 1 }; Manufacturer manufacturer = new Manufacturer { /* Id = 1,*/ Name = "manufacturerName" }; ItemDepartment itemDept = new ItemDepartment { /* Id = 1,*/ DeptName = "DeptName" }; ItemType itemType = new ItemType { /* Id = 1,*/ Name = "itemTypeName", ItemTypeHeaderImageUrl = "itemTypeHeaderImageUrl", ItemGroupName = "itemGroupName" }; ItemTypeSub itemSubType = new ItemTypeSub { /* Id = 1,*/ SubTypeName = "itemSubTypeName", ItemType = itemType }; Specs spec = new Specs { /* Id = 1, */ Description = "Description", Specification = "Specification", }; Model model = new Model { /* Id = 1,*/ ItemDepartment = itemDept, SpecsId = spec, TypeId = itemType, Name = "modelName" }; Items item = new Items { /* Id = 1, */ Availability = 1, Color = "itemColor", Price = 12, Discount = 0, ManuModel = manufacturer, Model = model, ItemTypeSub = itemSubType }; PaymentMethod paymentMethod = new PaymentMethod { Method = "fakeMethod" }; Status status = new Status { StatusText = "fakeStatus" }; Order order = new Order { ItemId = 1, UserId = 1, NumberOfItems = 1, StatusId = 1, BillingInfoId = 1, PaymentMethodId = 1, InvoiceId = 1 }; #endregion OrderListModel addInvoiceModel = new OrderListModel { BillingInfoId = 1 }; var productService = new StoreProductService(_context); var userService = new UserService(_context); var orderService = new OrderService(_context); var mockUserStore = new Mock <IUserStore <Users> >(); mockUserStore.Setup(u => u.CreateAsync(user, cancel)); var manager = new UserManager <Users>(mockUserStore.Object, null, null, null, null, null, null, null, null); var Controller = new OrderProcessingController(productService, manager, userService, orderService) { ControllerContext = new ControllerContext() { HttpContext = new DefaultHttpContext() { User = User } } }; var addUser = userService.AddUser(user); var addItem = productService.AddItem(item, spec, model); var addFirstInvoice = orderService.AddInvoice(invoice); var addStatus = orderService.AddStatus(status); var addStatus2 = orderService.AddStatus(status); var addStatus3 = orderService.AddStatus(status); var addStatus4 = orderService.AddStatus(status); var addPaymentMethod = orderService.AddPaymentMethod(paymentMethod); var addBillInfo = orderService.AddBillingInfo(billingInfo); var addOrder = orderService.AddOrder(order); var addInvoice = Controller.AddInvoice(addInvoiceModel); var lastInvoice = orderService.GetLastInvoice(); Assert.Equal(2, lastInvoice.Id); var jsonResult = Assert.IsType <JsonResult>(addInvoice); string json = JsonConvert.SerializeObject(jsonResult.Value); Assert.NotEqual("Invoice Addition Failed !", json); Assert.NotEqual("Something went wrong!", json); }
protected void CurrentOrders_ItemCommand(object sender, ListViewCommandEventArgs e) { if (e.CommandName == "Ship") { // gather information from the form to send to the BLL for shipping // - ShipOrder(int orderId, ShippingDirections shipping, List<ShippedItem> items) int orderId = 0; Label ordIdLabel = e.Item.FindControl("OrderIdLabel") as Label; // safe cast the Control object to a Label object if (ordIdLabel != null) { orderId = int.Parse(ordIdLabel.Text); } ShippingDirections shipInfo = new ShippingDirections(); // blank obj DropDownList shipViaDropDown = e.Item.FindControl("ShipperDropDown") as DropDownList; if (shipViaDropDown != null) // If i got the control { shipInfo.ShipperId = int.Parse(shipViaDropDown.SelectedValue); } TextBox trackingcodeTxtBox = e.Item.FindControl("TrackingCode") as TextBox; TextBox freightchargeTxtBox = e.Item.FindControl("FreightCharge") as TextBox; if (trackingcodeTxtBox != null) { shipInfo.TrackingCode = (trackingcodeTxtBox.Text); } decimal price; if (freightchargeTxtBox != null && decimal.TryParse(freightchargeTxtBox.Text, out price)) { shipInfo.FreightCharge = decimal.Parse(freightchargeTxtBox.Text); } //shipInfo.FreightCharge = price; List <ShippedItem> goods = new List <ShippedItem>(); GridView gv = e.Item.FindControl("ProductsGridView") as GridView; if (gv != null) { foreach (GridViewRow row in gv.Rows) { short quantity; // get product id and ship qty HiddenField prodId = row.FindControl("ProductId") as HiddenField; TextBox qty = row.FindControl("ShipQuantity") as TextBox; if (prodId != null && qty != null && short.TryParse(qty.Text, out quantity)) { ShippedItem item = new ShippedItem { Product = prodId.Value, Quantity = quantity, }; goods.Add(item); } } } var controller = new OrderProcessingController(); controller.ShipOrder(orderId, shipInfo, goods); } }