Exemplo n.º 1
0
        public void EnterMaintenance_WhenCalledTwice_SecondTimeShouldThrow()
        {
            MaintenanceControlService svc = new MaintenanceControlService(
                _dirMapperSvc,
                FakeStateStoreService.Create());
            Action testAction = () => svc.EnterMaintanence();

            testAction.ShouldNotThrow();
            // the second call to EnterMaintenance should throw,
            // as the maintenance mode is alreary on
            testAction.ShouldThrow <InvalidOperationException>();
        }
Exemplo n.º 2
0
        public void EnterMaintenance_WithNoParams_ShouldSucceed()
        {
            MaintenanceControlService svc = new MaintenanceControlService(
                _dirMapperSvc,
                FakeStateStoreService.Create());

            svc.EnterMaintanence();

            IMaintenanceState state = svc.GetState();

            state.IsMaintenanceOn.ShouldBeTrue();
            state.ExpirationDate.ShouldBeNull();
        }
Exemplo n.º 3
0
        public void EnterMaintenance_WithExpirationDate_ShouldSucceed()
        {
            MaintenanceControlService svc = new MaintenanceControlService(
                _dirMapperSvc,
                FakeStateStoreService.Create());

            svc.EnterMaintanence(DateTime.Now.AddSeconds(5));

            IMaintenanceState state = svc.GetState()
                                      .ShouldNotBeNull();

            state.IsMaintenanceOn.ShouldBeTrue();
            state.ExpirationDate.ShouldNotBeNull();
        }
Exemplo n.º 4
0
        public void EnterMaintenance_WithExpirationDate_ShouldEndMaintenanceAutomatically()
        {
            MaintenanceControlService svc = new MaintenanceControlService(
                _dirMapperSvc,
                FakeStateStoreService.Create());

            svc.EnterMaintanence(DateTime.Now.AddSeconds(5));

            IMaintenanceState state = svc.GetState();
            TimeSpan          delay = state.ExpirationDate.Value - DateTime.Now;

            Thread.Sleep((int)delay.TotalMilliseconds + 1000);
            svc.GetState().IsMaintenanceOn
            .ShouldBeFalse($"The maintenance mode didn't automatically end after the set {nameof(state.ExpirationDate)} date: {state.ExpirationDate}.");
        }
Exemplo n.º 5
0
        public void LeaveMaintenance_WhenMaintenanceIsOn_ShouldTurnMaintenanceOff()
        {
            MaintenanceControlService svc = new MaintenanceControlService(
                _dirMapperSvc,
                FakeStateStoreService.Create());

            svc.EnterMaintanence();
            bool isOnAfterEnter = svc.GetState().IsMaintenanceOn;

            svc.LeaveMaintanence();
            bool isStillOnAfterLeave = svc.GetState().IsMaintenanceOn;

            isOnAfterEnter.ShouldBeTrue();
            isStillOnAfterLeave.ShouldBeFalse();
        }
Exemplo n.º 6
0
        public void EnterMaintenance_WithNoMiddlewareOptions_GetOptionsToOverrideShouldReturnNull()
        {
            MaintenanceControlService svc = new MaintenanceControlService(
                _dirMapperSvc,
                FakeStateStoreService.Create());

            svc.EnterMaintanence();

            IMaintenanceState           state            = svc.GetState();
            IMiddlewareOptionsContainer optionsContainer = (IMiddlewareOptionsContainer)state;

            optionsContainer
            ?.MiddlewareOptions
            .ShouldBeNull();
        }
Exemplo n.º 7
0
        public void EnterMaintenance_WithMiddlewareOptions_ShouldSetMiddlewareOptionsToState()
        {
            MaintenanceControlService svc = new MaintenanceControlService(
                _dirMapperSvc,
                FakeStateStoreService.Create());

            svc.EnterMaintanence(null, options =>
            {
                options.BypassUser(testUserName);
            });


            OptionCollection overridenMiddlewareOpts = (svc
                                                        .GetState() as IMiddlewareOptionsContainer)?.MiddlewareOptions;

            overridenMiddlewareOpts
            .ShouldNotBeNull()
            .Any <ISerializableOption>()
            .ShouldBeTrue();
            overridenMiddlewareOpts
            .GetSingleOrDefault <BypassUserNameOption>()
            .Value.ShouldBe(testUserName);
        }