Example #1
0
        public void GetByName_ShouldReturnNeededCharacteristic()
        {
            string testName        = "Laminated";
            var    characteristics = new List <VehicleGlassCharacteristic>()
            {
                new VehicleGlassCharacteristic()
                {
                    Name = "Alarm Wire"
                },
                new VehicleGlassCharacteristic()
                {
                    Name = "Center Part"
                },
                new VehicleGlassCharacteristic()
                {
                    Name = "LAMINATED", Id = 1
                },
                new VehicleGlassCharacteristic()
                {
                    Name = "Top extrusion"
                }
            }.AsQueryable();

            var repositoryMock = new Mock <IInternalDbRepository <VehicleGlassCharacteristic> >();

            repositoryMock.Setup(x => x.All()).Returns(() => characteristics);

            VehicleGlassCharacteristicsService service = new VehicleGlassCharacteristicsService(repositoryMock.Object);

            VehicleGlassCharacteristic response = service.GetByName(testName);

            Assert.AreEqual(response.Id, 1);
            repositoryMock.VerifyAll();
        }
        // parses the GetCharacteristics for a given product.
        // if the same already exists -> return them
        // else adds them -> return them
        private List <VehicleGlassCharacteristic> HandleCharacteristics(List <string> characteristics)
        {
            List <VehicleGlassCharacteristic> characteristicsToAdd = new List <VehicleGlassCharacteristic>();

            foreach (var characteristicName in characteristics)
            {
                VehicleGlassCharacteristic existingcharacteristic = this.Characteristics.GetByName(characteristicName);
                if (existingcharacteristic == null)
                {
                    VehicleGlassCharacteristic newCharacteristic = new VehicleGlassCharacteristic()
                    {
                        Name = characteristicName
                    };

                    this.Characteristics.Add(newCharacteristic);
                    characteristicsToAdd.Add(newCharacteristic);
                }
                else
                {
                    characteristicsToAdd.Add(existingcharacteristic);
                }
            }

            return(characteristicsToAdd);
        }