Exemplo n.º 1
0
        public void AddProduct_ShouldReturn_Success()
        {
            // Arrange
            ProductsModel product = new ProductsModel()
            {
                SupplierId    = 1,
                CategoryId    = 1,
                GroupId       = 1,
                NameWebStore  = "product1",
                NameSupplier  = "Product1",
                CodeWebStore  = "111",
                CodeSupplier  = "112",
                UnitId        = 1,
                PriceWebStore = 1.5m,
                PriceSupplier = 1,
                Available     = "+",
                LinkWebStore  = "link1",
                LinkSupplier  = "link2",
                Notes         = "some notes"
            };

            fakeProductsRepository.Setup(a => a.Add(product));
            productsService = new ProductsService(fakeProductsRepository.Object,
                                                  new Mock <ICommonRepository>().Object);
            ProductsDtoModel productDto = new ProductsDtoModel()
            {
                SupplierId    = product.SupplierId,
                CategoryId    = product.CategoryId,
                GroupId       = product.GroupId,
                NameWebStore  = product.NameWebStore,
                NameSupplier  = product.NameSupplier,
                CodeWebStore  = product.CodeWebStore,
                CodeSupplier  = product.CodeSupplier,
                UnitId        = product.UnitId,
                PriceWebStore = product.PriceWebStore,
                PriceSupplier = product.PriceSupplier,
                Available     = product.Available,
                LinkWebStore  = product.LinkWebStore,
                LinkSupplier  = product.LinkSupplier,
                Notes         = product.Notes
            };

            try
            {
                // Act
                productsService.AddProduct(productDto);
                operationSucceeded = true;
            }
            catch (Exception ex)
            {
                errorMessage = ex.Message + " | " + ex.StackTrace;
            }

            // Assert
            Assert.IsTrue(operationSucceeded, errorMessage);
        }
Exemplo n.º 2
0
        public void GetProductById_ShouldReturn_NotNull()
        {
            // Arrange
            fakeProductsRepository.Setup(a => a.GetById(1)).Returns(new ProductsModel
            {
                Id            = 1,
                SupplierId    = 4,
                CategoryId    = 2,
                GroupId       = 1,
                NameWebStore  = "product1",
                NameSupplier  = "Product1",
                CodeWebStore  = "111",
                CodeSupplier  = "112",
                UnitId        = 1,
                PriceWebStore = 1.5m,
                PriceSupplier = 1,
                Available     = "+",
                LinkWebStore  = "link1",
                LinkSupplier  = "link2",
                Notes         = "some notes"
            });
            Mock <ICommonRepository> fakeCommonRepository = new Mock <ICommonRepository>();

            fakeCommonRepository.Setup(a => a.GetCategoriesIdNames()).Returns(new Dictionary <int, string> {
                { 2, "Category" }
            });
            fakeCommonRepository.Setup(a => a.GetGroupsIdNames()).Returns(new Dictionary <int, string> {
                { 1, "Group" }
            });
            fakeCommonRepository.Setup(a => a.GetSuppliersIdNames()).Returns(new Dictionary <int, string> {
                { 4, "Supplier" }
            });
            fakeCommonRepository.Setup(a => a.GetSuppliersIdCurrencies()).Returns(new Dictionary <int, string> {
                { 4, "USD" }
            });
            fakeCommonRepository.Setup(a => a.GetUnitsIdNames()).Returns(new Dictionary <int, string> {
                { 1, "p." }
            });
            productsService = new ProductsService(fakeProductsRepository.Object, fakeCommonRepository.Object);
            ProductsDtoModel productsModel = null;

            try
            {
                // Act
                productsModel = productsService.GetProductById(1);
            }
            catch (Exception ex)
            {
                errorMessage = ex.Message + " | " + ex.StackTrace;
            }

            // Assert
            Assert.IsNotNull(productsModel);
        }
Exemplo n.º 3
0
        public void SetupProductsDetailForEdit_ShouldReturn_Success()
        {
            // Arrange
            ProductsDtoModel productsDto = new ProductsDtoModel
            {
                Id            = 1,
                SupplierId    = 4,
                SupplierName  = "supplier",
                CategoryId    = 2,
                CategoryName  = "category",
                GroupId       = 1,
                GroupName     = "group",
                UnitId        = 1,
                UnitName      = "unit",
                NameWebStore  = "product1",
                NameSupplier  = "Product1",
                CodeWebStore  = "111",
                CodeSupplier  = "112",
                PriceWebStore = 1.5m,
                PriceSupplier = 1,
                Currency      = "USD",
                Available     = "+",
                LinkWebStore  = "link1",
                LinkSupplier  = "link2",
                Notes         = "some notes"
            };

            fakeFacadeService.Setup(s => s.GetSuppliersDto()).Returns(new List <SuppliersDtoModel>());
            fakeFacadeService.Setup(c => c.GetCategoriesDto()).Returns(new List <CategoriesDtoModel>());
            fakeFacadeService.Setup(g => g.GetGroupsDto()).Returns(new List <GroupsDtoModel>());
            fakeFacadeService.Setup(u => u.GetUnitsDto()).Returns(new List <UnitsDtoModel>());
            fakeFacadeService.Setup(p => p.GetProductById(1)).Returns(productsDto);
            productsDetailPresenter = new ProductsDetailPresenter(productsDetailUC,
                                                                  fakeFacadeService.Object);

            try
            {
                // Act
                productsDetailPresenter.SetupProductsDetailForEdit(1);
                operationSucceeded = true;
            }
            catch (Exception ex)
            {
                errorMessage = ex.Message + " | " + ex.StackTrace;
            }

            // Assert
            Assert.IsTrue(operationSucceeded, errorMessage);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Завантажує зображення з джерела постачальника
        /// </summary>
        /// <param name="localFoldersForImagesPath">Локальні каталоги для завантаження зображень</param>
        /// <returns>Список зображень</returns>
        public void GetExternalImages(string[] localFoldersForImagesPath)
        {
            List <ProductsDtoModel> productsWithoutSavedImages =
                GetProductsDto().Where(p => p.LinkSupplier.Contains("diasha")).ToList();

            foreach (ImagesDtoModel imagesDto in GetImagesDto().Distinct())
            {
                ProductsDtoModel productDto = productsWithoutSavedImages
                                              .Where(p => p.Id == imagesDto.ProductId).FirstOrDefault();
                if (productDto != null)
                {
                    productsWithoutSavedImages.Remove(productDto);
                }
            }
            foreach (var i in imagesAgent.GetExternalImages(productsWithoutSavedImages, localFoldersForImagesPath[0], true))
            {
                imagesService.AddImage(i);
            }
        }
Exemplo n.º 5
0
        private void SubscribeToEvents()
        {
            productsUC.AddNewProductEventRaised += (sender, e) => productsDetailPresenter.SetupProductsDetailForAdd();

            productsUC.EditProductEventRaised += (sender, e) =>
            {
                ProductsDtoModel productDto = (ProductsDtoModel)bindingSource.Current;
                productsDetailPresenter.SetupProductsDetailForEdit(productDto.Id);
            };

            productsUC.DeleteProductEventRaised += (sender, e) =>
            {
                ProductsDtoModel productDto = (ProductsDtoModel)bindingSource.Current;
                deleteConfirmView.ShowDeleteConfirmMessageView("Видалення товару",
                                                               $"Підтвердіть видалення товару: { productDto.NameWebStore }.", productDto.Id, "ProductsUC");
            };

            productsUC.LinkToSearchChangedInUCEventRaised += (sender, modelDictionary) =>
                                                             EventHelper.RaiseEvent(this, LinkToSearchChangedEventRaised, modelDictionary);

            productsUC.SortProductsByBindingPropertyNameEventRaised += (sender, sortParameters) =>
                                                                       OnSortProductsByBindingPropertyNameEventRaised(sender, sortParameters);
        }
        private void SubscribeToEvents()
        {
            productsDetailUC.SaveProductsDetailEventRaised += (sender, modelDictionary) =>
            {
                ProductsDtoModel productDto = new ProductsDtoModel
                {
                    Id            = modelDictionary.ModelDictionary["Id"] == "" ? 0 : int.Parse(modelDictionary.ModelDictionary["Id"]),
                    SupplierId    = Convert.ToInt32(modelDictionary.ModelDictionary["SupplierId"]),
                    CategoryId    = Convert.ToInt32(modelDictionary.ModelDictionary["CategoryId"]),
                    GroupId       = modelDictionary.ModelDictionary["GroupId"] == "" ? 0 : Convert.ToInt32(modelDictionary.ModelDictionary["GroupId"]),
                    NameWebStore  = modelDictionary.ModelDictionary["NameWebStore"],
                    NameSupplier  = modelDictionary.ModelDictionary["NameSupplier"],
                    CodeWebStore  = modelDictionary.ModelDictionary["CodeWebStore"],
                    CodeSupplier  = modelDictionary.ModelDictionary["CodeSupplier"],
                    UnitId        = Convert.ToInt32(modelDictionary.ModelDictionary["UnitId"]),
                    PriceWebStore = Convert.ToDecimal(modelDictionary.ModelDictionary["PriceWebStore"]),
                    PriceSupplier = Convert.ToDecimal(modelDictionary.ModelDictionary["PriceSupplier"]),
                    Available     = modelDictionary.ModelDictionary["Available"],
                    LinkWebStore  = modelDictionary.ModelDictionary["LinkWebStore"],
                    LinkSupplier  = modelDictionary.ModelDictionary["LinkSupplier"],
                    Notes         = modelDictionary.ModelDictionary["Notes"]
                };
                if (productDto.Id > 0)
                {
                    facade.UpdateProduct(productDto);
                }
                else
                {
                    facade.AddProduct(productDto);
                }

                EventHelper.RaiseEvent(this, SaveProductClickEventRaised, new EventArgs());
            };

            productsDetailUC.CancelProductsDetailEventRaised += (sender, e) => EventHelper.RaiseEvent(this, CancelClickEventRaised, new EventArgs());
        }
        private Dictionary <string, string> BuildModelDictionary(ProductsDtoModel model)
        {
            var modelDictionary = new Dictionary <string, string>()
            {
                { "Id", model.Id.ToString() },
                { "NameWebStore", model.NameWebStore },
                { "NameSupplier", model.NameSupplier },
                { "SupplierName", model.SupplierName },
                { "CategoryName", model.CategoryName },
                { "GroupName", model.GroupName },
                { "UnitName", model.UnitName },
                { "CodeWebStore", model.CodeWebStore },
                { "CodeSupplier", model.CodeSupplier },
                { "PriceWebStore", model.PriceWebStore.ToString() },
                { "PriceSupplier", model.PriceSupplier.ToString() },
                { "Currency", model.Currency },
                { "Available", model.Available },
                { "LinkWebStore", model.LinkWebStore },
                { "LinkSupplier", model.LinkSupplier },
                { "Notes", model.Notes }
            };

            return(modelDictionary);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Завантажує характеристики з джерела постачальника
        /// </summary>
        public void GetExternalParameters()
        {
            List <ProductsDtoModel> productsWithoutSavedParameters =
                GetProductsDto().Where(p => p.LinkSupplier.Contains("diasha")).ToList();

            foreach (ParametersDtoModel parametersDto in GetParametersDto().Distinct())
            {
                ProductsDtoModel productDto = productsWithoutSavedParameters
                                              .Where(p => p.Id == parametersDto.ProductId).FirstOrDefault();
                if (productDto != null)
                {
                    productsWithoutSavedParameters.Remove(productDto);
                }
            }
            // Add specific unit to parameter
            IEnumerable <UnitsDtoModel> unitsDtos = unitsService.GetUnits();

            foreach (var p in parametersAgent.GetExternalParameters(productsWithoutSavedParameters))
            {
                p.UnitId = unitsDtos.Where(u => u.Name == p.UnitName).FirstOrDefault().Id;
                parametersService.AddParameter(p);
            }
            ;
        }
Exemplo n.º 9
0
 private ProductsDtoModel ParseProductByLink(ProductsDtoModel item)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 10
0
 /// <summary>
 /// Оновлює товар
 /// </summary>
 /// <param name="productDto">Екземпляр товару</param>
 public void UpdateProduct(ProductsDtoModel productDto) => productsService.UpdateProduct(productDto);
Exemplo n.º 11
0
 /// <summary>
 /// Додає товар
 /// </summary>
 /// <param name="productDto">Екземпляр товару</param>
 public void AddProduct(ProductsDtoModel productDto) => productsService.AddProduct(productDto);