예제 #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);
        }
예제 #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);
        }
예제 #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);
        }
예제 #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);
        }
예제 #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);
        }
예제 #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());
        }
예제 #7
0
 /// <summary>
 /// Оновлює одиницю виміру
 /// </summary>
 /// <param name="unitDto">Екземпляр одиниці виміру</param>
 public void UpdateUnit(UnitsDtoModel unitDto) => unitsService.UpdateUnit(unitDto);
예제 #8
0
 /// <summary>
 /// Додає одиницю виміру
 /// </summary>
 /// <param name="unitDto">Екземпляр одиниці виміру</param>
 public void AddUnit(UnitsDtoModel unitDto) => unitsService.AddUnit(unitDto);