Exemplo n.º 1
0
        private void Assert(string expected, Action <IFluentBodyBuilder> factory)
        {
            var builder = new FluentBodyBuilder();

            factory(builder);

            var resultJToken   = builder.Build();
            var expectedJToken = JObject.Parse(expected);

            var envelope = new JObject(new JProperty("body", "{CONTENT}"));

            var body = envelope.Children()
                       .OfType <JProperty>()
                       .First(jp => jp.Name == "body").Value
                       .Value <JValue>();

            body.Replace(resultJToken);

            var result = envelope.ToString(Formatting.Indented);

            _outputHelper.WriteLine($"Expected:\n\n{expected}\n");
            _outputHelper.WriteLine($"Actual:\n\n{result}\n");

            envelope.Should().BeEquivalentTo(expectedJToken);
            //     JsonAssertionExtensions.Should(envelope).BeEquivalentTo(expectedJToken);
        }
        public IFluentHttpRequestBuilder WithContent([NotNull] Action <IFluentBodyBuilder> contentFactory)
        {
            var builder = new FluentBodyBuilder();

            contentFactory(builder);
            _body = builder.Build();
            return(this);
        }
        private static Body CreateBody([NotNull] Action <IFluentBodyBuilder> factory)
        {
            var type    = typeof(FluentBodyBuilder);
            var builder = new FluentBodyBuilder();

            factory(builder);

            var bodyProperty = type.GetProperty("Body", BindingFlags.NonPublic | BindingFlags.Instance);
            var body         = bodyProperty?.GetValue(builder) as Body;

            return(body);
        }
Exemplo n.º 4
0
 internal FluentMethodBuilder(_IFluentTypeBuilder typeBuilder, string name, Type returnType, bool isStatic, int creatorThreadId, int delegateIndex, bool respectVisibility)
 {
     _creatorThreadId   = creatorThreadId;
     _visitor           = new _Visitor(this);
     _returnTarget      = Expression.Label(returnType);
     TypeBuilder        = typeBuilder;
     _body              = new FluentBodyBuilder(this);
     Name               = name;
     ReturnType         = returnType;
     IsStatic           = isStatic;
     _delegateIndex     = delegateIndex;
     _respectVisibility = respectVisibility;
 }
Exemplo n.º 5
0
        /// <summary>
        /// Creates a new method builder.
        /// </summary>
        /// <param name="returnType">The type of the return of the method that will be generated.</param>
        public FluentMethodBuilder(Type returnType)
        {
            if (returnType == null)
            {
                throw new ArgumentNullException("returnType");
            }

            _delegateIndex   = -1;
            _creatorThreadId = Thread.CurrentThread.ManagedThreadId;
            _visitor         = new _Visitor(this);
            _returnTarget    = Expression.Label(returnType);
            _body            = new FluentBodyBuilder(this);
            ReturnType       = returnType;
            IsStatic         = true;
        }
        public IFluentHttpRequestBuilder WithBody(Body.BodyType type, string value)
        {
            var builder = new FluentBodyBuilder();

            switch (type)
            {
            case Body.BodyType.JSON:
                builder.WithExactJson(value);
                break;

            case Body.BodyType.JSON_PATH:
                builder.MatchingJsonPath(value);
                break;

            case Body.BodyType.JSON_SCHEMA:
                builder.MatchingJsonSchema(value);
                break;

            case Body.BodyType.XML:
                builder.WithXmlContent(value);
                break;

            case Body.BodyType.XPATH:
                builder.MatchingXPath(value);
                break;

            case Body.BodyType.XML_SCHEMA:
                builder.MatchingXmlSchema(value);
                break;

            case Body.BodyType.STRING:
                builder.WithExactContent(value);
                break;
            }

            _body = builder.Build();
            return(this);
        }