Skip to content

Commit cd2cceb

Browse files
committed
Broken tests fix, client documentation tweaks
1 parent eccdd90 commit cd2cceb

File tree

11 files changed

+192
-99
lines changed

11 files changed

+192
-99
lines changed

.build/VersionAssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
[assembly: System.Reflection.AssemblyVersion("0.5.37.45")]
1+
[assembly: System.Reflection.AssemblyVersion("0.5.38.48")]

URSA.Core.Tests/app.config

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<configuration>
22
<configSections>
33
<sectionGroup name="ursa">
4-
<section name="core" type="URSA.Configuration.UrsaConfigurationSection, URSA" />
4+
<section name="core" type="URSA.Configuration.UrsaConfigurationSection, URSA.Core" />
55
</sectionGroup>
66
</configSections>
77
<ursa>
88
<core installerAssemblyNameMask="URSA*"
99
serviceProviderType="URSA.ComponentModel.WindsorComponentProvider, URSA.CastleWindsor"
10-
converterProviderType="URSA.Web.Converters.DefaultConverterProvider, URSA" />
10+
converterProviderType="URSA.Web.Converters.DefaultConverterProvider, URSA.Core" />
1111
</ursa>
1212
</configuration>

URSA.Example.WebApplication/Web.config

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
<configSections>
44
<section name="romanticWeb" type="RomanticWeb.Configuration.ConfigurationSectionHandler, RomanticWeb" />
55
<sectionGroup name="ursa">
6-
<section name="core" type="URSA.Configuration.UrsaConfigurationSection, URSA" />
6+
<section name="core" type="URSA.Configuration.UrsaConfigurationSection, URSA.Core" />
77
<section name="description" type="URSA.Configuration.DescriptionConfigurationSection, URSA.Http.Description" />
88
</sectionGroup>
99
</configSections>
1010
<ursa>
11-
<core installerAssemblyNameMask="URSA*" serviceProviderType="URSA.ComponentModel.WindsorComponentProvider, URSA.CastleWindsor" converterProviderType="URSA.Web.Converters.DefaultConverterProvider, URSA" />
11+
<core installerAssemblyNameMask="URSA*" serviceProviderType="URSA.ComponentModel.WindsorComponentProvider, URSA.CastleWindsor" converterProviderType="URSA.Web.Converters.DefaultConverterProvider, URSA.Core" />
1212
<description typeDescriptionBuilderType="URSA.Web.Http.Description.HydraCompliantTypeDescriptionBuilder, URSA.Http.Description" />
1313
</ursa>
1414
<romanticWeb>

URSA.Http.Description.Tests/Given_instance_of_the/ApiDescriptionBuilder_class.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ private static IXmlDocProvider SetupXmlDocProvider()
134134
{
135135
var xmlDocProvider = new Mock<IXmlDocProvider>(MockBehavior.Strict);
136136
xmlDocProvider.Setup(instance => instance.GetDescription(It.IsAny<MethodInfo>())).Returns<MethodInfo>(method => method.Name);
137+
xmlDocProvider.Setup(instance => instance.GetDescription(It.IsAny<MethodInfo>(), It.IsAny<ParameterInfo>())).Returns<MethodInfo, ParameterInfo>((method, parameter) => parameter.Name);
137138
xmlDocProvider.Setup(instance => instance.GetDescription(It.IsAny<PropertyInfo>())).Returns<PropertyInfo>(property => property.Name);
138139
xmlDocProvider.Setup(instance => instance.GetDescription(It.IsAny<Type>())).Returns<Type>(type => type.Name);
139140
return xmlDocProvider.Object;
@@ -237,6 +238,7 @@ private static IIriTemplateMapping CreateIriTemplateMapping(EntityId id)
237238
var result = new Mock<IIriTemplateMapping>(MockBehavior.Strict);
238239
result.SetupGet(instance => instance.Id).Returns(id);
239240
result.SetupSet(instance => instance.Variable = It.IsAny<string>());
241+
result.SetupSet(instance => instance.Description = It.IsAny<string>());
240242
result.SetupSet(instance => instance.Required = It.IsAny<bool>());
241243
result.SetupSet(instance => instance.Property = It.IsAny<IProperty>());
242244
return result.Object;

URSA.Http.Description.Tests/Given_instance_of_the/XmlDocProvider_class.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,16 @@ public void it_should_extract_method_description()
3939
description.Should().Be("Creates the specified person which id is returned when created.");
4040
}
4141

42+
[TestMethod]
43+
public void it_should_extract_method_parameter_description()
44+
{
45+
var method = typeof(TestController).GetMethod("Create");
46+
47+
var description = _provider.GetDescription(method, method.GetParameters()[1]);
48+
49+
description.Should().Be("The person.");
50+
}
51+
4252
[TestInitialize]
4353
public void Setup()
4454
{

URSA.Http.Description/ApiDescriptionBuilder.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,8 @@ private IOperation BuildOperation(DescriptionContext context, OperationInfo<Verb
193193
template = BuildTemplate(context, operation, result);
194194
bool isRdfRequired;
195195
bool requiresRdf = false;
196-
IEnumerable<ParameterInfo> arguments = operation.Arguments.Where(parameter => parameter.Source is FromBodyAttribute).Select(parameter => parameter.Parameter);
197-
IEnumerable<ParameterInfo> results = operation.Results.Where(output => output.Target is ToBodyAttribute).Select(parameter => parameter.Parameter);
196+
var arguments = operation.Arguments.Where(parameter => parameter.Source is FromBodyAttribute).Select(parameter => parameter.Parameter);
197+
var results = operation.Results.Where(output => output.Target is ToBodyAttribute).Select(parameter => parameter.Parameter);
198198
if (operation.IsWriteControllerOperation())
199199
{
200200
arguments = (operation.UnderlyingMethod.GetParameters().Length > 1 ? new[] { operation.UnderlyingMethod.GetParameters()[1] } : new ParameterInfo[0]);
@@ -231,7 +231,7 @@ private IIriTemplate BuildTemplate(DescriptionContext context, OperationInfo<Ver
231231

232232
IIriTemplate template = null;
233233
var templateUri = operationDocumentation.Id.Uri.AddFragment("template");
234-
var templateMappings = from mapping in parameterMapping where !(mapping.Source is FromBodyAttribute) select BuildTemplateMapping(context, templateUri, mapping);
234+
var templateMappings = from mapping in parameterMapping where !(mapping.Source is FromBodyAttribute) select BuildTemplateMapping(context, templateUri, operation, mapping);
235235
foreach (var templateMapping in templateMappings)
236236
{
237237
if (template == null)
@@ -246,11 +246,12 @@ private IIriTemplate BuildTemplate(DescriptionContext context, OperationInfo<Ver
246246
return template;
247247
}
248248

249-
private IIriTemplateMapping BuildTemplateMapping(DescriptionContext context, Uri templateUri, ArgumentInfo mapping)
249+
private IIriTemplateMapping BuildTemplateMapping(DescriptionContext context, Uri templateUri, OperationInfo<Verb> operation, ArgumentInfo mapping)
250250
{
251251
IIriTemplateMapping templateMapping = context.ApiDocumentation.Context.Create<IIriTemplateMapping>(templateUri.AddFragment(mapping.VariableName));
252252
templateMapping.Variable = mapping.VariableName;
253253
templateMapping.Required = mapping.Parameter.ParameterType.IsValueType;
254+
templateMapping.Description = _xmlDocProvider.GetDescription(operation.UnderlyingMethod, mapping.Parameter);
254255
var linqBehaviors = mapping.Parameter.GetCustomAttributes<LinqServerBehaviorAttribute>(true);
255256
if (linqBehaviors.Any())
256257
{

URSA.Http.Description/IXmlDocProvider.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,23 @@ namespace URSA.Web.Http.Description
66
/// <summary>Provides a contract for XML documentation provider.</summary>
77
public interface IXmlDocProvider
88
{
9-
/// <summary>Gets the type description.</summary>
9+
/// <summary>Gets the type description of the type.</summary>
1010
/// <param name="type">Type to get description for.</param>
1111
/// <returns>Description of the given <paramref name="type" />.</returns>
1212
string GetDescription(Type type);
1313

14-
/// <summary>Gets the type description.</summary>
15-
/// <param name="method">odMeth to get description for.</param>
14+
/// <summary>Gets the type description of the method.</summary>
15+
/// <param name="method">Method to get description for.</param>
1616
/// <returns>Description of the given <paramref name="method" />.</returns>
1717
string GetDescription(MethodInfo method);
1818

19-
/// <summary>Gets the type description.</summary>
19+
/// <summary>Gets the type description of the method parameter.</summary>
20+
/// <param name="method">Parameter owning method.</param>
21+
/// <param name="parameter">Parameter for which to obtain the description.</param>
22+
/// <returns>Description of the given <paramref name="parameter" />.</returns>
23+
string GetDescription(MethodInfo method, ParameterInfo parameter);
24+
25+
/// <summary>Gets the type description of the property.</summary>
2026
/// <param name="property">Property to get description for.</param>
2127
/// <returns>Description of the given <paramref name="property" />.</returns>
2228
string GetDescription(PropertyInfo property);

URSA.Http.Description/XmlDocProvider.cs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ namespace URSA.Web.Http.Description
1212
public class XmlDocProvider : IXmlDocProvider
1313
{
1414
private static readonly IDictionary<Assembly, XDocument> AssemblyCache = new ConcurrentDictionary<Assembly, XDocument>();
15+
private static readonly Func<XElement, bool> DefaultAuxPredicate = element => element.Name == "summary";
1516

1617
/// <inheritdoc />
1718
public string GetDescription(Type type)
@@ -39,6 +40,26 @@ public string GetDescription(MethodInfo method)
3940
element => (element.Attribute("name") != null) && (element.Attribute("name").Value == CreateMemberName(method)));
4041
}
4142

43+
/// <inheritdoc />
44+
public string GetDescription(MethodInfo method, ParameterInfo parameter)
45+
{
46+
if (method == null)
47+
{
48+
throw new ArgumentNullException("method");
49+
}
50+
51+
if (parameter == null)
52+
{
53+
throw new ArgumentNullException("parameter");
54+
}
55+
56+
EnsureAssemblyDocumentation(method.DeclaringType.Assembly);
57+
return GetText(
58+
AssemblyCache[method.DeclaringType.Assembly],
59+
element => (element.Attribute("name") != null) && (element.Attribute("name").Value == CreateMemberName(method)),
60+
element => (element.Name.LocalName == "param") && (element.Attribute("name") != null) && (element.Attribute("name").Value == parameter.Name));
61+
}
62+
4263
/// <inheritdoc />
4364
public string GetDescription(PropertyInfo property)
4465
{
@@ -87,12 +108,12 @@ private static string CreateMemberName(MemberInfo member)
87108
return null;
88109
}
89110

90-
private static string GetText(XDocument document, Func<XElement, bool> predicate)
111+
private static string GetText(XDocument document, Func<XElement, bool> predicate, Func<XElement, bool> auxPredicate = null)
91112
{
92113
var element = document.Descendants("member").Where(predicate).FirstOrDefault();
93114
if (element != null)
94115
{
95-
element = element.Descendants("summary").FirstOrDefault();
116+
element = element.Descendants().Where(auxPredicate ?? DefaultAuxPredicate).FirstOrDefault();
96117
}
97118

98119
return (element == null ? null : GetText(element).Trim('\r', '\n', '\t', ' '));

URSA.Http.Tests/app.config

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<configuration>
22
<configSections>
33
<sectionGroup name="ursa">
4-
<section name="core" type="URSA.Configuration.UrsaConfigurationSection, URSA" />
4+
<section name="core" type="URSA.Configuration.UrsaConfigurationSection, URSA.Core" />
55
</sectionGroup>
66
</configSections>
77
<ursa>
88
<core installerAssemblyNameMask="URSA*"
99
serviceProviderType="URSA.ComponentModel.WindsorComponentProvider, URSA.CastleWindsor"
10-
converterProviderType="URSA.Web.Converters.DefaultConverterProvider, URSA" />
10+
converterProviderType="URSA.Web.Converters.DefaultConverterProvider, URSA.Core" />
1111
</ursa>
1212
</configuration>

0 commit comments

Comments
 (0)