Esempio n. 1
0
        public void SwitchEventCodeSet_Equality()
        {
            var set1 = new SwitchEventCodeSet();
            var set2 = new SwitchEventCodeSet();

            Assert.IsTrue(set1.Equals(set2));
            Assert.IsFalse(set1.Equals(null));
            Assert.IsFalse(set1.Equals("Hello World!"));
            Assert.AreEqual(set1.GetHashCode(), set2.GetHashCode());
            Assert.IsTrue(set1 == set2);
            Assert.IsFalse(set1 != set2);

            set1.Add(SwitchEventCode.Dtmf);
            set2.Add(SwitchEventCode.Dtmf);
            Assert.IsTrue(set1.Equals(set2));
            Assert.AreEqual(set1.GetHashCode(), set2.GetHashCode());
            Assert.IsTrue(set1 == set2);
            Assert.IsFalse(set1 != set2);

            set2.Add(SwitchEventCode.Heartbeat);
            Assert.IsFalse(set1.Equals(set2));
            Assert.AreNotEqual(set1.GetHashCode(), set2.GetHashCode());
            Assert.IsFalse(set1 == set2);
            Assert.IsTrue(set1 != set2);

            Assert.IsTrue((SwitchEventCodeSet)null == (SwitchEventCodeSet)null);
            Assert.IsFalse((SwitchEventCodeSet)null != (SwitchEventCodeSet)null);
            Assert.IsFalse(set1 == (SwitchEventCodeSet)null);
            Assert.IsFalse((SwitchEventCodeSet)null == set1);
            Assert.IsTrue(set1 != (SwitchEventCodeSet)null);
            Assert.IsTrue((SwitchEventCodeSet)null != set1);
        }
Esempio n. 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);
        }
Esempio n. 3
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());
        }