public void TrySelectTab() { // given const int TAB_PAGES_NO = 23; TabControl tabControl = TestControls.GetTestTabControl(TAB_PAGES_NO); const int SELECTED_TAB_1 = 3; const int SELECTED_TAB_2 = TAB_PAGES_NO + 1; const int SELECTED_TAB_3 = -TAB_PAGES_NO; const int SELECTED_TAB_4 = 0; // when UiControls.TrySelectTab(tabControl, SELECTED_TAB_1); int selectedTab1 = tabControl.SelectedIndex; UiControls.TrySelectTab(tabControl, SELECTED_TAB_2); int selectedTab2 = tabControl.SelectedIndex; UiControls.TrySelectTab(tabControl, SELECTED_TAB_3); int selectedTab3 = tabControl.SelectedIndex; UiControls.TrySelectTab(null, SELECTED_TAB_4); int selectedTab4 = tabControl.SelectedIndex; // then Assert.IsTrue(selectedTab1.Equals(SELECTED_TAB_1)); Assert.IsFalse(selectedTab2.Equals(SELECTED_TAB_2)); Assert.IsFalse(selectedTab3.Equals(SELECTED_TAB_3)); Assert.IsFalse(selectedTab4.Equals(SELECTED_TAB_4)); }
public void TryGetSelectedIndex() { // given const int CONTROL1_INDEX = 4; const int CONTROL1_ITEMS_NO = 77; ComboBox control1 = TestControls.GetTestComboBox(CONTROL1_ITEMS_NO); control1.SelectedIndex = CONTROL1_INDEX; const int ERROR_INDEX = -1; ComboBox control2 = new ComboBox(); const int CONTROL3_INDEX = 7; const int CONTROL3_ITEMS_NO = 52; ListBox control3 = TestControls.GetTestListBox(CONTROL3_ITEMS_NO); control3.SelectedIndex = CONTROL3_INDEX; const int CONTROL4_TAB_PAGES_NO = 23; const int CONTROL4_INDEX = CONTROL4_TAB_PAGES_NO / 3; TabControl control4 = TestControls.GetTestTabControl(CONTROL4_TAB_PAGES_NO); control4.SelectTab(CONTROL4_INDEX); // when int result1 = UiControls.TryGetSelectedIndex(control1); int result2 = UiControls.TryGetSelectedIndex(control2); int result3 = UiControls.TryGetSelectedIndex(control3); int result4 = UiControls.TryGetSelectedIndex(new Button()); int result5 = UiControls.TryGetSelectedIndex(null); int result6 = UiControls.TryGetSelectedIndex(control4); // then Assert.IsTrue(result1.Equals(CONTROL1_INDEX)); Assert.IsTrue(result2.Equals(ERROR_INDEX)); Assert.IsTrue(result3.Equals(CONTROL3_INDEX)); Assert.IsTrue(result4.Equals(ERROR_INDEX)); Assert.IsTrue(result5.Equals(ERROR_INDEX)); Assert.IsTrue(result6.Equals(CONTROL4_INDEX)); }