Exemple #1
0
        public void UseResponseStringOverload_WithInvalidData_ShouldThrow(string response,
                                                                          ResponseContentType contentType,
                                                                          int codePage,
                                                                          Type expectedException)
        {
            Encoding encoding   = Encoding.GetEncoding(codePage);
            var      builder    = new MiddlewareOptionsBuilder(_dirMapperSvc);
            Action   testAction = () =>
            {
                builder.UseResponse(response, contentType, encoding);
            };


            testAction.ShouldThrow(expectedException);
        }
Exemple #2
0
        public void MiddlewareOptionsBuilder_WhenDuplicateResponseOptionIsSet_GetOptionShouldThrow()
        {
            MiddlewareOptionsBuilder builder = new MiddlewareOptionsBuilder(_dirMapperSvc);

            builder.UseNoDefaultValues();
            builder.UseDefaultResponse();
            builder.UseResponse(Encoding.UTF8.GetBytes("test"), ResponseContentType.Text, Encoding.UTF8);

            Action testAction = () =>
            {
                builder.GetOptions();
            };

            testAction.ShouldThrow <ArgumentException>()
            .Message.ShouldStartWith("More than one response");
        }
Exemple #3
0
        public void UseResponseStringOverload_WithValidData_ValueShouldEqualInput(string response,
                                                                                  ResponseContentType contentType,
                                                                                  int codePage)
        {
            Encoding encoding = Encoding.GetEncoding(codePage);
            var      builder  = new MiddlewareOptionsBuilder(_dirMapperSvc);


            builder.UseResponse(response, contentType, encoding);


            var option = builder
                         .GetOptions()
                         .GetSingleOrDefault <ResponseOption>();

            option.Value.ShouldNotBeNull();
            option.Value.ContentBytes.ShouldBe(encoding.GetBytes(response));
            option.Value.ContentType.ShouldBe(contentType);
            option.Value.ContentEncoding.ShouldBe(encoding);
        }