Beispiel #1
0
        public void CategoriesGetterTest()
        {
            LocalUser       user       = Login();
            var             status     = CategoriesGetter.GetStatus.UnknownError;
            bool            done       = false;
            List <Category> categories = null;

            var getter = new CategoriesGetter(user, (_status, _categories) => {
                status     = _status;
                categories = _categories;
                done       = true;
            });

            getter.get();
            while (!done)
            {
            }
            Assert.AreEqual(status, CategoriesGetter.GetStatus.Success);
            Assert.AreNotEqual(categories, null);
        }
Beispiel #2
0
        public void CategoriesManagerFullTest()
        {
            LocalUser       user                   = Login(username: "******", password: "******");
            var             statusManager          = CategoryManager.ManagerStatus.UnknownError;
            var             statusGetterCategories = CategoriesGetter.GetStatus.UnknownError;
            bool            done                   = false;
            Category        category;
            List <Category> categories        = null;
            var             categoriesManager = new CategoryManager(user);

            categoriesManager.AddCategoryResult = (_status, _category) =>
            {
                statusManager = _status;
                category      = _category;
                done          = true;
            };

            categoriesManager.RemoveCategoryResult = (_status, _category) =>
            {
                statusManager = _status;
                category      = _category;
                done          = true;
            };

            categoriesManager.UpdateCategoryResult = (_status, _category) =>
            {
                statusManager = _status;
                category      = _category;
                done          = true;
            };

            var getterCategories = new CategoriesGetter(user, (_status, _categories) => {
                statusGetterCategories = _status;
                categories             = _categories;
                done = true;
            });

            ///Siunčiam category
            done = false;
            var random = new Random();

            category = new Category {
                Title = random.Next().ToString(), Description = random.Next().ToString()
            };
            categoriesManager.addCategory(category);

            while (!done)
            {
            }
            Assert.AreEqual(statusManager, CategoryManager.ManagerStatus.Success);
            Assert.AreNotEqual(category, null);
            ///

            ///Gaunam categories
            done = false;
            getterCategories.get();

            while (!done)
            {
            }
            Assert.AreEqual(statusGetterCategories, CategoriesGetter.GetStatus.Success);
            Assert.AreNotEqual(categories, null);
            ///Tikrinam ar yra mūsų
            var myCategory = categories.Find((_category) =>
            {
                return(_category.Title == category.Title &&
                       _category.Description == category.Description &&
                       _category.CreatorUsername == user.Username);
            });

            Assert.AreNotEqual(myCategory, null);
            ///

            ///Naujinam category
            category.Description += random.Next().ToString();
            done = false;
            categoriesManager.updateCategory(category);

            while (!done)
            {
            }
            Assert.AreEqual(statusManager, CategoryManager.ManagerStatus.Success);
            Assert.AreNotEqual(category, null);
            ///

            ///Gaunam categories
            done = false;
            getterCategories.get();

            while (!done)
            {
            }
            Assert.AreEqual(statusGetterCategories, CategoriesGetter.GetStatus.Success);
            Assert.AreNotEqual(categories, null);
            ///Tikrinam ar atsinaujino
            myCategory = categories.Find((_category) =>
            {
                return(_category.Title == category.Title &&
                       _category.Description == category.Description &&
                       _category.CreatorUsername == user.Username);
            });
            Assert.AreNotEqual(myCategory, null);
            ///

            ///Trinam category
            done = false;
            categoriesManager.removeCategory(category);

            while (!done)
            {
            }
            Assert.AreEqual(statusManager, CategoryManager.ManagerStatus.Success);
            Assert.AreNotEqual(category, null);
            ///

            ///Gaunam categories
            done = false;
            getterCategories.get();

            while (!done)
            {
            }
            Assert.AreEqual(statusGetterCategories, CategoriesGetter.GetStatus.Success);
            Assert.AreNotEqual(categories, null);
            ///Tikrinam ar išsitrynė
            myCategory = categories.Find((_category) =>
            {
                return(_category.Title == category.Title &&
                       _category.Description == category.Description &&
                       _category.CreatorUsername == user.Username);
            });
            Assert.AreEqual(myCategory, null);
            ///
        }
Beispiel #3
0
        public void HelpRequestManagerFullTest()
        {
            LocalUser                 user                   = Login();
            var                       statusManager          = HelpRequestManager.ManagerStatus.UnknownError;
            var                       statusGetterHelp       = HelpRequestGetter.GetStatus.UnknownError;
            var                       statusGetterCategories = CategoriesGetter.GetStatus.UnknownError;
            bool                      done                   = false;
            HelpRequest               helpRequest;
            List <HelpRequest>        helpRequests = null;
            Dictionary <String, User> users        = null;
            List <Category>           categories   = null;

            var helpRequestManager = new HelpRequestManager(user);

            helpRequestManager.PostHelpRequestResult = (_status, _helpRequest) =>
            {
                statusManager = _status;
                helpRequest   = _helpRequest;
                done          = true;
            };

            helpRequestManager.RemoveHelpRequestResult = (_status, _helpRequest) =>
            {
                statusManager = _status;
                helpRequest   = _helpRequest;
                done          = true;
            };

            var getterHelp = new HelpRequestGetter(user, (_status, _helpRequests, _users) => {
                statusGetterHelp = _status;
                helpRequests     = _helpRequests;
                users            = _users;
                done             = true;
            });

            var getterCategories = new CategoriesGetter(user, (_status, _categories) => {
                statusGetterCategories = _status;
                categories             = _categories;
                done = true;
            });

            ///Gaunam Kategorijas
            done = false;
            getterCategories.get();
            while (!done)
            {
            }
            Assert.AreEqual(statusGetterCategories, CategoriesGetter.GetStatus.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
            };
            helpRequestManager.postHelpRequest(helpRequest);

            while (!done)
            {
            }
            Assert.AreEqual(statusManager, HelpRequestManager.ManagerStatus.Success);
            Assert.AreNotEqual(helpRequest, null);
            ///

            ///Gaunam visus helpRequest
            done = false;
            getterHelp.get(true);
            while (!done)
            {
            }

            Assert.AreEqual(statusGetterHelp, HelpRequestGetter.GetStatus.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;
            helpRequestManager.removeHelpRequest(helpRequest);

            while (!done)
            {
            }
            Assert.AreEqual(statusManager, HelpRequestManager.ManagerStatus.Success);
            Assert.AreNotEqual(helpRequest, null);
            ///


            ///Gaunam visus helpRequest
            done = false;
            getterHelp.get(true);
            while (!done)
            {
            }

            Assert.AreEqual(statusGetterHelp, HelpRequestGetter.GetStatus.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);
            ///
        }