Exemple #1
0
        public UpdateItemFunctionTests()
        {
            _mockRepository = new Mock <IItemRepository>();
            _mockRepository.Setup(_ => _.Save(It.IsAny <Item>(), It.IsAny <CancellationToken>())).Returns(Task.CompletedTask);

            var serviceCollection = Startup.BuildContainer();

            serviceCollection.Replace(new ServiceDescriptor(typeof(IItemRepository), _ => _mockRepository.Object,
                                                            ServiceLifetime.Transient));

            _sut = new UpdateItemFunction(serviceCollection.BuildServiceProvider());
        }
Exemple #2
0
        public void ShowDialog()
        {
            _dialog.Title = Title;
            ComponentUtils.InsertIconToPanel(_dialog.InfoPanel, AppResources.GetInfoIcon, "Для большей информации об атрибуте, наведите на название этого атрибута");

            _entityList = new GenericEntityListControl <T>(ListTitle, _columnMatcher, DisplayUpdate);
            _dialog.ListPanel.Children.Add(_entityList.GetUiElement());

            foreach (var p in _propertyRows)
            {
                _dialog.PropertiesPanel.Children.Add(p);
            }

            ComponentUtils.InsertIconToButton(_dialog.AddButton, AppResources.GetAddItemIcon, OpenAddNewItemWindowButtonTitle);
            _dialog.AddButton.Click += (sender, args) => DisplayNew();

            _addButton.Click += (sender, args) => {
                if (!AddItemFunction.Invoke())
                {
                    return;
                }
                _entityList.SetSource(UpdateCollectionFunction.Invoke());
                DisplayNew();
            };
            _updateButton.Click += (sender, args) => {
                var selected = _entityList.Selected;
                if (!UpdateItemFunction.Invoke(selected))
                {
                    return;
                }

                var updatedList = UpdateCollectionFunction.Invoke().ToList();
                _entityList.SetSource(updatedList);

                _entityList.Selected = updatedList.First(t => t.Id == selected.Id);
            };
            _removeButton.Click += (sender, args) => {
                if (!RemoveItemFunction.Invoke(_entityList.Selected))
                {
                    return;
                }
                _entityList.SetSource(UpdateCollectionFunction.Invoke());
                DisplayNew();
            };

            _entityList.SetSource(UpdateCollectionFunction.Invoke());

            _dialog.ShowDialog();
        }