public async System.Threading.Tasks.Task TestPostAsync()
        {
            //Arrange
            ApiSV sv = new ApiSV();

            sv.url = sv.UrlBuilder(sv.QueryBuilder("{}", "&sort=Date&dir=-1"));
            TransactionModel obj = new TransactionModel();

            obj.Category       = "Test";
            obj.Comment        = "Sometest";
            obj.Date           = Convert.ToDateTime("01-22-1997");
            obj.PurchaseAmount = Decimal.Parse("50.00");
            sv.HttpBodyBuilder <TransactionModel>(obj);

            //Act
            try
            {
                await sv.Post <TransactionModel>();
            }
            catch (Exception ex)
            {
                Debug.WriteLine(Convert.ToString(ex.Message));
            }

            //Assert
            Assert.IsTrue(transactionDatum.Count != 0);              //Means that there is data from the Api Get call.
            Assert.IsTrue(sv.Post <TransactionModel>().IsCompleted); //Means that Post method was completed
        }
示例#2
0
        /// <summary>
        /// Method used to refresh the transactionList.
        /// </summary>
        /// <returns></returns>
        public static async Task RefreshList()
        {
            transactionDatum.Clear();
            ApiSV sv = new ApiSV();

            sv.url = sv.UrlBuilder(sv.QueryBuilder("{}", "&sort=Date&dir=-1"));

            try
            {
                List <TransactionModel> allData = await sv.Get <List <TransactionModel> >();

                foreach (var x in allData)
                {
                    transactionDatum.Add(x);
                }
            }
            catch (Exception ex)
            {
                await Application.Current.MainPage.DisplayAlert("Could not pull data", Convert.ToString(ex.Message), "OK");
            }
        }
        public async System.Threading.Tasks.Task TestGetAsync()
        {
            //Arrange
            ApiSV sv = new ApiSV();

            transactionDatum.Clear();
            sv.url = sv.UrlBuilder(sv.QueryBuilder("{}", "&sort=Date&dir=-1"));
            TransactionModel obj = new TransactionModel();

            obj.Category       = "Food";
            obj.Comment        = "Sandwhich";
            obj.Date           = Convert.ToDateTime("11-19-2017");
            obj.PurchaseAmount = Decimal.Parse("5.99");

            //Act
            try
            {
                List <TransactionModel> allData = await sv.Get <List <TransactionModel> >();

                foreach (var x in allData)
                {
                    transactionDatum.Add(x);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(Convert.ToString(ex.Message));
            }

            //Assert
            Assert.IsTrue(transactionDatum.Count != 0); //Means that there is data from the Api Get call.
            Assert.IsTrue(sv.Get <List <TransactionModel> >().IsCompleted);
            //Assert.IsTrue(obj.Category.Equals(transactionDatum[3].Category)); //Makes sure that we are receiving same Objects from database in that order
            //Assert.IsTrue(obj.Comment.Equals(transactionDatum[3].Comment));
            //Assert.IsTrue(obj.Date.Equals(transactionDatum[3].Date));
            //Assert.IsTrue(obj.PurchaseAmount.Equals(transactionDatum[3].PurchaseAmount));
        }
示例#4
0
        /// <summary>
        /// Method to calculate monthly totals and budgets as well as daily totals.
        /// </summary>
        /// <returns>Task T</returns>
        public static async Task CalcMonth()
        {
            //Calling API
            transactionDatum.Clear();
            janTot   = 0.00m;
            febTot   = 0.00m;
            marTot   = 0.00m;
            aprTot   = 0.00m;
            mayTot   = 0.00m;
            junTot   = 0.00m;
            julTot   = 0.00m;
            augTot   = 0.00m;
            sepTot   = 0.00m;
            octTot   = 0.00m;
            novTot   = 0.00m;
            decTot   = 0.00m;
            dailyTot = 0.00m;
            ApiSV sv = new ApiSV();

            sv.url = sv.UrlBuilder(sv.QueryBuilder("{}", "&sort=Date&dir=-1"));

            try
            {
                List <TransactionModel> allData = await sv.Get <List <TransactionModel> >();

                foreach (var x in allData)
                {
                    transactionDatum.Add(x);
                }
            }
            catch (Exception ex)
            {
                await Application.Current.MainPage.DisplayAlert("Could not pull data", Convert.ToString(ex.Message), "OK");
            }

            //Calculating monthly totals.
            foreach (var x in transactionDatum)
            {
                if (x.Date.Year == DateTime.Now.Year)
                {
                    switch (x.Date.Month)
                    {
                    case 1:
                        janTot += x.PurchaseAmount;
                        break;

                    case 2:
                        febTot += x.PurchaseAmount;
                        break;

                    case 3:
                        marTot += x.PurchaseAmount;
                        break;

                    case 4:
                        aprTot += x.PurchaseAmount;
                        break;

                    case 5:
                        mayTot += x.PurchaseAmount;
                        break;

                    case 6:
                        junTot += x.PurchaseAmount;
                        break;

                    case 7:
                        julTot += x.PurchaseAmount;
                        break;

                    case 8:
                        augTot += x.PurchaseAmount;
                        break;

                    case 9:
                        sepTot += x.PurchaseAmount;
                        break;

                    case 10:
                        octTot += x.PurchaseAmount;
                        break;

                    case 11:
                        novTot += x.PurchaseAmount;
                        break;

                    case 12:
                        decTot += x.PurchaseAmount;
                        break;

                    default:
                        break;
                    }
                }
                //Calculating daily totals.
                if (x.Date.Day == DateTime.Now.Day)
                {
                    dailyTot += x.PurchaseAmount;
                }
            }
            //Calculating monthly budget.
            if (!StorageSV.BudgetAmount.Equals("0.00"))
            {
                switch (DateTime.Now.Month)
                {
                case 1:
                    currentMonth = Convert.ToDecimal(StorageSV.BudgetAmount) - HomePageViewModel.janTot;
                    break;

                case 2:
                    currentMonth = Convert.ToDecimal(StorageSV.BudgetAmount) - HomePageViewModel.febTot;
                    break;

                case 3:
                    currentMonth = Convert.ToDecimal(StorageSV.BudgetAmount) - HomePageViewModel.marTot;
                    break;

                case 4:
                    currentMonth = Convert.ToDecimal(StorageSV.BudgetAmount) - HomePageViewModel.aprTot;
                    break;

                case 5:
                    currentMonth = Convert.ToDecimal(StorageSV.BudgetAmount) - HomePageViewModel.mayTot;
                    break;

                case 6:
                    currentMonth = Convert.ToDecimal(StorageSV.BudgetAmount) - HomePageViewModel.junTot;
                    break;

                case 7:
                    currentMonth = Convert.ToDecimal(StorageSV.BudgetAmount) - HomePageViewModel.julTot;
                    break;

                case 8:
                    currentMonth = Convert.ToDecimal(StorageSV.BudgetAmount) - HomePageViewModel.augTot;
                    break;

                case 9:
                    currentMonth = Convert.ToDecimal(StorageSV.BudgetAmount) - HomePageViewModel.sepTot;
                    break;

                case 10:
                    currentMonth = Convert.ToDecimal(StorageSV.BudgetAmount) - HomePageViewModel.octTot;
                    break;

                case 11:
                    currentMonth = Convert.ToDecimal(StorageSV.BudgetAmount) - HomePageViewModel.novTot;
                    break;

                case 12:
                    currentMonth = Convert.ToDecimal(StorageSV.BudgetAmount) - HomePageViewModel.decTot;
                    break;

                default:
                    currentMonth = Convert.ToDecimal(StorageSV.BudgetAmount) - 0;
                    break;
                }
            }
            else
            {
                currentMonth = Convert.ToDecimal("0.00");
            }
        }