public void TestClickSubmitProductInfoButton() { _target.SetFieldOrProperty(MEMBER_VARIABLE_NAME_PRODUCTS_MANAGEMENT_TAB_PAGE_STATE, ProductsManagementTabPageState.EditProduct); _target.SetFieldOrProperty(MEMBER_VARIABLE_NAME_CURRENT_SELECTED_PRODUCT, new Product(TestDefinition.DUMP_INTEGER, TestDefinition.DUMP_STRING, TestDefinition.DUMP_STRING, new Money(TestDefinition.DUMP_INTEGER), TestDefinition.DUMP_INTEGER, TestDefinition.DUMP_STRING, TestDefinition.DUMP_STRING)); int count = 0; _productsManagementTabPagePresentationModel.IsEditedProductInfoChanged += () => count++; var productInfo = new ProductInfo(TestDefinition.DUMP_STRING, TestDefinition.DUMP_STRING, new Money(TestDefinition.DUMP_INTEGER), TestDefinition.DUMP_STRING, TestDefinition.DUMP_STRING); _productsManagementTabPagePresentationModel.ClickSubmitProductInfoButton(productInfo); Assert.AreSame((( Product )_target.GetFieldOrProperty(MEMBER_VARIABLE_NAME_CURRENT_SELECTED_PRODUCT)).ProductInfo, productInfo); Assert.IsFalse(( bool )_target.GetFieldOrProperty(MEMBER_VARIABLE_NAME_IS_EDITED_PRODUCT_INFO)); Assert.AreEqual(count, 1); _target.SetFieldOrProperty(MEMBER_VARIABLE_NAME_PRODUCTS_MANAGEMENT_TAB_PAGE_STATE, ProductsManagementTabPageState.AddProduct); _productsManagementTabPagePresentationModel.ClickSubmitProductInfoButton(productInfo); Model model = ( Model )_target.GetFieldOrProperty(MEMBER_VARIABLE_NAME_MODEL); Assert.AreSame(model.GetProduct(1).ProductInfo, productInfo); }
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); }