コード例 #1
0
        public void PacActOnPerson_NoPerson()
        {
            var deviceMock = new Mock <IDevice>();

            deviceMock.Setup(foo => foo.On()).Verifiable();
            deviceMock.Setup(foo => foo.Off()).Verifiable();
            deviceMock.Setup(foo => foo.Restore()).Verifiable();

            var deivce = deviceMock.Object;


            var zoneMock = new Mock <Zone>();

            zoneMock.Setup(foo => foo.InZone(It.IsAny <Person>())).Returns(false).Verifiable();

            var zone = zoneMock.Object;

            var cal = new Cal();

            cal.AddScenario(new Scenario
            {
                Devices = new HashSet <IDevice> {
                    deivce
                },
                Identifier = "mock1",
                Zone       = zone
            });

            cal.ActOnPeoplePresent(new List <Person>());

            deviceMock.Verify(t => t.Restore(), Times.Never);
            deviceMock.Verify(t => t.Off(), Times.Once);
            deviceMock.Verify(t => t.On(), Times.Never);
            zoneMock.Verify(t => t.InZone(It.IsAny <Person>()), Times.Never);
        }
コード例 #2
0
        public void PacActOnPerson_TwoPerson_InNoZones()
        {
            var deviceMock1 = new Mock <IDevice>();

            deviceMock1.Setup(foo => foo.On()).Verifiable();
            deviceMock1.Setup(foo => foo.Off()).Verifiable();
            deviceMock1.Setup(foo => foo.Restore()).Verifiable();
            var deivce1 = deviceMock1.Object;

            var deviceMock2 = new Mock <IDevice>();

            deviceMock2.Setup(foo => foo.On()).Verifiable();
            deviceMock2.Setup(foo => foo.Off()).Verifiable();
            deviceMock2.Setup(foo => foo.Restore()).Verifiable();
            var deivce2 = deviceMock2.Object;


            var p1 = new Person();
            var p2 = new Person();

            var zoneMock1 = new Mock <Zone>();

            zoneMock1.Setup(foo => foo.InZone(p1)).Returns(false);
            zoneMock1.Setup(foo => foo.InZone(p2)).Returns(false);
            var zone1 = zoneMock1.Object;

            var zoneMock2 = new Mock <Zone>();

            zoneMock2.Setup(foo => foo.InZone(p1)).Returns(false);
            zoneMock2.Setup(foo => foo.InZone(p2)).Returns(false);
            var zone2 = zoneMock2.Object;

            var cal = new Cal();

            cal.AddScenario(new Scenario
            {
                Devices = new HashSet <IDevice> {
                    deivce1
                },
                Identifier = "mock1",
                Zone       = zone1
            });

            cal.AddScenario(new Scenario
            {
                Devices = new HashSet <IDevice> {
                    deivce2
                },
                Identifier = "mock2",
                Zone       = zone2
            });

            cal.ActOnPeoplePresent(new List <Person> {
                p1, p2
            });

            deviceMock1.Verify(t => t.Restore(), Times.Never);
            deviceMock1.Verify(t => t.Off(), Times.Once);
            deviceMock1.Verify(t => t.On(), Times.Never);

            deviceMock2.Verify(t => t.Restore(), Times.Never);
            deviceMock2.Verify(t => t.Off(), Times.Once);
            deviceMock2.Verify(t => t.On(), Times.Never);
        }