Пример #1
0
        public void SwitchEventCodeSet_ReadOnly()
        {
            var readOnly = new SwitchEventCodeSet(SwitchEventCode.Heartbeat);

            readOnly.IsReadOnly = true;
            Assert.IsTrue(readOnly.IsReadOnly);
            Assert.IsTrue(readOnly.Contains(SwitchEventCode.Heartbeat));

            ExtendedAssert.Throws <InvalidOperationException>(() => readOnly.IsReadOnly = false);
            ExtendedAssert.Throws <InvalidOperationException>(() => readOnly.Add(SwitchEventCode.Dtmf));
            ExtendedAssert.Throws <InvalidOperationException>(() => readOnly.Remove(SwitchEventCode.Dtmf));
            ExtendedAssert.Throws <InvalidOperationException>(() => readOnly.Clear());
        }
Пример #2
0
        public void SwitchEventCodeSet_Basic()
        {
            var set  = new SwitchEventCodeSet();
            var list = new List <SwitchEventCode>();

            Assert.IsFalse(set.IsReadOnly);

            Assert.IsTrue(set.IsEmpty);
            Assert.IsFalse(set.Contains(SwitchEventCode.Heartbeat));

            set.Add(SwitchEventCode.Heartbeat);
            Assert.IsFalse(set.IsEmpty);
            Assert.IsTrue(set.Contains(SwitchEventCode.Heartbeat));

            set.Clear();
            Assert.IsTrue(set.IsEmpty);
            Assert.IsFalse(set.Contains(SwitchEventCode.Heartbeat));

            list.Clear();
            foreach (var code in set)
            {
                list.Add(code);
            }

            Assert.AreEqual(0, list.Count);

            set.Add(SwitchEventCode.Heartbeat);
            list.Clear();
            foreach (var code in set)
            {
                list.Add(code);
            }

            Assert.AreEqual(1, list.Count);
            Assert.AreEqual(SwitchEventCode.Heartbeat, list[0]);

            set.Remove(SwitchEventCode.Heartbeat);
            Assert.IsTrue(set.IsEmpty);
        }