Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Testing for swagger parameter creation
- Loading branch information
Showing
6 changed files
with
208 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using System.ComponentModel; | ||
using System.ComponentModel.DataAnnotations; | ||
using FubuMVC.Core; | ||
using FubuMVC.Swagger.Specification; | ||
|
||
namespace FubuMVC.Swagger.Tests | ||
{ | ||
[Description("An api description")] | ||
public class ActionRequest | ||
{ | ||
[RouteInput, Description("Namey name name"), Required] | ||
public string input { get; set; } | ||
|
||
[QueryString, Description("Queryee query")] | ||
public string query { get; set; } | ||
|
||
[Description("Fishy fish")] | ||
[AllowableValues("value1", "value2")] | ||
[DefaultValue("value1")] | ||
public string redfish { get; set; } | ||
|
||
[Required] | ||
public bool required { get; set; } | ||
|
||
public bool notrequired { get; set; } | ||
} | ||
|
||
public class Action1 | ||
{ | ||
public void Execute(ActionRequest request) | ||
{ | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
using System.Linq; | ||
using System.Reflection; | ||
using FubuCore.Reflection; | ||
using FubuMVC.Core.Registration; | ||
using FubuMVC.Core.Registration.Routes; | ||
using FubuMVC.Swagger.Specification; | ||
using NUnit.Framework; | ||
|
||
namespace FubuMVC.Swagger.Tests | ||
{ | ||
[TestFixture] | ||
public class when_creating_parameters | ||
{ | ||
private Parameter _result; | ||
private PropertyInfo _property; | ||
private IRouteDefinition _route; | ||
|
||
[SetUp] | ||
public void Given() | ||
{ | ||
var graph = new BehaviorGraph(); | ||
var chain = graph.AddActionFor("api/action1/{input}/", typeof (Action1)); | ||
|
||
_route = chain.Route; | ||
_property = ReflectionHelper.GetProperty<ActionRequest>(a => a.redfish); | ||
|
||
_result = ActionCallMapper.createParameter(_property, _route); | ||
} | ||
|
||
[Test] | ||
public void allow_multiple_should_be_false() | ||
{ | ||
_result.allowMultiple.ShouldBeFalse(); | ||
} | ||
|
||
[Test] | ||
public void parameter_name_should_match_property() | ||
{ | ||
_result.name.ShouldEqual(_property.Name); | ||
} | ||
|
||
[Test] | ||
public void data_type_should_match_property() | ||
{ | ||
_result.dataType.ShouldEqual(_property.PropertyType.Name); | ||
} | ||
|
||
[Test] | ||
public void description_should_match_annotation() | ||
{ | ||
_result.description.ShouldEqual(_property.GetAttribute<System.ComponentModel.DescriptionAttribute>().Description); | ||
} | ||
|
||
[Test] | ||
public void default_value_should_match_annotation() | ||
{ | ||
_result.defaultValue.ShouldEqual(_property.GetAttribute<System.ComponentModel.DefaultValueAttribute>().Value); | ||
} | ||
|
||
[Test] | ||
public void allowable_value_should_match_annotation() | ||
{ | ||
var allowableValues = _result.allowableValues; | ||
allowableValues.valueType.ShouldEqual("LIST"); | ||
|
||
var values = allowableValues.values; | ||
values.Count().ShouldEqual(2); | ||
values[0].ShouldEqual("value1"); | ||
values[1].ShouldEqual("value2"); | ||
} | ||
|
||
[Test] | ||
public void required_should_be_false_when_not_annotated() | ||
{ | ||
_result.required.ShouldBeFalse(); | ||
} | ||
|
||
[Test] | ||
public void required_should_be_pulled_from_data_annotation() | ||
{ | ||
_property = ReflectionHelper.GetProperty<ActionRequest>(a => a.required); | ||
|
||
var result = ActionCallMapper.createParameter(_property, _route); | ||
|
||
result.required.ShouldBeTrue(); | ||
} | ||
|
||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
src/FubuMVC.Swagger.Tests/when_creating_parameters_paramTypes.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
using FubuCore.Reflection; | ||
using FubuMVC.Core.Registration; | ||
using FubuMVC.Core.Registration.Routes; | ||
using NUnit.Framework; | ||
|
||
namespace FubuMVC.Swagger.Tests | ||
{ | ||
[TestFixture] | ||
public class when_creating_parameters_paramTypes | ||
{ | ||
private IRouteDefinition _route; | ||
|
||
[SetUp] | ||
public void Given() | ||
{ | ||
var graph = new BehaviorGraph(); | ||
var chain = graph.AddActionFor("api/action1/{input}/", typeof(Action1)); | ||
|
||
_route = chain.Route; | ||
} | ||
|
||
[Test] | ||
public void for_route_input_should_have_paramType_path() | ||
{ | ||
var property = ReflectionHelper.GetProperty<ActionRequest>(a => a.input); | ||
|
||
var result = ActionCallMapper.createParameter(property, _route); | ||
|
||
result.paramType.ShouldEqual("path"); | ||
} | ||
|
||
[Test] | ||
public void for_querystring_input_should_have_paramType_query() | ||
{ | ||
var property = ReflectionHelper.GetProperty<ActionRequest>(a => a.query); | ||
|
||
var result = ActionCallMapper.createParameter(property, _route); | ||
|
||
result.paramType.ShouldEqual("query"); | ||
} | ||
|
||
[Test] | ||
public void for_normal_input_property_should_have_paramType_post() | ||
{ | ||
var property = ReflectionHelper.GetProperty<ActionRequest>(a => a.redfish); | ||
|
||
var result = ActionCallMapper.createParameter(property, _route); | ||
|
||
result.paramType.ShouldEqual("post"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters