public void DeleteUserProfileTestWhenUserIsATaskerWithActiveTasks()
        {
            AddNewAd newAdForm = new AddNewAd();

            newAdForm.TaskOwnerUsername  = user.Username;
            newAdForm.TitleField         = "Mock Title";
            newAdForm.DescriptionField   = "Mock Description";
            newAdForm.LocationField      = "Bursa";
            newAdForm.AddressField       = "Mock Address";
            newAdForm.Currency           = "TL";
            newAdForm.Category           = "Grocery Shopping";
            newAdForm.PaymentAmountField = "20";
            TaskController taskController = new TaskController();
            UserController userController = new UserController();

            taskController.ProcessNewAdData(newAdForm);
            user = userController.ReturnUserWithGivenUsername(newAdForm.TaskOwnerUsername);

            string usernameForTasker    = "Mock-User-2";
            string passwordForTasker    = "123";
            string nameForTasker        = "Mock2";
            string surnameForTasker     = "User";
            string emailForTasker       = "*****@*****.**";
            string addressForTasker     = "Mock Address";
            string phoneNumberForTasker = "123456789";

            Models.User.ContactInformationAttribute contactInfoForTasker = new Models.User.ContactInformationAttribute(emailForTasker, phoneNumberForTasker, addressForTasker);
            userController.AddNewUser(usernameForTasker, passwordForTasker, nameForTasker, surnameForTasker, contactInfoForTasker);
            User tasker = userController.ReturnUserWithGivenUsername(usernameForTasker);

            UpdateAdd assignTaskForm = new UpdateAdd();

            assignTaskForm.TaskIdField = user.Ads[1];
            assignTaskForm.Tasker      = usernameForTasker;

            var mockCurrentSession = new Mock <ICurrentSession>();

            mockCurrentSession.Setup(x => x.SetUsername(user.Username)).Returns(true);
            ProfileController profileController = new ProfileController(mockCurrentSession.Object);
            Profile           userProfile       = new Profile();

            userProfile.UsernameField = usernameForTasker;
            profileController.DeleteUserProfile(userProfile);
            user = userController.ReturnUserWithGivenUsername(user.Username);

            Models.Task task = taskController.ReturnTaskWithGivenTaskId(assignTaskForm.TaskIdField);
            Assert.AreNotEqual(null, task);
            Assert.AreEqual(false, task.IsAssignedToSomeone);
            Assert.AreEqual("", task.AssignedToUserWithThisUsername);
            Assert.AreEqual(true, user.Ads.Contains(assignTaskForm.TaskIdField));

            taskController.DeleteTaskWithGivenTaskId(assignTaskForm.TaskIdField);
        }
 public int AddNewTask(AddNewAd task)
 {
     if (task.Category.Equals("Other"))
     {
         if (task.OtherCategory != null)
         {
             task.Category = task.OtherCategory;
         }
     }
     return(AddNewTask(task.TaskOwnerUsername, task.CreationDate, task.TitleField, task.DescriptionField,
                       task.LocationField, task.AddressField, task.TaskPhotoUrl, false,
                       "", task.PaymentAmountField, false, task.Category));
 }
        public IActionResult ProcessNewAdData(AddNewAd task)
        {
            task.CreationDate       = DateTime.UtcNow.Date.ToString("dd/MM/yyyy");
            task.PaymentAmountField = task.PaymentAmountField.ToString() + " " + task.Currency;
            task.LocationField      = task.Country + " " + task.State + " " + task.City;
            AddNewTask(task);
            int taskID = _CurrentTaskId - 1;
            int numberOfRowsAffected = _UserController.AddNewAdToUserWithGivenUsername(task.TaskOwnerUsername, taskID);

            if (numberOfRowsAffected == 0)
            {
                ViewData["username"] = task.TaskOwnerUsername;
                ViewData["message"]  = "An error has occured.";
                return(AddNewAd(task.TaskOwnerUsername));
            }
            else
            {
                return(_HomeController.MyAds(task.TaskOwnerUsername)); // will be updated to My ads page when it is ready
            }
        }
        public void InitTest()
        {
            string username    = "******";
            string password    = "******";
            string name        = "Mock";
            string surname     = "User";
            string email       = "*****@*****.**";
            string address     = "Mock Address";
            string phoneNumber = "123456789";

            Models.User.ContactInformationAttribute contactInfo = new Models.User.ContactInformationAttribute(email, phoneNumber, address);

            UserController userController = new UserController();

            userController.AddNewUser(username, password, name, surname, contactInfo);
            user = userController.ReturnUserWithGivenUsername(username);

            newAdForm = new AddNewAd();
            newAdForm.TaskOwnerUsername  = user.Username;
            newAdForm.TitleField         = "Mock Title";
            newAdForm.DescriptionField   = "Mock Description";
            newAdForm.LocationField      = "Bursa";
            newAdForm.AddressField       = "Mock Address";
            newAdForm.Currency           = "TL";
            newAdForm.Category           = "Other";
            newAdForm.OtherCategory      = "Mock";
            newAdForm.PaymentAmountField = "20";

            string usernameForTasker    = "Mock-User-2";
            string passwordForTasker    = "123";
            string nameForTasker        = "Mock2";
            string surnameForTasker     = "User";
            string emailForTasker       = "*****@*****.**";
            string addressForTasker     = "Mock Address";
            string phoneNumberForTasker = "123456789";

            Models.User.ContactInformationAttribute contactInfoForTasker = new Models.User.ContactInformationAttribute(emailForTasker, phoneNumberForTasker, addressForTasker);

            userController.AddNewUser(usernameForTasker, passwordForTasker, nameForTasker, surnameForTasker, contactInfoForTasker);
            mockTasker = userController.ReturnUserWithGivenUsername(usernameForTasker);
        }
        public void InitTest()
        {
            UserController userController = new UserController();
            TaskController taskController = new TaskController();

            string username = "******";
            string name     = "Mock";
            string surname  = "User";
            string password = "******";

            User.ContactInformationAttribute contactInfo = new User.ContactInformationAttribute("*****@*****.**", "05398376436", "Rumelifeneri Mahallesi");
            userController.AddNewUser(username, password, name, surname, contactInfo);
            taskOwner = userController.ReturnUserWithGivenUsername(username);

            string usernameForTasker = "Mock-User-2";
            string nameForTasker     = "Mock2";
            string surnameForTasker  = "User";
            string passwordForTasker = "123";

            User.ContactInformationAttribute contactInfoForTasker = new User.ContactInformationAttribute("*****@*****.**", "05398376436", "Rumelifeneri Mahallesi");
            userController.AddNewUser(usernameForTasker, passwordForTasker, nameForTasker, surnameForTasker, contactInfoForTasker);
            tasker = userController.ReturnUserWithGivenUsername(usernameForTasker);

            AddNewAd newAdForm = new AddNewAd();

            newAdForm.TaskOwnerUsername  = username;
            newAdForm.TitleField         = "Mock Task 1";
            newAdForm.DescriptionField   = "Mock Test for Update ad controller";
            newAdForm.LocationField      = "Bursa";
            newAdForm.AddressField       = "Rumelifeneri";
            newAdForm.PaymentAmountField = "20";
            newAdForm.Category           = "Mock";
            newAdForm.Currency           = "TL";
            taskController.ProcessNewAdData(newAdForm);
            taskOwner = userController.ReturnUserWithGivenUsername(username);
            ad        = taskController.ReturnTaskWithGivenTaskId(taskOwner.Ads[1]);
        }