Ejemplo n.º 1
0
        public async Task TestFilterAsync()
        {
            var serviceClient = ProductsServiceClient.Mock.Object;

            // TODO Data could also retrieved and tested with the filter only partially filled.

            var categoriesExpected = await serviceClient.GetProductCategoriesAsync();

            const int categoryExpectedOrder = 2;
            var       categoryExpected      = categoriesExpected[categoryExpectedOrder - 1];

            // Note literals are used for the control names here as they are fields in the view classes.
            var masterFilterComboBox = TestSession.FindElementByAccessibilityIdWait("MasterFilterComboBox");

            Assert.IsNotNull(masterFilterComboBox);

            // Necessary to actually get the elements created in the GUI.
            masterFilterComboBox.Click();

            // TODO Check length of list?

            // Note that Click must be applied this way. Finding the element separately resulted in only a brief display on screen after which the Display property was false, which prevented Click.
            // TODO This tends to fail currently.
            masterFilterComboBox.FindElementByName(categoryExpected.Name).Click();

            var subcategoriesExpected = await serviceClient.GetProductSubcategoriesAsync();

            const int subcategoryExpectedOrder = 1;
            var       subcategoryExpected      = subcategoriesExpected.FindAll(subcategory => subcategory.ProductCategoryId == categoryExpected.Id)[subcategoryExpectedOrder - 1];

            var detailFilterComboBox = TestSession.FindElementByAccessibilityIdWait("DetailFilterComboBox");

            Assert.IsNotNull(detailFilterComboBox);
            detailFilterComboBox.Click();
            detailFilterComboBox.FindElementByName(subcategoryExpected.Name).Click();

            var searchString             = $"{categoryExpected.Id}.{subcategoryExpected.Id}";
            var productsOverviewExpected = await serviceClient.GetProductsOverviewByAsync(categoryExpected.Id, subcategoryExpected.Id, searchString);

            // Note this is a UserControl.
            var textFilterControl = TestSession.FindElementByAccessibilityIdWait("TextFilterTextBox");

            Assert.IsNotNull(textFilterControl);

            // The true text element within.
            var textFilterTextBox = textFilterControl.FindElementByClassName("TextBox");

            textFilterTextBox.Clear();
            textFilterTextBox.SendKeys(searchString.Substring(0, 2));

            // TODO Add enablement on the button depending on this control and test. Currently the control only colours on less than 3 characters.
            textFilterTextBox.SendKeys(searchString.Substring(2, 1));

            var filterButton = TestSession.FindElementByAccessibilityIdWait("FilterButton");

            Assert.IsNotNull(filterButton);
            filterButton.Click();

            var itemsCountTextBlock = TestSession.FindElementByAccessibilityIdWait("ItemsCountTextBlock");

            Assert.IsNotNull(itemsCountTextBlock);
            Assert.AreEqual(itemsCountTextBlock.Text, productsOverviewExpected.Count.ToString());
        }