/// <summary> /// Išsiunčiamas naujai sukurtas helpRequestas /// </summary> private void SendNewHelpRequest() { var helpRequestManager = HelpRequestSystemManager.NewHelpRequestPoster(); helpRequestManager.Result += (status, helprequest) => { Device.BeginInvokeOnMainThread(async() => { if (status == HelpRequestManageStatus.Success) { DependencyService.Get <IToast>().LongToast("Prašymas sėkmingai išsiųstas"); await Navigation.PopModalAsync(); } else { DependencyService.Get <IToast>().LongToast("Prašymas nebuvo išsiųstas"); //Console.WriteLine("Epic fail"); SaveButton.IsEnabled = true; } }); }; helpRequestManager.Post(new HelpRequest { Title = Title.Text, Description = Description.Text, CreatorUsername = LocalUserManager.LocalUser.Username, Category = Items[CategoryList.SelectedIndex].Title }); }
public void HelpRequestGetterTest() { LocalUser user = UnitTestAuth.Login(); var status = HelpRequestGetStatus.UnknownError; bool done = false; List <HelpRequest> helpRequests = null; Dictionary <String, User> users = null; var getter = HelpRequestSystemManager.NewHelpRequestGetter(); getter.Result += (_status, _helpRequests, _users) => { status = _status; helpRequests = _helpRequests; users = _users; done = true; }; getter.Get(true); while (!done) { } Assert.AreEqual(status, HelpRequestGetStatus.Success); Assert.AreNotEqual(users, null); Assert.AreNotEqual(helpRequests, null); }
/// <summary> /// Gauna visus HelpRequest iš DB ir iš karto filtruoja pagal parametrus /// </summary> private void HelpRequestListGetter() { var helpRequestGetter = HelpRequestSystemManager.NewHelpRequestGetter(); helpRequestGetter.Result += (status, requests, users) => { if (status == HelpRequestGetStatus.Success) { Device.BeginInvokeOnMainThread(() => { Items.Clear(); this.users = users; requests.ForEach(request => { Items.Add(new HelpRequestModel { Title = request.Title, Description = request.Description, Username = request.CreatorUsername, Name = users[request.CreatorUsername].FirstName + " " + users[request.CreatorUsername].LastName, Category = request.Category, Date = request.Timestamp.ToFullDate(), HelpRequest = request }); }); FilterFinal(); HelpRequestList.IsRefreshing = false; }); } else { Device.BeginInvokeOnMainThread(() => { HelpRequestList.IsRefreshing = false; }); } }; helpRequestGetter.Get(); }
private async void ToolbarItem_Clicked(object sender, EventArgs e) { if (await DisplayActionSheet("Ar tikrai norite ištrinti?", "Ne", "Taip") == "Taip") { var remover = HelpRequestSystemManager.NewHelpRequestRemover(); remover.Result += (status, helpRequest) => { Device.BeginInvokeOnMainThread(async() => { if (status == HelpRequestManageStatus.Success) { DependencyService.Get <IToast>().LongToast("Ištrinta sėkmingai"); await Navigation.PopAsync(); } else { DependencyService.Get <IToast>().LongToast("Ištrinti nepavyko"); } }); }; remover.Remove(viewModel.HelpRequestModel.HelpRequest); } return; }
public void HelpRequestFullTest() { LocalUser user = UnitTestAuth.Login(); var statusManager = HelpRequestManageStatus.UnknownError; var statusGetterHelp = HelpRequestGetStatus.UnknownError; var statusGetterCategories = CategoryGetStatus.UnknownError; bool done = false; HelpRequest helpRequest; List <HelpRequest> helpRequests = null; Dictionary <String, User> users = null; List <Category> categories = null; var adder = HelpRequestSystemManager.NewHelpRequestPoster(); var remover = HelpRequestSystemManager.NewHelpRequestRemover(); adder.Result = (_status, _helpRequest) => { statusManager = _status; helpRequest = _helpRequest; done = true; }; remover.Result = (_status, _helpRequest) => { statusManager = _status; helpRequest = _helpRequest; done = true; }; var getterHelpRequest = HelpRequestSystemManager.NewHelpRequestGetter(); getterHelpRequest.Result += (_status, _helpRequests, _users) => { statusGetterHelp = _status; helpRequests = _helpRequests; users = _users; done = true; }; var getterCategories = CategorySystemManager.NewCategoryGetter();; getterCategories.Result += (_status, _categories) => { statusGetterCategories = _status; categories = _categories; done = true; }; ///Gaunam Kategorijas done = false; getterCategories.Get(); while (!done) { } Assert.AreEqual(statusGetterCategories, CategoryGetStatus.Success); Assert.AreNotEqual(categories, null); Assert.AreNotEqual(categories.Count, 0); /// ///Siunčiam helpRequest done = false; var random = new Random(); helpRequest = new HelpRequest { Title = random.Next().ToString(), Description = random.Next().ToString(), Category = categories[0].Title }; adder.Post(helpRequest); while (!done) { } Assert.AreEqual(statusManager, HelpRequestManageStatus.Success); Assert.AreNotEqual(helpRequest, null); /// ///Gaunam visus helpRequest done = false; getterHelpRequest.Get(true); while (!done) { } Assert.AreEqual(statusGetterHelp, HelpRequestGetStatus.Success); Assert.AreNotEqual(users, null); Assert.AreNotEqual(helpRequests, null); ///Tikrinam ar mūsų yra var myHelpRequest = helpRequests.Find((_helpRequest) => { return(_helpRequest.Title == helpRequest.Title && _helpRequest.Description == helpRequest.Description && _helpRequest.CreatorUsername == user.Username && _helpRequest.Category == categories[0].Title); }); Assert.AreNotEqual(myHelpRequest, null); /// ///Trinam helpRequest done = false; remover.Remove(helpRequest); while (!done) { } Assert.AreEqual(statusManager, HelpRequestManageStatus.Success); Assert.AreNotEqual(helpRequest, null); /// ///Gaunam visus helpRequest done = false; getterHelpRequest.Get(true); while (!done) { } Assert.AreEqual(statusGetterHelp, HelpRequestGetStatus.Success); Assert.AreNotEqual(users, null); Assert.AreNotEqual(helpRequests, null); ///Tikrinam ar mūsų nėra myHelpRequest = helpRequests.Find((_helpRequest) => { return(_helpRequest.Title == helpRequest.Title && _helpRequest.Description == helpRequest.Description && _helpRequest.CreatorUsername == user.Username && _helpRequest.Category == categories[0].Title); }); Assert.AreEqual(myHelpRequest, null); /// }