public void Store_WithStateStateWithOptions_OptionsShouldEqualInput()
        {
            FileStateStore store      = GetStateStore();
            var            testState  = new StorableMaintenanceState();
            StorableOption testOption = new StorableOption
            {
                StringValue = "test",
                TypeName    = "testType"
            };

            testState.MiddlewareOptions = new List <StorableOption>
            {
                testOption
            };

            store.SetState(testState);

            store.GetState().MiddlewareOptions
            .ShouldNotBeNull()
            .ShouldNotBeEmpty();
            StorableOption firstOption = store.GetState()
                                         .MiddlewareOptions.First();

            firstOption.StringValue
            .ShouldBe(testOption.StringValue);
            firstOption.TypeName
            .ShouldBe(testOption.TypeName);
        }
        public void Store_WithEmptyState_ShouldNotThrow()
        {
            FileStateStore store      = GetStateStore();
            Action         testAction = ()
                                        => store.SetState(new StorableMaintenanceState());

            testAction.ShouldNotThrow();
        }
        public void SetState_WhenDirectoryDoesNotExist_ShouldNotThrow()
        {
            FileStateStore store = GetStateStore();

            Action testAction = () =>
            {
                store.SetState(new StorableMaintenanceState());
            };

            testAction
            .ShouldNotThrow();
        }
        public void Store_WithStateStateWithDate_DateShouldEqualInput()
        {
            FileStateStore store     = GetStateStore();
            var            testState = new StorableMaintenanceState
            {
                ExpirationDate = DateTime.Now
            };

            store.SetState(testState);

            store.GetState().ExpirationDate
            .ShouldBe(testState.ExpirationDate);
        }
        public void Store_WithStateState_StateShouldEqualInput(bool isOn)
        {
            FileStateStore store     = GetStateStore();
            var            testState = new StorableMaintenanceState
            {
                IsMaintenanceOn = isOn
            };

            store.SetState(testState);

            store.GetState().IsMaintenanceOn
            .ShouldBe(isOn);
        }
        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);
        }
        public void GetState_WhenFileIsEmpty_ShouldReturnNull()
        {
            string         tempDir = null;
            FileStateStore store   = GetStateStore((s) => { tempDir = s; });

            store.SetState(new StorableMaintenanceState());
            if (Directory.Exists(tempDir))
            {
                var fileToNullOut = Directory.GetFiles(tempDir, "*.json").FirstOrDefault();
                File.WriteAllText(fileToNullOut, "");
            }

            Func <StorableMaintenanceState> testFunc = () =>
            {
                return(store.GetState());
            };

            testFunc
            .ShouldNotThrow()
            .ShouldBeNull();
        }