public void AddNotification_NotificationAdded_AddNotificationInDb()
        {
            var projectDetailService = new ProjectDetailService(new DataContextFactory());

            var target = new ProjectController(projectDetailService);

            // Act
            target.CreateProject(new ProjectDetail
            {
                ProjectName = "Katana",
                Status      = "Green"
            });

            target.CreateProject(new ProjectDetail
            {
                ProjectName = "KRE",
                Status      = "Yello"
            });

            var data       = target.GetProjectDetails(new DataSourceRequest()) as JsonResult;
            var actualList = ((DataSourceResult)(data.Data)).Data as List <ProjectDetail>;

            //Assert
            Assert.AreEqual(2, actualList.Count);
        }
Exemple #2
0
        public async Task StartAndStopTimerTest()
        {
            await TestAuthHelpers.LogInUser(database, configuration, controllers);

            GenericResponseDTO <int> projectCreationResponse = await projectController.CreateProject(new ProjectCreateDTO {
                ProjectName = "A Cool Project",
                ClientName  = "Misha",
                Tags        = new List <string>(),
                Description = "A very cool Project"
            });

            Project project = (await database.Projects
                               .AsQueryable()
                               .FirstOrDefaultAsync(p => p.Id == projectCreationResponse.Data));

            project.Students
            .Add(project.Teacher);

            await database.SaveChangesAsync();

            int projectId = projectCreationResponse.Data;

            GenericResponseDTO <TimerDTO> startTimerResponse = await timerController.StartTimer(new TimerCreateDTO {
                Notes     = "Working on stuff",
                ProjectId = projectId
            });

            Assert.IsTrue(startTimerResponse.Success);
            Assert.AreEqual(startTimerResponse.Data.Notes, "Working on stuff");
            Assert.AreEqual(startTimerResponse.Data.ProjectId, projectId);

            GenericResponseDTO <List <TimerDTO> > getTimersResponse = await timerController.GetAllTimers();

            List <TimerDTO> timers = getTimersResponse.Data;

            Assert.AreEqual(timers.Count, 1);
            Assert.AreEqual(timers[0].ProjectId, projectId);
            Assert.IsTrue(timers[0].Notes.SequenceEqual("Working on stuff"));
            Assert.AreEqual(timers[0].StartTime, startTimerResponse.Data.StartTime);

            GenericResponseDTO <TimeEntryDTO> stopTimerResponse = await timerController.StopTimer(timers[0].Id);

            DateTime responseGottenTime = DateTime.UtcNow;

            Assert.IsTrue(stopTimerResponse.Success);
            Assert.IsTrue(stopTimerResponse.Data.ProjectId == projectId);
            Assert.AreEqual(stopTimerResponse.Data.Notes, "Working on stuff");
            Assert.AreEqual((responseGottenTime - stopTimerResponse.Data.Day).Minutes, 0);

            getTimersResponse = await timerController.GetAllTimers();

            Assert.AreEqual(getTimersResponse.Data.Count, 0);
        }
Exemple #3
0
        public void CreateProject_WithNumberOfTracksBelowThreshold()
        {
            var project = new ProjectCreationViewModel
            {
                BasicInfo   = new ProjectExtendedDto(),
                PublisherId = 1337,
                Songs       = Builder <SongWithPerformersDto> .CreateListOfSize(80).Build()
            };

            var result = _projectController.CreateProject(project);

            Assert.IsInstanceOfType(result, typeof(OkResult));
        }
        private ProjectController CreateProject(string sourceName)
        {
            // generate name parameters from source name
            string newName           = $"{sourceName}Copy";
            string sourceProjectPath = GetChildPath(sourceName.ToLower());
            string newProjectPath    = GetChildPath(newName.ToLower());

            // clean up old test structure
            if (Directory.Exists(newProjectPath))
            {
                Directory.Delete(newProjectPath, true);
            }

            // run controller test
            var projectController = new ProjectController
            {
                SourceProjectDirectory = new DirectoryInfo(sourceProjectPath),
                NewProjectName         = newName
            };

            var createProjectTask = projectController.CreateProject();

            createProjectTask.Wait();
            return(projectController);
        }
Exemple #5
0
        public void ShouldCreateProject()
        {
            var projectId = new Random().Next(2, 100);
            var process   = new Mock <IProjectManagementProcess>();

            process.Setup(m => m.AddProject(It.IsAny <Project>())).Returns <Project>(p =>
            {
                p.Id = projectId;
                return(true);
            });
            var controller = new ProjectController(process.Object);

            controller.Request = new System.Net.Http.HttpRequestMessage
            {
                RequestUri = new Uri("http://localhost/api/createproject"),
                Method     = System.Net.Http.HttpMethod.Post
            };
            var output = controller.CreateProject(new Project {
            });

            Assert.IsNotNull(output);
            Assert.IsInstanceOfType(output, typeof(CreatedNegotiatedContentResult <Project>));
            var result = output as CreatedNegotiatedContentResult <Project>;

            Assert.AreEqual(projectId, result.Content.Id);
        }
Exemple #6
0
        public void CreateProject()
        {
            //Arrange
            Project createdProject = Projects.CreatedProject;

            var        projectService = new Mock <IProjectService>();
            NewProject newProject     = Projects.NewProject;


            projectService.Setup(service => service.IsProjectNameExists(newProject.ProjectName))
            .Returns(false);

            projectService.Setup(service => service.IsProtocolIDExists(newProject.ProtocolID))
            .Returns(false);

            var controller = new ProjectController(projectService.Object);

            // Act
            var values = controller.CreateProject(newProject);
            var result = values as CreatedResult;


            //Assert
            Assert.Equal(201, result.StatusCode);
            Assert.Equal(ResponseMessages.PROJECT_CREATED, result.Location);
        }
Exemple #7
0
        public void SaveProjects()
        {
            var context    = new ProjectManagerAPI.Tests.TestContext();
            var controller = new ProjectController(context);
            var okresult   = controller.CreateProject(GetDemoProjectModel());

            Assert.IsInstanceOfType(okresult, typeof(OkResult));
        }
Exemple #8
0
        public void PostProjectTest()
        {
            var result = controller.CreateProject(new ProjectDBModel {
                ProjectID = 1, ProjectTitle = "HIT 1402", Priority = 1
            });

            Assert.IsNotNull(result);
        }
Exemple #9
0
        public void TestCreateProject()
        {
            var project     = Util.RandomProject();
            var userProject = (UserCreatedProject)((ObjectResult)_projController.CreateProject(project).Result).Value;

            project.Id = userProject.Project.Id;
            Assert.Contains(project, _projRepo.GetAllProjects().Result);
        }
Exemple #10
0
        public TestCaseContext WithNewProjectForUser(UserInfoDto user, AddProjectDto addProjectDto, out ProjectInfoDto projectInfo)
        {
            projectInfo = ProjectController.CreateProject(addProjectDto).Value;

            Assert.NotNull(projectInfo);

            return(this);
        }
        public void UpdateProjects()
        {
            var context    = new TestContext();
            var controller = new ProjectController(context);
            var okresult   = controller.CreateProject(GetDemoProject());

            Assert.IsInstanceOfType(okresult, typeof(OkResult));
        }
Exemple #12
0
        public async Task CreateProject()
        {
            var createResult = await projectController.CreateProject(new ProjectCreateDTO()
            {
                ClientName  = "Test Client",
                Description = "Test Description",
                ProjectName = "Test Name",
                Tags        = new List <string>()
                {
                    "Test Tag 1",
                    "Test Tag 2"
                }
            });

            Assert.IsTrue(createResult.Success);

            var allProjects = await projectController.GetActiveProjectsByUser();

            Assert.IsTrue(allProjects.Success);
            Assert.AreEqual(allProjects.Data.Count, 1);

            Assert.AreEqual(allProjects.Data[0].ClientName, "Test Client");
            Assert.AreEqual(allProjects.Data[0].Description, "Test Description");
            Assert.AreEqual(allProjects.Data[0].Name, "Test Name");

            Assert.AreEqual(allProjects.Data[0].Tags.Count, 2);

            var newTag = await projectController.AddTag(new CreateTagDTO()
            {
                ProjectId = allProjects.Data[0].Id,
                Tag       = "New Tag"
            });

            var projectById = await projectController.GetProjectById(allProjects.Data[0].Id);

            Assert.IsTrue(projectById.Success);

            Assert.AreEqual(projectById.Data.ClientName, "Test Client");
            Assert.AreEqual(projectById.Data.Description, "Test Description");
            Assert.AreEqual(projectById.Data.Name, "Test Name");

            Assert.AreEqual(projectById.Data.Tags.Count, 3);
            Assert.IsTrue(projectById.Data.Tags.Any(x => x.Name == "New Tag"));
        }
Exemple #13
0
        public async Task CreateTestUserWithInviteCode()
        {
            await TestAuthHelpers.LogInUser(database, configuration, projectController);

            ProjectCreateDTO projectInfo = new ProjectCreateDTO {
                ProjectName = "Soup Delivery Website",
                ClientName  = "Soup Delivery LLC"
            };

            GenericResponseDTO <int> createProjectResponse = await projectController.CreateProject(projectInfo);

            Assert.IsTrue(createProjectResponse.Success);

            int     projectID = createProjectResponse.Data;
            Project project   = await database.Projects
                                .AsNoTracking()
                                .FirstOrDefaultAsync(p => p.Id == projectID);

            string projectInviteCode = project.InviteCode;

            UserDTO registrationInfo = new UserDTO {
                Email      = "*****@*****.**",
                Password   = "******",
                FirstName  = "Suzuya",
                LastName   = "Z.",
                InviteCode = projectInviteCode
            };

            GenericResponseDTO <int> registerResponse = await authController.Register(registrationInfo);

            Assert.IsTrue(registerResponse.Success);

            User user = await database.Users
                        .Include(x => x.Projects)
                        .FirstOrDefaultAsync(u => u.Id == registerResponse.Data);

            Assert.IsTrue(user.Projects.Count == 1);
            Assert.IsTrue(user.Projects[0].Id == project.Id);
        }
Exemple #14
0
        public async Task Add_NullObjectPassed_ReturnsBadRequest()
        {
            // Act
            var badResponse = await _controller.CreateProject(null);

            // Assert
            Assert.IsInstanceOfType(badResponse, typeof(BadRequestResult));
        }
Exemple #15
0
        public void ShouldGetErrorOnCreateProject()
        {
            var process = new Mock <IProjectManagementProcess>();

            process.Setup(m => m.AddProject(It.IsAny <Project>())).Throws(new Exception("Internal Error"));
            var controller = new ProjectController(process.Object);
            var output     = controller.CreateProject(new Project {
            });

            Assert.IsNotNull(output);
            Assert.IsInstanceOfType(output, typeof(ExceptionResult));
            var result = output as ExceptionResult;

            Assert.AreEqual("Internal Error", result.Exception.Message);
        }
Exemple #16
0
        public void Task_CreateProjectTest()
        {
            Project testproject2 = new Project
            {
                Id        = 5,
                Name      = "ProjectManagement2",
                Detail    = "this is a project management project2",
                CreatedOn = DateTime.Parse(V)
            };
            var controller = new ProjectController(_service);

            var data = controller.CreateProject(testproject2);

            Assert.IsType <OkObjectResult>(data);
        }
        public void CreateProject_Should_Return_BadRequest()
        {
            // Arrange
            ProjectResponse response = new ProjectResponse("message");

            _mockProjectBL.Setup(repo => repo.CreateAsync(It.IsAny <ProjectDto>(), It.IsAny <string>())).ReturnsAsync(response);
            var projectController = new ProjectController(_mockProjectBL.Object);
            // Act
            var res1 = projectController.CreateProject(It.IsAny <ProjectDto>()).Result;
            // Assert
            var viewResult = Assert.IsType <BadRequestObjectResult>(res1);
            var message    = Assert.IsAssignableFrom <string>(viewResult.Value);

            Assert.Equal("message", message);
        }
Exemple #18
0
        public void CreateProject_should_call_CreateProject_method_once_in_project_controller()
        {
            //Arrange
            var model = new ProjectLogicModel
            {
                Name = "Test1",
                Id   = 5
            };

            //Act
            _projectController.CreateProject(model.ToViewModel());

            //Assert
            _projectLogicMock.Verify(x => x.Create(It.IsAny <UserLogicModel>(), It.IsAny <ProjectLogicModel>()), Times.Once);
        }
        public async void CreateProject_should_return_ProjectResponseDto_dto()
        {
            CreateProjectRequestDto projectDto = new CreateProjectRequestDto();

            projectDto.Name        = "Name";
            projectDto.Description = "Description";
            projectDto.CreatedBy   = Guid.Parse("ab2bd817-98cd-4cf3-a80a-53ea0cd9c100");

            var result = await _controller.CreateProject(projectDto) as OkObjectResult;

            var project = Assert.IsType <ProjectResponseDto>(result.Value);

            Assert.Equal("Name", project.Name);
            Assert.Equal("Description", project.Description);
            Assert.Equal(200, result.StatusCode);
        }
        public async void CreateProject_ReturnsCreatedProject()
        {
            _projectService
            .Setup(s => s.CreateProject(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(),
                                        It.IsAny <List <(int, int)> >(), It.IsAny <List <ProjectDataModel> >(), It.IsAny <List <JobDefinition> >(),
                                        It.IsAny <int>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync((string projectName, string displayName, string client, List <(int, int)> projectMembers,
                           List <ProjectDataModel> models, List <JobDefinition> jobs, int currentUserId, CancellationToken cancellationToken) =>
                          new Project
            {
                Id     = 1,
                Name   = projectName,
                Client = client,
                Models = models,
                Jobs   = jobs
            });

            var httpContext = new DefaultHttpContext()
            {
                User = new ClaimsPrincipal(new[]
                {
                    new ClaimsIdentity(new[] { new Claim(ClaimTypes.NameIdentifier, "1") })
                })
            };

            var controller = new ProjectController(_projectService.Object, _mapper, _logger.Object)
            {
                ControllerContext = new ControllerContext {
                    HttpContext = httpContext
                }
            };

            var dto = new NewProjectDto
            {
                Name    = "Project01",
                Members = new List <Shared.Dto.NewProjectMemberDto>(),
                Models  = new List <Shared.Dto.ProjectDataModel.CreateProjectDataModelWithPropertiesDto>(),
                Jobs    = new List <Shared.Dto.JobDefinition.CreateJobDefinitionWithTasksDto>()
            };
            var result = await controller.CreateProject(dto);

            var createAtRouteActionResult = Assert.IsType <CreatedAtRouteResult>(result);
            var returnValue = Assert.IsType <ProjectDto>(createAtRouteActionResult.Value);

            Assert.Equal(1, returnValue.Id);
            Assert.Equal("Project01", returnValue.Name);
        }
        public void CreateProject_Should_Work_Return_Ok()
        {
            // Arrange
            ProjectDto projectDto = new ProjectDto {
                Id = 1, Name = "Project name", Description = "Some description"
            };
            ProjectResponse response = new ProjectResponse(projectDto);

            _mockProjectBL.Setup(repo => repo.CreateAsync(projectDto, It.IsAny <string>())).ReturnsAsync(response);
            var projectController = new ProjectController(_mockProjectBL.Object);
            // Act
            var res1 = projectController.CreateProject(projectDto).Result;
            // Assert
            var viewResult = Assert.IsType <OkResult>(res1);

            _mockProjectBL.Verify(r => r.CreateAsync(projectDto, It.IsAny <string>()), Times.Once);
        }
Exemple #22
0
        public void ShouldNotCreateProject()
        {
            var process = new Mock <IProjectManagementProcess>();

            process.Setup(m => m.AddProject(It.IsAny <Project>())).Returns(false);
            var controller = new ProjectController(process.Object);

            controller.Request = new System.Net.Http.HttpRequestMessage
            {
                RequestUri = new Uri("http://localhost/api/createproject"),
                Method     = System.Net.Http.HttpMethod.Post
            };
            var output = controller.CreateProject(new Project {
            });

            Assert.IsNotNull(output);
            Assert.IsInstanceOfType(output, typeof(BadRequestErrorMessageResult));
        }
Exemple #23
0
        public async System.Threading.Tasks.Task CreateProject_Returns_CreatedAtActionResult()
        {
            // Arrange
            var tenantId = Guid.NewGuid();
            var project  = new Project()
            {
                Id          = 1,
                Name        = "Test Unit Project",
                StartDate   = new DateTime(2019, 8, 8),
                EndDate     = new DateTime(2019, 8, 12),
                Description = "This is a unit test",
                Status      = EStatus.NotStarted,
                TenantId    = tenantId
            };
            // Act
            var response = await sut.CreateProject(project);

            // Assert
            Assert.IsType <CreatedAtActionResult>(response);
        }
Exemple #24
0
        public async Task CreateProject_ShouldReturnTheCreatedProject()
        {
            var projectOperations = new Mock <IProjectOperations>();
            var planOperations    = new Mock <IPlanOperations>();

            var model    = new CreateProjectModel();
            var expected = new ProjectModel();

            projectOperations.Setup(o => o.CreateProject(model)).ReturnsAsync(expected);

            var controller = new ProjectController(projectOperations.Object, planOperations.Object);

            var result =
                await controller.CreateProject(model).ConfigureAwait(false) as OkNegotiatedContentResult <ProjectModel>;

            if (result == null)
            {
                Assert.Fail();
            }

            Assert.AreEqual(expected, result.Content);
        }
        public void When_CreateProject_Then_ProjectIsCreated()
        {
            var taskModel = new ProjectModel()
            {
                ProjectId   = 1,
                ProjectName = "New test project",
                StartDate   = DateTime.Today.AddDays(-15),
                EndDate     = DateTime.Today.AddDays(-15),
                Priority    = 5,
                UserId      = 1
            };

            // Arrange & Act
            var result        = Controller.CreateProject(taskModel);
            var contentResult = result as NegotiatedContentResult <ProjectModel>;


            // Assert
            Assert.IsNotNull(result);
            Assert.IsNotNull(contentResult);
            Assert.AreEqual(HttpStatusCode.OK, contentResult.StatusCode);
            Assert.IsNotNull(contentResult.Content);
        }
        public void Create()
        {
            var result = controller.CreateProject();

            Assert.IsNull(result);
        }
Exemple #27
0
        public async Task TestTimeEntry()
        {
            var projectResults = await projectController.CreateProject(new ProjectCreateDTO()
            {
                ClientName  = "Test Client",
                Description = "Test Desciption",
                ProjectName = "Best project 10/10",
                Tags        = new List <string>()
                {
                    "AngryCarrot"
                }
            });

            database.ChangeTracker.Clear();

            var projectId = projectResults.Data;

            var testTimeEntry = new TimeEntryDTO()
            {
                Day       = new DateTime(1999, 6, 18),
                Length    = 5,
                Notes     = "Happy Birthday",
                ProjectId = projectId
            };

            // Create time
            var createTimeResults = await timeEntryController.CreateTime(testTimeEntry);

            Assert.IsTrue(createTimeResults.Success);
            Assert.IsTrue(createTimeResults.Data > 0);

            // Get the time entry
            var getCreatedTimeResults = await timeEntryController.Get(createTimeResults.Data);

            Assert.AreEqual(getCreatedTimeResults.Success, true);
            Assert.AreEqual(testTimeEntry.Day, getCreatedTimeResults.Data.Day);
            Assert.AreEqual(testTimeEntry.Length, getCreatedTimeResults.Data.Length);
            Assert.AreEqual(testTimeEntry.Notes, getCreatedTimeResults.Data.Notes);
            Assert.IsTrue(DateTime.UtcNow > getCreatedTimeResults.Data.CreatedTime);

            var updatedTimeEntry = new TimeEntryDTO()
            {
                Id     = createTimeResults.Data,
                Day    = new DateTime(1989, 10, 24),
                Notes  = "pewdiepie",
                Length = 5
            };

            // Update time
            var updateTimeResuls = await timeEntryController.UpdateTime(updatedTimeEntry);

            // Get the time entry
            var getUpdatedTimeResults = await timeEntryController.Get(updateTimeResuls.Data);

            Assert.AreEqual(getUpdatedTimeResults.Success, true);
            Assert.AreEqual(getUpdatedTimeResults.Data.Id, getCreatedTimeResults.Data.Id);
            Assert.AreEqual(updatedTimeEntry.Day, getUpdatedTimeResults.Data.Day);
            Assert.AreEqual(updatedTimeEntry.Length, getUpdatedTimeResults.Data.Length);
            Assert.AreEqual(updatedTimeEntry.Notes, getUpdatedTimeResults.Data.Notes);
            Assert.AreEqual(getUpdatedTimeResults.Data.CreatedTime, getCreatedTimeResults.Data.CreatedTime);
            Assert.IsTrue(getCreatedTimeResults.Data.LastModified < getUpdatedTimeResults.Data.LastModified);

            // Search for projects

            var singleDayNoResults = await timeEntryController.GetInDateRange(new DateRangeDTO()
            {
                StartDate = DateTime.Now,
                EndDate   = DateTime.Now
            });

            Assert.AreEqual(singleDayNoResults.Success, true);
            Assert.AreEqual(singleDayNoResults.Data.Count, 0);

            var singleDayResults = await timeEntryController.GetInDateRange(new DateRangeDTO()
            {
                StartDate = updatedTimeEntry.Day,
                EndDate   = updatedTimeEntry.Day
            });

            Assert.AreEqual(singleDayResults.Success, true);
            Assert.AreEqual(singleDayResults.Data.Count, 1);

            var multipleDayResults = await timeEntryController.GetInDateRange(new DateRangeDTO()
            {
                StartDate = updatedTimeEntry.Day.AddDays(-10),
                EndDate   = updatedTimeEntry.Day.AddDays(123)
            });

            Assert.AreEqual(multipleDayResults.Success, true);
            Assert.AreEqual(multipleDayResults.Data.Count, 1);
        }
        protected void btn_ProjAdd_Click(object sender, EventArgs e)
        {
            ProjectController pc = new ProjectController(Convert.ToInt32(Session["userId"]));

            pc.CreateProject(txt_ProjName.Text, txt_ProjDesc.Text, txt_ProjClient.Text, Convert.ToDateTime(txt_ProjStartDate.Text), Convert.ToDateTime(txt_ProjEndDate.Text), Convert.ToInt32(Session["userId"]));
        }
Exemple #29
0
        private async Task <int> setupTest()
        {
            // Create a project and time entry
            var mainProject = await projectController.CreateProject(new ProjectCreateDTO()
            {
                ClientName  = "Spongebob Squarepants",
                Description = "Eat spongebob's pineapple house",
                ProjectName = "Eat Pineapple",
                Tags        = new List <string>()
                {
                    "Food"
                }
            });

            var timeEntries = new List <TimeEntryDTO>()
            {
                new TimeEntryDTO()
                {
                    CreatedTime = DateTime.Now,
                    Day         = new DateTime(1999, 1, 10),
                    Length      = 5,
                    Notes       = "Consumed leafs",
                    ProjectId   = mainProject.Data
                },
                new TimeEntryDTO()
                {
                    CreatedTime = DateTime.Now,
                    Day         = new DateTime(1999, 1, 10),
                    Length      = 2,
                    Notes       = "Consumed Door",
                    ProjectId   = mainProject.Data
                },
                new TimeEntryDTO()
                {
                    CreatedTime = DateTime.Now,
                    Day         = new DateTime(1999, 1, 10),
                    Length      = 3,
                    Notes       = "Consumed back of pineapple",
                    ProjectId   = mainProject.Data
                }
            };

            foreach (var entry in timeEntries)
            {
                await timeEntryController.CreateTime(entry);
            }

            // Get project invite code
            var projectDetails = await projectController.GetProjectById(mainProject.Data);

            // Login as 2nd user
            TestAuthHelpers.LogInUser(database, configuration, new List <ControllerBase>()
            {
                timeEntryController,
                projectController,
                reportController
            }, projectDetails.Data.InviteCode).GetAwaiter().GetResult();

            var timeEntries2 = new List <TimeEntryDTO>()
            {
                new TimeEntryDTO()
                {
                    CreatedTime = DateTime.Now,
                    Day         = new DateTime(2000, 1, 10),
                    Length      = 1,
                    Notes       = "Consumed left window",
                    ProjectId   = mainProject.Data
                },
                new TimeEntryDTO()
                {
                    CreatedTime = DateTime.Now,
                    Day         = new DateTime(2000, 1, 10),
                    Length      = 1,
                    Notes       = "Consumed right window",
                    ProjectId   = mainProject.Data
                }
            };

            foreach (var entry in timeEntries2)
            {
                await timeEntryController.CreateTime(entry);
            }

            return(mainProject.Data);
        }