public async Task ensureUpdateFinishPostFailsForNonExistingMaterial()
        {
            FinishDTO finishDTOToRemove = new FinishDTO();

            finishDTOToRemove.description = "ola";

            var response = await client.DeleteAsync(String.Format(urlBase + "/{0}/{1}/{2}", -1, "colors", finishDTOToRemove.id));

            Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
            Assert.NotNull(response.Content.ReadAsStringAsync());
        }
        public async Task ensureUpdateFinishesPostFailsForNonExistingMaterial()
        {
            FinishDTO finishDTO = new FinishDTO();

            finishDTO.description = "ola";

            var response = await client.PostAsJsonAsync(String.Format(urlBase + "/{0}/{1}", -1, "finishes"), finishDTO);

            Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
            Assert.NotNull(response.Content.ReadAsStringAsync());
        }
Exemple #3
0
        public void testToDTO()
        {
            Console.WriteLine("toDTO");
            string description = "this is the best finish ever";
            float  shininess   = 12;

            Finish    finish = Finish.valueOf(description, shininess);
            FinishDTO dto    = new FinishDTO();

            dto.description = description;
            dto.shininess   = shininess;

            Assert.Equal(dto.description, finish.toDTO().description);
            Assert.Equal(dto.shininess, finish.toDTO().shininess);
        }
        public async Task ensureUpdateFinishesDeleteSucceedsWhenRemovingFinish()
        {
            FinishDTO finishDTOToRemove = new FinishDTO();

            finishDTOToRemove.description = "ola";
            var materialDTO = ensurePostMaterialWorks();

            materialDTO.Wait();

            var response = await client.DeleteAsync(String.
                                                    Format(urlBase + "/{0}/{1}/{2}", materialDTO.Id, "finishes", finishDTOToRemove.id));

            Assert.Equal(HttpStatusCode.NoContent, response.StatusCode);
            Assert.NotNull(response.Content.ReadAsStringAsync());
        }
        public async Task ensureUpdateFinishesPostSucceedsWhenAddingFinish()
        {
            FinishDTO finishDTOToAdd = new FinishDTO();

            finishDTOToAdd.description = "new finish";
            var materialDTO = ensurePostMaterialWorks();

            materialDTO.Wait();

            var response = await client.PostAsJsonAsync(String.
                                                        Format(urlBase + "/{0}/{1}", materialDTO.Id, "finishes"), finishDTOToAdd);

            Assert.Equal(HttpStatusCode.Created, response.StatusCode);
            Assert.NotNull(response.Content.ReadAsStringAsync());
        }
Exemple #6
0
        /// <summary>
        /// Add the finish of a material from update
        /// </summary>
        /// <param name="idMaterial">id of the material to be updated</param>
        /// <param name="addFinishDTO">FinishDTO with the information of finish to add</param>
        /// <returns>boolean true if the update was successful, false if not</returns>
        public AddFinishModelView addFinish(long idMaterial, FinishDTO addFinishDTO)
        {
            MaterialRepository materialRepository = PersistenceContext.repositories().createMaterialRepository();
            Material           material           = materialRepository.find(idMaterial);

            if (addFinishDTO != null)
            {
                material.addFinish(addFinishDTO.toEntity());


                materialRepository.update(material);
                AddFinishModelView addFinishModelView = new AddFinishModelView();
                addFinishModelView.finish = addFinishDTO;
                return(addFinishModelView);
            }
            return(null);
        }
        public async Task <MaterialDTO> ensurePostMaterialWorks()
        {
            MaterialDTO materialDTO = new MaterialDTO();

            materialDTO.designation = "mdf";
            materialDTO.reference   = "bananas" + Guid.NewGuid().ToString("n");
            materialDTO.image       = "image.png";
            ColorDTO colorDTO = new ColorDTO();

            colorDTO.name  = "lilxan";
            colorDTO.red   = 100;
            colorDTO.green = 200;
            colorDTO.blue  = 10;
            colorDTO.alpha = 0;
            ColorDTO otherColorDTO = new ColorDTO();

            otherColorDTO.name  = "another color";
            otherColorDTO.red   = 10;
            otherColorDTO.green = 10;
            otherColorDTO.blue  = 10;
            otherColorDTO.alpha = 10;
            FinishDTO finishDTO      = new FinishDTO();
            FinishDTO otherFinishDTO = new FinishDTO();

            finishDTO.description      = "ola";
            otherFinishDTO.description = "another finish";
            materialDTO.colors         = new List <ColorDTO>(new[] { colorDTO, otherColorDTO });
            materialDTO.finishes       = new List <FinishDTO>(new[] { finishDTO, otherFinishDTO });
            var response = await client.PostAsJsonAsync(urlBase, materialDTO);

            MaterialDTO materialDTOFromPost = JsonConvert.DeserializeObject <MaterialDTO>(await response.Content.ReadAsStringAsync());

            Assert.Equal(HttpStatusCode.Created, response.StatusCode);
            Assert.NotNull(response.Content.ReadAsStringAsync());
            Assert.True(materialDTO.id != -1);
            Assert.Equal(materialDTO.reference, materialDTOFromPost.reference);
            Assert.Equal(materialDTO.image, materialDTOFromPost.image);
            Assert.NotNull(materialDTOFromPost.colors);
            Assert.NotNull(materialDTOFromPost.finishes);
            Assert.Equal(materialDTO.designation, materialDTOFromPost.designation);

            return(materialDTOFromPost);
        }
Exemple #8
0
        private async Task <MaterialDTO> createMaterial(string testNumber)
        {
            MaterialDTO materialDTO = new MaterialDTO();

            materialDTO.designation = "Material Designation Test" + testNumber;
            materialDTO.reference   = "Material Reference Test" + testNumber;
            materialDTO.image       = "Material Image Test" + testNumber + ".jpeg";
            ColorDTO  colorDTO       = new ColorDTO();
            ColorDTO  otherColorDTO  = new ColorDTO();
            FinishDTO finishDTO      = new FinishDTO();
            FinishDTO otherFinishDTO = new FinishDTO();

            colorDTO.red               = 100;
            colorDTO.blue              = 100;
            colorDTO.green             = 100;
            colorDTO.alpha             = 10;
            colorDTO.name              = "Color Test" + testNumber;
            otherColorDTO.red          = 150;
            otherColorDTO.blue         = 150;
            otherColorDTO.green        = 150;
            otherColorDTO.alpha        = 100;
            otherColorDTO.name         = "Other Color Test" + testNumber;
            finishDTO.description      = "Finish Test" + testNumber;
            otherFinishDTO.description = "Other Finish Test" + testNumber;
            materialDTO.colors         = new List <ColorDTO>()
            {
                colorDTO, otherColorDTO
            };
            materialDTO.finishes = new List <FinishDTO>()
            {
                finishDTO, otherFinishDTO
            };

            var response = await httpClient.PostAsJsonAsync("mycm/api/materials", materialDTO);

            Assert.Equal(HttpStatusCode.Created, response.StatusCode);

            MaterialDTO createdMaterial =
                await response.Content.ReadAsAsync <MaterialDTO>();

            return(createdMaterial);
        }
 public ActionResult addFinish(long idMaterial, [FromBody] FinishDTO addFinishDTO)
 {
     try
     {
         AddFinishModelView addFinishModelView = new core.application.MaterialsController().addFinish(idMaterial, addFinishDTO);
         if (addFinishModelView != null)
         {
             return(Created(Request.Path, addFinishModelView));
         }
     }
     catch (NullReferenceException)
     {
         return(BadRequest(new SimpleJSONMessageService(INVALID_REQUEST_BODY_MESSAGE)));
     }
     catch (Exception)
     {
         return(StatusCode(500, UNEXPECTED_ERROR));
     }
     return(BadRequest(new SimpleJSONMessageService(UNABLE_TO_UPDATE_MATERIAL)));
 }
Exemple #10
0
        /// <summary>
        /// Creates a new instance of CustomizedMaterial.
        /// </summary>
        /// <param name="addCustomizedMaterialModelView">AddCustomizedMaterialModelView representing the CustomizedMaterial's data.</param>
        /// <returns>An instance of CustomizedMaterial.</returns>
        /// <exception cref="System.ArgumentException">Thrown when no Material could be found with the provided identifier.</exception>
        public static CustomizedMaterial create(AddCustomizedMaterialModelView addCustomizedMaterialModelView)
        {
            MaterialRepository materialRepository = PersistenceContext.repositories().createMaterialRepository();

            Material material = materialRepository.find(addCustomizedMaterialModelView.materialId);

            if (material == null)
            {
                throw new ArgumentException(string.Format(ERROR_UNABLE_TO_FIND_MATERIAL, addCustomizedMaterialModelView.materialId));
            }
            //TODO: replace usage of dto
            FinishDTO finishDTO = addCustomizedMaterialModelView.finish;
            ColorDTO  colorDTO  = addCustomizedMaterialModelView.color;

            if (finishDTO == null && colorDTO == null)
            {
                throw new ArgumentException(NULL_COLOR_AND_FINISH);
            }

            CustomizedMaterial customizedMaterial = null;

            if (finishDTO == null && colorDTO != null)
            {
                customizedMaterial = CustomizedMaterial.valueOf(material, colorDTO.toEntity());
            }
            else if (finishDTO != null && colorDTO == null)
            {
                customizedMaterial = CustomizedMaterial.valueOf(material, finishDTO.toEntity());
            }
            else
            {
                customizedMaterial = CustomizedMaterial.valueOf(material, colorDTO.toEntity(), finishDTO.toEntity());
            }

            return(customizedMaterial);
        }