-
Notifications
You must be signed in to change notification settings - Fork 742
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from sergey-shandar/testgenlib1
TestGen Library.
- Loading branch information
Showing
9 changed files
with
106 additions
and
28 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
1 change: 0 additions & 1 deletion
1
src/core/AutoRest.Core.TestGen.Tests/Properties/AssemblyInfo.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
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,55 @@ | ||
using AutoRest.Core.Utilities; | ||
using AutoRest.Swagger; | ||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Linq; | ||
using System.Collections.Generic; | ||
using Xunit; | ||
|
||
namespace AutoRest.Core.TestGen.Tests | ||
{ | ||
public sealed class SampleTest | ||
{ | ||
[Fact] | ||
public void SimpleSampleTest() | ||
{ | ||
var fileSystem = new MemoryFileSystem(); | ||
|
||
fileSystem.WriteFile("swagger.json", JObject.FromObject(new { }).ToString()); | ||
var swagger = SwaggerParser.Load("swagger.json", fileSystem); | ||
|
||
var sampleSource = new | ||
{ | ||
title = "Title", | ||
operationId = "Operation", | ||
parameters = new | ||
{ | ||
a = "3", | ||
}, | ||
responses = new Dictionary<string, object> | ||
{ | ||
{ | ||
"200", | ||
new | ||
{ | ||
headers = new Dictionary<string, string> | ||
{ | ||
{ "Content-Type", "application/json" } | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
|
||
var sampleSourceStr = JObject.FromObject(sampleSource).ToString(); | ||
var x = JsonConvert.DeserializeObject<Sample>(sampleSourceStr); | ||
|
||
fileSystem.WriteFile("sample.json", sampleSourceStr); | ||
var simple = Sample.Load("sample.json", fileSystem); | ||
|
||
Assert.Equal(simple.Title, "Title"); | ||
Assert.Equal(simple.OperationId, "Operation"); | ||
Assert.Equal(simple.Parameters["a"], "3"); | ||
Assert.Equal(simple.Responses["200"].Headers["Content-Type"], "application/json"); | ||
} | ||
} | ||
} |
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,12 @@ | ||
using Newtonsoft.Json.Linq; | ||
using System.Collections.Generic; | ||
|
||
namespace AutoRest.Core.TestGen | ||
{ | ||
public sealed class Response | ||
{ | ||
public Dictionary<string, string> Headers { get; set; } | ||
|
||
public JToken Body { get; set; } | ||
} | ||
} |
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 |
---|---|---|
@@ -1,9 +1,26 @@ | ||
namespace AutoRest.Core.TestGen | ||
using AutoRest.Core.Utilities; | ||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Linq; | ||
using System.Collections.Generic; | ||
|
||
namespace AutoRest.Core.TestGen | ||
{ | ||
public sealed class Sample | ||
{ | ||
public string Title { get; } | ||
public string Title { get; set; } | ||
|
||
public string OperationId { get; set; } | ||
|
||
public Dictionary<string, JToken> Parameters { get; set; } | ||
|
||
public Dictionary<string, Response> Responses { get; set; } | ||
|
||
public static readonly JsonSerializerSettings Settings = new JsonSerializerSettings | ||
{ | ||
ContractResolver = new CamelCaseContractResolver() | ||
}; | ||
|
||
public string OerationId { get; } | ||
public static Sample Load(string fileName, IFileSystem fileSystem) | ||
=> JsonConvert.DeserializeObject<Sample>(fileSystem.ReadFileAsText(fileName), Settings); | ||
} | ||
} |
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