예제 #1
0
 private static string TrimParameter(EndpointParameter model)
 {
     if (model.ItemValue.IsNullOrEmpty())
     {
         return(null);
     }
     return(model.ItemValue.TrimEnd());
 }
예제 #2
0
        public void CanDeserializeStatusCodeParamRef()
        {
            var response = ParseResponse("{'match': {}, 'literal': 'Hello world', 'statuscode': '$s'}");
            var param    = new EndpointParameter {
                Name = "s", DefaultValue = "404"
            };

            endpoint.AddParameter(param);
            Assert.Equal(404, (response.Item2 as SimpleResponseCreator).StatusCode);
            param.Value = "403";
            Assert.Equal(403, (response.Item2 as SimpleResponseCreator).StatusCode);
        }
예제 #3
0
        public void CanDeserializeDelayParamRef()
        {
            var response = ParseResponse("{'match': {}, 'literal': 'Hello world', 'delay': '$delay'}");
            var param    = new EndpointParameter {
                Name = "delay", DefaultValue = "123"
            };

            endpoint.AddParameter(param);
            Assert.Equal(123, response.Item2.Delay);
            param.Value = "321";
            Assert.Equal(321, response.Item2.Delay);
        }
예제 #4
0
        public void ValueAndDefaultWorksAsExpected()
        {
            var ep = new EndpointParameter {
                DefaultValue = "a"
            };

            Assert.Equal("a", ep.Value);
            Assert.True(ep.ValueIsDefault);

            ep.Value = "b";
            Assert.Equal("b", ep.Value);
            Assert.False(ep.ValueIsDefault);
        }
예제 #5
0
        public ActionResult Edit(string id, string item, EndpointParameter model)
        {
            var parameter = reader.GetEnpointParameter(item);

            ViewBag.Trail = parameter.GetTrail();
            if (!parameter.UserHasAccessTo())
            {
                throw new UnauthorizedAccessException("Access denied to configset");
            }
            parameter.ItemValue   = TrimParameter(model);
            parameter.Description = model.Description;
            reader.UpdateEndpointParameter(parameter);
            return(View(parameter));
        }
예제 #6
0
        public EndpointParameter ToViewModel(EndpointParameterPart part)
        {
            var tokenState = new Dictionary <string, object> {
                { "Content", part.ContentItem }
            };

            var viewModel = new EndpointParameter()
            {
                ApiName             = part.ApiName,
                DataType            = part.DataType,
                Description         = _tokenizer.Replace(part.As <BodyPart>().Text, tokenState),
                Example             = _tokenizer.Replace(part.Example, tokenState),
                Required            = part.Required,
                AssociatedEndpoints = GetAssociatedEndpoints(part).Select(ToViewModel)
            };

            return(viewModel);
        }
예제 #7
0
 public CheckParametersUsage()
 {
     endpoint = new Endpoint("foo", "bar")
     {
         Directory = dc.DirectoryName
     };
     filenameParam = new EndpointParameter
     {
         Name         = "filename",
         DefaultValue = "file.txt"
     };
     contenttypeParam = new EndpointParameter
     {
         Name         = "contenttype",
         DefaultValue = "text/plain"
     };
     fooParam = new EndpointParameter
     {
         Name         = "foo",
         DefaultValue = "FOO"
     };
     delayParam = new EndpointParameter
     {
         Name         = "delay",
         DefaultValue = "0"
     };
     statusCodeParam = new EndpointParameter
     {
         Name         = "statuscode",
         DefaultValue = "200"
     };
     endpoint.AddParameter(filenameParam);
     endpoint.AddParameter(contenttypeParam);
     endpoint.AddParameter(fooParam);
     endpoint.AddParameter(delayParam);
     endpoint.AddParameter(statusCodeParam);
 }