Exemple #1
0
        public void testToDTO()
        {
            string reference   = "el. psy. kongroo.";
            string designation = "I am mad scientist!";

            List <Color> colors = new List <Color>();

            Color color = Color.valueOf("Blue", 0, 0, 255, 0);

            colors.Add(color);

            List <Finish> finishes = new List <Finish>();

            Finish finish = Finish.valueOf("Glossy", 13);

            finishes.Add(finish);

            Material material = new Material(reference, designation, "HelloGIMPTransparentBackground.jpg", colors, finishes);


            MaterialDTO expected = new MaterialDTO();

            expected.reference   = reference;
            expected.designation = designation;
            expected.colors      = new List <ColorDTO>(DTOUtils.parseToDTOS(colors));
            expected.finishes    = new List <FinishDTO>(DTOUtils.parseToDTOS(finishes));

            MaterialDTO actual = material.toDTO();

            Assert.Equal(expected.reference, actual.reference);
            Assert.Equal(expected.designation, actual.designation);

            int actualColorListSize   = actual.colors.Count;
            int expectedColorListSize = expected.colors.Count;

            Assert.Equal(expectedColorListSize, actualColorListSize);

            for (int i = 0; i < actualColorListSize; i++)
            {
                Assert.Equal(expected.colors[i].red, actual.colors[i].red);
                Assert.Equal(expected.colors[i].green, actual.colors[i].green);
                Assert.Equal(expected.colors[i].blue, actual.colors[i].blue);
                Assert.Equal(expected.colors[i].alpha, actual.colors[i].alpha);
            }

            int actualFinishListSize   = actual.finishes.Count;
            int expectedFinishListSize = expected.finishes.Count;

            Assert.Equal(expectedFinishListSize, actualFinishListSize);

            for (int i = 0; i < actualFinishListSize; i++)
            {
                Assert.Equal(expected.finishes[i].description, actual.finishes[i].description);
            }
        }
Exemple #2
0
        /// <summary>
        /// Creates a model view with a material information
        /// </summary>
        /// <param name="material">Material with the material being created the model view</param>
        /// <returns>GetMaterialModelView with the material information model view</returns>
        public static GetMaterialModelView fromEntity(Material material)
        {
            GetMaterialModelView materialModelView = new GetMaterialModelView();

            materialModelView.id            = material.Id;
            materialModelView.reference     = material.reference;
            materialModelView.designation   = material.designation;
            materialModelView.imageFilename = material.image;
            materialModelView.colors        = DTOUtils.parseToDTOS(material.Colors).ToList();
            materialModelView.finishes      = DTOUtils.parseToDTOS(material.Finishes).ToList();
            return(materialModelView);
        }