Exemplo n.º 1
0
        public void FillInfo_ShouldNotAddGlass_WhenServiceAddThrowsValidationException()
        {
            string solutionDirectory = "solution";
            string testFile          = $@"{solutionDirectory}\ggg\products_test.json";

            solution.Setup(x => x.GetSolutionPath()).Returns(() => solutionDirectory);

            makes.Setup(x => x.Add(It.IsAny <VehicleMake>())).Throws(new DbEntityValidationException("error validation"));

            GlassesInfoDbFiller service = new GlassesInfoDbFiller(glasses.Object, vehicles.Object, makes.Object, models.Object,
                                                                  bodytypes.Object, images.Object, characteristics.Object, interchangeableParts.Object,
                                                                  superceeds.Object, accessories.Object, logger.Object, reader.Object, solution.Object);

            List <GlassJsonInfoModel> glassesInfoList = new List <GlassJsonInfoModel>
            {
                new GlassJsonInfoModel {
                    Description = "description", Make = string.Empty
                }
            };

            service.FillInfo(glassesInfoList, testFile);

            reader.Verify(x => x.Read(It.IsAny <string>()), Times.Never());
            glasses.Verify(x => x.Add(It.IsAny <VehicleGlass>()), Times.Never());
            solution.VerifyAll();
        }
Exemplo n.º 2
0
        public void FillInfo_ShouldCallIReader_WhenGlassesDictionaryIsNull()
        {
            string testFile = "testFile";

            reader.Setup(x => x.Read(testFile)).Returns(() => ""); // returns empty array
            solution.Setup(x => x.GetSolutionPath()).Returns(() => "solution");

            GlassesInfoDbFiller service = new GlassesInfoDbFiller(glasses.Object, vehicles.Object, makes.Object, models.Object,
                                                                  bodytypes.Object, images.Object, characteristics.Object, interchangeableParts.Object,
                                                                  superceeds.Object, accessories.Object, logger.Object, reader.Object, solution.Object);

            service.FillInfo(null, testFile);

            reader.VerifyAll();
            solution.VerifyAll();
        }
Exemplo n.º 3
0
        public void FillInfo_AllServicesShouldDoNothing_WhenGlassExistsInDbByLocalcode()
        {
            mapper.Execute();

            string solutionDirectory = "solution";
            string testFile          = $@"{solutionDirectory}\ggg\products_test.json";

            solution.Setup(x => x.GetSolutionPath()).Returns(() => solutionDirectory);

            GlassesInfoDbFiller service = new GlassesInfoDbFiller(glasses.Object, vehicles.Object, makes.Object, models.Object,
                                                                  bodytypes.Object, images.Object, characteristics.Object, interchangeableParts.Object,
                                                                  superceeds.Object, accessories.Object, logger.Object, reader.Object, solution.Object);

            List <GlassJsonInfoModel> glassesInfoList = new List <GlassJsonInfoModel>
            {
                new GlassJsonInfoModel {
                    LocalCode = localCode
                }
            };

            var codes = new List <string>
            {
                localCode, materialNumber
            }.AsQueryable();

            glasses.Setup(x => x.GetAllUniqueCodesFromDb())
            .Returns(codes);

            // ACT
            service.FillInfo(glassesInfoList, testFile);

            // ASSERT
            makes.Verify(x => x.Add(It.IsAny <VehicleMake>()), Times.Never());
            models.Verify(x => x.Add(It.IsAny <VehicleModel>()), Times.Never());
            bodytypes.Verify(x => x.Add(It.IsAny <VehicleBodyType>()), Times.Never());
            vehicles.Verify(x => x.Add(It.IsAny <Vehicle>()), Times.Never());
            characteristics.Verify(x => x.Add(It.IsAny <VehicleGlassCharacteristic>()), Times.Never());
            images.Verify(x => x.Add(It.IsAny <VehicleGlassImage>()), Times.Never());
            interchangeableParts.Verify(x => x.Add(It.IsAny <VehicleGlassInterchangeablePart>()), Times.Never());
            accessories.Verify(x => x.Add(It.IsAny <VehicleGlassAccessory>()), Times.Never());
            superceeds.Verify(x => x.Add(It.IsAny <VehicleGlassSuperceed>()), Times.Never());
            reader.Verify(x => x.Read(It.IsAny <string>()), Times.Never());
            glasses.Verify(x => x.Add(It.IsAny <VehicleGlass>()), Times.Never());
            glasses.VerifyAll();
            solution.VerifyAll();
        }
Exemplo n.º 4
0
        public void FillInfo_ShouldCallIReaderWithDefaultFile_WhenEmptyString()
        {
            string testFile          = null;
            string solutionDirectory = "solution";

            reader.Setup(x => x.Read($@"{solutionDirectory}\ggg\products_test.json")).Returns(() => "[]"); // returns empty json array
            solution.Setup(x => x.GetSolutionPath()).Returns(() => solutionDirectory);

            GlassesInfoDbFiller service = new GlassesInfoDbFiller(glasses.Object, vehicles.Object, makes.Object, models.Object,
                                                                  bodytypes.Object, images.Object, characteristics.Object, interchangeableParts.Object,
                                                                  superceeds.Object, accessories.Object, logger.Object, reader.Object, solution.Object);

            service.FillInfo(null, testFile);

            reader.VerifyAll();
            logger.Verify(x => x.LogError(It.IsAny <string>(), It.IsAny <string>()), Times.Never());
            solution.VerifyAll();
        }
Exemplo n.º 5
0
        public void FillInfo_LoggerShouldLogException_WhenJArrayParseFails()
        {
            string testFile          = "testFile";
            string solutionDirectory = "solution";

            reader.Setup(x => x.Read(testFile)).Returns(() => "{wrong json}"); // returns wrong json
            solution.Setup(x => x.GetSolutionPath()).Returns(() => solutionDirectory);
            logger.Setup(x => x.LogError(It.Is <string>(y => y.Contains("Error while parsing string to Jarray:")),
                                         It.Is <string>(z => z.Contains($@"{solutionDirectory}\DbFillInErorrs_"))));

            GlassesInfoDbFiller service = new GlassesInfoDbFiller(glasses.Object, vehicles.Object, makes.Object, models.Object,
                                                                  bodytypes.Object, images.Object, characteristics.Object, interchangeableParts.Object,
                                                                  superceeds.Object, accessories.Object, logger.Object, reader.Object, solution.Object);

            service.FillInfo(null, testFile);

            reader.VerifyAll();
            logger.VerifyAll();
            solution.VerifyAll();
        }
Exemplo n.º 6
0
        public void FillInfo_ShouldNotCallAllHandlersAddServices_WhenItemsExistInDb()
        {
            mapper.Execute();

            string solutionDirectory = "solution";
            string testFile          = $@"{solutionDirectory}\ggg\products_test.json";

            solution.Setup(x => x.GetSolutionPath()).Returns(() => solutionDirectory);

            GlassesInfoDbFiller service = new GlassesInfoDbFiller(glasses.Object, vehicles.Object, makes.Object, models.Object,
                                                                  bodytypes.Object, images.Object, characteristics.Object, interchangeableParts.Object,
                                                                  superceeds.Object, accessories.Object, logger.Object, reader.Object, solution.Object);
            var glassesInfoList = GetFullGlassInfoModelsList();

            makes.Setup(x => x.GetByName(make)).Returns(new VehicleMake {
                Id = 1, Name = make
            });
            models.Setup(x => x.GetByName(model)).Returns(new VehicleModel {
                Id = 1, Name = model
            });
            bodytypes.Setup(x => x.GetByCode(code))
            .Returns(new VehicleBodyType {
                Id = 1, Code = code
            });
            vehicles.Setup(x => x.GetVehicleByMakeModelAndBodyTypeIds(1, 1, 1))
            .Returns(new Vehicle {
                Id = 1, MakeId = 1, ModelId = 1, BodyTypeId = 1
            });
            characteristics.Setup(x => x.GetByName("A"))
            .Returns(new VehicleGlassCharacteristic {
                Id = 1, Name = "A"
            });
            characteristics.Setup(x => x.GetByName("B"))
            .Returns(new VehicleGlassCharacteristic {
                Id = 2, Name = "B"
            });
            images.Setup(x => x.GetByOriginalId(2))
            .Returns(new VehicleGlassImage {
                Id = 1, OriginalId = 2, Caption = caption
            });
            interchangeableParts.Setup(x => x.GetInterchangeablePart(interEuroCode, interMaterialNumber, interLocalCode, interScanCode, interNagsCode))
            .Returns(new VehicleGlassInterchangeablePart
            {
                Id             = 1,
                EuroCode       = interEuroCode,
                MaterialNumber = interMaterialNumber,
                LocalCode      = interLocalCode,
                ScanCode       = interScanCode,
                NagsCode       = interNagsCode
            });
            interchangeableParts.Setup(x => x.GetInterchangeablePart(interEuroCode, interMaterialNumber, interLocalCode, interScanCode, interNagsCode))
            .Returns(new VehicleGlassInterchangeablePart
            {
                Id             = 1,
                EuroCode       = interEuroCode,
                MaterialNumber = interMaterialNumber,
                LocalCode      = interLocalCode,
                ScanCode       = interScanCode,
                NagsCode       = interNagsCode
            });
            accessories.Setup(x => x.GetAccessory(accessoryIndustryCode, accessoryMaterialNumber))
            .Returns(new VehicleGlassAccessory
            {
                Id             = 1,
                MaterialNumber = accessoryMaterialNumber,
                IndustryCode   = accessoryIndustryCode
            });
            superceeds.Setup(x => x.GetSuperceed(oldEuroCode, oldLocalCode, oldMaterialNumber))
            .Returns(new VehicleGlassSuperceed
            {
                Id                = 1,
                OldEuroCode       = oldEuroCode,
                OldMaterialNumber = oldMaterialNumber,
                OldLocalCode      = oldLocalCode,
                OldOesCode        = oldOesCode
            });

            // ACT
            service.FillInfo(glassesInfoList, testFile);

            // ASSERT
            makes.Verify(x => x.Add(It.IsAny <VehicleMake>()), Times.Never());
            makes.VerifyAll();
            models.Verify(x => x.Add(It.IsAny <VehicleModel>()), Times.Never());
            models.VerifyAll();
            bodytypes.Verify(x => x.Add(It.IsAny <VehicleBodyType>()), Times.Never());
            bodytypes.VerifyAll();
            vehicles.Verify(x => x.Add(It.IsAny <Vehicle>()), Times.Never());
            vehicles.VerifyAll();
            characteristics.Verify(x => x.Add(It.IsAny <VehicleGlassCharacteristic>()), Times.Never());
            characteristics.VerifyAll();
            images.Verify(x => x.Add(It.IsAny <VehicleGlassImage>()), Times.Never());
            images.VerifyAll();
            interchangeableParts.Verify(x => x.Add(It.IsAny <VehicleGlassInterchangeablePart>()), Times.Never());
            interchangeableParts.VerifyAll();
            accessories.Verify(x => x.Add(It.IsAny <VehicleGlassAccessory>()), Times.Never());
            accessories.VerifyAll();
            superceeds.Verify(x => x.Add(It.IsAny <VehicleGlassSuperceed>()), Times.Never());
            superceeds.VerifyAll();

            reader.Verify(x => x.Read(It.IsAny <string>()), Times.Never());
            glasses.Verify(x => x.Add(It.Is <VehicleGlass>(y =>
                                                           y.EuroCode == euroCode &&
                                                           y.MaterialNumber == materialNumber &&
                                                           y.LocalCode == localCode &&
                                                           y.IndustryCode == industryCode &&
                                                           y.Description == description &&
                                                           y.ProductType == productType &&
                                                           y.Modification == modification &&
                                                           y.Tint == tint &&
                                                           y.FittingType == fittingType &&
                                                           y.FittingTimeHours == 2 &&
                                                           y.HasFittingMethod == true &&
                                                           y.Height == 2 &&
                                                           y.Width == 2 &&
                                                           y.FeaturedImageId == 2 &&
                                                           y.IsAccessory == false &&
                                                           y.IsYesGlass == false &&
                                                           y.IsAcoustic == true &&
                                                           y.IsCalibration == true &&
                                                           y.ModelDate == "10/11 - 10/12" &&
                                                           y.PartDate == "10/11 - 10/12"
                                                           )), Times.Once());
            glasses.VerifyAll();
            solution.VerifyAll();

            logger.Verify(x => x.LogError(It.IsAny <string>(), It.IsAny <string>()), Times.Never());
        }