コード例 #1
0
        public void GetAccessories_ShouldReturnNeededItems()
        {
            int id = 2;

            var glass = new VehicleGlass()
            {
                Id = 2,
                VehicleGlassAccessories = new List <VehicleGlassAccessory>()
                {
                    new VehicleGlassAccessory()
                    {
                        Id = 3
                    },
                    new VehicleGlassAccessory()
                    {
                        Id = 4
                    },
                }
            };

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

            repositoryMock.Setup(x => x.GetById(id)).Returns(() => glass);

            var service = new VehicleGlassesService(repositoryMock.Object);

            var response = service.GetAccessories(id).ToList();

            Assert.AreEqual(response.Count, 2);
            Assert.AreEqual(response[0].Id, 3);
            Assert.AreEqual(response[1].Id, 4);
            repositoryMock.VerifyAll();
        }
コード例 #2
0
        public void GetDetailedInfo_ShouldReturnGlassByLocalCode_WhenByEuroCodeNotFoundAndLocalCodePassed()
        {
            mapper.Execute();

            var glassesMock = new Mock <IVehicleGlassesService>();

            string testCode      = "testCode";
            string testLocalCode = "testLocalCode";
            var    glass         = new VehicleGlass()
            {
                Id = 2, LocalCode = testLocalCode
            };

            glassesMock.Setup(v => v.GetByEuroCode(testCode)).Returns(() => null);
            glassesMock.Setup(v => v.GetByLocalCode(testLocalCode)).Returns(() => glass);

            var controller = new ProductsController(null, null, glassesMock.Object, null, null, null);
            var result     = controller.GetDetailedInfo(null, testCode, null, null, testLocalCode);

            Assert.IsInstanceOfType(result, typeof(OkNegotiatedContentResult <VehicleGlassResponseModel>));
            var responseContent = ((OkNegotiatedContentResult <VehicleGlassResponseModel>)result).Content;

            Assert.AreEqual(responseContent.Id, 2);
            Assert.AreEqual(responseContent.LocalCode, testLocalCode);
            glassesMock.VerifyAll();
            glassesMock.Verify(x => x.GetByIndustryCode(It.IsAny <string>()), Times.Exactly(0));
            glassesMock.Verify(x => x.GetByMaterialNumber(It.IsAny <string>()), Times.Exactly(0));
        }
コード例 #3
0
        public void GetByScanCode_ShouldReturnNeededItem()
        {
            string testCode = "2353AA";
            var    items    = new List <VehicleGlass>()
            {
                new VehicleGlass()
                {
                    IndustryCode = "2233aB", LocalCode = testCode, MaterialNumber = "2233a", EuroCode = "2233a", OesCode = testCode
                },
                new VehicleGlass()
                {
                    IndustryCode = testCode, LocalCode = testCode, MaterialNumber = "2353aA", EuroCode = "2353аA", Id = 1
                },
                new VehicleGlass()
                {
                    IndustryCode = "2233aC", LocalCode = testCode, MaterialNumber = "2728b", EuroCode = "2233a"
                },
                new VehicleGlass()
                {
                    IndustryCode = "2728bD", LocalCode = testCode, MaterialNumber = "2728b", EuroCode = "2233a"
                }
            }.AsQueryable();

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

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

            var service = new VehicleGlassesService(repositoryMock.Object);

            VehicleGlass response = service.GetByIndustryCode(testCode);

            Assert.AreEqual(response.Id, 1);
            repositoryMock.VerifyAll();
        }
コード例 #4
0
        private IEnumerable <ProductInfoResponseModel> GetProductInfos(VehicleGlass glass, User user)
        {
            var code = this._glasses.GetCode(glass);

            var quantities = this._productQuantities.GetPriceAndQuantitiesByCode(code, user);

            return(quantities);
        }
コード例 #5
0
        public IHttpActionResult GetDetailedInfo(int?id, string eurocode = "", string materialNumber = "", string industryCode = "", string localCode = "")
        {
            try
            {
                if (id == null && string.IsNullOrWhiteSpace(eurocode) && string.IsNullOrWhiteSpace(materialNumber) &&
                    string.IsNullOrWhiteSpace(industryCode) && string.IsNullOrWhiteSpace(localCode))
                {
                    return(BadRequest("No code passed"));
                }

                VehicleGlass glass = null;
                if (id != null)
                {
                    glass = _glasses.GetById(id);
                }

                if (!string.IsNullOrEmpty(eurocode))
                {
                    glass = _glasses.GetByEuroCode(eurocode);
                }

                if (glass == null && !string.IsNullOrEmpty(materialNumber))
                {
                    glass = this._glasses.GetByMaterialNumber(materialNumber);
                }

                if (glass == null && !string.IsNullOrEmpty(industryCode))
                {
                    glass = this._glasses.GetByIndustryCode(industryCode);
                }

                if (glass == null && !string.IsNullOrEmpty(localCode))
                {
                    glass = _glasses.GetByLocalCode(localCode);
                }

                var  glassResponse = this.Mapper.Map <VehicleGlassResponseModel>(glass);
                User user          = null;
                if (User.Identity.IsAuthenticated)
                {
                    user = _users.GetByEmail(User.Identity.Name);
                }

                glassResponse.ProductInfos = GetProductInfos(glass, user);

                return(Ok(glassResponse));
            }
            catch (Exception e)
            {
                HandlExceptionLogging(e, "", _controllerName);
                return(InternalServerError());
            }
        }
コード例 #6
0
        public void GetCode_ShouldReturnNull_WhenNoCodeAvailable()
        {
            var glass = new VehicleGlass()
            {
                IndustryCode = "", LocalCode = "", MaterialNumber = "", EuroCode = "", OesCode = null
            };

            var service = new VehicleGlassesService(null);

            var response = service.GetCode(glass);

            Assert.IsNull(response);
        }
コード例 #7
0
        public void GetCode_ShouldReturnOesCode_WhenAvailable()
        {
            string code  = "2353A";
            var    glass = new VehicleGlass()
            {
                IndustryCode   = null,
                LocalCode      = "",
                MaterialNumber = "",
                EuroCode       = null,
                OesCode        = code
            };
            var service = new VehicleGlassesService(null);

            var response = service.GetCode(glass);

            Assert.AreEqual(code, response);
        }
コード例 #8
0
        public void GetDetailedInfo_ShouldReturnGlass_WhenIdPassed()
        {
            mapper.Execute();

            var glassesMock = new Mock <IVehicleGlassesService>();

            string testCode   = "AC22AGNBL1C";
            string testNumber = "testNumber";
            var    glass      = new VehicleGlass()
            {
                Id       = 1,
                EuroCode = testCode,
                VehicleGlassAccessories = new List <VehicleGlassAccessory>()
                {
                    new VehicleGlassAccessory()
                    {
                        IndustryCode = testCode, MaterialNumber = testNumber
                    }
                },
                VehicleGlassInterchangeableParts = new List <VehicleGlassInterchangeablePart>()
                {
                    new VehicleGlassInterchangeablePart()
                    {
                        EuroCode = $"{testCode};CHEVROLET ASTRO VAN 1985 93;", MaterialNumber = testNumber
                    }
                }
            };

            glassesMock.Setup(v => v.GetById(1)).Returns(() => glass);

            var controller = new ProductsController(null, null, glassesMock.Object, null, null, null);
            var result     = controller.GetDetailedInfo(1);

            Assert.IsInstanceOfType(result, typeof(OkNegotiatedContentResult <VehicleGlassResponseModel>));
            var responseContent = ((OkNegotiatedContentResult <VehicleGlassResponseModel>)result).Content;

            Assert.AreEqual(responseContent.Id, 1);
            Assert.AreEqual(responseContent.Accessories.ToList()[0].MaterialNumber, testNumber);
            Assert.AreEqual(responseContent.Accessories.ToList()[0].IndustryCode, testCode);
            Assert.AreEqual(responseContent.InterchangeableParts.ToList()[0].MaterialNumber, testNumber);
            glassesMock.VerifyAll();
        }
コード例 #9
0
        private void CreateNewGlassWithAllRelations(GlassJsonInfoModel glassInfoModel,
                                                    List <Vehicle> vehicles, List <VehicleGlassCharacteristic> characteristics,
                                                    List <VehicleGlassImage> images, List <VehicleGlassInterchangeablePart> interchaneableParts,
                                                    List <VehicleGlassSuperceed> superceeds, List <VehicleGlassAccessory> accessories)
        {
            VehicleGlass glass = this.Mapper.Map <VehicleGlass>(glassInfoModel);

            this.Glasses.Add(glass);

            // -------------- for optimization
            var uniqueCode = this.Glasses.GetCode(glass);

            this.GlassesCodesProjectionFromDb.Add(uniqueCode);
            // -------------- for optimization

            foreach (var vehicle in vehicles)
            {
                vehicle.VehicleGlasses.Add(glass);
            }
            foreach (var characteristic in characteristics)
            {
                characteristic.VehicleGlasses.Add(glass);
            }
            foreach (var image in images)
            {
                image.VehicleGlasses.Add(glass);
            }
            foreach (var interchangeablePart in interchaneableParts)
            {
                interchangeablePart.VehicleGlasses.Add(glass);
            }
            foreach (var supereed in superceeds)
            {
                supereed.VehicleGlasses.Add(glass);
            }
            foreach (var accessory in accessories)
            {
                accessory.VehicleGlasses.Add(glass);
            }
        }
コード例 #10
0
        public void GetPriceAndQuantities_ShouldReturnProductsQuantitiesAndPriceInfo_WhenIdPassed()
        {
            mapper.Execute();
            int          testId      = 1;
            string       testCode    = "2021AGGN";
            string       testUserId  = "userId";
            VehicleGlass testProduct = new VehicleGlass()
            {
                EuroCode = testCode, OesCode = "test"
            };

            var glassesMock = new Mock <IVehicleGlassesService>();

            glassesMock.Setup(v => v.GetById(testId)).Returns(testProduct);
            glassesMock.Setup(v => v.GetCode(testProduct)).Returns(testCode);

            var usersMock = new Mock <IUsersService>();

            string nordglassGroup = "Nordglass";
            string yesglassGroup  = "Yesglass";

            List <ProductInfoResponseModel> productQuantitiesAndPriceInfo = new List <ProductInfoResponseModel>()
            {
                new ProductInfoResponseModel()
                {
                    Group = nordglassGroup
                },
                new ProductInfoResponseModel()
                {
                    Group = yesglassGroup
                }
            };

            // moq the user
            var claim        = new Claim("test", testUserId);
            var mockIdentity = Mock.Of <ClaimsIdentity>(ci => ci.FindFirst(It.IsAny <string>()) == claim);

            // moq identity and role
            var mockPrincipal = new Mock <IPrincipal>();

            mockPrincipal.Setup(x => x.Identity).Returns(mockIdentity);

            var productPriceAndQuantitiesMock = new Mock <IProductQuantitiesService>();

            productPriceAndQuantitiesMock.Setup(x => x.GetPriceAndQuantitiesByCode(testCode, It.IsAny <User>())).Returns(productQuantitiesAndPriceInfo);

            var controller = new ProductsController(null, null, glassesMock.Object, productPriceAndQuantitiesMock.Object, usersMock.Object, null)
            {
                User = mockPrincipal.Object
            };
            var result = controller.GetPriceAndQuantities(testId);

            Assert.IsInstanceOfType(result, typeof(OkNegotiatedContentResult <IEnumerable <ProductInfoResponseModel> >));
            var responseContent = ((OkNegotiatedContentResult <IEnumerable <ProductInfoResponseModel> >)result).Content;

            Assert.AreEqual(2, responseContent.ToList().Count);
            Assert.AreEqual(nordglassGroup, responseContent.First().Group);
            Assert.AreEqual(yesglassGroup, responseContent.Last().Group);

            glassesMock.VerifyAll();
            productPriceAndQuantitiesMock.VerifyAll();
            usersMock.VerifyAll();
        }