Пример #1
0
 public ActionResult CreateProgram(NewProgram newProgram)
 {
     // if is program exists throw error message
     if (projectService.IsProgramNameExists(newProgram.ProgramName.Trim(), newProgram.ResourceID))
     {
         return(Conflict(new ErrorDetails
         {
             ExceptionMessage = ResponseMessages.PROGRAM_NAME_EXISTS,
             StatusCode = ResponseCodes.STATUS_CODE_CONFLICT
         }));
     }
     else
     {
         ProgramModel createdProgram = projectService.CreateProgram(newProgram);
         return(Created(ResponseMessages.PROGRAM_CREATED, createdProgram));
     }
 }
Пример #2
0
        public void CreateProgram()
        {
            //Arrange
            ProgramModel createdProgram = Programs.CreatedProgram;

            NewProgram newProgram = Programs.NewProgram;


            var projectService = new Mock <IProjectService>();

            projectService.Setup(service => service.IsProgramNameExists(createdProgram.Name, createdProgram.ResourceID))
            .Returns(false);

            var controller = new ProgramController(projectService.Object);

            // Act
            var values = controller.CreateProgram(newProgram);
            var result = values as CreatedResult;


            //Assert
            Assert.Equal(201, result.StatusCode);
            Assert.Equal(ResponseMessages.PROGRAM_CREATED, result.Location);
        }