public void is_AllManagerStatusesAppended_ReturnMessage()
        {
            string id = "id";

            // Arrange
            string msgDoorManager      = "Doors,OK,OK,OK,FAULT,OK,FAULT,OK,OK,OK,OK";
            string msgLightManager     = "Lights,OK,OK,OK,OK,OK,OK,OK,OK,OK,OK";
            string msgFireAlarmManager = "FireAlarm,OK,OK,OK,OK,OK,OK,OK,OK,OK,OK";

            var stubFireAlarmManager = Substitute.For <IFireAlarmManager>();
            var stubDoorManager      = Substitute.For <IDoorManager>();
            var stubLightManger      = Substitute.For <ILightManager>();
            var stubWebService       = Substitute.For <IWebService>();

            stubDoorManager.GetStatus().Returns(msgDoorManager);
            stubFireAlarmManager.GetStatus().Returns(msgFireAlarmManager);
            stubLightManger.GetStatus().Returns(msgLightManager);

            // Act

            BuildingController bc = new BuildingController(id, stubLightManger, stubFireAlarmManager, stubDoorManager
                                                           , stubWebService, GetMockEmailService());

            string result = bc.GetStatusReport();

            // Assert
            Assert.AreEqual(stubLightManger.GetStatus() + stubDoorManager.GetStatus() + stubFireAlarmManager.GetStatus()
                            , result);
        }
        public void are_DoorAndFireAlarmFaulty_LogMessageDoorsFireAlarm()
        {
            // Arrange

            string msgLightManager     = "Lights,OK,OK,OK,OK,OK,OK,OK,OK,OK,OK";
            string msgDoorManager      = "Doors,OK,FAULT,OK,OK,OK,OK,OK,OK,OK,OK";
            string msgFireAlarmManager = "FireAlarm,OK,OK,OK,OK,FAULT,OK,OK,OK,OK,OK";

            var stubFireAlarmManager = Substitute.For <IFireAlarmManager>();
            var stubDoorManager      = Substitute.For <IDoorManager>();
            var stubLightManger      = Substitute.For <ILightManager>();
            var stubWebService       = Substitute.For <IWebService>();


            stubDoorManager.GetStatus().Returns(msgDoorManager);
            stubFireAlarmManager.GetStatus().Returns(msgFireAlarmManager);
            stubLightManger.GetStatus().Returns(msgLightManager);
            var stubIEmailService = Substitute.For <IEmailService>();

            // Act
            BuildingController bc = new BuildingController(ID, stubLightManger, stubFireAlarmManager, stubDoorManager, stubWebService, stubIEmailService);

            bc.GetStatusReport();


            // Assert
            stubWebService.Received().LogEngineerRerquired("Doors, FireAlarm");
        }
        // check if invalid id is accessed ..
        public void is_idInValid_ReturnFalse()
        {
            // Arrange
            BuildingController b = new BuildingController(ID);

            // Act

            // Assert
            Assert.AreNotEqual(b.GetBuildingID(), "John");
        }
        // --> ( L1 R5 ) <--
        // check if initial state is "out of hours"
        public void is_initialStateOutOfHours_ReturnSame()
        {
            // Arrange
            BuildingController b = new BuildingController(ID);

            // Act
            string expected = STATE_OUT_OF_HOURS;

            // Assert
            Assert.Equals(expected, b.GetCurrentState());
        }
        public void is_StateValid_ReturTrue(string state)
        {
            // Arrange

            // Act
            BuildingController bc = new BuildingController(ID);
            bool result           = bc.SetCurrentState(state);

            // Assert
            Assert.IsTrue(result);
        }
        // --> ( L1 R2 ) <--
        // if buildingId is within the constraints -> get it..
        public void is_idValid_ReturnId()
        {
            // Arrange
            BuildingController b = new BuildingController(ID);

            // Act
            string id = b.GetBuildingID();

            // Assert
            Assert.AreEqual(ID, id);
        }
        public void is_StateInLowerCaseValid_ReturnTrue(string state)
        {
            // Arrange
            string             id = "newId";
            BuildingController bc = new BuildingController(id, state);

            // Act
            bool result = bc.AnalayzeStateLetterForm();

            // Assert
            Assert.IsTrue(result);
        }
        public void is_newStateFireSameAsCurrentState_ReturnTrue(string oldState, string currentState, string newState)
        {
            // Arrange
            BuildingController bc = new BuildingController(ID);
            // Act
            bool oState = bc.SetCurrentState(oldState);
            bool cState = bc.SetCurrentState(currentState);
            bool nState = bc.SetCurrentState(newState);

            // Assert
            Assert.IsTrue(nState);
        }
        public void is_StateInvalid_ReturnFalse(string state)
        {
            // Arrange
            string             id = "newId";
            BuildingController bc = new BuildingController(id);

            // Act
            bool result = bc.SetCurrentState(state);

            // Assert
            Assert.IsFalse(result);
        }
        public void is_stateChangeFireSequenceInvalid_ReturnFalse(string oldState, string currentState, string newState)
        {
            // Arrange
            BuildingController bc = new BuildingController(ID);

            // Act
            bool oState = bc.SetCurrentState(oldState);
            bool cState = bc.SetCurrentState(currentState);
            bool nState = bc.SetCurrentState(newState);

            // Assert
            Assert.IsFalse(nState);
        }
        public void is_stateChangeSequencialValid_ReturnTrue(string state, string newState)
        {
            // Arrange

            BuildingController bc = new BuildingController(ID);

            // Act
            bool result  = bc.SetCurrentState(state);
            bool fResult = bc.SetCurrentState(newState);

            // Assert
            Assert.IsTrue(fResult);
        }
        public void is_stateChangesToOpenFailToUnlocksAllDoors_ReturnFalse()
        {
            // Arrange
            var stubDoorManager = Substitute.For <IDoorManager>();

            stubDoorManager.OpenAllDoors().Returns(false);

            // Act
            BuildingController bc = new BuildingController(ID, GetMockLightManager(), GetMockFireAlarmManager(), stubDoorManager, GetMockIWebService(), GetMockEmailService());

            bool result = bc.SetCurrentState(STATE_OPEN);

            // Assert
            Assert.AreEqual(stubDoorManager.OpenAllDoors(), result);
        }
        public void is_StateChangesToClosedLockAllDoorsAndTurnOffLights_ReturnTrue()
        {
            // Arrange
            var stubDoorManager  = Substitute.For <IDoorManager>();
            var stubLightManager = Substitute.For <ILightManager>();

            stubDoorManager.LockAllDoors().Returns(true);
            /// stubLightManager.SetAllLights(false);

            // Act
            BuildingController bc = new BuildingController(ID, stubLightManager, GetMockFireAlarmManager(), stubDoorManager, GetMockIWebService(), GetMockEmailService());

            bool result   = bc.SetCurrentState(STATE_CLOSED);
            bool expected = true;

            // Assert
            Assert.AreEqual(expected, result);
        }
        public void is_FireAlarmManagerGetStatus_ReturnsMessage()
        {
            // Arrange
            string message          = "FireAlarm,OK,OK,OK,FAULT,OK,FAULT,OK,OK,OK,OK";
            var    stubLightManager = Substitute.For <ILightManager>();
            var    stubFireManager  = Substitute.For <IFireAlarmManager>();
            var    stubDoorManager  = Substitute.For <IDoorManager>();
            var    stubWebService   = Substitute.For <IWebService>();

            stubFireManager.GetStatus().Returns(message);
            stubDoorManager.GetStatus().Returns("");
            stubLightManager.GetStatus().Returns("");

            // Act
            BuildingController b = new BuildingController(ID, stubLightManager, stubFireManager, stubDoorManager, stubWebService, GetMockEmailService());

            // Assert

            Assert.AreEqual(message, b.GetStatusReport());
        }
        public void is_state_FireAlarm_EnableAlarmUnlockAllDoorsTurnOnLights_ReturnTrue()
        {
            // Arrange
            var stubFireAlarmManager = Substitute.For <IFireAlarmManager>();
            var stubDoorManager      = Substitute.For <IDoorManager>();
            var stubLightManager     = Substitute.For <ILightManager>();
            var stubWebService       = Substitute.For <IWebService>();
            var stubIEmailService    = Substitute.For <IEmailService>();



            // Act
            BuildingController bc = new BuildingController(ID, stubLightManager, stubFireAlarmManager, stubDoorManager, stubWebService, stubIEmailService);
            bool result           = bc.SetCurrentState(STATE_FIRE_ALARM);


            // Assert
            stubWebService.Received().LogFireAlarm("fire alarm");
            stubFireAlarmManager.Received().SetAlarm(true);
            stubLightManager.Received().SetAllLights(true);
            stubDoorManager.Received().OpenAllDoors();
        }
        public void is_stateChangesToOpenFromFireStatesFailsToUnlocksAllDoors_ReturnFalse(string Oldstate, string currentState, string newState)
        {
            // Arrange
            var stubDoorManager      = Substitute.For <IDoorManager>();
            var stubFireAlarmManager = Substitute.For <IFireAlarmManager>();
            var stubLightManager     = Substitute.For <ILightManager>();
            var stubWebService       = Substitute.For <IWebService>();
            var stubEmailService     = Substitute.For <IEmailService>();

            stubDoorManager.OpenAllDoors().Returns(true, false);

            // Act
            BuildingController bc = new BuildingController(ID, stubLightManager, stubFireAlarmManager, stubDoorManager, stubWebService, stubEmailService);

            bool stateFirst  = bc.SetCurrentState(Oldstate);
            bool stateSecond = bc.SetCurrentState(currentState);
            bool result      = bc.SetCurrentState(newState);

            bool expected = false;

            // Assert
            Assert.AreEqual(expected, result);
        }
        public void if_LogFireAlarmThrowsException_SendEmail()
        {
            // Arrange

            var stubFireAlarmManager = Substitute.For <IFireAlarmManager>();
            var stubDoorManager      = Substitute.For <IDoorManager>();
            var stubLightManager     = Substitute.For <ILightManager>();
            var mockWebService       = Substitute.For <IWebService>();
            var stubEmailService     = Substitute.For <IEmailService>();

            mockWebService.When(
                service => service.LogFireAlarm(Arg.Any <string>())).
            Do(info => { throw new Exception(); });

            // Act
            BuildingController bc = new BuildingController(ID, stubLightManager, stubFireAlarmManager, stubDoorManager, mockWebService, stubEmailService);

            bc.SetCurrentState(STATE_FIRE_ALARM);


            // Assert

            stubEmailService.Received().SendEmail(Arg.Any <string>(), Arg.Any <string>(), Arg.Any <string>());
        }