Beispiel #1
0
        public void SetupCategoriesDetailForEdit_ShouldReturn_Success()
        {
            // Arrange
            CategoriesDtoModel categoriesDto = new CategoriesDtoModel
            {
                Id           = 1,
                Name         = "name",
                SupplierId   = 1,
                SupplierName = "supplier",
                Link         = "link",
                Rate         = 1.5m,
                Notes        = "notes"
            };

            fakeFacadeService.Setup(c => c.GetCategoryById(1)).Returns(categoriesDto);
            categoriesDetailPresenter = new CategoriesDetailPresenter(categoriesDetailUC, fakeFacadeService.Object);

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

            // Assert
            Assert.IsTrue(operationSucceeded, errorMessage);
        }
        private void SubscribeToEvents()
        {
            categoriesDetailUC.SaveCategoriesDetailEventRaised += (sender, modelDictionary) =>
            {
                CategoriesDtoModel category = new CategoriesDtoModel()
                {
                    Id           = modelDictionary.ModelDictionary["Id"] == "" ? 0 : int.Parse(modelDictionary.ModelDictionary["Id"]),
                    Name         = modelDictionary.ModelDictionary["Name"],
                    SupplierId   = int.Parse(modelDictionary.ModelDictionary["SupplierId"]),
                    SupplierName = modelDictionary.ModelDictionary["SupplierName"],
                    Link         = modelDictionary.ModelDictionary["Link"],
                    Rate         = decimal.Parse(modelDictionary.ModelDictionary["Rate"]),
                    Notes        = modelDictionary.ModelDictionary["Notes"]
                };
                if (category.Id > 0)
                {
                    facade.UpdateCategory(category);
                }
                else
                {
                    facade.AddCategory(category);
                }

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

            categoriesDetailUC.CancelCategoriesDetailEventRaised += (sender, e) => EventHelper.RaiseEvent(this, CancelClickEventRaised, new EventArgs());
        }
Beispiel #3
0
        public void GetCategoryById_ShouldReturn_NotNull()
        {
            // Arrange
            fakeCategoriesRepository.Setup(a => a.GetById(2)).Returns(new CategoriesModel {
                Id = 2, SupplierId = 4, Name = "Category name", Link = "Categories link", Rate = 1, Notes = "notes"
            });
            Mock <ICommonRepository> fakeCommonRepository = new Mock <ICommonRepository>();

            fakeCommonRepository.Setup(a => a.GetSuppliersIdNames()).Returns(new Dictionary <int, string> {
                { 4, "Supplier" }
            });
            categoriesService = new CategoriesService(fakeCategoriesRepository.Object,
                                                      fakeCommonRepository.Object);

            CategoriesDtoModel categoriesDto = null;

            try
            {
                // Act
                categoriesDto = categoriesService.GetCategoryById(2);
            }
            catch (Exception ex)
            {
                errorMessage = ex.Message + " | " + ex.StackTrace;
            }

            // Assert
            Assert.IsNotNull(categoriesDto, errorMessage);
        }
        private Dictionary <string, string> BuildModelDictionary(CategoriesDtoModel model)
        {
            var modelDictionary = new Dictionary <string, string>()
            {
                { "Id", model.Id.ToString() },
                { "Name", model.Name },
                { "SupplierId", model.SupplierId.ToString() },
                { "SupplierName", model.SupplierName },
                { "Link", model.Link },
                { "Rate", model.Rate.ToString() },
                { "Notes", model.Notes }
            };

            return(modelDictionary);
        }
Beispiel #5
0
        public void AddCategory_ShouldReturn_Success()
        {
            // Arrange
            CategoriesModel category = new CategoriesModel
            {
                Name       = "New category",
                SupplierId = 2,
                Link       = "link",
                Rate       = 1.5m,
                Notes      = "notes"
            };

            fakeCategoriesRepository.Setup(a => a.Add(category));
            categoriesService = new CategoriesService(fakeCategoriesRepository.Object,
                                                      new Mock <ICommonRepository>().Object);
            CategoriesDtoModel categoriesDto = new CategoriesDtoModel
            {
                Name         = category.Name,
                SupplierId   = category.SupplierId,
                SupplierName = "Supplier",
                Link         = category.Link,
                Rate         = 1.5m,
                Notes        = category.Notes
            };

            try
            {
                // Act
                categoriesService.AddCategory(categoriesDto);
                operationSucceeded = true;
            }
            catch (Exception ex)
            {
                errorMessage = ex.Message + " | " + ex.StackTrace;
            }

            // Assert
            Assert.IsTrue(operationSucceeded, errorMessage);
        }
        private void SubscribeToEvents()
        {
            categoriesUC.AddNewCategoryEventRaised += (sender, e) => categoriesDetailPresenter.SetupCategoriesDetailForAdd();

            categoriesUC.EditCategoryEventRaised += (sender, e) =>
            {
                CategoriesDtoModel categoriesDto = (CategoriesDtoModel)bindingSource.Current;
                categoriesDetailPresenter.SetupCategoriesDetailForEdit(categoriesDto.Id);
            };

            categoriesUC.DeleteCategoryEventRaised += (sender, e) =>
            {
                CategoriesDtoModel categoriesDto = (CategoriesDtoModel)bindingSource.Current;
                deleteConfirmView.ShowDeleteConfirmMessageView("Видалення категорії",
                                                               $"Підтвердіть видалення категорії товару: { categoriesDto.Name }.", categoriesDto.Id, "CategoriesUC");
            };

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

            categoriesUC.SortCategoriesByBindingPropertyNameEventRaised += (sender, sortParameters) =>
                                                                           OnSortCategoriesByBindingPropertyNameEventRaised(sender, sortParameters);
        }
Beispiel #7
0
 private List <string> GetProductLinksByCategory(CategoriesDtoModel category)
 {
     throw new NotImplementedException();
 }
Beispiel #8
0
 /// <summary>
 /// Додає категорію
 /// </summary>
 /// <param name="categoryDto">Екземпляр категорії</param>
 public void AddCategory(CategoriesDtoModel categoryDto) => categoriesService.AddCategory(categoryDto);
Beispiel #9
0
 /// <summary>
 /// Оновлює категорію
 /// </summary>
 /// <param name="categoryDto">Екземпляр категорії</param>
 public void UpdateCategory(CategoriesDtoModel categoryDto) => categoriesService.UpdateCategory(categoryDto);