public void TestInitialise_NonEditableGroup() { //setup IContextSpecificRoutingDetailController controller = new DeviceTypeRoutingDetailController(); MockUI mockUI = new MockUI(); controller.UI = mockUI; mockUI.MembersInputPanelEnabled = false; //Non-editable group - check that data is converted to display representation, and all checkboxes are checked controller.Initialise(GetTestRoutingItemCollectionData()); DeviceTypeDisplayTranslator displayTranslator = DeviceTypeDisplayTranslator.Instance; List<string> allDeviceTypesData = displayTranslator.DataTypes; //device types list box: Assert.AreEqual(allDeviceTypesData.Count, mockUI.m_listBox.Items.Count, "Incorrect number of device types in listbox"); CheckedListBox.ObjectCollection allDeviceTypesInListBox = mockUI.m_listBox.Items; for (int index = 0; index < allDeviceTypesData.Count; index++) { Assert.AreEqual(displayTranslator.GetDisplayType(allDeviceTypesData[index]), allDeviceTypesInListBox[index], "incorrect device type display"); } CheckedListBox.CheckedItemCollection checkedDeviceTypesInListBox = mockUI.m_listBox.CheckedItems; Assert.AreEqual(3 , checkedDeviceTypesInListBox.Count, "unexpected number of checked items"); Assert.AreEqual(displayTranslator.GetDisplayType(allDeviceTypesData[0]), checkedDeviceTypesInListBox[0].ToString(), "item not checked"); Assert.AreEqual(displayTranslator.GetDisplayType(allDeviceTypesData[1]), checkedDeviceTypesInListBox[1].ToString(), "item not checked"); Assert.AreEqual(displayTranslator.GetDisplayType(allDeviceTypesData[2]), checkedDeviceTypesInListBox[2].ToString(), "item not checked"); //volume names: Assert.AreEqual(String.Empty, mockUI.m_volumeName); //volume ids: Assert.AreEqual(String.Empty, mockUI.m_volumeID); }
public void TestRoutingItems_Nominal() { //setup IContextSpecificRoutingDetailController controller = new DeviceTypeRoutingDetailController(); MockUI mockUI = new MockUI(); controller.UI = mockUI; mockUI.MembersInputPanelEnabled = true; //Lets Set some values here and then check that the display representation is //converted to the underlying data. DeviceTypeDisplayTranslator displayTranslator = DeviceTypeDisplayTranslator.Instance; mockUI.m_listBox.Items.Add(displayTranslator.GetDisplayType(displayTranslator.DataTypes[0]), false); mockUI.m_listBox.Items.Add(displayTranslator.GetDisplayType(displayTranslator.DataTypes[1]), true); mockUI.m_listBox.Items.Add(displayTranslator.GetDisplayType(displayTranslator.DataTypes[2]), true); //be aware that the ItemCheck event is raised *before* the item is checked. So, make sure the //controller takes this into account; the following item should be included in our collection mockUI.RaiseDeviceTypeCheck(2, CheckState.Checked, CheckState.Unchecked); //also check that we can handle various different separators in the volume name and volume id text mockUI.m_volumeName = "AVolumeName; ; My Volumne"; mockUI.m_volumeID = "AnotherNewVolumeID"; List<IRoutingItem> newRoutingItems = controller.RoutingItems; Assert.AreEqual(5, newRoutingItems.Count, "unexpected number of items in routing item collection"); IRoutingItem routingItem = newRoutingItems[0]; Assert.AreEqual(displayTranslator.DataTypes[1], routingItem.Name.Value, "incorrect name on routing item"); Assert.AreEqual(displayTranslator.DataTypes[1], routingItem.Content, "incorrect content on routing item"); routingItem = newRoutingItems[1]; Assert.AreEqual(displayTranslator.DataTypes[2], routingItem.Name.Value, "incorrect name on routing item"); Assert.AreEqual(displayTranslator.DataTypes[2], routingItem.Content, "incorrect content on routing item"); //volume ids: routingItem = newRoutingItems[2]; Assert.AreEqual("AVolumeName", routingItem.Name.Value, "incorrect name on routing item"); Assert.AreEqual("AVolumeName", routingItem.Content, "incorrect content on routing item"); routingItem = newRoutingItems[3]; Assert.AreEqual("My Volumne", routingItem.Name.Value, "incorrect name on routing item"); Assert.AreEqual("My Volumne", routingItem.Content, "incorrect content on routing item"); //volume names: routingItem = newRoutingItems[4]; Assert.AreEqual("AnotherNewVolumeID", routingItem.Name.Value, "incorrect name on routing item"); Assert.AreEqual("AnotherNewVolumeID", routingItem.Content, "incorrect content on routing item"); //now, ensure that if we set the RoutingItemCollection again, we don't screw up with the last item //check in the device types checkbox when we next get. We were seeing a problem where we weren't //resetting the last item checked, and so items were being added to the new collection which shouldn't //have been added. controller.Initialise(new RoutingItemCollection()); newRoutingItems = controller.RoutingItems; Assert.AreEqual(0, newRoutingItems.Count, "incorrect number of routing items in collection"); }
public void TestInitialise_NoRoutingItemCollection() { //setup IContextSpecificRoutingDetailController controller = new DeviceTypeRoutingDetailController(); MockUI mockUI = new MockUI(); controller.UI = mockUI; mockUI.MembersInputPanelEnabled = true; //no routing item collection try { controller.Initialise(null); Assert.IsTrue(false, "Failed to throw on unset RoutingItemCollection"); } catch (NullReferenceException) { Assert.IsTrue(true); } catch { Assert.IsTrue(false, "Threw unexpected exception on unset RoutingItemCollection"); } }
public void TestMembersChanged() { //setup IContextSpecificRoutingDetailController controller = new DeviceTypeRoutingDetailController(); MockUI mockUI = new MockUI(); controller.UI = mockUI; controller.MembersChanged += new EventHandler<EventArgs>(controller_MembersChanged); controller.Initialise(GetTestRoutingItemCollectionData()); //Device type changed m_membersChangedRaised = false; Assert.AreEqual(false, m_membersChangedRaised, "test setup failure - m_membersChangedRaised should be false"); mockUI.RaiseDeviceTypeCheck(0, CheckState.Unchecked, CheckState.Checked); Assert.AreEqual(true, m_membersChangedRaised, "test setup failure - m_membersChangedRaised should be true"); //Volume name changed m_membersChangedRaised = false; Assert.AreEqual(false, m_membersChangedRaised, "test setup failure - m_membersChangedRaised should be false"); mockUI.RaiseVolumeNameChanged(); Assert.AreEqual(true, m_membersChangedRaised, "test setup failure - m_membersChangedRaised should be true"); //volume id changed m_membersChangedRaised = false; Assert.AreEqual(false, m_membersChangedRaised, "test setup failure - m_membersChangedRaised should be false"); mockUI.RaiseVolumeIDsChanged(); Assert.AreEqual(true, m_membersChangedRaised, "test setup failure - m_membersChangedRaised should be true"); }