add test case, update c# model constructor to remove readonly property

This commit is contained in:
wing328 2016-02-23 19:16:26 +08:00
parent 0520e68e29
commit 82d7c2d780
10 changed files with 83 additions and 29 deletions

View File

@ -23,11 +23,11 @@ namespace {{packageName}}.Model
/// Initializes a new instance of the <see cref="{{classname}}" />class. /// Initializes a new instance of the <see cref="{{classname}}" />class.
/// </summary> /// </summary>
/// <exception cref="System.InvalidDataException">Thrown when required property is null</exception> /// <exception cref="System.InvalidDataException">Thrown when required property is null</exception>
{{#vars}} /// <param name="{{name}}">{{#description}}{{description}}{{/description}}{{^description}}{{name}}{{/description}}{{#required}} (required){{/required}}{{#defaultValue}} (default to {{defaultValue}}){{/defaultValue}}.</param> {{#vars}}{{^isReadOnly}} /// <param name="{{name}}">{{#description}}{{description}}{{/description}}{{^description}}{{name}}{{/description}}{{#required}} (required){{/required}}{{#defaultValue}} (default to {{defaultValue}}){{/defaultValue}}.</param>
{{/vars}} {{/isReadOnly}}{{/vars}}
public {{classname}}({{#vars}}{{{datatype}}} {{name}} = null{{#hasMore}}, {{/hasMore}}{{/vars}}) public {{classname}}({{#vars}}{{^isReadOnly}}{{{datatype}}} {{name}} = null{{#hasMore}}, {{/hasMore}}{{/isReadOnly}}{{/vars}})
{ {
{{#vars}}{{#required}}// to ensure "{{name}}" is required (not null) {{#vars}}{{^isReadOnly}}{{#required}}// to ensure "{{name}}" is required (not null)
if ({{name}} == null) if ({{name}} == null)
{ {
throw new InvalidDataException("{{name}} is a required property for {{classname}} and cannot be null"); throw new InvalidDataException("{{name}} is a required property for {{classname}} and cannot be null");
@ -36,7 +36,7 @@ namespace {{packageName}}.Model
{ {
this.{{name}} = {{name}}; this.{{name}} = {{name}};
} }
{{/required}}{{/vars}}{{#vars}}{{^required}}{{#defaultValue}}// use default value if no "{{name}}" provided {{/required}}{{/isReadOnly}}{{/vars}}{{#vars}}{{^isReadOnly}}{{^required}}{{#defaultValue}}// use default value if no "{{name}}" provided
if ({{name}} == null) if ({{name}} == null)
{ {
this.{{name}} = {{{defaultValue}}}; this.{{name}} = {{{defaultValue}}};
@ -46,7 +46,7 @@ namespace {{packageName}}.Model
this.{{name}} = {{name}}; this.{{name}} = {{name}};
} }
{{/defaultValue}}{{^defaultValue}}this.{{name}} = {{name}}; {{/defaultValue}}{{^defaultValue}}this.{{name}} = {{name}};
{{/defaultValue}}{{/required}}{{/vars}} {{/defaultValue}}{{/required}}{{/isReadOnly}}{{/vars}}
} }
{{#vars}} {{#vars}}

View File

@ -23,6 +23,7 @@ namespace IO.Swagger.Model
/// <exception cref="System.InvalidDataException">Thrown when required property is null</exception> /// <exception cref="System.InvalidDataException">Thrown when required property is null</exception>
/// <param name="Id">Id.</param> /// <param name="Id">Id.</param>
/// <param name="Name">Name.</param> /// <param name="Name">Name.</param>
public Category(long? Id = null, string Name = null) public Category(long? Id = null, string Name = null)
{ {
this.Id = Id; this.Id = Id;

View File

@ -21,15 +21,14 @@ namespace IO.Swagger.Model
/// Initializes a new instance of the <see cref="Order" />class. /// Initializes a new instance of the <see cref="Order" />class.
/// </summary> /// </summary>
/// <exception cref="System.InvalidDataException">Thrown when required property is null</exception> /// <exception cref="System.InvalidDataException">Thrown when required property is null</exception>
/// <param name="Id">Id.</param>
/// <param name="PetId">PetId.</param> /// <param name="PetId">PetId.</param>
/// <param name="Quantity">Quantity.</param> /// <param name="Quantity">Quantity.</param>
/// <param name="ShipDate">ShipDate.</param> /// <param name="ShipDate">ShipDate.</param>
/// <param name="Status">Order Status.</param> /// <param name="Status">Order Status.</param>
/// <param name="Complete">Complete.</param> /// <param name="Complete">Complete.</param>
public Order(long? Id = null, long? PetId = null, int? Quantity = null, DateTime? ShipDate = null, string Status = null, bool? Complete = null)
public Order(long? PetId = null, int? Quantity = null, DateTime? ShipDate = null, string Status = null, bool? Complete = null)
{ {
this.Id = Id;
this.PetId = PetId; this.PetId = PetId;
this.Quantity = Quantity; this.Quantity = Quantity;
this.ShipDate = ShipDate; this.ShipDate = ShipDate;

View File

@ -27,6 +27,7 @@ namespace IO.Swagger.Model
/// <param name="PhotoUrls">PhotoUrls (required).</param> /// <param name="PhotoUrls">PhotoUrls (required).</param>
/// <param name="Tags">Tags.</param> /// <param name="Tags">Tags.</param>
/// <param name="Status">pet status in the store.</param> /// <param name="Status">pet status in the store.</param>
public Pet(long? Id = null, Category Category = null, string Name = null, List<string> PhotoUrls = null, List<Tag> Tags = null, string Status = null) public Pet(long? Id = null, Category Category = null, string Name = null, List<string> PhotoUrls = null, List<Tag> Tags = null, string Status = null)
{ {
// to ensure "Name" is required (not null) // to ensure "Name" is required (not null)

View File

@ -23,6 +23,7 @@ namespace IO.Swagger.Model
/// <exception cref="System.InvalidDataException">Thrown when required property is null</exception> /// <exception cref="System.InvalidDataException">Thrown when required property is null</exception>
/// <param name="Id">Id.</param> /// <param name="Id">Id.</param>
/// <param name="Name">Name.</param> /// <param name="Name">Name.</param>
public Tag(long? Id = null, string Name = null) public Tag(long? Id = null, string Name = null)
{ {
this.Id = Id; this.Id = Id;

View File

@ -29,6 +29,7 @@ namespace IO.Swagger.Model
/// <param name="Password">Password.</param> /// <param name="Password">Password.</param>
/// <param name="Phone">Phone.</param> /// <param name="Phone">Phone.</param>
/// <param name="UserStatus">User Status.</param> /// <param name="UserStatus">User Status.</param>
public User(long? Id = null, string Username = null, string FirstName = null, string LastName = null, string Email = null, string Password = null, string Phone = null, int? UserStatus = null) public User(long? Id = null, string Username = null, string FirstName = null, string LastName = null, string Email = null, string Password = null, string Phone = null, int? UserStatus = null)
{ {
this.Id = Id; this.Id = Id;

View File

@ -58,6 +58,7 @@
<Compile Include="TestApiClient.cs" /> <Compile Include="TestApiClient.cs" />
<Compile Include="TestConfiguration.cs" /> <Compile Include="TestConfiguration.cs" />
<Compile Include="Lib\SwaggerClient\src\main\csharp\IO\Swagger\Client\ApiResponse.cs" /> <Compile Include="Lib\SwaggerClient\src\main\csharp\IO\Swagger\Client\ApiResponse.cs" />
<Compile Include="TestOrder.cs" />
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup> <ItemGroup>

View File

@ -1,18 +1,10 @@
<Properties StartupItem="SwaggerClientTest.csproj"> <Properties StartupItem="SwaggerClientTest.csproj">
<MonoDevelop.Ide.Workspace ActiveConfiguration="Debug" /> <MonoDevelop.Ide.Workspace ActiveConfiguration="Debug" />
<MonoDevelop.Ide.Workbench ActiveDocument="TestPet.cs"> <MonoDevelop.Ide.Workbench ActiveDocument="TestOrder.cs">
<Files> <Files>
<File FileName="TestPet.cs" Line="250" Column="4" /> <File FileName="TestPet.cs" Line="84" Column="10" />
<File FileName="Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Pet.cs" Line="21" Column="64" /> <File FileName="TestOrder.cs" Line="42" Column="12" />
<File FileName="TestConfiguration.cs" Line="1" Column="1" />
</Files> </Files>
<Pads>
<Pad Id="MonoDevelop.NUnit.TestPad">
<State name="__root__">
<Node name="SwaggerClientTest" expanded="True" />
</State>
</Pad>
</Pads>
</MonoDevelop.Ide.Workbench> </MonoDevelop.Ide.Workbench>
<MonoDevelop.Ide.DebuggingService.Breakpoints> <MonoDevelop.Ide.DebuggingService.Breakpoints>
<BreakpointStore /> <BreakpointStore />

View File

@ -0,0 +1,58 @@
using NUnit.Framework;
using System;
using System.Linq;
using System.IO;
using System.Collections.Generic;
using IO.Swagger.Api;
using IO.Swagger.Model;
using IO.Swagger.Client;
using System.Reflection;
using Newtonsoft.Json;
namespace SwaggerClientTest.TestORder
{
[TestFixture ()]
public class TestOrder
{
public TestOrder ()
{
}
/// <summary>
/// Test creating a new instance of Order
/// </summary>
[Test ()]
public void TestNewOrder()
{
Order o = new Order ();
Assert.IsNull (o.Id);
}
/// <summary>
/// Test deserialization of JSON to Order and its readonly property
/// </summary>
[Test ()]
public void TesOrderDeserialization()
{
string json = @"{
'id': 1982,
'petId': 1020,
'quantity': 1,
'status': 'placed',
'complete': true,
}";
var o = JsonConvert.DeserializeObject<Order>(json);
Assert.AreEqual (1982, o.Id);
Assert.AreEqual (1020, o.PetId);
Assert.AreEqual (1, o.Quantity);
Assert.AreEqual ("placed", o.Status);
Assert.AreEqual (true, o.Complete);
}
}
}

View File

@ -1,9 +1,9 @@
/Users/williamcheng/Code/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/.NETFramework,Version=v4.5.AssemblyAttribute.cs /Users/williamcheng/Code/wing328/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/.NETFramework,Version=v4.5.AssemblyAttribute.cs
/Users/williamcheng/Code/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.swagger-logo.png /Users/williamcheng/Code/wing328/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.swagger-logo.png
/Users/williamcheng/Code/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll.mdb /Users/williamcheng/Code/wing328/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll.mdb
/Users/williamcheng/Code/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll /Users/williamcheng/Code/wing328/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll
/Users/williamcheng/Code/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.dll /Users/williamcheng/Code/wing328/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.dll
/Users/williamcheng/Code/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.dll.mdb /Users/williamcheng/Code/wing328/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.dll.mdb
/Users/williamcheng/Code/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/Newtonsoft.Json.dll /Users/williamcheng/Code/wing328/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/Newtonsoft.Json.dll
/Users/williamcheng/Code/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/nunit.framework.dll /Users/williamcheng/Code/wing328/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/nunit.framework.dll
/Users/williamcheng/Code/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/RestSharp.dll /Users/williamcheng/Code/wing328/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/RestSharp.dll