private void SubscribeToEvents() { groupsDetailUC.SaveGroupsDetailEventRaised += (sender, modelDictionary) => { GroupsDtoModel groupDto = new GroupsDtoModel { Id = modelDictionary.ModelDictionary["Id"] == "" ? 0 : int.Parse(modelDictionary.ModelDictionary["Id"]), Name = modelDictionary.ModelDictionary["Name"], Number = modelDictionary.ModelDictionary["Number"], Identifier = modelDictionary.ModelDictionary["Identifier"], AncestorNumber = modelDictionary.ModelDictionary["AncestorNumber"], AncestorIdentifier = modelDictionary.ModelDictionary["AncestorIdentifier"], ProductType = modelDictionary.ModelDictionary["ProductType"], Link = modelDictionary.ModelDictionary["Link"], Notes = modelDictionary.ModelDictionary["Notes"] }; if (groupDto.Id > 0) { facade.UpdateGroup(groupDto); } else { facade.AddGroup(groupDto); } EventHelper.RaiseEvent(this, SaveGroupClickEventRaised, new EventArgs()); }; groupsDetailUC.CancelGroupsDetailEventRaised += (sender, e) => EventHelper.RaiseEvent(this, CancelClickEventRaised, new EventArgs()); }
private Dictionary <string, string> BuildModelDictionary(GroupsDtoModel model) { var modelDictionary = new Dictionary <string, string>() { { "Id", model.Id.ToString() }, { "Name", model.Name }, { "Number", model.Number }, { "Identifier", model.Identifier }, { "AncestorNumber", model.AncestorNumber }, { "AncestorIdentifier", model.AncestorIdentifier }, { "ProductType", model.ProductType }, { "Link", model.Link }, { "Notes", model.Notes } }; return(modelDictionary); }
public void AddGroup_ShouldReturn_Success() { // Arrange GroupsModel group = new GroupsModel() { Name = "Group 1", Number = "1", Identifier = "_1", AncestorNumber = "2", AncestorIdentifier = "_2", ProductType = "r", Link = "some link", Notes = "some notes" }; fakeGroupsRepository.Setup(a => a.Add(group)); groupsService = new GroupsService(fakeGroupsRepository.Object); GroupsDtoModel groupDto = new GroupsDtoModel() { Name = group.Name, Number = group.Number, Identifier = group.Identifier, AncestorNumber = group.AncestorNumber, AncestorIdentifier = group.AncestorIdentifier, ProductType = group.ProductType, Link = group.Link, Notes = group.Notes }; try { // Act groupsService.AddGroup(groupDto); operationSucceeded = true; } catch (Exception ex) { errorMessage = ex.Message + " | " + ex.StackTrace; } // Assert Assert.IsTrue(operationSucceeded, errorMessage); }
public void GetGroupById_ShouldReturn_NotNull() { // Arrange GroupsDtoModel group = null; fakeGroupsRepository.Setup(a => a.GetById(1)).Returns(new GroupsModel()); groupsService = new GroupsService(fakeGroupsRepository.Object); try { // Act group = groupsService.GetGroupById(1); } catch (Exception ex) { errorMessage = ex.Message + " | " + ex.StackTrace; } // Assert Assert.IsNotNull(group, errorMessage); }
private void SubscribeToEvents() { groupsUC.AddNewGroupEventRaised += (sender, e) => groupsDetailPresenter.SetupGroupsDetailForAdd(); groupsUC.EditGroupEventRaised += (sender, e) => { GroupsDtoModel groupDto = (GroupsDtoModel)bindingSource.Current; groupsDetailPresenter.SetupGroupsDetailForEdit(groupDto.Id); }; groupsUC.DeleteGroupEventRaised += (sender, e) => { GroupsDtoModel groupDto = (GroupsDtoModel)bindingSource.Current; deleteConfirmView.ShowDeleteConfirmMessageView("Видалення групи товарів", $"Підтвердіть видалення групи товарів: { groupDto.Name }.", groupDto.Id, "GroupsUC"); }; groupsUC.LinkToSearchChangedInUCEventRaised += (sender, modelDictionary) => EventHelper.RaiseEvent(this, LinkToSearchChangedEventRaised, modelDictionary); groupsUC.SortGroupsByBindingPropertyNameEventRaised += (sender, sortParameters) => OnSortGroupsByBindingPropertyNameEventRaised(sender, sortParameters); }
public void SetupGroupsDetailForEdit_ShouldReturn_Success() { // Arrange GroupsDtoModel groupsDto = new GroupsDtoModel { Id = 1, Name = "name", ProductType = "r", Number = "number", Identifier = "identifier", AncestorNumber = "ancestornumber", AncestorIdentifier = "ancestoridentifier", Link = "link", Notes = "notes" }; Mock <IStoreFacade> fakeFacadeService = new Mock <IStoreFacade>(); fakeFacadeService.Setup(g => g.GetGroupById(1)).Returns(groupsDto); GroupsDetailPresenter groupsDetailPresenter = new GroupsDetailPresenter( new GroupsDetailUC(new ErrorMessageView()), fakeFacadeService.Object); bool operationSucceeded = false; string errorMessage = ""; try { // Act groupsDetailPresenter.SetupGroupsDetailForEdit(1); operationSucceeded = true; } catch (Exception ex) { errorMessage = ex.Message + " | " + ex.StackTrace; } //Assert Assert.IsTrue(operationSucceeded, errorMessage); }
/// <summary> /// Оновлює групу /// </summary> /// <param name="groupDto">Екземпляр групи</param> public void UpdateGroup(GroupsDtoModel groupDto) => groupsService.UpdateGroup(groupDto);
/// <summary> /// Додає групу /// </summary> /// <param name="groupDto">Екземпляр групи</param> public void AddGroup(GroupsDtoModel groupDto) => groupsService.AddGroup(groupDto);