示例#1
0
        public void TestAddNewAddress()
        {
            Mock <IAddressDao> dao = new Mock <IAddressDao>(MockBehavior.Loose);

            Task <bool> res5 = new Task <bool>(() => true);

            res5.RunSynchronously();
            dao.Setup(x => x.InsertAsync(It.IsAny <Address>())).Returns(res5);

            Task <long> res = new Task <long>(() => 13);

            res.RunSynchronously();
            dao.Setup(x => x.GetNextId()).Returns(res);
            Address address = new Address()
            {
                AddressId   = 3,
                CommunityId = 5,
                Location    = "AddressxD"
            };

            AddressManager m  = new AddressManager(null, null, null, null, dao.Object);
            long           id = m.AddNewAddress(address).Result;

            Assert.AreEqual(12, id);
            dao.Verify(c => c.GetNextId(), Times.Once);
            dao.Verify(c => c.InsertAsync(address), Times.Once);
        }
        /// <summary>
        ///  Saves the order to the database and emails the appropriate accounts.
        /// </summary>
        private void SaveOrder()
        {
            VehicleManager vehicle = null;
            DateTime       hireStart = DateTime.Now, hireEnd = DateTime.Now;
            string         payerID = "", customerEmailAddress, locationEmailAddress, companyEmailAddress,
                           subject = "", managerBody, body, orderInfo;
            double          totalDays = 0, totalCost = 0;
            AddressManager  address  = null;
            CustomerManager customer = null;
            LocationManager location = null;

            LoadInformation(ref vehicle, ref totalDays, ref totalCost, ref hireStart,
                            ref hireEnd, ref address, ref customer, ref location);

            bool useLocation = (bool)Session["UseLocation"];

            //Gets the customer, location and company email addresses to send the confirmation of the order to.
            customerEmailAddress = customer.EmailAddress;
            locationEmailAddress = location.EmailAddress;
            companyEmailAddress  = CompanyManager.GetCompanyByLocation(location.LocationID);

            if (CompletePayment(totalCost, vehicle.Currency, ref payerID) == true)
            {
                //String that will be placed in email to summarise order.
                orderInfo = "<br /><br /><b>Vehicle:</b> " + vehicle.Manufacturer + " " + vehicle.Model + "<br /><b>SIPP Code:</b> " + vehicle.SIPPCode
                            + "<br /><b>Total Cost:</b> " + vehicle.Currency + " " + totalCost + ". For " + totalDays + " days." +
                            "<br /><b>Start:</b> " + hireStart.ToString() + ". <b>End:</b> " + hireEnd.ToString() + "<br /><b>Address:</b> " + address.GetAddressStr()
                            + "<br /><br /><b>PayPal Payer ID:</b> " + payerID;

                body        = "<a href=" + Variables.URL + "Account/ViewOrders>Your Account </a>" + orderInfo;
                managerBody = "Complete this order by going to the <a href=" + Variables.URL + "Account/ViewCustomerOrders>customer orders page</a>" + orderInfo;
                if (useLocation == false)
                {
                    //If address is similar to address already on the system use that one
                    if (AddressManager.GetAddresses().Any(x => x.AddressID == address.AddressID))
                    {
                        OrderManager.InsertNewOrder(customer.CustomerID, address.AddressID, hireStart, hireEnd, vehicle.VehicleAvailableID, payerID);
                        confirmOrderNotify(customerEmailAddress, subject, body);
                        confirmOrderNotify(locationEmailAddress, subject, managerBody);
                        confirmOrderNotify(companyEmailAddress, subject, managerBody);
                    }
                    else
                    {
                        AddressManager.AddNewAddress(1, address.AddressLine1, address.AddressLine2, address.City
                                                     , address.ZipOrPostcode, address.CountyStateProvince, address.Country);
                        OrderManager.InsertNewOrder(customer.CustomerID, address.AddressID, hireStart, hireEnd, vehicle.VehicleAvailableID, payerID);
                        confirmOrderNotify(customerEmailAddress, subject, body);
                        confirmOrderNotify(locationEmailAddress, subject, managerBody);
                        confirmOrderNotify(companyEmailAddress, subject, managerBody);
                    }
                }
                else
                {
                    //Don't insert address ID as location address is used
                    OrderManager.InsertNewOrder(customer.CustomerID, 0, hireStart, hireEnd, vehicle.VehicleAvailableID, payerID);
                    confirmOrderNotify(customerEmailAddress, subject, body);
                    confirmOrderNotify(locationEmailAddress, subject, managerBody);
                    confirmOrderNotify(companyEmailAddress, subject, managerBody);
                }
            }
            else
            {
                Response.Redirect("~/Account/InformUser.aspx?InfoString=A+problem+has+occured+in+the+PayPal+payment.+Please+try+again.", false);
            }
        }
        private async void ExecuteAddNewStation()
        {
            Station newStation = new Station();

            newStation.Name          = this.StationName;
            newStation.Latitude      = this.Latitude;
            newStation.Longitude     = this.Longitude;
            newStation.StationTypeId = this.SelectedStationType.StationTypeId;
            newStation.UserId        = this.loginViewModel.loggedInUser.UserId;

            Address a = new Address();

            a.CommunityId = this.selectedCommunity.CommunityId;
            a.Location    = this.addressString;

            int newId = -1;

            try
            {
                newId = unchecked ((int)await addressManager.AddNewAddress(a));
            }
            catch (BusinessSqlException ex)
            {
                notifierManager.ShowError(ex.Message);
                return;
            }

            if (newId == -1)
            {
                notifierManager.ShowSuccess("Failed to create address");
            }
            else
            {
                notifierManager.ShowSuccess("Address creation successful");
            }

            newStation.AddressId = newId;

            bool result = false;

            try
            {
                result = await stationManager.AddStation(newStation);
            }
            catch (BusinessSqlException ex)
            {
                notifierManager.ShowError(ex.Message);
                return;
            }

            if (!result)
            {
                notifierManager.ShowError("Failed to create station");
            }
            else
            {
                notifierManager.ShowSuccess("Station creation successful");
            }

            /* Reload station data */
            await LoadStations();

            this.SelectedStation = this.Stations.Last();
            RaisePropertyChanged(nameof(SelectedStation));
            RaisePropertyChanged(nameof(Stations));
        }