コード例 #1
0
ファイル: TeamupService.cs プロジェクト: lheinemann/TeamUp
        public async Task <int> CreateProjectAsync(TeamUpProject project)
        {
            int projectId = 0;

            var        projectHandler = new ProjectHandler(_client);
            Newproject newProject     = new Newproject()
            {
                Name            = project.ProjectName,
                Description     = project.ProjectDescription,
                StartDate       = project.StartDate.ToString("yyyyMMdd"),
                EndDate         = project.EndDate.ToString("yyyyMMdd"),
                CategoryId      = CategoryId,
                UseBilling      = "1",
                UseFiles        = "1",
                UseLinks        = "1",
                UseMessages     = "1",
                UseMilestones   = "1",
                UseNotebook     = "1",
                UseRiskregister = "1",
                UseTasks        = "1",
                UseTime         = "1"
            };

            //Add project
            var result = await projectHandler.AddProject(newProject);

            if (result != null && result.StatusCode == System.Net.HttpStatusCode.OK)
            {
                projectId = (int)result.ContentObj;
                var taskListHandler = new TasklistHandler(_client);

                string sourceProjectId = string.IsNullOrEmpty(project.SourceProjectId) ? DefaultSourceProjectId : project.SourceProjectId;

                //get tasklist based on reference project
                List <string> TaskLists = await taskListHandler.GetTaskLists(sourceProjectId);

                if (TaskLists != null && TaskLists.Count > 0)
                {
                    //copy taskLists to project
                    List <Task> taskStack = new List <Task>();
                    TaskLists.ForEach(t =>
                    {
                        taskStack.Add(taskListHandler.CopyTaskList(t, projectId));
                    });

                    await Task.WhenAll(taskStack.ToArray());
                }
            }

            return(projectId);
        }
コード例 #2
0
        public void AddProject_Failure_Test()
        {
            ProjectViewModel pjVM = new ProjectViewModel();

            pjVM.ProjectName = "testproj1";
            pjVM.StartDate   = DateTime.Now;
            pjVM.EndDate     = DateTime.Now.AddDays(1);
            pjVM.Priority    = 10;
            pjVM.UserId      = 1;

            Project pj1 = new Project();

            pj1.ProjectName = "testproj1";
            pj1.StartDate   = DateTime.Now;
            pj1.EndDate     = DateTime.Now.AddDays(1);
            pj1.Priority    = 10;
            pj1.UserId      = 1;
            pj1.ProjectId   = 1;
            Project pj2 = new Project();

            pj2.ProjectName = "testproj2";
            pj2.StartDate   = DateTime.Now;
            pj2.EndDate     = DateTime.Now.AddDays(1);
            pj2.Priority    = 10;
            pj2.UserId      = 1;
            pj2.ProjectId   = 2;
            List <Project> projList = new List <Project>();

            projList.Add(pj1);
            projList.Add(pj2);
            IQueryable <Project> Projects = projList.AsQueryable();
            var mockRepo = new Mock <IProjectRepository>();

            mockRepo.Setup(p => p.GetAllProject()).Returns(Projects);
            var handler = new ProjectHandler(mockRepo.Object);

            Assert.That(() => handler.AddProject(pjVM),
                        Throws.TypeOf <CustomException>());
            mockRepo.Verify(mock => mock.GetAllProject(), Times.Once());
        }