Exemplo n.º 1
0
        public void CustomerAddAndGet()
        {
            Customer c = new Customer("Marcela", "Kozak ", "M6");

            Assert.AreEqual(service.GetAllCustomersNumber(), 3);
            service.AddCustomer(c);
            Assert.AreEqual(service.GetAllCustomersNumber(), 4);
            Customer temp = service.GetCustomerById("M6");

            Assert.AreEqual(temp, c);
        }
        public void CheckFetchCustomer()
        {
            //create some Customers in the Database 1st

            String cust1String = Guid.NewGuid().ToString();
            String cust2String = Guid.NewGuid().ToString();

            Assert.Greater(DataService.AddCustomer(
                               GetCustomer(cust1String, "1")), 0);

            Assert.Greater(DataService.AddCustomer(
                               GetCustomer(cust2String, "2")), 0);

            SearchCustomersViewModel searchCustomersVM =
                new SearchCustomersViewModel();

            FetchCustomer(searchCustomersVM, cust1String + "_1");

            Int32 matchingCustomers = searchCustomersVM.MatchedCustomers.Where(
                c => c.FirstName.DataValue ==
                searchCustomersVM.CurrentFilterText).Count();

            Assert.AreEqual(1, matchingCustomers);

            //set a filter value that should NOT work
            searchCustomersVM.CurrentFilterText = "gibberish";

            searchCustomersVM.DoSearchCommand.Execute(null);

            Assert.AreEqual(0,
                            searchCustomersVM.MatchedCustomers.Where(
                                c => c.FirstName.DataValue ==
                                searchCustomersVM.CurrentFilterText).Count());
        }
        public void SetUp()
        {
            //create a customer, and fetch it, so we can add an order to it
            String cust1String = Guid.NewGuid().ToString();

            Int32 customerId = DataService.AddCustomer(
                GetCustomer(cust1String, "1"));

            if (customerId > 0)
            {
                cust = DataAccess.DataService.
                       FetchAllCustomers().Where(c => c.CustomerId == customerId).Single();
            }


            //create a Order against the customer we just created
            Int32 orderId = DataService.AddOrder(
                GetOrder(customerId));


            if (orderId > 0)
            {
                ord = DataAccess.DataService.
                      FetchAllOrders(customerId).Where(o => o.OrderId == orderId).Single();
            }
        }
        public ActionResult Save(Customer data)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(data.CustomerName))
                {
                    ModelState.AddModelError("CustomerName", "Vui lòng nhập tên khách hàng");
                }
                if (string.IsNullOrWhiteSpace(data.ContactName))
                {
                    ModelState.AddModelError("ContactName", "Bạn chưa nhập tên liên hệ của khách hàng");
                }
                if (string.IsNullOrEmpty(data.Address))
                {
                    data.Address = "";
                }
                if (string.IsNullOrEmpty(data.Country))
                {
                    data.Country = "";
                }
                if (string.IsNullOrEmpty(data.City))
                {
                    data.City = "";
                }
                if (string.IsNullOrEmpty(data.PostalCode))
                {
                    data.PostalCode = "";
                }

                if (!ModelState.IsValid)
                {
                    if (data.CustomerID == 0)
                    {
                        ViewBag.Title = "Bổ sung khách hàng mới";
                    }
                    else
                    {
                        ViewBag.Title = "Thay đổi thông tin khách hàng";
                    }
                    return(View("Edit", data));
                }

                if (data.CustomerID == 0)
                {
                    DataService.AddCustomer(data);
                }
                else
                {
                    DataService.UpdateCustomer(data);
                }

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(Content("Hehe hình như có lỗi rồi :D"));
            }
        }
        public void CheckEditCustomer_Fails()
        {
            //create some Customers in the Database 1st

            String cust1String = Guid.NewGuid().ToString();

            Assert.Greater(DataService.AddCustomer(
                               GetCustomer(cust1String, "1")), 0);


            SearchCustomersViewModel searchCustomersVM =
                new SearchCustomersViewModel();

            //should not be able to delete without a current customer
            Assert.AreEqual(false,
                            searchCustomersVM.EditCustomerCommand.CanExecute(null));

            FetchCustomer(searchCustomersVM, String.Format("{0}_1", cust1String));

            Assert.AreEqual(1,
                            searchCustomersVM.MatchedCustomers.Where(
                                c => c.FirstName.DataValue ==
                                searchCustomersVM.CurrentFilterText).Count());

            searchCustomersVM.CurrentCustomer = searchCustomersVM.MatchedCustomers[0];

            //should be able to delete with a current customer
            Assert.AreEqual(true,
                            searchCustomersVM.EditCustomerCommand.CanExecute(null));

            //As we are testing for failure ensure that this Customer up for editing
            //is currently being edited within the AddEditCustomerViewModel workspace
            //within the MainWindowViewModel.
            //Then try and edit the customer, but can only do it if the customer
            //is not being edited in MainWindowViewModel, so should fail
            MainWindowViewModel      mainWindowViewModel      = new MainWindowViewModel();
            AddEditCustomerViewModel addEditCustomerViewModel =
                new AddEditCustomerViewModel();

            addEditCustomerViewModel.CurrentCustomer =
                searchCustomersVM.MatchedCustomers[0];

            mainWindowViewModel.Workspaces.Add(addEditCustomerViewModel);

            searchCustomersVM.EditCustomerCommand.Execute(null);

            //should only have the 1 AddEditCustomerViewModel
            Int32 openCustomerWorkSpaces =
                mainWindowViewModel.Workspaces.Where(w => w.GetType() ==
                                                     typeof(AddEditCustomerViewModel)).Count();

            Assert.AreEqual(1, openCustomerWorkSpaces);
            Assert.IsNull(searchCustomersVM.CurrentCustomer);
        }
        public void AddCustomerPositiveTest()
        {
            int oldListSize = data.customers.Count;

            Customer customer = new Customer()
            {
                name         = "Kamil",
                surname      = "Filipczak",
                emailAddress = "*****@*****.**",
                age          = 51
            };

            service.AddCustomer(customer);
            int newListSize = data.customers.Count;

            //check if size of new and old list is different
            Assert.AreNotEqual(oldListSize, newListSize);

            //check if list contains object
            Assert.IsTrue(data.customers.Contains(customer));
        }
        public void CheckEditCustomer_Passes()
        {
            //create some Customers in the Database 1st

            String cust1String = Guid.NewGuid().ToString();

            Assert.Greater(DataService.AddCustomer(
                               GetCustomer(cust1String, "1")), 0);


            SearchCustomersViewModel searchCustomersVM =
                new SearchCustomersViewModel();

            //should not be able to delete without a current customer
            Assert.AreEqual(false,
                            searchCustomersVM.EditCustomerCommand.CanExecute(null));

            FetchCustomer(searchCustomersVM, String.Format("{0}_1", cust1String));

            Assert.AreEqual(1,
                            searchCustomersVM.MatchedCustomers.Where(
                                c => c.FirstName.DataValue ==
                                searchCustomersVM.CurrentFilterText).Count());

            searchCustomersVM.CurrentCustomer = searchCustomersVM.MatchedCustomers[0];

            //should be able to delete with a current customer
            Assert.AreEqual(true,
                            searchCustomersVM.EditCustomerCommand.CanExecute(null));

            //As the customer is not being edited within the mainWindowViewModel,
            //as there is no active AddEditCustomerViewModel workspacce, should be
            //able to edit it, but we need to make sure the mainWindowViewModel
            //is available to notify us back that it is ok to proceed with the delete
            MainWindowViewModel mainWindowViewModel = new MainWindowViewModel();

            searchCustomersVM.EditCustomerCommand.Execute(null);

            //should only have the 1 AddEditCustomerViewModel
            Int32 openCustomerWorkSpaces =
                mainWindowViewModel.Workspaces.Where(w => w.GetType() ==
                                                     typeof(AddEditCustomerViewModel)).Count();

            Assert.AreEqual(1, openCustomerWorkSpaces);
            Assert.IsNull(searchCustomersVM.CurrentCustomer);
        }
Exemplo n.º 8
0
        public ActionResult Save(Customer data)
        {
            if (!ModelState.IsValid)
            {
                return(View("Edit", data));
            }

            if (data.CustomerID == 0)
            {
                DataService.AddCustomer(data);
            }
            else
            {
                DataService.UpdateCustomer(data);
            }
            return(RedirectToAction("Index", "Customer"));
        }
Exemplo n.º 9
0
 public void AddingCustomersTest()
 {
     service.AddCustomer(101, "Mark", "Twain");
     Assert.AreEqual(5, service.GetAllCustomers().Count);
 }
Exemplo n.º 10
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>

        public ActionResult Save(Customer data)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(data.CustomerName))
                {
                    ModelState.AddModelError("CustomerName", "Vui lòng nhập tên của nhà cung cấp!");
                }
                if (string.IsNullOrWhiteSpace(data.ContactName))
                {
                    ModelState.AddModelError("ContactName", "Bạn chưa nhập tên liên hệ của nhà cung cấp!");
                }
                if (string.IsNullOrWhiteSpace(data.Address))
                {
                    ModelState.AddModelError("Address", "Bạn chưa nhập địa chỉ của nhà cung cấp!");
                }
                if (string.IsNullOrEmpty(data.Country))
                {
                    data.Country = "";
                }
                if (string.IsNullOrEmpty(data.City))
                {
                    data.City = "";
                }
                if (string.IsNullOrEmpty(data.PostalCode))
                {
                    data.PostalCode = "";
                }
                if (string.IsNullOrEmpty(data.Email))
                {
                    data.Email = "";
                }
                if (string.IsNullOrEmpty(data.Password))
                {
                    data.Password = "";
                }
                if (!ModelState.IsValid)
                {
                    if (data.CustomerID == 0)
                    {
                        ViewBag.Title = "Tạo mới khách hàng";
                    }
                    else
                    {
                        ViewBag.Title = "Thay đổi thông tin khách hàng";
                    }
                    return(View("Edit", data));
                }

                if (data.CustomerID == 0)
                {
                    DataService.AddCustomer(data);
                }
                else
                {
                    DataService.UpdateCustomer(data);
                }
                return(RedirectToAction("Index"));
                // return Json(data);
            }
            catch
            {
                return(Content("Oops! Trang này hình như không tồn tại :)"));
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// Executes the SaveCustomerCommand
        /// </summary>
        private void ExecuteSaveCustomerCommand()
        {
            try
            {
                SaveCustomerCommand.CommandSucceeded = false;

                if (!CurrentCustomer.IsValid)
                {
                    messageBoxService.ShowError("There customer is invalid");
                    SaveCustomerCommand.CommandSucceeded = false;
                    return;
                }

                //Customer is valid, so end the edit and try and save/update it
                this.CurrentCustomer.EndEdit();

                switch (currentViewMode)
                {
                    #region AddMode
                //AddMode
                case ViewMode.AddMode:
                    Int32 custId =
                        DataService.AddCustomer(
                            TranslateUICustomerToDataLayerCustomer(currentCustomer));

                    if (custId > 0)
                    {
                        this.CurrentCustomer.CustomerId.DataValue = custId;
                        messageBoxService.ShowInformation(
                            "Sucessfully saved customer");
                        this.CurrentViewMode = ViewMode.ViewOnlyMode;
                    }
                    else
                    {
                        messageBoxService.ShowError(
                            "There was a problem saving the customer");
                    }
                    SaveCustomerCommand.CommandSucceeded = true;
                    break;

                    #endregion
                    #region EditMode
                //EditMode
                case ViewMode.EditMode:
                    Boolean custUpdated =
                        DataService.UpdateCustomer(
                            TranslateUICustomerToDataLayerCustomer(currentCustomer));

                    if (custUpdated)
                    {
                        messageBoxService.ShowInformation(
                            "Sucessfully updated customer");
                        this.CurrentViewMode = ViewMode.ViewOnlyMode;
                    }
                    else
                    {
                        messageBoxService.ShowError(
                            "There was a problem updating the customer");
                    }
                    SaveCustomerCommand.CommandSucceeded = true;
                    break;
                    #endregion
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
                messageBoxService.ShowError(
                    "There was a problem saving the customer");
            }
        }
Exemplo n.º 12
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public ActionResult Save(Customer data)
        {
            try
            {
                //return Json(data);
                if (string.IsNullOrWhiteSpace(data.CustomerName))
                {
                    ModelState.AddModelError("CustomerName", "Vui long nhap ten khách hàng !");
                }
                if (string.IsNullOrWhiteSpace(data.ContactName))
                {
                    ModelState.AddModelError("ContactName", "Ban chua nhap ten lien he cua nha cung cap !");
                }
                if (string.IsNullOrEmpty(data.Address))
                {
                    data.Address = "";
                }
                if (string.IsNullOrEmpty(data.Country))
                {
                    data.Country = "";
                }
                if (string.IsNullOrEmpty(data.City))
                {
                    data.City = "";
                }
                if (string.IsNullOrEmpty(data.PostalCode))
                {
                    data.PostalCode = "";
                }
                if (string.IsNullOrEmpty(data.Email))
                {
                    data.Email = "";
                }
                if (string.IsNullOrEmpty(data.Password))
                {
                    data.Password = "";
                }

                if (!ModelState.IsValid)
                {
                    if (data.CustomerID == 0)
                    {
                        ViewBag.Title = "Bổ sung khách hàng";
                    }
                    else
                    {
                        ViewBag.Title = "Thay đổi thông tin khách hàng";
                    }
                    return(View("Edit", data));
                }

                if (data.CustomerID == 0)
                {
                    DataService.AddCustomer(data);
                }
                else
                {
                    DataService.UpdateCustomer(data.CustomerID, data);
                }

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(Content("Oops! Trang nay khong ton tai :)"));
            }
        }
Exemplo n.º 13
0
        public ActionResult Save(Customer data)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(data.CustomerName))
                {
                    ModelState.AddModelError("CustomerName", "Vui lòng nhập tên khách hàng");
                }
                if (string.IsNullOrWhiteSpace(data.ContactName))
                {
                    ModelState.AddModelError("ContactName", "Vui lòng nhập tên liên hệ");
                }
                if (string.IsNullOrEmpty(data.Address))
                {
                    data.Address = "";
                }
                if (string.IsNullOrEmpty(data.Country))
                {
                    data.Country = "";
                }
                if (string.IsNullOrEmpty(data.City))
                {
                    data.City = "";
                }
                if (string.IsNullOrEmpty(data.PostalCode))
                {
                    data.PostalCode = "";
                }
                if (string.IsNullOrEmpty(data.Email))
                {
                    data.Email = "";
                }
                if (string.IsNullOrEmpty(data.Password))
                {
                    data.Password = "******";
                }
                if (!ModelState.IsValid)
                {
                    if (data.CustomerID == 0)
                    {
                        ViewBag.Title = "Thêm khách hàng";
                    }
                    else
                    {
                        ViewBag.Title = "Sửa thông tin khách hàng";
                    }
                    return(View("Edit", data));
                }

                if (data.CustomerID == 0)
                {
                    DataService.AddCustomer(data);
                }
                else
                {
                    DataService.UpdateCustomer(data);
                }
                return(RedirectToAction("Index"));
            }
            catch
            {
                return(Content("Trang này hình như không tồn tại"));
            }
        }