Ejemplo n.º 1
0
        public void SetupUnitsDetailForEdit_ShouldReturn_Success()
        {
            // Arrange
            UnitsDtoModel unitsDto = new UnitsDtoModel
            {
                Id    = 1,
                Name  = "unit",
                Notes = "notes"
            };
            Mock <IStoreFacade> fakeFacadeService = new Mock <IStoreFacade>();

            fakeFacadeService.Setup(u => u.GetUnitById(1)).Returns(unitsDto);
            UnitsDetailPresenter unitsDetailPresenter = new UnitsDetailPresenter(
                new UnitsDetailUC(new ErrorMessageView()), fakeFacadeService.Object);
            bool   operationSucceeded = false;
            string errorMessage       = "";

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

            // Assert
            Assert.IsTrue(operationSucceeded, errorMessage);
        }
Ejemplo n.º 2
0
        public void Update_ShouldReturn_Success()
        {
            // Arrange
            UnitsModel unit = new UnitsModel {
                Id = 1, Name = "g", Notes = "gram"
            };

            fakeUnitsRepository.Setup(a => a.Update(unit));
            unitsService = new UnitsService(fakeUnitsRepository.Object);
            UnitsDtoModel unitDto = new UnitsDtoModel {
                Id = 1, Name = "g", Notes = "updated notes"
            };

            try
            {
                // Act
                unitsService.UpdateUnit(unitDto);
                operationSucceeded = true;
            }
            catch (Exception ex)
            {
                errorMessage = ex.Message + " | " + ex.StackTrace;
            }

            // Assert
            Assert.IsTrue(operationSucceeded, errorMessage);
        }
Ejemplo n.º 3
0
        private Dictionary <string, string> BuildModelDictionary(UnitsDtoModel unitDto)
        {
            var modelDictionary = new Dictionary <string, string>()
            {
                { "Id", unitDto.Id.ToString() },
                { "Name", unitDto.Name },
                { "Notes", unitDto.Notes }
            };

            return(modelDictionary);
        }
Ejemplo n.º 4
0
        private void SubscribeToEvents()
        {
            unitsUC.AddNewUnitEventRaised += (sender, e) => unitsDetailPresenter.SetupUnitsDetailForAdd();

            unitsUC.EditUnitEventRaised += (sender, e) =>
            {
                UnitsDtoModel unitDto = (UnitsDtoModel)bindingSource.Current;
                unitsDetailPresenter.SetupUnitsDetailForEdit(unitDto.Id);
            };

            unitsUC.DeleteUnitEventRaised += (sender, e) =>
            {
                UnitsDtoModel unitDto = (UnitsDtoModel)bindingSource.Current;
                deleteConfirmView.ShowDeleteConfirmMessageView("Видалення одиниці виміру",
                                                               $"Підтвердіть видалення одиниці виміру: { unitDto.Name }.", unitDto.Id, "UnitsUC");
            };

            unitsUC.SortUnitsByBindingPropertyNameEventRaised += (sender, sortParameters) =>
                                                                 OnSortUnitsByBindingPropertyNameEventRaised(sender, sortParameters);
        }
Ejemplo n.º 5
0
        public void GetUnitById_ShouldReturn_NotNull()
        {
            // Arrange
            fakeUnitsRepository.Setup(a => a.GetById(1)).Returns(new UnitsModel());
            unitsService = new UnitsService(fakeUnitsRepository.Object);

            UnitsDtoModel unitDto = null;

            try
            {
                // Act
                unitDto = unitsService.GetUnitById(1);
            }
            catch (Exception ex)
            {
                errorMessage = ex.Message + " | " + ex.StackTrace;
            }

            // Assert
            Assert.IsNotNull(unitDto, errorMessage);
        }
Ejemplo n.º 6
0
        private void SubscribeToEvents()
        {
            unitsDetaileUC.SaveUnitsDetailEventRaised += (sender, modelDictionary) =>
            {
                UnitsDtoModel unitDto = new UnitsDtoModel
                {
                    Id    = modelDictionary.ModelDictionary["Id"] == "" ? 0 : int.Parse(modelDictionary.ModelDictionary["Id"]),
                    Name  = modelDictionary.ModelDictionary["Name"],
                    Notes = modelDictionary.ModelDictionary["Notes"]
                };
                if (unitDto.Id > 0)
                {
                    facade.UpdateUnit(unitDto);
                }
                else
                {
                    facade.AddUnit(unitDto);
                }

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

            unitsDetaileUC.CancelUnitsDetailEventRaised += (sender, e) => EventHelper.RaiseEvent(this, CancelClickEventRaised, new EventArgs());
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Оновлює одиницю виміру
 /// </summary>
 /// <param name="unitDto">Екземпляр одиниці виміру</param>
 public void UpdateUnit(UnitsDtoModel unitDto) => unitsService.UpdateUnit(unitDto);
Ejemplo n.º 8
0
 /// <summary>
 /// Додає одиницю виміру
 /// </summary>
 /// <param name="unitDto">Екземпляр одиниці виміру</param>
 public void AddUnit(UnitsDtoModel unitDto) => unitsService.AddUnit(unitDto);