コード例 #1
0
        public void TestSortedInsert()
        {
            // Test successfully insert
            TransportConfig config = TransportRegistry.Instance.CreateConfig(nameof(TestSortedInsert));

            Assert.IsNotNull(config);

            // Create transport instance B
            TransportInst instB = TransportRegistry.Instance.CreateInst(nameof(TestSortedInsert) + "B", "shmem");

            config.SortedInsert(instB);
            Assert.IsNotNull(instB);

            Assert.IsNotNull(config.Transports);
            Assert.AreEqual(1, config.Transports.Count);
            Assert.AreEqual(instB.Name, config.Transports.First().Name);
            Assert.AreEqual(instB.TransportType, "shmem");

            // Create transport instance A
            TransportInst instA = TransportRegistry.Instance.CreateInst(nameof(TestSortedInsert) + "A", "udp");

            config.SortedInsert(instA);
            Assert.IsNotNull(instA);

            // Check the transport list
            Assert.IsNotNull(config.Transports);
            Assert.AreEqual(2, config.Transports.Count);
            Assert.AreEqual(instA.Name, config.Transports.ElementAt(0).Name);
            Assert.AreEqual(instA.TransportType, "udp");
            Assert.AreEqual(instB.Name, config.Transports.ElementAt(1).Name);
            Assert.AreEqual(instB.TransportType, "shmem");

            // Test parameter guard
            bool exception = false;

            try
            {
                config.SortedInsert(null);
            }
            catch (Exception ex)
            {
                exception = true;
                Assert.IsTrue(ex.GetType() == typeof(ArgumentNullException));
            }
            Assert.IsTrue(exception);

            TransportRegistry.Instance.RemoveConfig(config);
        }