/// <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 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); /// }