public async System.Threading.Tasks.Task TestPutAsync() { //Arrange ApiSV sv = new ApiSV(); string id = transactionDatum[0]._id; sv.url = sv.UrlBuilder("/" + id); TransactionModel obj = new TransactionModel(); obj.Category = "Testing put"; obj.Comment = transactionDatum[0].Comment; obj.Date = transactionDatum[0].Date; obj.PurchaseAmount = transactionDatum[0].PurchaseAmount; 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.Put <TransactionModel>().IsCompleted); //Means that Post method was completed //Assert.IsTrue(transactionDatum[0].Category.Equals("Testing put")); }
/// <summary> /// Mehod for the Delete button clicked event. /// </summary> /// <param name="sender">Sender Object</param> /// <param name="e">EventArgs e</param> private async void delButton_Clicked(object sender, EventArgs e) { if (id != null) { ApiSV sv = new ApiSV(); sv.url = sv.UrlBuilder("/" + id); var answer = await DisplayAlert("Wait!", "Are you sure you want to delete this transaction?", "YES", "NO"); if (answer) { try { load.IsRunning = true; await sv.Delete <TransactionModel>(); load.IsRunning = false; await DisplayAlert("Success!", "Transaction was deleted!", "OK"); await Navigation.PopToRootAsync(); } catch { await DisplayAlert("Error", "Something went wrong with the API Call, Try Again!", "OK"); load.IsRunning = false; } } else { return; } } }
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 }
/// <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 TestDeleteAsync() { //Arrange ApiSV sv = new ApiSV(); string id = transactionDatum.Last()._id; sv.url = sv.UrlBuilder("/" + id); //Act try { await sv.Delete <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.Delete <TransactionModel>().IsCompleted); //Means that Post method was completed //Assert.IsTrue(transactionDatum[0].Category.Equals("Testing put")); }
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)); }
/// <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"); } }
/// <summary> /// Method for when the Save button is clicked. /// </summary> /// <param name="sender">Sender Object</param> /// <param name="e">EventArgs e</param> private async void saveButton_Clicked(object sender, EventArgs e) { if (categoryEntry.Text == null || commentEntry.Text == null || purchaseAmountEntry.Text == null || dateEntry.Text == null) { await DisplayAlert("Oops!", "One of the fields are empty, please try again!", "OK"); } else { TransactionModel obj = new TransactionModel(); try { obj.Category = categoryEntry.Text; obj.Comment = commentEntry.Text; obj.Date = Convert.ToDateTime(dateEntry.Text); obj.PurchaseAmount = Decimal.Parse(purchaseAmountEntry.Text); } catch { await DisplayAlert("Oops!", "One of the input parameters is not in the correct format, Please try again!", "OK"); load.IsRunning = false; return; } ApiSV sv = new ApiSV(); sv.HttpBodyBuilder <TransactionModel>(obj); if (id == null) { sv.url = sv.UrlBuilder(""); try { load.IsRunning = true; await sv.Post <TransactionModel>(); load.IsRunning = false; await DisplayAlert("Success!", "New transaction was created!", "OK"); await Navigation.PopToRootAsync(); } catch { await DisplayAlert("Error", "Something went wrong with the API Call, Try Again!", "OK"); load.IsRunning = false; } } else { sv.url = sv.UrlBuilder("/" + id); try { load.IsRunning = true; await sv.Put <TransactionModel>(); load.IsRunning = false; await DisplayAlert("Success!", "Transaction was edited!", "OK"); await Navigation.PopToRootAsync(); } catch { await DisplayAlert("Error", "Something went wrong with the API Call, Try Again!", "OK"); load.IsRunning = false; } } } }