示例#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();
        }
示例#2
0
        public void SetState_WithValidState_ShouldNotThrow()
        {
            IStateStoreService       stateStoreSvc = new StateStoreService(new InMemoryStateStore());
            IDirectoryMapperService  dirMapperSvc  = FakeDirectoryMapperService.Create();
            MiddlewareOptionsBuilder builder       = new MiddlewareOptionsBuilder(dirMapperSvc);

            builder.BypassAllAuthenticatedUsers();

            Action testAction = () => stateStoreSvc.SetState(new MaintenanceState(null, isMaintenanceOn: true, builder.GetOptions()));

            testAction.ShouldNotThrow();
        }
示例#3
0
        private MiddlewareTestDesk GetTestDesk(
            Action <HttpContext> contextSetup,
            Action <IMiddlewareOptionsBuilder> optionsSetup,
            Action <IMiddlewareOptionsBuilder> optionsOverrideSetup = null,
            string tempDir = null)
        {
            DefaultHttpContext httpContext = new DefaultHttpContext();

            httpContext.Response.Body = new MemoryStream();

            contextSetup(httpContext);

            bool            isNextDelegateCalled = false;
            RequestDelegate nextDelegate         = (HttpContext hc) =>
            {
                isNextDelegateCalled = true;
                return(Task.CompletedTask);
            };

            if (tempDir == null)
            {
                tempDir = Path.GetTempPath();
            }

            IDirectoryMapperService dirMapperSvc = FakeDirectoryMapperService.Create(tempDir);

            OptionCollection middlewareOptions = null;

            if (optionsOverrideSetup != null)
            {
                MiddlewareOptionsBuilder optionOverrideBuilder = new MiddlewareOptionsBuilder(dirMapperSvc);
                optionsOverrideSetup.Invoke(optionOverrideBuilder);
                middlewareOptions = optionOverrideBuilder.GetOptions();
            }

            IMaintenanceControlService svc = Substitute.For <IMaintenanceControlService>();

            svc.GetState().Returns(new MaintenanceState(null, isMaintenanceOn: true, middlewareOptions));

            MaintenanceMiddleware middleware = new MaintenanceMiddleware(
                nextDelegate,
                svc,
                dirMapperSvc,
                optionsSetup);

            return(new MiddlewareTestDesk
            {
                CurrentHttpContext = httpContext,
                IsNextDelegateCalled = isNextDelegateCalled,
                MiddlewareInstance = middleware
            });
        }
        private FileStateStore GetStateStore(Action <string> onFullTempDirGenerated = null)
        {
            string tempDir = Path.GetTempPath();

            tempDir = SafeTempPath.Create(tempDir);

            var    dirMapperSvc = FakeDirectoryMapperService.Create(tempDir);
            string fullTempPath = dirMapperSvc.GetAbsolutePath(EnvDirectory.ContentRootPath);

            onFullTempDirGenerated?.Invoke(fullTempPath);

            FileStateStore store = new FileStateStore(dirMapperSvc);

            return(store);
        }