Пример #1
0
        public void LoadFromString_WithInvalidOrNullValue_ShouldThrow(string input, Type expectedException)
        {
            var    option     = new ResponseFromFileOption();
            Action testAction = () => option.LoadFromString(input);

            testAction.ShouldThrow(expectedException);
        }
Пример #2
0
        public void LoadFromString_WithInvalidRetryTimeout_ShouldThrowArgumentException()
        {
            string input      = "ContentRootPath;file.txt;abc";
            var    option     = new ResponseFromFileOption();
            Action testAction = () => option.LoadFromString(input);

            testAction.ShouldThrow <ArgumentException>();
        }
Пример #3
0
        public void LoadFromString_WithValidInput_StringValueShouldEqualInput()
        {
            const string input  = "ContentRootPath;file.txt;5300";
            var          option = new ResponseFromFileOption();

            option.LoadFromString(input);

            option.GetStringValue().ShouldBe(input);
        }
Пример #4
0
        public void LoadFromString_WithValidInput_ValueShouldNotBeNull()
        {
            const string input  = "ContentRootPath;file.txt;5300";
            var          option = new ResponseFromFileOption();

            option.LoadFromString(input);

            option.Value.ShouldNotBeNull();
        }
Пример #5
0
        public void LoadFromString_WithValidRetryTimeout_RetryTimeoutInValueShouldMatch(string input, int expectedTimeout)
        {
            var option = new ResponseFromFileOption();

            option.LoadFromString(input);

            option.Value.Code503RetryInterval
            .ShouldBe(expectedTimeout);
        }
Пример #6
0
        public void LoadFromString_WithDirrefectLetterCasing_CasingInValueShouldMatchInput(string input, string path, bool shouldBeEqual)
        {
            var option = new ResponseFromFileOption();

            option.LoadFromString(input);

            bool isPathEqual = option.Value.File.Path == path;

            isPathEqual.ShouldBe(shouldBeEqual);
        }
Пример #7
0
        public void LoadFromString_WithVariousEnvDirectory_EnvDirectoryInValueShouldMatchInput(string input, EnvDirectory baseDir, bool shouldBeEqual)
        {
            var option = new ResponseFromFileOption();

            option.LoadFromString(input);

            bool isDirEqual = option.Value.File.BaseDir == baseDir;

            isDirEqual.ShouldBe(shouldBeEqual);
        }
Пример #8
0
        public void LoadFromString_WithValidFileType_ShouldSucceed(string input, string fileName)
        {
            var    option   = new ResponseFromFileOption();
            string filePath = Path.Combine(_webHostEnvironment.ContentRootPath, fileName);

            File.Create(filePath);

            option.LoadFromString(input);

            option.Value.File.Path
            .ShouldEndWith(fileName);
        }
Пример #9
0
        public void ParametrizedConstructor_WithValidParams_ValueShouldEqualParams()
        {
            string       filePath             = "some.txt";
            EnvDirectory baseDir              = EnvDirectory.ContentRootPath;
            int          code503RetryInterval = 2000;

            ResponseFromFileOption opt =
                new ResponseFromFileOption(filePath, baseDir, code503RetryInterval);

            opt.Value.ShouldNotBeNull();
            opt.Value.File.Path.ShouldBe(filePath);
            opt.Value.File.BaseDir.ShouldBe(baseDir);
            opt.Value.Code503RetryInterval.ShouldBe(code503RetryInterval);
        }
Пример #10
0
        public void LoadFromString_WithInvalidFileType_ShouldThrow(string input,
                                                                   string fileName,
                                                                   Type expectedExceptionType)
        {
            var    option   = new ResponseFromFileOption();
            string filePath = Path.Combine(_webHostEnvironment.ContentRootPath, fileName);

            File.Create(filePath);
            Action testAction = () =>
            {
                option.LoadFromString(input);
            };


            testAction.ShouldThrow(expectedExceptionType);
        }
Пример #11
0
        public void UseResponseFile_WithValidData_GetOptionsValueShouldEqualInput(string relativePath,
                                                                                  EnvDirectory baseDir)
        {
            MiddlewareOptionsBuilder builder = new MiddlewareOptionsBuilder(_dirMapperSvc);
            string filePath = Path.Combine(_dirMapperSvc.GetAbsolutePath(baseDir), relativePath);

            File.Create(filePath);

            builder.UseResponseFromFile(relativePath, baseDir);

            ResponseFromFileOption option = builder
                                            .GetOptions()
                                            .GetSingleOrDefault <ResponseFromFileOption>();

            option.Value.ShouldNotBeNull();
            option.Value.File.Path.ShouldBe(relativePath);
            option.Value.File.BaseDir.ShouldBe(baseDir);
        }