public void If_Project_UserId_Does_Not_Match_Current_User_Do_Not_Add()
        {
            // Spoof an authenticated user by generating a ClaimsPrincipal
            var user = new ClaimsPrincipal(new ClaimsIdentity(new Claim[] {
                new Claim(ClaimTypes.NameIdentifier, "FIREBASE_USER1"),
            }, "TestAuthentication"));

            // Create a new project
            ProjectFormViewModel projectForm = new ProjectFormViewModel
            {
                Project = new Project()
                {
                    // have a userId coming in that does not match
                    UserId       = 666,
                    Name         = "New stuff",
                    CreationDate = DateTime.Now - TimeSpan.FromDays(10)
                },
                ProjectCollections = new List <ProjectCollection>()
            };

            // Spoof UserController
            var controller = new ProjectController(_fakeUserRepo.Object, _fakeProjectRepo.Object, _fakeProjColRepo.Object);

            controller.ControllerContext             = new ControllerContext(); // Required to create the controller
            controller.ControllerContext.HttpContext = new DefaultHttpContext {
                User = user
            };                                                                                 // Pretend the user is making a request to the controller

            // Attempt to Get this User's projects
            var response = controller.Add(projectForm);

            // Returns Ok
            Assert.IsType <BadRequestResult>(response);
        }
        public void AddProject_Test_ReturnSuccess()
        {
            var projectAdd = new Project {
                Name = "Project3", CreatedOn = DateTime.Now, Detail = "This is project 3"
            };

            mockObject.Setup(m => m.Add(projectAdd)).Returns(() => Task <Project> .FromResult(projectAdd));
            ProjectController projectController = new ProjectController(mockObject.Object);
            var result = projectController.Add(projectAdd);

            Assert.NotNull(result);
        }
Esempio n. 3
0
 private void btnSave_Click(object sender, EventArgs e)
 {
     if (IsNew)
     {
         ProjectController.Add(Project, _frmList);
     }
     else
     {
         ProjectController.Update(Project, _frmList, _urcProject);
     }
     this.Close();
 }
        public void User_Can_Not_Add_Projects_With_Duplicate_Names()
        {
            // Create a project with a duplicate name
            var projectForm = new ProjectFormViewModel
            {
                Project = new Project()
                {
                    UserId       = 1,
                    Name         = "It",
                    CreationDate = DateTime.Now - TimeSpan.FromDays(15)
                },

                ProjectCollections = new List <ProjectCollection>()
                {
                    new ProjectCollection()
                    {
                        ProjectId    = 0, // I won't know this until it's made
                        CollectionId = 2
                    },
                    new ProjectCollection()
                    {
                        ProjectId    = 0, // I won't know this until it's made
                        CollectionId = 1
                    }
                }
            };

            // Spoof an authenticated user by generating a ClaimsPrincipal
            var user = new ClaimsPrincipal(new ClaimsIdentity(new Claim[] {
                new Claim(ClaimTypes.NameIdentifier, "FIREBASE_ID_1"),
            }, "TestAuthentication"));

            // Instantiate a real repos
            var projectRepo = new ProjectRepository(_context);
            var userRepo    = new UserRepository(_context);
            var projColRepo = new ProjectCollectionRepository(_context);

            // Instantiate a real ProjectController, passing in ProjectRepo
            var controller = new ProjectController(userRepo, projectRepo, projColRepo);

            controller.ControllerContext             = new ControllerContext(); // Required to create the controller
            controller.ControllerContext.HttpContext = new DefaultHttpContext {
                User = user
            };                                                                                 // Pretend the user is making a request to the controller

            // Attempt to Add project
            var response = controller.Add(projectForm);

            // Should return created result
            Assert.IsType <NotFoundResult>(response);
        }
Esempio n. 5
0
 private void txtTaskName_KeyPress(object sender, KeyPressEventArgs e)
 {
     if (e.KeyChar == Convert.ToChar(Keys.Enter))
     {
         if (IsNew)
         {
             ProjectController.Add(Project, _frmList);
             IsNew   = false;
             Project = ProjectController._project;
         }
         Task task = new Task();
         task.TaskName  = txtTaskName.Text;
         task.StartDate = dtpTaskStartDate.Value;
         task.EndDate   = dtpTaskEndDate.Value;
         task.IDProject = Project.IDProject;
         TaskController.AddNewTask(task, this);
         txtTaskName.Text = "Thêm công việc";
     }
 }
        public void Anonymous_User_Can_Not_Add_Project()
        {
            // Spoof an authenticated user by generating a ClaimsPrincipal
            var user = new ClaimsPrincipal(new ClaimsIdentity(new Claim[] {
                new Claim(ClaimTypes.NameIdentifier, "FIREBASE_USER666"),
            }, "TestAuthentication"));

            // Create a new project
            ProjectFormViewModel projectForm = new ProjectFormViewModel
            {
                Project = new Project()
                {
                    Id           = 1,
                    UserId       = 1,
                    Name         = "New stuff",
                    CreationDate = DateTime.Now - TimeSpan.FromDays(10)
                },
                ProjectCollections = new List <ProjectCollection>()
            };

            // Spoof UserController
            var controller = new ProjectController(_fakeUserRepo.Object, _fakeProjectRepo.Object, _fakeProjColRepo.Object);

            controller.ControllerContext             = new ControllerContext(); // Required to create the controller
            controller.ControllerContext.HttpContext = new DefaultHttpContext {
                User = user
            };                                                                                 // Pretend the user is making a request to the controller

            // Attempt to Get this User's projects
            var response = controller.Add(projectForm);

            // Returns Ok
            Assert.IsType <NotFoundResult>(response);
            // Verify we never called the repo method
            _fakeProjectRepo.Verify(r => r.Add(It.IsAny <Project>()), Times.Never());
        }