diff --git a/src/core/AutoRest.Core.TestGen.Tests/AutoRest.Core.TestGen.Tests.xproj b/src/core/AutoRest.Core.TestGen.Tests/AutoRest.Core.TestGen.Tests.xproj index c3470c39f0..23159e9e31 100644 --- a/src/core/AutoRest.Core.TestGen.Tests/AutoRest.Core.TestGen.Tests.xproj +++ b/src/core/AutoRest.Core.TestGen.Tests/AutoRest.Core.TestGen.Tests.xproj @@ -4,7 +4,6 @@ 14.0 $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - 15c24e56-21aa-4dcb-ab6c-36bc4e93f24a @@ -13,9 +12,11 @@ .\bin\ v4.5.2 - 2.0 + + + - + \ No newline at end of file diff --git a/src/core/AutoRest.Core.TestGen.Tests/Properties/AssemblyInfo.cs b/src/core/AutoRest.Core.TestGen.Tests/Properties/AssemblyInfo.cs index 320d24534c..ed32931b9c 100644 --- a/src/core/AutoRest.Core.TestGen.Tests/Properties/AssemblyInfo.cs +++ b/src/core/AutoRest.Core.TestGen.Tests/Properties/AssemblyInfo.cs @@ -1,5 +1,4 @@ using System.Reflection; -using System.Runtime.CompilerServices; using System.Runtime.InteropServices; // General Information about an assembly is controlled through the following diff --git a/src/core/AutoRest.Core.TestGen.Tests/SampleTest.cs b/src/core/AutoRest.Core.TestGen.Tests/SampleTest.cs new file mode 100644 index 0000000000..dc49b40653 --- /dev/null +++ b/src/core/AutoRest.Core.TestGen.Tests/SampleTest.cs @@ -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 + { + { + "200", + new + { + headers = new Dictionary + { + { "Content-Type", "application/json" } + } + } + } + } + }; + + var sampleSourceStr = JObject.FromObject(sampleSource).ToString(); + var x = JsonConvert.DeserializeObject(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"); + } + } +} diff --git a/src/core/AutoRest.Core.TestGen.Tests/project.json b/src/core/AutoRest.Core.TestGen.Tests/project.json index 8ab6b75dc3..f6ef47bd4d 100644 --- a/src/core/AutoRest.Core.TestGen.Tests/project.json +++ b/src/core/AutoRest.Core.TestGen.Tests/project.json @@ -29,6 +29,10 @@ "dependencies": { "xunit": "2.2.0-beta2-build3300", "dotnet-test-xunit": "2.2.0-preview2-build1029", + "AutoRest.Swagger": { + "target": "project", + "type": "build" + }, "AutoRest.Core.TestGen": { "target": "project", "type": "build" diff --git a/src/core/AutoRest.Core.TestGen/Response.cs b/src/core/AutoRest.Core.TestGen/Response.cs new file mode 100644 index 0000000000..1436396e0f --- /dev/null +++ b/src/core/AutoRest.Core.TestGen/Response.cs @@ -0,0 +1,12 @@ +using Newtonsoft.Json.Linq; +using System.Collections.Generic; + +namespace AutoRest.Core.TestGen +{ + public sealed class Response + { + public Dictionary Headers { get; set; } + + public JToken Body { get; set; } + } +} diff --git a/src/core/AutoRest.Core.TestGen/Sample.cs b/src/core/AutoRest.Core.TestGen/Sample.cs index 54b4d452d2..1085967e98 100644 --- a/src/core/AutoRest.Core.TestGen/Sample.cs +++ b/src/core/AutoRest.Core.TestGen/Sample.cs @@ -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 Parameters { get; set; } + + public Dictionary 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(fileSystem.ReadFileAsText(fileName), Settings); } } diff --git a/src/core/AutoRest.Core.TestGen/project.json b/src/core/AutoRest.Core.TestGen/project.json index 38cb879509..2a370f579f 100644 --- a/src/core/AutoRest.Core.TestGen/project.json +++ b/src/core/AutoRest.Core.TestGen/project.json @@ -22,6 +22,10 @@ "dependencies": { "Newtonsoft.Json": "[9.0.1,10.0)", - "YamlDotNet.Signed": "3.8.0" + "YamlDotNet.Signed": "3.8.0", + "AutoRest.Swagger": { + "target": "project", + "type": "build" + } } } diff --git a/src/core/AutoRest.Core/Utilities/MemoryFileSystem.cs b/src/core/AutoRest.Core/Utilities/MemoryFileSystem.cs index ede4c5e80a..e3fbf5f854 100644 --- a/src/core/AutoRest.Core/Utilities/MemoryFileSystem.cs +++ b/src/core/AutoRest.Core/Utilities/MemoryFileSystem.cs @@ -18,21 +18,14 @@ public class MemoryFileSystem : IFileSystem, IDisposable { private const string FolderKey = "Folder"; - private Dictionary _virtualStore = + public Dictionary VirtualStore { get; } = new Dictionary(); - public Dictionary VirtualStore - { - get { return _virtualStore; } - } - public bool IsCompletePath(string path) => Uri.IsWellFormedUriString(path, UriKind.Relative); public string MakePathRooted(Uri rootPath, string relativePath) - { - return (new Uri(Path.Combine(rootPath.ToString(), relativePath).ToString(), UriKind.Relative)).ToString(); - } + => (new Uri(Path.Combine(rootPath.ToString(), relativePath).ToString(), UriKind.Relative)).ToString(); public Uri GetParentDir(string path) { @@ -98,9 +91,7 @@ public TextWriter GetTextWriter(string path) } public bool FileExists(string path) - { - return VirtualStore.ContainsKey(path); - } + => VirtualStore.ContainsKey(path); public void DeleteFile(string path) { @@ -222,15 +213,11 @@ protected virtual void Dispose(bool disposing) { if (disposing) { - _virtualStore?.Clear(); + VirtualStore?.Clear(); } } + public string CurrentDirectory - { - get - { - return ""; - } - } + => ""; } } diff --git a/src/modeler/AutoRest.Swagger/SwaggerParser.cs b/src/modeler/AutoRest.Swagger/SwaggerParser.cs index e5553e7a20..f0cda943a5 100644 --- a/src/modeler/AutoRest.Swagger/SwaggerParser.cs +++ b/src/modeler/AutoRest.Swagger/SwaggerParser.cs @@ -2,7 +2,6 @@ // Licensed under the MIT License. See License.txt in the project root for license information. using System; -using System.Globalization; using System.Linq; using AutoRest.Core; using AutoRest.Core.Logging;