Пример #1
0
        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
        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>
        /// 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;
                    }
                }
            }
        }