Exemple #1
0
        public void GetState_AfterStoredState_ShouldRestoreSameState()
        {
            // store
            IStateStoreService       stateStoreSvc1 = new StateStoreService(new InMemoryStateStore());
            IDirectoryMapperService  dirMapperSvc   = FakeDirectoryMapperService.Create();
            MiddlewareOptionsBuilder builder        = new MiddlewareOptionsBuilder(dirMapperSvc);

            builder.BypassAllAuthenticatedUsers();

            stateStoreSvc1.SetState(new MaintenanceState(null, isMaintenanceOn: true, builder.GetOptions()));

            // restore
            IStateStoreService stateStoreSvc2 = new StateStoreService(new InMemoryStateStore());

            Func <MaintenanceState> testFunc = () => stateStoreSvc2.GetState();

            MaintenanceState state = testFunc.ShouldNotThrow()
                                     .ShouldNotBeNull();
            IMiddlewareOptionsContainer optionsContainer = state;

            optionsContainer.MiddlewareOptions
            .ShouldNotBeNull()
            .Any <BypassAllAuthenticatedUsersOption>()
            .ShouldBeTrue();
        }
        public override int GetHashCode()
        {
            int hash = 1;

            if (entityId_ != null)
            {
                hash ^= EntityId.GetHashCode();
            }
            if (RoomNumber.Length != 0)
            {
                hash ^= RoomNumber.GetHashCode();
            }
            if (Description.Length != 0)
            {
                hash ^= Description.GetHashCode();
            }
            if (AdditionalDescription.Length != 0)
            {
                hash ^= AdditionalDescription.GetHashCode();
            }
            if (NightsOccupiedCounter != 0)
            {
                hash ^= NightsOccupiedCounter.GetHashCode();
            }
            if (lastCleanedAt_ != null)
            {
                hash ^= LastCleanedAt.GetHashCode();
            }
            if (MaintenanceState != 0)
            {
                hash ^= MaintenanceState.GetHashCode();
            }
            if (roomTypeId_ != null)
            {
                hash ^= RoomTypeId.GetHashCode();
            }
            if (RoomTypeName.Length != 0)
            {
                hash ^= RoomTypeName.GetHashCode();
            }
            if (connectedRoom_ != null)
            {
                hash ^= ConnectedRoom.GetHashCode();
            }
            if (TrunkId.Length != 0)
            {
                hash ^= TrunkId.GetHashCode();
            }
            if (occupyingReservation_ != null)
            {
                hash ^= OccupyingReservation.GetHashCode();
            }
            if (KcrRoomNumber.Length != 0)
            {
                hash ^= KcrRoomNumber.GetHashCode();
            }
            return(hash);
        }
        void IStateStoreService.SetState(MaintenanceState state)
        {
            _state = state;

            if (CanStoreState())
            {
                StoreState();
            }
        }
Exemple #4
0
        public void RestoreState_WhenStateStoreReturnsNull_ShouldNotReturnNull()
        {
            IStateStore        stateStore = Substitute.For <IStateStore>();
            IStateStoreService svc        = new StateStoreService(stateStore);

            stateStore.GetState().ReturnsNull();

            MaintenanceState state = svc.GetState();

            state.ShouldNotBeNull();
        }
Exemple #5
0
        public IMaintenanceState GetState()
        {
            MaintenanceState state = _stateStoreService.GetState();

            if (state.ExpirationDate <= DateTime.Now)
            {
                LeaveMaintanence();

                state = new MaintenanceState(isMaintenanceOn: false);
            }

            return(state);
        }
        internal static string ToSerializedValue(this MaintenanceState value)
        {
            switch (value)
            {
            case MaintenanceState.None:
                return("None");

            case MaintenanceState.Draining:
                return("Draining");

            case MaintenanceState.Suspended:
                return("Suspended");
            }
            return(null);
        }
        MaintenanceState IStateStoreService.GetState()
        {
            if (_state == null)
            {
                if (CanStoreState())
                {
                    RestoreState();
                }
                else
                {
                    _state = new MaintenanceState();
                }
            }

            return(_state);
        }
Exemple #8
0
        public MaintenanceState GetDeviceMaintenanceState(long deviceId)
        {
            MaintenanceState result = MaintenanceState.NotConfig;
            var hierarchyId         = this.hierarchyRepository.GetBuildingId(deviceId);

            var building = this.buildingRepository.GetById(hierarchyId);

            if (building != null)
            {
                var date = building.MaintenanceDate;
                if (date.HasValue)
                {
                    if (date.Value.Date >= DateTime.Now.Date)
                    {
                        result = MaintenanceState.Normal;
                    }
                }
            }


            return(result);
        }
        private void RestoreState()
        {
            StorableMaintenanceState restored = _stateStore.GetState();

            if (restored != null)
            {
                OptionCollection restoredOptions = null;
                if (restored.MiddlewareOptions != null)
                {
                    restoredOptions = new OptionCollection(
                        restored.MiddlewareOptions
                        .Select(o => RestoreOption(o)));
                }

                _state = new MaintenanceState(restored.ExpirationDate,
                                              restored.IsMaintenanceOn,
                                              restoredOptions);
            }
            else
            {
                _state = new MaintenanceState();
            }
        }
 // Level2
 internal static int AddScooter(string model, double electricityLeft, double electricityTotal, MaintenanceState maintenanceState)
 {
     throw new NotImplementedException();
 }
Exemple #11
0
 protected Maintenance()
 {
     _jobState  = MaintenanceState.Pending;
     _createdOn = DateTime.Now;
     _attempts  = 0;
 }