public void TestSetCurrentSelectedProductTypeAndNotifyObserver() { int count = 0; _productTypesManagementTabPagePresentationModel.CurrentSelectedProductTypeChanged += () => count++; _productTypesManagementTabPagePresentationModel.SetCurrentSelectedProductTypeAndNotifyObserver("New Type"); Assert.AreSame(_target.GetFieldOrProperty(MEMBER_VARIABLE_NAME_CURRENT_SELECTED_PRODUCT_TYPE), "New Type"); Assert.AreEqual(count, 1); }
public ProductManagementForm(ProductsManagementTabPagePresentationModel productsManagementTabPagePresentationModelData, ProductTypesManagementTabPagePresentationModel productTypesManagementTabPagePresentationModelData, Model modelData) { InitializeComponent(); _productsManagementTabPagePresentationModel = productsManagementTabPagePresentationModelData; _productTypesManagementTabPagePresentationModel = productTypesManagementTabPagePresentationModelData; _model = modelData; this.Disposed += RemoveEvents; // Observers _model.ProductInfoChanged += ResetViewOnProductInfoChangedOrOnProductAdded; _model.ProductAdded += ResetViewOnProductInfoChangedOrOnProductAdded; _model.ProductTypeAdded += ResetViewOnProductTypeAdded; _productsManagementTabPagePresentationModel.CurrentSelectedProductChanged += UpdateProductInfoViewAndSetIsEditedProductInfo; _productsManagementTabPagePresentationModel.SubmitProductInfoButtonEnabledChanged += UpdateSubmitProductInfoButtonView; _productTypesManagementTabPagePresentationModel.CurrentSelectedProductTypeChanged += UpdateProductTypeInfoView; _productTypesManagementTabPagePresentationModel.SubmitProductTypeInfoButtonEnabledChanged += UpdateProductTypeInfoButtonView; // UI _productsListBox.SelectedIndexChanged += ChangeProductsListBoxSelectedIndex; _productTypesListBox.SelectedIndexChanged += ChangeProductTypesListBoxSelectedIndex; _productPriceField.KeyPress += InputHelper.InputNumbersOrBackSpace; _productImageBrowseButton.Click += (sender, eventArguments) => BrowseImageAndSetProductImagePath(); _submitProductInfoButton.Click += (sender, eventArguments) => _productsManagementTabPagePresentationModel.ClickSubmitProductInfoButton(new ProductInfo(_productNameField.Text, _productTypeField.Text, new Money(int.Parse(_productPriceField.Text)), _productDescriptionField.Text, _productImagePathField.Text)); _submitProductTypeInfoButton.Click += (sender, eventArguments) => _productTypesManagementTabPagePresentationModel.ClickSubmitProductTypeInfoButton(_productTypeNameField.Text); _addProductButton.Click += (sender, eventArguments) => SetProductsManagementTabPageStateAndUpdateViewOnAddProductButtonClicked(); _addProductTypeButton.Click += (sender, eventArguments) => SetProductTypesManagementTabPageStateAndUpdateViewOnAddProductTypeButtonClicked(); // Product info _productNameField.TextChanged += (sender, eventArguments) => _productsManagementTabPagePresentationModel.SetIsEditedProductInfoAndNotifyObserver(true); _productPriceField.TextChanged += (sender, eventArguments) => _productsManagementTabPagePresentationModel.SetIsEditedProductInfoAndNotifyObserver(true); _productTypeField.TextChanged += (sender, eventArguments) => _productsManagementTabPagePresentationModel.SetIsEditedProductInfoAndNotifyObserver(true); _productImagePathField.TextChanged += (sender, eventArguments) => _productsManagementTabPagePresentationModel.SetIsEditedProductInfoAndNotifyObserver(true); _productDescriptionField.TextChanged += (sender, eventArguments) => _productsManagementTabPagePresentationModel.SetIsEditedProductInfoAndNotifyObserver(true); // Input inspecting textboxes InitializeInputInspectingTextBoxesTextBoxInspectors(); InitializeInputInspectingTextBoxes(); InitializeInputInspectingTextBoxesTextBoxInspectorsCollectionChangedEventHandlers(); // Input inspecting drop-down lists InitializeInputInspectingDropDownListsDropDownListInspectors(); InitializeInputInspectingDropDownLists(); InitializeInputInspectingDropDownListsDropDownListInspectorsCollectionChangedEventHandlers(); // Input inspectors collection InitializeInputInspectorsCollection(); // Input inspecting textbox of product types management tab page _productTypeNameField.AddTextBoxInspectors(InputInspectorTypeHelper.FLAG_TEXT_BOX_IS_NOT_EMPTY); _productTypeNameField.TextBoxInspectorsCollectionChanged += () => UpdateErrorProviderViewAndIsValidProductTypeInfo(_productTypeNameField, _productTypeNameField.GetInputInspectorsError()); // Initial UI States InitializeProductTypeField(); InitializeProductsListBox(); InitializeProductTypesListBox(); _productsManagementTabPagePresentationModel.SetCurrentSelectedProductAndNotifyObserver(null); _productsManagementTabPagePresentationModel.SetIsValidProductInfoAndNotifyObserver(false); _productsManagementTabPagePresentationModel.SetIsEditedProductInfoAndNotifyObserver(false); _productsManagementTabPagePresentationModel.SetProductsManagementTabPageStateAndNotifyObserver(ProductsManagementTabPageState.EditProduct); _productTypesManagementTabPagePresentationModel.SetCurrentSelectedProductTypeAndNotifyObserver(null); _productTypesManagementTabPagePresentationModel.SetIsValidProductTypeInfoAndNotifyObserver(false); _productTypesManagementTabPagePresentationModel.SetProductTypesManagementTabPageStateAndNotifyObserver(ProductTypesManagementTabPageState.ViewProductType); }
/// <summary> /// Changes the index of the product types ListBox selected. /// </summary> private void ChangeProductTypesListBoxSelectedIndex(object sender, EventArgs eventArguments) { _productTypesManagementTabPagePresentationModel.SetProductTypesManagementTabPageStateAndNotifyObserver(ProductTypesManagementTabPageState.ViewProductType); _productTypesManagementTabPagePresentationModel.SetCurrentSelectedProductTypeAndNotifyObserver(( string )_productTypesListBox.SelectedItem); UpdateViewOnProductTypesListBoxSelectedIndexChanged(); }