コード例 #1
0
ファイル: SerializationTests.cs プロジェクト: rasomc/emul8
        public void ShouldSerializeGPIOs()
        {
            var mocks = new GPIOMock[3];

            mocks[0] = new GPIOMock {
                Id = 1
            };
            mocks[1] = new GPIOMock {
                Id = 2
            };
            mocks[2] = new GPIOMock {
                Id = 3
            };

            mocks[0].Connections[0].Connect(mocks[1], 5);
            mocks[1].Connections[1].Connect(mocks[2], 0);
            mocks[2].Connections[2].Connect(mocks[1], 6);
            mocks[0].GPIOSet(0, true);
            mocks[2].GPIOSet(1, true);
            mocks[2].GPIOSet(2, true);

            var devs = Serializer.DeepClone(mocks).ToList();

            Assert.AreEqual(3, devs.Count);
            var mock1 = devs.First(x => x.Id == 1);
            var mock2 = devs.First(x => x.Id == 2);
            var mock3 = devs.First(x => x.Id == 3);

            // checking connections
            var conn1 = mock1.Connections[0].Endpoint;

            Assert.AreEqual(5, conn1.Number);
            Assert.AreEqual(mock2, conn1.Receiver);
            var conn2 = mock2.Connections[1].Endpoint;

            Assert.AreEqual(0, conn2.Number);
            Assert.AreEqual(mock3, conn2.Receiver);
            var conn3 = mock3.Connections[2].Endpoint;

            Assert.AreEqual(6, conn3.Number);
            Assert.AreEqual(mock2, conn3.Receiver);

            // checking signaled state
            Assert.IsTrue(mock2.HasSignaled(5), "Mock 2:5 is not signaled!");
            Assert.IsTrue(mock2.HasSignaled(6), "Mock 2:6 is not signaled!");
            Assert.IsFalse(mock3.HasSignaled(0), "Mock 3:0 is signaled!");

            // now we connect sth to signaled mock3:1 and what happens?
            mock3.Connections[1].Connect(mock1, 9);
            Assert.IsTrue(mock1.HasSignaled(9), "Mock 1:9 is not signaled!");
        }
コード例 #2
0
ファイル: SerializationTests.cs プロジェクト: rte-se/emul8
		public void ShouldSerializeGPIOs()
		{
			var mocks = new GPIOMock[3];
			mocks[0] = new GPIOMock { Id = 1 };
			mocks[1] = new GPIOMock { Id = 2 };
			mocks[2] = new GPIOMock { Id = 3 };

            mocks[0].Connections[0].Connect(mocks[1], 5);
            mocks[1].Connections[1].Connect(mocks[2], 0);
            mocks[2].Connections[2].Connect(mocks[1], 6);
			mocks[0].GPIOSet(0, true);
			mocks[2].GPIOSet(1, true);
			mocks[2].GPIOSet(2, true);

			var devs = Serializer.DeepClone(mocks).ToList();
			Assert.AreEqual(3, devs.Count);
			var mock1 = devs.First(x => x.Id == 1);
			var mock2 = devs.First(x => x.Id == 2);
			var mock3 = devs.First(x => x.Id == 3);

			// checking connections
            var conn1 = mock1.Connections[0].Endpoint;
			Assert.AreEqual(5, conn1.Number);
			Assert.AreEqual(mock2, conn1.Receiver);
            var conn2 = mock2.Connections[1].Endpoint;
			Assert.AreEqual(0, conn2.Number);
			Assert.AreEqual(mock3, conn2.Receiver);
            var conn3 = mock3.Connections[2].Endpoint;
			Assert.AreEqual(6, conn3.Number);
			Assert.AreEqual(mock2, conn3.Receiver);
			
			// checking signaled state
			Assert.IsTrue(mock2.HasSignaled(5), "Mock 2:5 is not signaled!");
			Assert.IsTrue(mock2.HasSignaled(6), "Mock 2:6 is not signaled!");
			Assert.IsFalse(mock3.HasSignaled(0), "Mock 3:0 is signaled!");
			
			// now we connect sth to signaled mock3:1 and what happens?
            mock3.Connections[1].Connect(mock1, 9);
			Assert.IsTrue(mock1.HasSignaled(9), "Mock 1:9 is not signaled!");
		}