Skip to content

Commit 24070af

Browse files
committed
api tests, content binder updates
1 parent 75f5043 commit 24070af

18 files changed

+65
-85
lines changed

src/NetCoreStack.Proxy/Binders/HttpDeleteContentBinder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public class HttpDeleteContentBinder : ContentModelBinder
1111

1212
public override void BindContent(ContentModelBindingContext bindingContext)
1313
{
14-
ModelDictionaryResult result = bindingContext.GetResolvedContentResult();
14+
ModelDictionaryResult result = bindingContext.ModelContentResolver.Resolve(bindingContext.Parameters, bindingContext.Args);
1515
List<string> keys = result.Dictionary.Keys.ToList();
1616
EnsureTemplate(bindingContext.MethodMarkerTemplate, bindingContext.UriDefinition, result.Dictionary, keys);
1717

src/NetCoreStack.Proxy/Binders/HttpGetContentBinder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public class HttpGetContentBinder : ContentModelBinder
1111

1212
public override void BindContent(ContentModelBindingContext bindingContext)
1313
{
14-
ModelDictionaryResult result = bindingContext.GetResolvedContentResult();
14+
ModelDictionaryResult result = bindingContext.ModelContentResolver.Resolve(bindingContext.Parameters, bindingContext.Args);
1515
List<string> keys = result.Dictionary.Keys.ToList();
1616
EnsureTemplate(bindingContext.MethodMarkerTemplate, bindingContext.UriDefinition, result.Dictionary, keys);
1717

src/NetCoreStack.Proxy/Binders/HttpPostContentBinder.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using NetCoreStack.Proxy.Extensions;
2-
using System.Net.Http;
1+
using System.Net.Http;
32

43
namespace NetCoreStack.Proxy
54
{
@@ -12,7 +11,7 @@ public override void BindContent(ContentModelBindingContext bindingContext)
1211
var isMultiPartFormData = bindingContext.IsMultiPartFormData;
1312
if (isMultiPartFormData)
1413
{
15-
ModelDictionaryResult result = bindingContext.GetResolvedContentResult();
14+
ModelDictionaryResult result = bindingContext.ModelContentResolver.Resolve(bindingContext.Parameters, bindingContext.Args);
1615
var content = GetMultipartFormDataContent(result);
1716
bindingContext.ContentResult = ContentModelBindingResult.Success(content);
1817
return;

src/NetCoreStack.Proxy/Binders/HttpPutContentBinder.cs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using NetCoreStack.Proxy.Extensions;
2-
using System.Collections.Generic;
1+
using System.Collections.Generic;
32
using System.Linq;
43
using System.Net.Http;
54

@@ -12,18 +11,25 @@ public class HttpPutContentBinder : BodyContentBinder
1211
public override void BindContent(ContentModelBindingContext bindingContext)
1312
{
1413
var isMultiPartFormData = bindingContext.IsMultiPartFormData;
15-
var templateKeys = bindingContext.UriDefinition.TemplateKeys;
16-
17-
// bindingContext.Parameters.Select(p => p.PropertyName);
18-
19-
//if (bindingContext.ArgsLength == 1)
14+
//var templateParameterKeys = bindingContext.UriDefinition.TemplateParameterKeys;
15+
//List<ProxyModelMetadata> modelMetadataKeyList = new List<ProxyModelMetadata>();
16+
//int parameterOffset = 0;
17+
//foreach (var key in templateParameterKeys)
2018
//{
21-
19+
// // Key template must be top level object property or parameter
20+
// ProxyModelMetadata keyModelMetadata = bindingContext.Parameters.FirstOrDefault(p => p.PropertyName == key);
21+
// if (keyModelMetadata != null)
22+
// {
23+
// modelMetadataKeyList.Add(keyModelMetadata);
24+
// bindingContext.Parameters.Remove(keyModelMetadata);
25+
// parameterOffset++;
26+
// }
2227
//}
2328

24-
ModelDictionaryResult result = bindingContext.GetResolvedContentResult();
29+
ModelDictionaryResult result = bindingContext.ModelContentResolver.Resolve(bindingContext.Parameters, bindingContext.Args);
2530
List<string> keys = result.Dictionary.Keys.ToList();
2631
EnsureTemplate(bindingContext.MethodMarkerTemplate, bindingContext.UriDefinition, result.Dictionary, keys);
32+
2733
if (isMultiPartFormData)
2834
{
2935
var content = GetMultipartFormDataContent(result);

src/NetCoreStack.Proxy/DefaultContentModelBinder.cs

Lines changed: 0 additions & 10 deletions
This file was deleted.

src/NetCoreStack.Proxy/DefaultModelContentResolver.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System;
33
using System.Collections;
44
using System.Collections.Generic;
5+
using System.Linq;
56
using System.Reflection;
67

78
namespace NetCoreStack.Proxy
@@ -227,7 +228,7 @@ public ModelDictionaryResult Resolve(List<ProxyModelMetadata> parameters, object
227228
{
228229
var result = new ModelDictionaryResult(new Dictionary<string, string>(StringComparer.Ordinal),
229230
new Dictionary<string, IFormFile>(StringComparer.Ordinal));
230-
231+
231232
for (int i = 0; i < parameters.Count; i++)
232233
{
233234
var modelMetadata = parameters[i];

src/NetCoreStack.Proxy/Extensions/ContentModelBindingContextExtensions.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,6 @@ namespace NetCoreStack.Proxy.Extensions
66
{
77
public static class ContentModelBindingContextExtensions
88
{
9-
public static ModelDictionaryResult GetResolvedContentResult(this ContentModelBindingContext bindingContext)
10-
{
11-
return bindingContext.ModelContentResolver.Resolve(bindingContext.Parameters, bindingContext.Args);
12-
}
13-
149
public static void TrySetContent(this ContentModelBindingContext bindingContext, HttpRequestMessage httpRequest)
1510
{
1611
if (bindingContext.ContentResult != null && bindingContext.ContentResult.IsContentSet)

src/NetCoreStack.Proxy/Interfaces/IModelContentResolver.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ public interface IModelContentResolver
66
{
77
ModelDictionaryResult Resolve(List<ProxyModelMetadata> parameters, object[] args);
88
}
9-
}
9+
}

src/NetCoreStack.Proxy/Types/ProxyModelMetadata.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public class ProxyModelMetadata: IEquatable<ProxyModelMetadata>
4545

4646
public bool IsReferenceOrNullableType { get; private set; }
4747

48-
public IReadOnlyList<ProxyModelMetadata> Properties { get; private set; }
48+
public IList<ProxyModelMetadata> Properties { get; private set; }
4949

5050
public int PropertiesCount => Properties.Count;
5151

src/NetCoreStack.Proxy/Types/ProxyUriDefinition.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,15 @@ public class ProxyUriDefinition
1616

1717
public List<string> TemplateKeys { get; private set; }
1818

19+
public List<string> TemplateParameterKeys { get; private set; }
20+
1921
public List<TemplatePart> ParameterParts { get; private set; }
2022

2123
public ProxyUriDefinition(UriBuilder uriBuilder)
2224
{
2325
UriBuilder = uriBuilder;
2426
TemplateKeys = new List<string>();
27+
TemplateParameterKeys = new List<string>();
2528
}
2629

2730
public void ResolveTemplate(RouteTemplate routeTemplate, string route, string template)
@@ -45,6 +48,10 @@ public void ResolveTemplate(RouteTemplate routeTemplate, string route, string te
4548
.SelectMany(s => s.Parts.Where(p => p.IsLiteral)
4649
.Select(t => t.Text)).ToList();
4750

51+
TemplateParameterKeys = routeTemplate.Segments
52+
.SelectMany(s => s.Parts.Where(p => p.IsParameter)
53+
.Select(t => t.Name)).ToList();
54+
4855
tmpl = string.Join("/", TemplateKeys);
4956
TemplateCache.Add(key, tmpl);
5057

0 commit comments

Comments
 (0)