diff --git a/.travis.yml b/.travis.yml
index ab73003e51f94..51223465035c8 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -24,6 +24,7 @@ install:
- export LD_LIBRARY_PATH=$HOME/.local/lib/:$LD_LIBRARY_PATH
# Install npm
- curl -sSL https://raw.githubusercontent.com/aspnet/Home/dev/dnvminstall.sh | sh && source ~/.dnx/dnvm/dnvm.sh && dnvm upgrade
+ - rm -rf ~/.nvm && git clone https://github.com/creationix/nvm.git ~/.nvm && (cd ~/.nvm && git checkout `git describe --abbrev=0 --tags`) && source ~/.nvm/nvm.sh && nvm install 4
- npm install -g npm@'>=1.4.3'
- npm install
# Install ruby dependencies
@@ -34,7 +35,8 @@ install:
# Install android SDK
- mkdir android
- wget -qO- "http://dl.google.com/android/android-sdk_r23.0.2-linux.tgz" | tar -zxv -C ./android
- - echo y | ./android/android-sdk-linux/tools/android update sdk --all --filter platform-tools,android-23,build-tools-23.0.1,extra-android-support,extra-android-m2repository,extra-google-m2repository --no-ui --force
+ - echo y | ./android/android-sdk-linux/tools/android update sdk --all --filter platform-tools,android-23,build-tools-23.0.1 --no-ui --force
+ - echo y | ./android/android-sdk-linux/tools/android update sdk --all --filter extra-android-support,extra-android-m2repository,extra-google-m2repository --no-ui --force
- export ANDROID_HOME=`pwd`/android/android-sdk-linux
script:
- dnvm install 1.0.0-rc1-final -r mono
@@ -49,4 +51,4 @@ after_script:
- cat TestResults/*.log
notifications:
slack:
- secure: d0PFVLcyqcMxNtmZ8JaEpIBzXbUbZCgKs8QtBB5qEIXDnxflSR3AhczlILNhTBKtMEBlwVzsz65yP09XcmvB6xpAfJbHqSRzk2frKa5viPcAD8Wr/NYamt9/UiTCsnql8MqzjVy0tLdMscXKRmsUey4YF570zl0b7gAbq7XTqxM=
\ No newline at end of file
+ secure: d0PFVLcyqcMxNtmZ8JaEpIBzXbUbZCgKs8QtBB5qEIXDnxflSR3AhczlILNhTBKtMEBlwVzsz65yP09XcmvB6xpAfJbHqSRzk2frKa5viPcAD8Wr/NYamt9/UiTCsnql8MqzjVy0tLdMscXKRmsUey4YF570zl0b7gAbq7XTqxM=
diff --git a/AutoRest.sln b/AutoRest.sln
index f616c9ac420d0..b11b89d798ca5 100644
--- a/AutoRest.sln
+++ b/AutoRest.sln
@@ -118,6 +118,12 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutoRest.Modeler.CompositeS
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutoRest.Modeler.CompositeSwagger.Tests", "AutoRest\Modelers\CompositeSwagger.Tests\AutoRest.Modeler.CompositeSwagger.Tests.csproj", "{DA37E6A9-5D59-45A3-A809-ABA85031C369}"
EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "AzureResourceSchema", "AzureResourceSchema", "{B6A1FC1E-0779-4900-84EE-262DD0E53FF4}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutoRest.Generator.AzureResourceSchema", "AutoRest\Generators\AzureResourceSchema\AzureResourceSchema\AutoRest.Generator.AzureResourceSchema.csproj", "{654344A5-0556-49C7-BFB3-59676D7440D3}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutoRest.Generator.AzureResourceSchema.Tests", "AutoRest\Generators\AzureResourceSchema\AzureResourceSchema.Tests\AutoRest.Generator.AzureResourceSchema.Tests.csproj", "{1C3B4A33-E045-4C8F-9202-1B651A686567}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Net45-Debug|Any CPU = Net45-Debug|Any CPU
@@ -366,6 +372,22 @@ Global
{DA37E6A9-5D59-45A3-A809-ABA85031C369}.Portable-Debug|Any CPU.Build.0 = Portable-Debug|Any CPU
{DA37E6A9-5D59-45A3-A809-ABA85031C369}.Portable-Release|Any CPU.ActiveCfg = Portable-Release|Any CPU
{DA37E6A9-5D59-45A3-A809-ABA85031C369}.Portable-Release|Any CPU.Build.0 = Portable-Release|Any CPU
+ {654344A5-0556-49C7-BFB3-59676D7440D3}.Net45-Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {654344A5-0556-49C7-BFB3-59676D7440D3}.Net45-Debug|Any CPU.Build.0 = Debug|Any CPU
+ {654344A5-0556-49C7-BFB3-59676D7440D3}.Net45-Release|Any CPU.ActiveCfg = Release|Any CPU
+ {654344A5-0556-49C7-BFB3-59676D7440D3}.Net45-Release|Any CPU.Build.0 = Release|Any CPU
+ {654344A5-0556-49C7-BFB3-59676D7440D3}.Portable-Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {654344A5-0556-49C7-BFB3-59676D7440D3}.Portable-Debug|Any CPU.Build.0 = Debug|Any CPU
+ {654344A5-0556-49C7-BFB3-59676D7440D3}.Portable-Release|Any CPU.ActiveCfg = Release|Any CPU
+ {654344A5-0556-49C7-BFB3-59676D7440D3}.Portable-Release|Any CPU.Build.0 = Release|Any CPU
+ {1C3B4A33-E045-4C8F-9202-1B651A686567}.Net45-Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {1C3B4A33-E045-4C8F-9202-1B651A686567}.Net45-Debug|Any CPU.Build.0 = Debug|Any CPU
+ {1C3B4A33-E045-4C8F-9202-1B651A686567}.Net45-Release|Any CPU.ActiveCfg = Release|Any CPU
+ {1C3B4A33-E045-4C8F-9202-1B651A686567}.Net45-Release|Any CPU.Build.0 = Release|Any CPU
+ {1C3B4A33-E045-4C8F-9202-1B651A686567}.Portable-Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {1C3B4A33-E045-4C8F-9202-1B651A686567}.Portable-Debug|Any CPU.Build.0 = Debug|Any CPU
+ {1C3B4A33-E045-4C8F-9202-1B651A686567}.Portable-Release|Any CPU.ActiveCfg = Release|Any CPU
+ {1C3B4A33-E045-4C8F-9202-1B651A686567}.Portable-Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -407,5 +429,8 @@ Global
{74BE0601-FF65-4B46-8A8B-E670056061C4} = {74F7C659-952F-400C-839F-90BED9BB66C3}
{31AEC9B5-35C9-4FEA-8420-4C34D3FEAAC8} = {02144BF6-4489-4AFC-9B2D-0306C3DD3C19}
{DA37E6A9-5D59-45A3-A809-ABA85031C369} = {02144BF6-4489-4AFC-9B2D-0306C3DD3C19}
+ {B6A1FC1E-0779-4900-84EE-262DD0E53FF4} = {EF9E346D-70C6-45F5-8FF9-9B734F4A1298}
+ {654344A5-0556-49C7-BFB3-59676D7440D3} = {B6A1FC1E-0779-4900-84EE-262DD0E53FF4}
+ {1C3B4A33-E045-4C8F-9202-1B651A686567} = {B6A1FC1E-0779-4900-84EE-262DD0E53FF4}
EndGlobalSection
EndGlobal
diff --git a/AutoRest/AutoRest.Core.Tests/CodeGeneratorsTests.cs b/AutoRest/AutoRest.Core.Tests/CodeGeneratorsTests.cs
index c58c81e4e6b0c..8cadb3f6414f4 100644
--- a/AutoRest/AutoRest.Core.Tests/CodeGeneratorsTests.cs
+++ b/AutoRest/AutoRest.Core.Tests/CodeGeneratorsTests.cs
@@ -86,8 +86,11 @@ public void OutputToSingleFile()
};
string path = Path.Combine(settings.OutputDirectory, "test.file.cs");
+ string existingContents = "this is dummy";
+ _fileSystem.VirtualStore[path] = new StringBuilder(existingContents);
var codeGenerator = new SampleCodeGenerator(settings);
codeGenerator.Generate(new ServiceClient()).GetAwaiter().GetResult();
+ Assert.DoesNotContain(existingContents, _fileSystem.VirtualStore[path].ToString());
Assert.Equal(4, _fileSystem.VirtualStore.Count);
Assert.True(_fileSystem.VirtualStore.ContainsKey(path));
Assert.True(_fileSystem.VirtualStore.ContainsKey("AutoRest.json"));
diff --git a/AutoRest/AutoRest.Core/ClientModel/KnownPrimaryType.cs b/AutoRest/AutoRest.Core/ClientModel/KnownPrimaryType.cs
index 25465a14c18e6..94dd5ffd7b726 100644
--- a/AutoRest/AutoRest.Core/ClientModel/KnownPrimaryType.cs
+++ b/AutoRest/AutoRest.Core/ClientModel/KnownPrimaryType.cs
@@ -24,6 +24,8 @@ public enum KnownPrimaryType
TimeSpan,
Boolean,
Credentials,
- Uuid
+ Uuid,
+ Base64Url,
+ UnixTime
}
}
diff --git a/AutoRest/AutoRest.Core/CodeGenerator.cs b/AutoRest/AutoRest.Core/CodeGenerator.cs
index 8efb1c0311361..57dbecb697346 100644
--- a/AutoRest/AutoRest.Core/CodeGenerator.cs
+++ b/AutoRest/AutoRest.Core/CodeGenerator.cs
@@ -16,6 +16,7 @@ namespace Microsoft.Rest.Generator
public abstract class CodeGenerator
{
public const string EnumObject = "x-ms-enum";
+ private bool firstTimeWriteSingleFile = true;
protected CodeGenerator(Settings settings)
{
@@ -99,7 +100,7 @@ public async Task Write(ITemplate template, string fileName)
///
public async Task Write(string template, string fileName)
{
- string relativeFilePath = null;
+ string filePath = null;
if (Settings.OutputFileName != null)
{
@@ -110,17 +111,19 @@ public async Task Write(string template, string fileName)
ErrorManager.ThrowErrors();
}
- relativeFilePath = Settings.OutputFileName;
+ filePath = Path.Combine(Settings.OutputDirectory, Settings.OutputFileName);
+
+ if (firstTimeWriteSingleFile)
+ {
+ // for SingleFileGeneration clean the file before writing only if its the first time
+ Settings.FileSystem.DeleteFile(filePath);
+ firstTimeWriteSingleFile = false;
+ }
}
else
{
- relativeFilePath = fileName;
- }
- string filePath = Path.Combine(Settings.OutputDirectory, relativeFilePath);
-
- // cleans file before writing unless single file
- if (!(Settings.OutputFileName != null && IsSingleFileGenerationSupported))
- {
+ filePath = Path.Combine(Settings.OutputDirectory, fileName);
+ // cleans file before writing
Settings.FileSystem.DeleteFile(filePath);
}
// Make sure the directory exist
diff --git a/AutoRest/AutoRest.Core/Settings.cs b/AutoRest/AutoRest.Core/Settings.cs
index a014456a63bca..df99585e02d31 100644
--- a/AutoRest/AutoRest.Core/Settings.cs
+++ b/AutoRest/AutoRest.Core/Settings.cs
@@ -157,6 +157,10 @@ public string Header
{
_header = MicrosoftApacheLicenseHeader + Environment.NewLine + DefaultCodeGenerationHeaderWithoutVersion;
}
+ else if (value == "MICROSOFT_MIT_NO_CODEGEN")
+ {
+ _header = MicrosoftMitLicenseHeader;
+ }
else if (value == "NONE")
{
_header = String.Empty;
diff --git a/AutoRest/AutoRest.Core/Utilities/Extensions.cs b/AutoRest/AutoRest.Core/Utilities/Extensions.cs
index 23bea5173d9db..9a18e21f1f5b4 100644
--- a/AutoRest/AutoRest.Core/Utilities/Extensions.cs
+++ b/AutoRest/AutoRest.Core/Utilities/Extensions.cs
@@ -244,7 +244,7 @@ public static string EscapeXmlComment(this string comment)
}
///
- /// Returns true is the type is a PrimaryType with KnownPrimaryType matching typeToMatch.
+ /// Returns true if the type is a PrimaryType with KnownPrimaryType matching typeToMatch.
///
///
///
@@ -263,5 +263,54 @@ public static bool IsPrimaryType(this IType type, KnownPrimaryType typeToMatch)
}
return false;
}
+
+ ///
+ /// Returns true if the is a PrimaryType with KnownPrimaryType matching
+ /// or a DictionaryType with ValueType matching or a SequenceType matching
+ ///
+ ///
+ ///
+ ///
+ public static bool IsOrContainsPrimaryType(this IType type, KnownPrimaryType typeToMatch)
+ {
+ if (type == null)
+ {
+ return false;
+ }
+
+ if (type.IsPrimaryType(typeToMatch) ||
+ type.IsDictionaryContainingType(typeToMatch) ||
+ type.IsSequenceContainingType(typeToMatch))
+ {
+ return true;
+ }
+ return false;
+ }
+
+ ///
+ /// Returns true if the is a DictionaryType with ValueType matching
+ ///
+ ///
+ ///
+ ///
+ public static bool IsDictionaryContainingType(this IType type, KnownPrimaryType typeToMatch)
+ {
+ DictionaryType dictionaryType = type as DictionaryType;
+ PrimaryType dictionaryPrimaryType = dictionaryType?.ValueType as PrimaryType;
+ return dictionaryPrimaryType != null && dictionaryPrimaryType.IsPrimaryType(typeToMatch);
+ }
+
+ ///
+ /// Returns true if the is a SequenceType matching
+ ///
+ ///
+ ///
+ ///
+ public static bool IsSequenceContainingType(this IType type, KnownPrimaryType typeToMatch)
+ {
+ SequenceType sequenceType = type as SequenceType;
+ PrimaryType sequencePrimaryType = sequenceType?.ElementType as PrimaryType;
+ return sequencePrimaryType != null && sequencePrimaryType.IsPrimaryType(typeToMatch);
+ }
}
}
\ No newline at end of file
diff --git a/AutoRest/AutoRest.Core/Utilities/FileSystem.cs b/AutoRest/AutoRest.Core/Utilities/FileSystem.cs
index 91b4f6c18bdd0..13fab28c4cd4c 100644
--- a/AutoRest/AutoRest.Core/Utilities/FileSystem.cs
+++ b/AutoRest/AutoRest.Core/Utilities/FileSystem.cs
@@ -3,6 +3,7 @@
using System.IO;
using System.Net;
+using System.Text;
namespace Microsoft.Rest.Generator.Utilities
{
@@ -10,13 +11,15 @@ public class FileSystem : IFileSystem
{
public void WriteFile(string path, string contents)
{
- File.WriteAllText(path, contents);
+ File.WriteAllText(path, contents, Encoding.UTF8);
}
public string ReadFileAsText(string path)
{
using (var client = new WebClient())
{
+ client.Headers.Add("User-Agent: AutoRest");
+ client.Encoding = Encoding.UTF8;
return client.DownloadString(path);
}
}
diff --git a/AutoRest/AutoRest/AutoRest.csproj b/AutoRest/AutoRest/AutoRest.csproj
index 8bd5ec84e97dd..7c578e0980acb 100644
--- a/AutoRest/AutoRest/AutoRest.csproj
+++ b/AutoRest/AutoRest/AutoRest.csproj
@@ -31,6 +31,7 @@
Properties\AssemblyVersionInfo.cs
+
@@ -70,4 +71,4 @@
-
+
\ No newline at end of file
diff --git a/AutoRest/AutoRest/ExitCode.cs b/AutoRest/AutoRest/ExitCode.cs
new file mode 100644
index 0000000000000..fe09a82b44c21
--- /dev/null
+++ b/AutoRest/AutoRest/ExitCode.cs
@@ -0,0 +1,14 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License. See License.txt in the project root for license information.
+
+namespace Microsoft.Rest.Generator.Cli
+{
+ ///
+ /// Available exit codes.
+ ///
+ public enum ExitCode : int
+ {
+ Success = 0,
+ Error = 1
+ }
+}
diff --git a/AutoRest/AutoRest/Program.cs b/AutoRest/AutoRest/Program.cs
index b0c4aa7abea2b..f7bdf406b1066 100644
--- a/AutoRest/AutoRest/Program.cs
+++ b/AutoRest/AutoRest/Program.cs
@@ -12,8 +12,10 @@ namespace Microsoft.Rest.Generator.Cli
{
internal class Program
{
- private static void Main(string[] args)
+ private static int Main(string[] args)
{
+ int exitCode = (int)ExitCode.Error;
+
try
{
Settings settings = null;
@@ -69,6 +71,7 @@ private static void Main(string[] args)
{
Console.WriteLine(Resources.GenerationComplete,
settings.CodeGenerator, settings.Input);
+ exitCode = (int)ExitCode.Success;
}
}
@@ -91,6 +94,7 @@ private static void Main(string[] args)
Console.Error.WriteLine(Resources.ConsoleErrorMessage, exception.Message);
Console.Error.WriteLine(Resources.ConsoleErrorStackTrace, exception.StackTrace);
}
+ return exitCode;
}
///
diff --git a/AutoRest/Generators/AzureResourceSchema/AzureResourceSchema.Tests/AutoRest.Generator.AzureResourceSchema.Tests.csproj b/AutoRest/Generators/AzureResourceSchema/AzureResourceSchema.Tests/AutoRest.Generator.AzureResourceSchema.Tests.csproj
new file mode 100644
index 0000000000000..01522ea89f2b4
--- /dev/null
+++ b/AutoRest/Generators/AzureResourceSchema/AzureResourceSchema.Tests/AutoRest.Generator.AzureResourceSchema.Tests.csproj
@@ -0,0 +1,89 @@
+
+
+
+
+
+ Debug
+ AnyCPU
+ {1C3B4A33-E045-4C8F-9202-1B651A686567}
+ Library
+ Properties
+ AutoRest.Generator.AzureResourceSchema.Tests
+ AutoRest.Generator.AzureResourceSchema.Tests
+ v4.5.2
+ 512
+
+
+
+
+ true
+ full
+ false
+ bin\Debug\
+ DEBUG;TRACE
+ prompt
+ 4
+
+
+ pdbonly
+ true
+ bin\Release\
+ TRACE
+ prompt
+ 4
+
+
+
+
+
+
+
+
+
+
+
+ ..\packages\xunit.abstractions.2.0.0\lib\net35\xunit.abstractions.dll
+ True
+
+
+ ..\packages\xunit.assert.2.1.0\lib\dotnet\xunit.assert.dll
+ True
+
+
+ ..\packages\xunit.extensibility.core.2.1.0\lib\dotnet\xunit.core.dll
+ True
+
+
+ ..\packages\xunit.extensibility.execution.2.1.0\lib\net45\xunit.execution.desktop.dll
+ True
+
+
+
+
+
+
+
+ PreserveNewest
+
+
+
+
+ {654344a5-0556-49c7-bfb3-59676d7440d3}
+ AutoRest.Generator.AzureResourceSchema
+
+
+
+
+
+ This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.
+
+
+
+
+
\ No newline at end of file
diff --git a/AutoRest/Generators/AzureResourceSchema/AzureResourceSchema.Tests/Properties/AssemblyInfo.cs b/AutoRest/Generators/AzureResourceSchema/AzureResourceSchema.Tests/Properties/AssemblyInfo.cs
new file mode 100644
index 0000000000000..d8be4efbcaee3
--- /dev/null
+++ b/AutoRest/Generators/AzureResourceSchema/AzureResourceSchema.Tests/Properties/AssemblyInfo.cs
@@ -0,0 +1,36 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("AutoRest.Generator.AzureResourceSchema.Tests")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("AutoRest.Generator.AzureResourceSchema.Tests")]
+[assembly: AssemblyCopyright("Copyright © 2016")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components. If you need to access a type in this assembly from
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("1c3b4a33-e045-4c8f-9202-1b651a686567")]
+
+// Version information for an assembly consists of the following four values:
+//
+// Major Version
+// Minor Version
+// Build Number
+// Revision
+//
+// You can specify all the values or you can default the Build and Revision Numbers
+// by using the '*' as shown below:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
diff --git a/AutoRest/Generators/AzureResourceSchema/AzureResourceSchema.Tests/packages.config b/AutoRest/Generators/AzureResourceSchema/AzureResourceSchema.Tests/packages.config
new file mode 100644
index 0000000000000..4e690e09d9def
--- /dev/null
+++ b/AutoRest/Generators/AzureResourceSchema/AzureResourceSchema.Tests/packages.config
@@ -0,0 +1,10 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/AutoRest/Generators/AzureResourceSchema/AzureResourceSchema/AutoRest.Generator.AzureResourceSchema.csproj b/AutoRest/Generators/AzureResourceSchema/AzureResourceSchema/AutoRest.Generator.AzureResourceSchema.csproj
new file mode 100644
index 0000000000000..9afbe46b7ef40
--- /dev/null
+++ b/AutoRest/Generators/AzureResourceSchema/AzureResourceSchema/AutoRest.Generator.AzureResourceSchema.csproj
@@ -0,0 +1,53 @@
+
+
+
+
+ Debug
+ AnyCPU
+ {654344A5-0556-49C7-BFB3-59676D7440D3}
+ Library
+ Properties
+ Microsoft.Rest.Generator.AzureResourceSchema
+ AutoRest.Generator.AzureResourceSchema
+ v4.5.2
+ 512
+
+
+ true
+ full
+ false
+ bin\Debug\
+ DEBUG;TRACE
+ prompt
+ 4
+
+
+ pdbonly
+ true
+ bin\Release\
+ TRACE
+ prompt
+ 4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/AutoRest/Generators/AzureResourceSchema/AzureResourceSchema/Properties/AssemblyInfo.cs b/AutoRest/Generators/AzureResourceSchema/AzureResourceSchema/Properties/AssemblyInfo.cs
new file mode 100644
index 0000000000000..34f7036d5899a
--- /dev/null
+++ b/AutoRest/Generators/AzureResourceSchema/AzureResourceSchema/Properties/AssemblyInfo.cs
@@ -0,0 +1,36 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("AutoRest.Generator.AzureResourceSchema")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("AutoRest.Generator.AzureResourceSchema")]
+[assembly: AssemblyCopyright("Copyright © 2016")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components. If you need to access a type in this assembly from
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("654344a5-0556-49c7-bfb3-59676d7440d3")]
+
+// Version information for an assembly consists of the following four values:
+//
+// Major Version
+// Minor Version
+// Build Number
+// Revision
+//
+// You can specify all the values or you can default the Build and Revision Numbers
+// by using the '*' as shown below:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
diff --git a/AutoRest/Generators/CSharp/Azure.CSharp.Tests/AcceptanceTests.cs b/AutoRest/Generators/CSharp/Azure.CSharp.Tests/AcceptanceTests.cs
index ec21cdd514493..6c254399697c3 100644
--- a/AutoRest/Generators/CSharp/Azure.CSharp.Tests/AcceptanceTests.cs
+++ b/AutoRest/Generators/CSharp/Azure.CSharp.Tests/AcceptanceTests.cs
@@ -274,6 +274,10 @@ public void LroSadPathTests()
Assert.Equal("Error from the server", exception.Body.Message);
Assert.NotNull(exception.Request);
Assert.NotNull(exception.Response);
+ exception =
+ Assert.Throws(() => client.LROSADs.PutNonRetry201Creating400InvalidJson(new Product { Location = "West US" }));
+ Assert.Null(exception.Body);
+ Assert.Equal("Long running operation failed with status 'BadRequest'.", exception.Message);
exception =
Assert.Throws(
() => client.LROSADs.PutAsyncRelativeRetry400(new Product {Location = "West US"}));
diff --git a/AutoRest/Generators/CSharp/Azure.CSharp.Tests/Expected/AcceptanceTests/AzureBodyDuration/DurationOperations.cs b/AutoRest/Generators/CSharp/Azure.CSharp.Tests/Expected/AcceptanceTests/AzureBodyDuration/DurationOperations.cs
index 0a81d725f40a0..1bb297f05c5be 100644
--- a/AutoRest/Generators/CSharp/Azure.CSharp.Tests/Expected/AcceptanceTests/AzureBodyDuration/DurationOperations.cs
+++ b/AutoRest/Generators/CSharp/Azure.CSharp.Tests/Expected/AcceptanceTests/AzureBodyDuration/DurationOperations.cs
@@ -262,9 +262,12 @@ internal DurationOperations(AutoRestDurationTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(durationBody, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(durationBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(durationBody, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Set Credentials
if (this.Client.Credentials != null)
{
diff --git a/AutoRest/Generators/CSharp/Azure.CSharp.Tests/Expected/AcceptanceTests/AzureCompositeModelClient/ArrayOperations.cs b/AutoRest/Generators/CSharp/Azure.CSharp.Tests/Expected/AcceptanceTests/AzureCompositeModelClient/ArrayOperations.cs
index 1f102b7d253f8..084e2252f5c2f 100644
--- a/AutoRest/Generators/CSharp/Azure.CSharp.Tests/Expected/AcceptanceTests/AzureCompositeModelClient/ArrayOperations.cs
+++ b/AutoRest/Generators/CSharp/Azure.CSharp.Tests/Expected/AcceptanceTests/AzureCompositeModelClient/ArrayOperations.cs
@@ -267,9 +267,12 @@ internal ArrayOperations(AzureCompositeModel client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(complexBody, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(complexBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(complexBody, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Set Credentials
if (this.Client.Credentials != null)
{
@@ -552,9 +555,12 @@ internal ArrayOperations(AzureCompositeModel client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(complexBody, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(complexBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(complexBody, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Set Credentials
if (this.Client.Credentials != null)
{
diff --git a/AutoRest/Generators/CSharp/Azure.CSharp.Tests/Expected/AcceptanceTests/AzureCompositeModelClient/AzureCompositeModel.cs b/AutoRest/Generators/CSharp/Azure.CSharp.Tests/Expected/AcceptanceTests/AzureCompositeModelClient/AzureCompositeModel.cs
index 1b85b132a8e1f..4a1b72d67ed36 100644
--- a/AutoRest/Generators/CSharp/Azure.CSharp.Tests/Expected/AcceptanceTests/AzureCompositeModelClient/AzureCompositeModel.cs
+++ b/AutoRest/Generators/CSharp/Azure.CSharp.Tests/Expected/AcceptanceTests/AzureCompositeModelClient/AzureCompositeModel.cs
@@ -598,9 +598,12 @@ private void Initialize()
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(bodyParameter, this.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(bodyParameter != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(bodyParameter, this.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Set Credentials
if (this.Credentials != null)
{
@@ -781,9 +784,12 @@ private void Initialize()
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(bodyParameter, this.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(bodyParameter != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(bodyParameter, this.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Set Credentials
if (this.Credentials != null)
{
diff --git a/AutoRest/Generators/CSharp/Azure.CSharp.Tests/Expected/AcceptanceTests/AzureCompositeModelClient/BasicOperations.cs b/AutoRest/Generators/CSharp/Azure.CSharp.Tests/Expected/AcceptanceTests/AzureCompositeModelClient/BasicOperations.cs
index 971958b5cce24..48f31b747d153 100644
--- a/AutoRest/Generators/CSharp/Azure.CSharp.Tests/Expected/AcceptanceTests/AzureCompositeModelClient/BasicOperations.cs
+++ b/AutoRest/Generators/CSharp/Azure.CSharp.Tests/Expected/AcceptanceTests/AzureCompositeModelClient/BasicOperations.cs
@@ -273,9 +273,12 @@ internal BasicOperations(AzureCompositeModel client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(complexBody, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(complexBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(complexBody, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Set Credentials
if (this.Client.Credentials != null)
{
diff --git a/AutoRest/Generators/CSharp/Azure.CSharp.Tests/Expected/AcceptanceTests/AzureCompositeModelClient/DictionaryOperations.cs b/AutoRest/Generators/CSharp/Azure.CSharp.Tests/Expected/AcceptanceTests/AzureCompositeModelClient/DictionaryOperations.cs
index 7bff642eb2e8e..00abbb1a9f230 100644
--- a/AutoRest/Generators/CSharp/Azure.CSharp.Tests/Expected/AcceptanceTests/AzureCompositeModelClient/DictionaryOperations.cs
+++ b/AutoRest/Generators/CSharp/Azure.CSharp.Tests/Expected/AcceptanceTests/AzureCompositeModelClient/DictionaryOperations.cs
@@ -267,9 +267,12 @@ internal DictionaryOperations(AzureCompositeModel client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(complexBody, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(complexBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(complexBody, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Set Credentials
if (this.Client.Credentials != null)
{
@@ -552,9 +555,12 @@ internal DictionaryOperations(AzureCompositeModel client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(complexBody, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(complexBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(complexBody, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Set Credentials
if (this.Client.Credentials != null)
{
diff --git a/AutoRest/Generators/CSharp/Azure.CSharp.Tests/Expected/AcceptanceTests/AzureCompositeModelClient/InheritanceOperations.cs b/AutoRest/Generators/CSharp/Azure.CSharp.Tests/Expected/AcceptanceTests/AzureCompositeModelClient/InheritanceOperations.cs
index e9259e72611d0..6fc88683f2532 100644
--- a/AutoRest/Generators/CSharp/Azure.CSharp.Tests/Expected/AcceptanceTests/AzureCompositeModelClient/InheritanceOperations.cs
+++ b/AutoRest/Generators/CSharp/Azure.CSharp.Tests/Expected/AcceptanceTests/AzureCompositeModelClient/InheritanceOperations.cs
@@ -270,9 +270,12 @@ internal InheritanceOperations(AzureCompositeModel client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(complexBody, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(complexBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(complexBody, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Set Credentials
if (this.Client.Credentials != null)
{
diff --git a/AutoRest/Generators/CSharp/Azure.CSharp.Tests/Expected/AcceptanceTests/AzureCompositeModelClient/PolymorphicrecursiveOperations.cs b/AutoRest/Generators/CSharp/Azure.CSharp.Tests/Expected/AcceptanceTests/AzureCompositeModelClient/PolymorphicrecursiveOperations.cs
index 2498f6ef1f370..62c2becc51e81 100644
--- a/AutoRest/Generators/CSharp/Azure.CSharp.Tests/Expected/AcceptanceTests/AzureCompositeModelClient/PolymorphicrecursiveOperations.cs
+++ b/AutoRest/Generators/CSharp/Azure.CSharp.Tests/Expected/AcceptanceTests/AzureCompositeModelClient/PolymorphicrecursiveOperations.cs
@@ -323,9 +323,12 @@ internal PolymorphicrecursiveOperations(AzureCompositeModel client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(complexBody, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(complexBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(complexBody, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Set Credentials
if (this.Client.Credentials != null)
{
diff --git a/AutoRest/Generators/CSharp/Azure.CSharp.Tests/Expected/AcceptanceTests/AzureCompositeModelClient/PolymorphismOperations.cs b/AutoRest/Generators/CSharp/Azure.CSharp.Tests/Expected/AcceptanceTests/AzureCompositeModelClient/PolymorphismOperations.cs
index 58c94cd664148..e731fe36e914a 100644
--- a/AutoRest/Generators/CSharp/Azure.CSharp.Tests/Expected/AcceptanceTests/AzureCompositeModelClient/PolymorphismOperations.cs
+++ b/AutoRest/Generators/CSharp/Azure.CSharp.Tests/Expected/AcceptanceTests/AzureCompositeModelClient/PolymorphismOperations.cs
@@ -304,9 +304,12 @@ internal PolymorphismOperations(AzureCompositeModel client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(complexBody, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(complexBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(complexBody, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Set Credentials
if (this.Client.Credentials != null)
{
@@ -474,9 +477,12 @@ internal PolymorphismOperations(AzureCompositeModel client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(complexBody, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(complexBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(complexBody, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Set Credentials
if (this.Client.Credentials != null)
{
diff --git a/AutoRest/Generators/CSharp/Azure.CSharp.Tests/Expected/AcceptanceTests/AzureCompositeModelClient/PrimitiveOperations.cs b/AutoRest/Generators/CSharp/Azure.CSharp.Tests/Expected/AcceptanceTests/AzureCompositeModelClient/PrimitiveOperations.cs
index 973c9684fdf7a..6e66f9fa38195 100644
--- a/AutoRest/Generators/CSharp/Azure.CSharp.Tests/Expected/AcceptanceTests/AzureCompositeModelClient/PrimitiveOperations.cs
+++ b/AutoRest/Generators/CSharp/Azure.CSharp.Tests/Expected/AcceptanceTests/AzureCompositeModelClient/PrimitiveOperations.cs
@@ -267,9 +267,12 @@ internal PrimitiveOperations(AzureCompositeModel client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(complexBody, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(complexBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(complexBody, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Set Credentials
if (this.Client.Credentials != null)
{
@@ -552,9 +555,12 @@ internal PrimitiveOperations(AzureCompositeModel client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(complexBody, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(complexBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(complexBody, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Set Credentials
if (this.Client.Credentials != null)
{
@@ -837,9 +843,12 @@ internal PrimitiveOperations(AzureCompositeModel client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(complexBody, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(complexBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(complexBody, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Set Credentials
if (this.Client.Credentials != null)
{
@@ -1123,9 +1132,12 @@ internal PrimitiveOperations(AzureCompositeModel client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(complexBody, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(complexBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(complexBody, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Set Credentials
if (this.Client.Credentials != null)
{
@@ -1408,9 +1420,12 @@ internal PrimitiveOperations(AzureCompositeModel client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(complexBody, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(complexBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(complexBody, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Set Credentials
if (this.Client.Credentials != null)
{
@@ -1693,9 +1708,12 @@ internal PrimitiveOperations(AzureCompositeModel client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(complexBody, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(complexBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(complexBody, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Set Credentials
if (this.Client.Credentials != null)
{
@@ -1978,9 +1996,12 @@ internal PrimitiveOperations(AzureCompositeModel client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(complexBody, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(complexBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(complexBody, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Set Credentials
if (this.Client.Credentials != null)
{
@@ -2263,9 +2284,12 @@ internal PrimitiveOperations(AzureCompositeModel client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(complexBody, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(complexBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(complexBody, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Set Credentials
if (this.Client.Credentials != null)
{
@@ -2549,9 +2573,12 @@ internal PrimitiveOperations(AzureCompositeModel client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(complexBody, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(complexBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(complexBody, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Set Credentials
if (this.Client.Credentials != null)
{
@@ -2831,9 +2858,12 @@ internal PrimitiveOperations(AzureCompositeModel client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(complexBody, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(complexBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(complexBody, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Set Credentials
if (this.Client.Credentials != null)
{
@@ -3116,9 +3146,12 @@ internal PrimitiveOperations(AzureCompositeModel client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(complexBody, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(complexBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(complexBody, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Set Credentials
if (this.Client.Credentials != null)
{
diff --git a/AutoRest/Generators/CSharp/Azure.CSharp.Tests/Expected/AcceptanceTests/AzureCompositeModelClient/ReadonlypropertyOperations.cs b/AutoRest/Generators/CSharp/Azure.CSharp.Tests/Expected/AcceptanceTests/AzureCompositeModelClient/ReadonlypropertyOperations.cs
index 56feb12b1ce51..70e1a11d28b4b 100644
--- a/AutoRest/Generators/CSharp/Azure.CSharp.Tests/Expected/AcceptanceTests/AzureCompositeModelClient/ReadonlypropertyOperations.cs
+++ b/AutoRest/Generators/CSharp/Azure.CSharp.Tests/Expected/AcceptanceTests/AzureCompositeModelClient/ReadonlypropertyOperations.cs
@@ -266,9 +266,12 @@ internal ReadonlypropertyOperations(AzureCompositeModel client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(complexBody, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(complexBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(complexBody, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Set Credentials
if (this.Client.Credentials != null)
{
diff --git a/AutoRest/Generators/CSharp/Azure.CSharp.Tests/Expected/AcceptanceTests/AzureParameterGrouping/ParameterGroupingOperations.cs b/AutoRest/Generators/CSharp/Azure.CSharp.Tests/Expected/AcceptanceTests/AzureParameterGrouping/ParameterGroupingOperations.cs
index 9a2bf74564bac..7fe382cfcdee6 100644
--- a/AutoRest/Generators/CSharp/Azure.CSharp.Tests/Expected/AcceptanceTests/AzureParameterGrouping/ParameterGroupingOperations.cs
+++ b/AutoRest/Generators/CSharp/Azure.CSharp.Tests/Expected/AcceptanceTests/AzureParameterGrouping/ParameterGroupingOperations.cs
@@ -161,9 +161,12 @@ internal ParameterGroupingOperations(AutoRestParameterGroupingTestService client
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(body, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(body != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(body, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Set Credentials
if (this.Client.Credentials != null)
{
diff --git a/AutoRest/Generators/CSharp/Azure.CSharp.Tests/Expected/AcceptanceTests/AzureResource/AutoRestResourceFlatteningTestService.cs b/AutoRest/Generators/CSharp/Azure.CSharp.Tests/Expected/AcceptanceTests/AzureResource/AutoRestResourceFlatteningTestService.cs
index ce1bd46bdd5d8..a922764f2b369 100644
--- a/AutoRest/Generators/CSharp/Azure.CSharp.Tests/Expected/AcceptanceTests/AzureResource/AutoRestResourceFlatteningTestService.cs
+++ b/AutoRest/Generators/CSharp/Azure.CSharp.Tests/Expected/AcceptanceTests/AzureResource/AutoRestResourceFlatteningTestService.cs
@@ -347,9 +347,12 @@ private void Initialize()
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(resourceArray, this.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(resourceArray != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(resourceArray, this.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Set Credentials
if (this.Credentials != null)
{
@@ -628,9 +631,12 @@ private void Initialize()
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(resourceDictionary, this.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(resourceDictionary != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(resourceDictionary, this.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Set Credentials
if (this.Credentials != null)
{
@@ -909,9 +915,12 @@ private void Initialize()
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(resourceComplexObject, this.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(resourceComplexObject != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(resourceComplexObject, this.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Set Credentials
if (this.Credentials != null)
{
diff --git a/AutoRest/Generators/CSharp/Azure.CSharp.Tests/Expected/AcceptanceTests/Lro/ILROSADsOperations.cs b/AutoRest/Generators/CSharp/Azure.CSharp.Tests/Expected/AcceptanceTests/Lro/ILROSADsOperations.cs
index 60ac71a045d3e..5717f7f8f64e8 100644
--- a/AutoRest/Generators/CSharp/Azure.CSharp.Tests/Expected/AcceptanceTests/Lro/ILROSADsOperations.cs
+++ b/AutoRest/Generators/CSharp/Azure.CSharp.Tests/Expected/AcceptanceTests/Lro/ILROSADsOperations.cs
@@ -79,6 +79,34 @@ public partial interface ILROSADsOperations
///
Task> BeginPutNonRetry201Creating400WithHttpMessagesAsync(Product product = default(Product), Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken));
///
+ /// Long running put request, service returns a Product with
+ /// 'ProvisioningState' = 'Creating' and 201 response code
+ ///
+ ///
+ /// Product to put
+ ///
+ ///
+ /// The headers that will be added to request.
+ ///
+ ///
+ /// The cancellation token.
+ ///
+ Task> PutNonRetry201Creating400InvalidJsonWithHttpMessagesAsync(Product product = default(Product), Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken));
+ ///
+ /// Long running put request, service returns a Product with
+ /// 'ProvisioningState' = 'Creating' and 201 response code
+ ///
+ ///
+ /// Product to put
+ ///
+ ///
+ /// The headers that will be added to request.
+ ///
+ ///
+ /// The cancellation token.
+ ///
+ Task> BeginPutNonRetry201Creating400InvalidJsonWithHttpMessagesAsync(Product product = default(Product), Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken));
+ ///
/// Long running put request, service returns a 200 with
/// ProvisioningState=’Creating’. Poll the endpoint indicated in the
/// Azure-AsyncOperation header for operation status
diff --git a/AutoRest/Generators/CSharp/Azure.CSharp.Tests/Expected/AcceptanceTests/Lro/LRORetrysOperations.cs b/AutoRest/Generators/CSharp/Azure.CSharp.Tests/Expected/AcceptanceTests/Lro/LRORetrysOperations.cs
index 0717455b58c3c..9ed93a653fb58 100644
--- a/AutoRest/Generators/CSharp/Azure.CSharp.Tests/Expected/AcceptanceTests/Lro/LRORetrysOperations.cs
+++ b/AutoRest/Generators/CSharp/Azure.CSharp.Tests/Expected/AcceptanceTests/Lro/LRORetrysOperations.cs
@@ -145,9 +145,12 @@ internal LRORetrysOperations(AutoRestLongRunningOperationTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(product, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(product != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(product, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Set Credentials
if (this.Client.Credentials != null)
{
@@ -349,9 +352,12 @@ internal LRORetrysOperations(AutoRestLongRunningOperationTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(product, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(product != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(product, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Set Credentials
if (this.Client.Credentials != null)
{
@@ -1083,9 +1089,12 @@ internal LRORetrysOperations(AutoRestLongRunningOperationTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(product, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(product != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(product, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Set Credentials
if (this.Client.Credentials != null)
{
@@ -1262,9 +1271,12 @@ internal LRORetrysOperations(AutoRestLongRunningOperationTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(product, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(product != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(product, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Set Credentials
if (this.Client.Credentials != null)
{
diff --git a/AutoRest/Generators/CSharp/Azure.CSharp.Tests/Expected/AcceptanceTests/Lro/LROSADsOperations.cs b/AutoRest/Generators/CSharp/Azure.CSharp.Tests/Expected/AcceptanceTests/Lro/LROSADsOperations.cs
index bf8e7415095a3..cbd54f78112ae 100644
--- a/AutoRest/Generators/CSharp/Azure.CSharp.Tests/Expected/AcceptanceTests/Lro/LROSADsOperations.cs
+++ b/AutoRest/Generators/CSharp/Azure.CSharp.Tests/Expected/AcceptanceTests/Lro/LROSADsOperations.cs
@@ -139,9 +139,12 @@ internal LROSADsOperations(AutoRestLongRunningOperationTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(product, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(product != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(product, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Set Credentials
if (this.Client.Credentials != null)
{
@@ -339,9 +342,215 @@ internal LROSADsOperations(AutoRestLongRunningOperationTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(product, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(product != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(product, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
+ // Set Credentials
+ if (this.Client.Credentials != null)
+ {
+ cancellationToken.ThrowIfCancellationRequested();
+ await this.Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
+ }
+ // Send Request
+ if (_shouldTrace)
+ {
+ ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
+ }
+ cancellationToken.ThrowIfCancellationRequested();
+ _httpResponse = await this.Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
+ if (_shouldTrace)
+ {
+ ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
+ }
+ HttpStatusCode _statusCode = _httpResponse.StatusCode;
+ cancellationToken.ThrowIfCancellationRequested();
+ string _responseContent = null;
+ if ((int)_statusCode != 200 && (int)_statusCode != 201)
+ {
+ var ex = new CloudException(string.Format("Operation returned an invalid status code '{0}'", _statusCode));
+ try
+ {
+ _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
+ CloudError _errorBody = SafeJsonConvert.DeserializeObject(_responseContent, this.Client.DeserializationSettings);
+ if (_errorBody != null)
+ {
+ ex = new CloudException(_errorBody.Message);
+ ex.Body = _errorBody;
+ }
+ }
+ catch (JsonException)
+ {
+ // Ignore the exception
+ }
+ ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
+ ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
+ if (_httpResponse.Headers.Contains("x-ms-request-id"))
+ {
+ ex.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
+ }
+ if (_shouldTrace)
+ {
+ ServiceClientTracing.Error(_invocationId, ex);
+ }
+ _httpRequest.Dispose();
+ if (_httpResponse != null)
+ {
+ _httpResponse.Dispose();
+ }
+ throw ex;
+ }
+ // Create Result
+ var _result = new AzureOperationResponse();
+ _result.Request = _httpRequest;
+ _result.Response = _httpResponse;
+ if (_httpResponse.Headers.Contains("x-ms-request-id"))
+ {
+ _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
+ }
+ // Deserialize Response
+ if ((int)_statusCode == 200)
+ {
+ _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
+ try
+ {
+ _result.Body = SafeJsonConvert.DeserializeObject(_responseContent, this.Client.DeserializationSettings);
+ }
+ catch (JsonException ex)
+ {
+ _httpRequest.Dispose();
+ if (_httpResponse != null)
+ {
+ _httpResponse.Dispose();
+ }
+ throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
+ }
+ }
+ // Deserialize Response
+ if ((int)_statusCode == 201)
+ {
+ _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
+ try
+ {
+ _result.Body = SafeJsonConvert.DeserializeObject(_responseContent, this.Client.DeserializationSettings);
+ }
+ catch (JsonException ex)
+ {
+ _httpRequest.Dispose();
+ if (_httpResponse != null)
+ {
+ _httpResponse.Dispose();
+ }
+ throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
+ }
+ }
+ if (_shouldTrace)
+ {
+ ServiceClientTracing.Exit(_invocationId, _result);
+ }
+ return _result;
+ }
+
+ ///
+ /// Long running put request, service returns a Product with
+ /// 'ProvisioningState' = 'Creating' and 201 response code
+ ///
+ ///
+ /// Product to put
+ ///
+ ///
+ /// The headers that will be added to request.
+ ///
+ ///
+ /// The cancellation token.
+ ///
+ public async Task> PutNonRetry201Creating400InvalidJsonWithHttpMessagesAsync(Product product = default(Product), Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken))
+ {
+ // Send Request
+ AzureOperationResponse _response = await BeginPutNonRetry201Creating400InvalidJsonWithHttpMessagesAsync(
+ product, customHeaders, cancellationToken);
+ return await this.Client.GetPutOrPatchOperationResultAsync(_response,
+ customHeaders,
+ cancellationToken);
+ }
+
+ ///
+ /// Long running put request, service returns a Product with
+ /// 'ProvisioningState' = 'Creating' and 201 response code
+ ///
+ ///
+ /// Product to put
+ ///
+ ///
+ /// Headers that will be added to request.
+ ///
+ ///
+ /// The cancellation token.
+ ///
+ ///
+ /// A response object containing the response body and response headers.
+ ///
+ public async Task> BeginPutNonRetry201Creating400InvalidJsonWithHttpMessagesAsync(Product product = default(Product), Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken))
+ {
+ // Tracing
+ bool _shouldTrace = ServiceClientTracing.IsEnabled;
+ string _invocationId = null;
+ if (_shouldTrace)
+ {
+ _invocationId = ServiceClientTracing.NextInvocationId.ToString();
+ Dictionary tracingParameters = new Dictionary();
+ tracingParameters.Add("product", product);
+ tracingParameters.Add("cancellationToken", cancellationToken);
+ ServiceClientTracing.Enter(_invocationId, this, "BeginPutNonRetry201Creating400InvalidJson", tracingParameters);
+ }
+ // Construct URL
+ var _baseUrl = this.Client.BaseUri.AbsoluteUri;
+ var _url = new Uri(new Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "lro/nonretryerror/put/201/creating/400/invalidjson").ToString();
+ List _queryParameters = new List();
+ if (_queryParameters.Count > 0)
+ {
+ _url += "?" + string.Join("&", _queryParameters);
+ }
+ // Create HTTP transport objects
+ HttpRequestMessage _httpRequest = new HttpRequestMessage();
+ HttpResponseMessage _httpResponse = null;
+ _httpRequest.Method = new HttpMethod("PUT");
+ _httpRequest.RequestUri = new Uri(_url);
+ // Set Headers
+ if (this.Client.GenerateClientRequestId != null && this.Client.GenerateClientRequestId.Value)
+ {
+ _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", Guid.NewGuid().ToString());
+ }
+ if (this.Client.AcceptLanguage != null)
+ {
+ if (_httpRequest.Headers.Contains("accept-language"))
+ {
+ _httpRequest.Headers.Remove("accept-language");
+ }
+ _httpRequest.Headers.TryAddWithoutValidation("accept-language", this.Client.AcceptLanguage);
+ }
+ if (customHeaders != null)
+ {
+ foreach(var _header in customHeaders)
+ {
+ if (_httpRequest.Headers.Contains(_header.Key))
+ {
+ _httpRequest.Headers.Remove(_header.Key);
+ }
+ _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
+ }
+ }
+
+ // Serialize Request
+ string _requestContent = null;
+ if(product != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(product, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Set Credentials
if (this.Client.Credentials != null)
{
@@ -541,9 +750,12 @@ internal LROSADsOperations(AutoRestLongRunningOperationTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(product, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(product != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(product, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Set Credentials
if (this.Client.Credentials != null)
{
@@ -1225,9 +1437,12 @@ internal LROSADsOperations(AutoRestLongRunningOperationTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(product, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(product != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(product, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Set Credentials
if (this.Client.Credentials != null)
{
@@ -1398,9 +1613,12 @@ internal LROSADsOperations(AutoRestLongRunningOperationTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(product, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(product != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(product, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Set Credentials
if (this.Client.Credentials != null)
{
@@ -1575,9 +1793,12 @@ internal LROSADsOperations(AutoRestLongRunningOperationTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(product, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(product != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(product, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Set Credentials
if (this.Client.Credentials != null)
{
@@ -1752,9 +1973,12 @@ internal LROSADsOperations(AutoRestLongRunningOperationTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(product, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(product != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(product, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Set Credentials
if (this.Client.Credentials != null)
{
@@ -1954,9 +2178,12 @@ internal LROSADsOperations(AutoRestLongRunningOperationTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(product, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(product != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(product, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Set Credentials
if (this.Client.Credentials != null)
{
@@ -2151,9 +2378,12 @@ internal LROSADsOperations(AutoRestLongRunningOperationTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(product, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(product != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(product, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Set Credentials
if (this.Client.Credentials != null)
{
@@ -2663,9 +2893,12 @@ internal LROSADsOperations(AutoRestLongRunningOperationTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(product, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(product != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(product, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Set Credentials
if (this.Client.Credentials != null)
{
@@ -2840,9 +3073,12 @@ internal LROSADsOperations(AutoRestLongRunningOperationTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(product, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(product != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(product, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Set Credentials
if (this.Client.Credentials != null)
{
@@ -3017,9 +3253,12 @@ internal LROSADsOperations(AutoRestLongRunningOperationTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(product, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(product != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(product, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Set Credentials
if (this.Client.Credentials != null)
{
@@ -3201,9 +3440,12 @@ internal LROSADsOperations(AutoRestLongRunningOperationTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(product, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(product != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(product, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Set Credentials
if (this.Client.Credentials != null)
{
@@ -3398,9 +3640,12 @@ internal LROSADsOperations(AutoRestLongRunningOperationTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(product, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(product != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(product, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Set Credentials
if (this.Client.Credentials != null)
{
@@ -4088,9 +4333,12 @@ internal LROSADsOperations(AutoRestLongRunningOperationTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(product, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(product != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(product, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Set Credentials
if (this.Client.Credentials != null)
{
@@ -4265,9 +4513,12 @@ internal LROSADsOperations(AutoRestLongRunningOperationTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(product, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(product != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(product, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Set Credentials
if (this.Client.Credentials != null)
{
@@ -4442,9 +4693,12 @@ internal LROSADsOperations(AutoRestLongRunningOperationTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(product, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(product != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(product, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Set Credentials
if (this.Client.Credentials != null)
{
diff --git a/AutoRest/Generators/CSharp/Azure.CSharp.Tests/Expected/AcceptanceTests/Lro/LROSADsOperationsExtensions.cs b/AutoRest/Generators/CSharp/Azure.CSharp.Tests/Expected/AcceptanceTests/Lro/LROSADsOperationsExtensions.cs
index 86b6c1b083fc9..dc7d177cbe402 100644
--- a/AutoRest/Generators/CSharp/Azure.CSharp.Tests/Expected/AcceptanceTests/Lro/LROSADsOperationsExtensions.cs
+++ b/AutoRest/Generators/CSharp/Azure.CSharp.Tests/Expected/AcceptanceTests/Lro/LROSADsOperationsExtensions.cs
@@ -162,6 +162,78 @@ public static partial class LROSADsOperationsExtensions
}
}
+ ///
+ /// Long running put request, service returns a Product with
+ /// 'ProvisioningState' = 'Creating' and 201 response code
+ ///
+ ///
+ /// The operations group for this extension method.
+ ///
+ ///
+ /// Product to put
+ ///
+ public static Product PutNonRetry201Creating400InvalidJson(this ILROSADsOperations operations, Product product = default(Product))
+ {
+ return Task.Factory.StartNew(s => ((ILROSADsOperations)s).PutNonRetry201Creating400InvalidJsonAsync(product), operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Long running put request, service returns a Product with
+ /// 'ProvisioningState' = 'Creating' and 201 response code
+ ///
+ ///
+ /// The operations group for this extension method.
+ ///
+ ///
+ /// Product to put
+ ///
+ ///
+ /// The cancellation token.
+ ///
+ public static async Task PutNonRetry201Creating400InvalidJsonAsync(this ILROSADsOperations operations, Product product = default(Product), CancellationToken cancellationToken = default(CancellationToken))
+ {
+ using (var _result = await operations.PutNonRetry201Creating400InvalidJsonWithHttpMessagesAsync(product, null, cancellationToken).ConfigureAwait(false))
+ {
+ return _result.Body;
+ }
+ }
+
+ ///
+ /// Long running put request, service returns a Product with
+ /// 'ProvisioningState' = 'Creating' and 201 response code
+ ///
+ ///
+ /// The operations group for this extension method.
+ ///
+ ///
+ /// Product to put
+ ///
+ public static Product BeginPutNonRetry201Creating400InvalidJson(this ILROSADsOperations operations, Product product = default(Product))
+ {
+ return Task.Factory.StartNew(s => ((ILROSADsOperations)s).BeginPutNonRetry201Creating400InvalidJsonAsync(product), operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Long running put request, service returns a Product with
+ /// 'ProvisioningState' = 'Creating' and 201 response code
+ ///
+ ///
+ /// The operations group for this extension method.
+ ///
+ ///
+ /// Product to put
+ ///
+ ///
+ /// The cancellation token.
+ ///
+ public static async Task BeginPutNonRetry201Creating400InvalidJsonAsync(this ILROSADsOperations operations, Product product = default(Product), CancellationToken cancellationToken = default(CancellationToken))
+ {
+ using (var _result = await operations.BeginPutNonRetry201Creating400InvalidJsonWithHttpMessagesAsync(product, null, cancellationToken).ConfigureAwait(false))
+ {
+ return _result.Body;
+ }
+ }
+
///
/// Long running put request, service returns a 200 with
/// ProvisioningState=’Creating’. Poll the endpoint indicated in the
diff --git a/AutoRest/Generators/CSharp/Azure.CSharp.Tests/Expected/AcceptanceTests/Lro/LROsCustomHeaderOperations.cs b/AutoRest/Generators/CSharp/Azure.CSharp.Tests/Expected/AcceptanceTests/Lro/LROsCustomHeaderOperations.cs
index ef38e4360dffc..a6475eba268d4 100644
--- a/AutoRest/Generators/CSharp/Azure.CSharp.Tests/Expected/AcceptanceTests/Lro/LROsCustomHeaderOperations.cs
+++ b/AutoRest/Generators/CSharp/Azure.CSharp.Tests/Expected/AcceptanceTests/Lro/LROsCustomHeaderOperations.cs
@@ -147,9 +147,12 @@ internal LROsCustomHeaderOperations(AutoRestLongRunningOperationTestService clie
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(product, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(product != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(product, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Set Credentials
if (this.Client.Credentials != null)
{
@@ -348,9 +351,12 @@ internal LROsCustomHeaderOperations(AutoRestLongRunningOperationTestService clie
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(product, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(product != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(product, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Set Credentials
if (this.Client.Credentials != null)
{
@@ -550,9 +556,12 @@ internal LROsCustomHeaderOperations(AutoRestLongRunningOperationTestService clie
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(product, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(product != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(product, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Set Credentials
if (this.Client.Credentials != null)
{
@@ -731,9 +740,12 @@ internal LROsCustomHeaderOperations(AutoRestLongRunningOperationTestService clie
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(product, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(product != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(product, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Set Credentials
if (this.Client.Credentials != null)
{
diff --git a/AutoRest/Generators/CSharp/Azure.CSharp.Tests/Expected/AcceptanceTests/Lro/LROsOperations.cs b/AutoRest/Generators/CSharp/Azure.CSharp.Tests/Expected/AcceptanceTests/Lro/LROsOperations.cs
index 1ff59d6881ad5..b518b2963bc7e 100644
--- a/AutoRest/Generators/CSharp/Azure.CSharp.Tests/Expected/AcceptanceTests/Lro/LROsOperations.cs
+++ b/AutoRest/Generators/CSharp/Azure.CSharp.Tests/Expected/AcceptanceTests/Lro/LROsOperations.cs
@@ -141,9 +141,12 @@ internal LROsOperations(AutoRestLongRunningOperationTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(product, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(product != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(product, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Set Credentials
if (this.Client.Credentials != null)
{
@@ -323,9 +326,12 @@ internal LROsOperations(AutoRestLongRunningOperationTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(product, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(product != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(product, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Set Credentials
if (this.Client.Credentials != null)
{
@@ -507,9 +513,12 @@ internal LROsOperations(AutoRestLongRunningOperationTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(product, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(product != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(product, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Set Credentials
if (this.Client.Credentials != null)
{
@@ -693,9 +702,12 @@ internal LROsOperations(AutoRestLongRunningOperationTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(product, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(product != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(product, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Set Credentials
if (this.Client.Credentials != null)
{
@@ -897,9 +909,12 @@ internal LROsOperations(AutoRestLongRunningOperationTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(product, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(product != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(product, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Set Credentials
if (this.Client.Credentials != null)
{
@@ -1083,9 +1098,12 @@ internal LROsOperations(AutoRestLongRunningOperationTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(product, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(product != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(product, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Set Credentials
if (this.Client.Credentials != null)
{
@@ -1287,9 +1305,12 @@ internal LROsOperations(AutoRestLongRunningOperationTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(product, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(product != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(product, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Set Credentials
if (this.Client.Credentials != null)
{
@@ -1471,9 +1492,12 @@ internal LROsOperations(AutoRestLongRunningOperationTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(product, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(product != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(product, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Set Credentials
if (this.Client.Credentials != null)
{
@@ -1668,9 +1692,12 @@ internal LROsOperations(AutoRestLongRunningOperationTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(product, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(product != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(product, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Set Credentials
if (this.Client.Credentials != null)
{
@@ -1865,9 +1892,12 @@ internal LROsOperations(AutoRestLongRunningOperationTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(product, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(product != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(product, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Set Credentials
if (this.Client.Credentials != null)
{
@@ -2062,9 +2092,12 @@ internal LROsOperations(AutoRestLongRunningOperationTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(product, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(product != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(product, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Set Credentials
if (this.Client.Credentials != null)
{
@@ -2259,9 +2292,12 @@ internal LROsOperations(AutoRestLongRunningOperationTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(product, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(product != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(product, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Set Credentials
if (this.Client.Credentials != null)
{
@@ -2456,9 +2492,12 @@ internal LROsOperations(AutoRestLongRunningOperationTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(product, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(product != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(product, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Set Credentials
if (this.Client.Credentials != null)
{
@@ -2649,9 +2688,12 @@ internal LROsOperations(AutoRestLongRunningOperationTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(sku, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(sku != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(sku, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Set Credentials
if (this.Client.Credentials != null)
{
@@ -2829,9 +2871,12 @@ internal LROsOperations(AutoRestLongRunningOperationTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(sku, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(sku != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(sku, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Set Credentials
if (this.Client.Credentials != null)
{
@@ -3009,9 +3054,12 @@ internal LROsOperations(AutoRestLongRunningOperationTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(product, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(product != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(product, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Set Credentials
if (this.Client.Credentials != null)
{
@@ -3189,9 +3237,12 @@ internal LROsOperations(AutoRestLongRunningOperationTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(product, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(product != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(product, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Set Credentials
if (this.Client.Credentials != null)
{
@@ -5698,9 +5749,12 @@ internal LROsOperations(AutoRestLongRunningOperationTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(product, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(product != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(product, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Set Credentials
if (this.Client.Credentials != null)
{
@@ -5873,9 +5927,12 @@ internal LROsOperations(AutoRestLongRunningOperationTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(product, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(product != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(product, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Set Credentials
if (this.Client.Credentials != null)
{
@@ -6068,9 +6125,12 @@ internal LROsOperations(AutoRestLongRunningOperationTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(product, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(product != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(product, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Set Credentials
if (this.Client.Credentials != null)
{
@@ -6263,9 +6323,12 @@ internal LROsOperations(AutoRestLongRunningOperationTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(product, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(product != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(product, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Set Credentials
if (this.Client.Credentials != null)
{
@@ -6458,9 +6521,12 @@ internal LROsOperations(AutoRestLongRunningOperationTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(product, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(product != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(product, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Set Credentials
if (this.Client.Credentials != null)
{
@@ -6635,9 +6701,12 @@ internal LROsOperations(AutoRestLongRunningOperationTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(product, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(product != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(product, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Set Credentials
if (this.Client.Credentials != null)
{
diff --git a/AutoRest/Generators/CSharp/Azure.CSharp/AzureCSharpCodeGenerator.cs b/AutoRest/Generators/CSharp/Azure.CSharp/AzureCSharpCodeGenerator.cs
index 6ec3ab05bd8c4..5c7f0b5bb3809 100644
--- a/AutoRest/Generators/CSharp/Azure.CSharp/AzureCSharpCodeGenerator.cs
+++ b/AutoRest/Generators/CSharp/Azure.CSharp/AzureCSharpCodeGenerator.cs
@@ -18,7 +18,7 @@ public class AzureCSharpCodeGenerator : CSharpCodeGenerator
{
private readonly AzureCSharpCodeNamer _namer;
- private const string ClientRuntimePackage = "Microsoft.Rest.ClientRuntime.Azure.3.1.0";
+ private const string ClientRuntimePackage = "Microsoft.Rest.ClientRuntime.Azure.3.2.0";
// page extensions class dictionary.
private IDictionary, string> pageClasses;
diff --git a/AutoRest/Generators/CSharp/CSharp.Tests/AcceptanceTests.cs b/AutoRest/Generators/CSharp/CSharp.Tests/AcceptanceTests.cs
index 66b37df45fc4a..804db915e6111 100644
--- a/AutoRest/Generators/CSharp/CSharp.Tests/AcceptanceTests.cs
+++ b/AutoRest/Generators/CSharp/CSharp.Tests/AcceptanceTests.cs
@@ -50,6 +50,7 @@
using Fixtures.PetstoreV2;
using Fixtures.AcceptanceTestsCompositeBoolIntClient;
using Fixtures.AcceptanceTestsCustomBaseUri;
+using Fixtures.AcceptanceTestsCustomBaseUriMoreOptions;
using System.Net.Http;
using Fixtures.AcceptanceTestsModelFlattening;
using Fixtures.AcceptanceTestsModelFlattening.Models;
@@ -197,12 +198,16 @@ public void IntegerTests()
client.IntModel.PutMin32(Int32.MinValue);
client.IntModel.PutMax64(Int64.MaxValue);
client.IntModel.PutMin64(Int64.MinValue);
+ client.IntModel.PutUnixTimeDate(new DateTime(2016, 4, 13, 0, 0, 0));
client.IntModel.GetNull();
Assert.Throws(() => client.IntModel.GetInvalid());
Assert.Throws(() => client.IntModel.GetOverflowInt32());
Assert.Throws(() => client.IntModel.GetOverflowInt64());
Assert.Throws(() => client.IntModel.GetUnderflowInt32());
Assert.Throws(() => client.IntModel.GetUnderflowInt64());
+ Assert.Throws(() => client.IntModel.GetInvalidUnixTime());
+ Assert.Null(client.IntModel.GetNullUnixTime());
+ Assert.Equal(new DateTime(2016, 4, 13, 0, 0, 0), client.IntModel.GetUnixTime());
}
[Fact]
@@ -275,6 +280,12 @@ public void StringTests()
Assert.Null(client.StringModel.GetNotProvided());
Assert.Equal(Colors.Redcolor, client.EnumModel.GetNotExpandable());
client.EnumModel.PutNotExpandable(Colors.Redcolor);
+ var base64UrlEncodedString = client.StringModel.GetBase64UrlEncoded();
+ var base64EncodedString = client.StringModel.GetBase64Encoded();
+ Assert.Equal(Encoding.UTF8.GetString(base64UrlEncodedString), "a string that gets encoded with base64url");
+ Assert.Equal(Encoding.UTF8.GetString(base64EncodedString), "a string that gets encoded with base64");
+ Assert.Null(client.StringModel.GetNullBase64UrlEncoded());
+ client.StringModel.PutBase64UrlEncoded(Encoding.UTF8.GetBytes("a string that gets encoded with base64url"));
}
}
@@ -652,6 +663,11 @@ public void ArrayTests()
Assert.Equal(new List { guid1, guid2, guid3 }, client.Array.GetUuidValid());
client.Array.PutUuidValid(new List { guid1, guid2, guid3 });
Assert.Throws(() => client.Array.GetUuidInvalidChars());
+
+ var base64Url1 = Encoding.UTF8.GetBytes("a string that gets encoded with base64url");
+ var base64Url2 = Encoding.UTF8.GetBytes("test string");
+ var base64Url3 = Encoding.UTF8.GetBytes("Lorem ipsum");
+ Assert.Equal(new List { base64Url1, base64Url2, base64Url3 }, client.Array.GetBase64Url());
}
}
@@ -961,6 +977,13 @@ private static void TestDictionaryPrimitiveTypes(AutoRestSwaggerBATdictionarySer
Assert.True(bytesResult.ContainsKey(key));
Assert.Equal(bytesNull[key], bytesResult[key], new ByteArrayEqualityComparer());
}
+ // GET prim/base64url/valid
+ var base64UrlString1 = Encoding.UTF8.GetBytes("a string that gets encoded with base64url");
+ var base64UrlString2 = Encoding.UTF8.GetBytes("test string");
+ var base64UrlString3 = Encoding.UTF8.GetBytes("Lorem ipsum");
+ var base64UrlStringValid = new Dictionary {{"0", base64UrlString1}, {"1", base64UrlString2}, {"2", base64UrlString3}};
+ var base64UrlStringResult = client.Dictionary.GetBase64Url();
+ Assert.Equal(base64UrlStringValid, base64UrlStringResult);
}
private static void TestBasicDictionaryParsing(AutoRestSwaggerBATdictionaryService client)
@@ -1329,6 +1352,10 @@ public void UrlPathTests()
Assert.Throws(() => client.Paths.StringNull(null));
client.Paths.StringUrlEncoded();
client.Paths.EnumValid(UriColor.Greencolor);
+ client.Paths.Base64Url(Encoding.UTF8.GetBytes("lorem"));
+ var testArray = new List { "ArrayPath1", @"begin!*'();:@ &=+$,/?#[]end", null, "" };
+ client.Paths.ArrayCsvInPath(testArray);
+ client.Paths.UnixTimeUrl(new DateTime(2016, 4, 13, 0, 0, 0));
}
}
@@ -1930,6 +1957,21 @@ public void CustomBaseUriTests()
}
}
+ [Fact]
+ public void CustomBaseUriMoreOptionsTests()
+ {
+ SwaggerSpecRunner.RunTests(
+ SwaggerPath("custom-baseUrl-more-options.json"), ExpectedPath("CustomBaseUriMoreOptions"));
+ using (var client = new AutoRestParameterizedCustomHostTestClient())
+ {
+ client.SubscriptionId = "test12";
+ // small modification to the "host" portion to include the port and the '.'
+ client.DnsSuffix = string.Format(CultureInfo.InvariantCulture, "{0}.:{1}", "host", Fixture.Port);
+ Assert.Equal(HttpStatusCode.OK,
+ client.Paths.GetEmptyWithHttpMessagesAsync("http://lo", "cal", "key1").Result.Response.StatusCode);
+ }
+ }
+
[Fact]
public void CustomBaseUriNegativeTests()
{
@@ -2165,7 +2207,8 @@ public void ModelFlatteningSimpleTest()
Description = "product description",
ProductId = "123",
MaxProductDisplayName = "max name",
- Odatavalue = "http://foo"
+ Odatavalue = "http://foo",
+ GenericValue = "https://generic"
};
var resultProduct = client.PutSimpleProduct(simpleProduct);
Assert.Equal(JsonConvert.SerializeObject(resultProduct), JsonConvert.SerializeObject(simpleProduct));
@@ -2185,7 +2228,7 @@ public void ModelFlatteningWithParameterFlatteningTest()
MaxProductDisplayName = "max name",
Odatavalue = "http://foo"
};
- var resultProduct = client.PostFlattenedSimpleProduct("123", "max name", "product description", "http://foo");
+ var resultProduct = client.PostFlattenedSimpleProduct("123", "max name", "product description", null, "http://foo");
Assert.Equal(JsonConvert.SerializeObject(resultProduct), JsonConvert.SerializeObject(simpleProduct));
}
}
diff --git a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyArray/Array.cs b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyArray/Array.cs
index 0b9d94dc699a5..3812833eacaae 100644
--- a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyArray/Array.cs
+++ b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyArray/Array.cs
@@ -459,9 +459,12 @@ public Array(AutoRestSwaggerBATArrayService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(arrayBody, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(arrayBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(arrayBody, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -689,9 +692,12 @@ public Array(AutoRestSwaggerBATArrayService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(arrayBody, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(arrayBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(arrayBody, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -1157,9 +1163,12 @@ public Array(AutoRestSwaggerBATArrayService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(arrayBody, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(arrayBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(arrayBody, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -1625,9 +1634,12 @@ public Array(AutoRestSwaggerBATArrayService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(arrayBody, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(arrayBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(arrayBody, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -2093,9 +2105,12 @@ public Array(AutoRestSwaggerBATArrayService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(arrayBody, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(arrayBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(arrayBody, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -2561,9 +2576,12 @@ public Array(AutoRestSwaggerBATArrayService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(arrayBody, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(arrayBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(arrayBody, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -3029,9 +3047,12 @@ public Array(AutoRestSwaggerBATArrayService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(arrayBody, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(arrayBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(arrayBody, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -3501,9 +3522,12 @@ public Array(AutoRestSwaggerBATArrayService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(arrayBody, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(arrayBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(arrayBody, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -3850,9 +3874,12 @@ public Array(AutoRestSwaggerBATArrayService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(arrayBody, new DateJsonConverter());
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(arrayBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(arrayBody, new DateJsonConverter());
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -4320,9 +4347,12 @@ public Array(AutoRestSwaggerBATArrayService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(arrayBody, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(arrayBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(arrayBody, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -4790,9 +4820,12 @@ public Array(AutoRestSwaggerBATArrayService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(arrayBody, new DateTimeRfc1123JsonConverter());
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(arrayBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(arrayBody, new DateTimeRfc1123JsonConverter());
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -5020,9 +5053,12 @@ public Array(AutoRestSwaggerBATArrayService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(arrayBody, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(arrayBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(arrayBody, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -5252,9 +5288,12 @@ public Array(AutoRestSwaggerBATArrayService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(arrayBody, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(arrayBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(arrayBody, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -5429,6 +5468,126 @@ public Array(AutoRestSwaggerBATArrayService client)
return _result;
}
+ ///
+ /// Get array value ['a string that gets encoded with base64url', 'test
+ /// string' 'Lorem ipsum'] with the items base64url encoded
+ ///
+ ///
+ /// Headers that will be added to request.
+ ///
+ ///
+ /// The cancellation token.
+ ///
+ ///
+ /// A response object containing the response body and response headers.
+ ///
+ public async Task>> GetBase64UrlWithHttpMessagesAsync(Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken))
+ {
+ // Tracing
+ bool _shouldTrace = ServiceClientTracing.IsEnabled;
+ string _invocationId = null;
+ if (_shouldTrace)
+ {
+ _invocationId = ServiceClientTracing.NextInvocationId.ToString();
+ Dictionary tracingParameters = new Dictionary();
+ tracingParameters.Add("cancellationToken", cancellationToken);
+ ServiceClientTracing.Enter(_invocationId, this, "GetBase64Url", tracingParameters);
+ }
+ // Construct URL
+ var _baseUrl = this.Client.BaseUri.AbsoluteUri;
+ var _url = new Uri(new Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "array/prim/base64url/valid").ToString();
+ // Create HTTP transport objects
+ HttpRequestMessage _httpRequest = new HttpRequestMessage();
+ HttpResponseMessage _httpResponse = null;
+ _httpRequest.Method = new HttpMethod("GET");
+ _httpRequest.RequestUri = new Uri(_url);
+ // Set Headers
+ if (customHeaders != null)
+ {
+ foreach(var _header in customHeaders)
+ {
+ if (_httpRequest.Headers.Contains(_header.Key))
+ {
+ _httpRequest.Headers.Remove(_header.Key);
+ }
+ _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
+ }
+ }
+
+ // Serialize Request
+ string _requestContent = null;
+ // Send Request
+ if (_shouldTrace)
+ {
+ ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
+ }
+ cancellationToken.ThrowIfCancellationRequested();
+ _httpResponse = await this.Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
+ if (_shouldTrace)
+ {
+ ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
+ }
+ HttpStatusCode _statusCode = _httpResponse.StatusCode;
+ cancellationToken.ThrowIfCancellationRequested();
+ string _responseContent = null;
+ if ((int)_statusCode != 200)
+ {
+ var ex = new ErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusCode));
+ try
+ {
+ _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
+ Error _errorBody = SafeJsonConvert.DeserializeObject(_responseContent, this.Client.DeserializationSettings);
+ if (_errorBody != null)
+ {
+ ex.Body = _errorBody;
+ }
+ }
+ catch (JsonException)
+ {
+ // Ignore the exception
+ }
+ ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
+ ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
+ if (_shouldTrace)
+ {
+ ServiceClientTracing.Error(_invocationId, ex);
+ }
+ _httpRequest.Dispose();
+ if (_httpResponse != null)
+ {
+ _httpResponse.Dispose();
+ }
+ throw ex;
+ }
+ // Create Result
+ var _result = new HttpOperationResponse>();
+ _result.Request = _httpRequest;
+ _result.Response = _httpResponse;
+ // Deserialize Response
+ if ((int)_statusCode == 200)
+ {
+ _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
+ try
+ {
+ _result.Body = SafeJsonConvert.DeserializeObject>(_responseContent, new Base64UrlJsonConverter());
+ }
+ catch (JsonException ex)
+ {
+ _httpRequest.Dispose();
+ if (_httpResponse != null)
+ {
+ _httpResponse.Dispose();
+ }
+ throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
+ }
+ }
+ if (_shouldTrace)
+ {
+ ServiceClientTracing.Exit(_invocationId, _result);
+ }
+ return _result;
+ }
+
///
/// Get array of complex type null value
///
@@ -6082,9 +6241,12 @@ public Array(AutoRestSwaggerBATArrayService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(arrayBody, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(arrayBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(arrayBody, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -6790,9 +6952,12 @@ public Array(AutoRestSwaggerBATArrayService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(arrayBody, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(arrayBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(arrayBody, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -7504,9 +7669,12 @@ public Array(AutoRestSwaggerBATArrayService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(arrayBody, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(arrayBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(arrayBody, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
diff --git a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyArray/ArrayExtensions.cs b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyArray/ArrayExtensions.cs
index 283d2324b9961..1b1f220f613eb 100644
--- a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyArray/ArrayExtensions.cs
+++ b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyArray/ArrayExtensions.cs
@@ -1344,6 +1344,36 @@ public static IList GetByteInvalidNull(this IArray operations)
}
}
+ ///
+ /// Get array value ['a string that gets encoded with base64url', 'test
+ /// string' 'Lorem ipsum'] with the items base64url encoded
+ ///
+ ///
+ /// The operations group for this extension method.
+ ///
+ public static IList GetBase64Url(this IArray operations)
+ {
+ return Task.Factory.StartNew(s => ((IArray)s).GetBase64UrlAsync(), operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Get array value ['a string that gets encoded with base64url', 'test
+ /// string' 'Lorem ipsum'] with the items base64url encoded
+ ///
+ ///
+ /// The operations group for this extension method.
+ ///
+ ///
+ /// The cancellation token.
+ ///
+ public static async Task> GetBase64UrlAsync(this IArray operations, CancellationToken cancellationToken = default(CancellationToken))
+ {
+ using (var _result = await operations.GetBase64UrlWithHttpMessagesAsync(null, cancellationToken).ConfigureAwait(false))
+ {
+ return _result.Body;
+ }
+ }
+
///
/// Get array of complex type null value
///
diff --git a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyArray/IArray.cs b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyArray/IArray.cs
index 51288d0a84660..65f46721b9268 100644
--- a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyArray/IArray.cs
+++ b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyArray/IArray.cs
@@ -520,6 +520,17 @@ public partial interface IArray
///
Task>> GetByteInvalidNullWithHttpMessagesAsync(Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken));
///
+ /// Get array value ['a string that gets encoded with base64url',
+ /// 'test string' 'Lorem ipsum'] with the items base64url encoded
+ ///
+ ///
+ /// The headers that will be added to request.
+ ///
+ ///
+ /// The cancellation token.
+ ///
+ Task>> GetBase64UrlWithHttpMessagesAsync(Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken));
+ ///
/// Get array of complex type null value
///
///
diff --git a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyBoolean/BoolModel.cs b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyBoolean/BoolModel.cs
index d287e6188c543..d78403311ec8c 100644
--- a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyBoolean/BoolModel.cs
+++ b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyBoolean/BoolModel.cs
@@ -217,9 +217,12 @@ public BoolModel(AutoRestBoolTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(boolBody, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(boolBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(boolBody, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -443,9 +446,12 @@ public BoolModel(AutoRestBoolTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(boolBody, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(boolBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(boolBody, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
diff --git a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyByte/ByteModel.cs b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyByte/ByteModel.cs
index 6faca5d0f82c5..6343dc98de5e5 100644
--- a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyByte/ByteModel.cs
+++ b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyByte/ByteModel.cs
@@ -460,9 +460,12 @@ public ByteModel(AutoRestSwaggerBATByteService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(byteBody, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(byteBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(byteBody, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
diff --git a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyComplex/Array.cs b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyComplex/Array.cs
index f24a2d97284af..5009f9e28bcea 100644
--- a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyComplex/Array.cs
+++ b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyComplex/Array.cs
@@ -222,9 +222,12 @@ public Array(AutoRestComplexTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(complexBody, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(complexBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(complexBody, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -453,9 +456,12 @@ public Array(AutoRestComplexTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(complexBody, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(complexBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(complexBody, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
diff --git a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyComplex/BasicOperations.cs b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyComplex/BasicOperations.cs
index a9dd0b484a555..39cc806a8c839 100644
--- a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyComplex/BasicOperations.cs
+++ b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyComplex/BasicOperations.cs
@@ -231,9 +231,12 @@ public BasicOperations(AutoRestComplexTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(complexBody, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(complexBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(complexBody, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
diff --git a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyComplex/Dictionary.cs b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyComplex/Dictionary.cs
index 03d740e5eae86..d707e2106fd98 100644
--- a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyComplex/Dictionary.cs
+++ b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyComplex/Dictionary.cs
@@ -222,9 +222,12 @@ public Dictionary(AutoRestComplexTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(complexBody, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(complexBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(complexBody, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -453,9 +456,12 @@ public Dictionary(AutoRestComplexTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(complexBody, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(complexBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(complexBody, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
diff --git a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyComplex/Inheritance.cs b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyComplex/Inheritance.cs
index d8b687fe82965..8884055cd84c5 100644
--- a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyComplex/Inheritance.cs
+++ b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyComplex/Inheritance.cs
@@ -225,9 +225,12 @@ public Inheritance(AutoRestComplexTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(complexBody, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(complexBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(complexBody, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
diff --git a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyComplex/Polymorphicrecursive.cs b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyComplex/Polymorphicrecursive.cs
index 8a4753fa788be..9e3d47fc4a98a 100644
--- a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyComplex/Polymorphicrecursive.cs
+++ b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyComplex/Polymorphicrecursive.cs
@@ -278,9 +278,12 @@ public Polymorphicrecursive(AutoRestComplexTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(complexBody, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(complexBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(complexBody, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
diff --git a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyComplex/Polymorphism.cs b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyComplex/Polymorphism.cs
index 62d9e5af2d7c7..e9f32ec1faccf 100644
--- a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyComplex/Polymorphism.cs
+++ b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyComplex/Polymorphism.cs
@@ -259,9 +259,12 @@ public Polymorphism(AutoRestComplexTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(complexBody, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(complexBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(complexBody, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -402,9 +405,12 @@ public Polymorphism(AutoRestComplexTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(complexBody, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(complexBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(complexBody, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
diff --git a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyComplex/Primitive.cs b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyComplex/Primitive.cs
index caed868d0e270..334e0f205ddcf 100644
--- a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyComplex/Primitive.cs
+++ b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyComplex/Primitive.cs
@@ -222,9 +222,12 @@ public Primitive(AutoRestComplexTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(complexBody, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(complexBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(complexBody, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -453,9 +456,12 @@ public Primitive(AutoRestComplexTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(complexBody, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(complexBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(complexBody, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -684,9 +690,12 @@ public Primitive(AutoRestComplexTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(complexBody, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(complexBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(complexBody, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -916,9 +925,12 @@ public Primitive(AutoRestComplexTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(complexBody, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(complexBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(complexBody, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -1147,9 +1159,12 @@ public Primitive(AutoRestComplexTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(complexBody, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(complexBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(complexBody, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -1378,9 +1393,12 @@ public Primitive(AutoRestComplexTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(complexBody, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(complexBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(complexBody, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -1609,9 +1627,12 @@ public Primitive(AutoRestComplexTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(complexBody, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(complexBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(complexBody, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -1840,9 +1861,12 @@ public Primitive(AutoRestComplexTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(complexBody, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(complexBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(complexBody, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -2072,9 +2096,12 @@ public Primitive(AutoRestComplexTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(complexBody, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(complexBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(complexBody, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -2300,9 +2327,12 @@ public Primitive(AutoRestComplexTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(complexBody, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(complexBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(complexBody, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -2531,9 +2561,12 @@ public Primitive(AutoRestComplexTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(complexBody, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(complexBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(complexBody, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
diff --git a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyComplex/Readonlyproperty.cs b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyComplex/Readonlyproperty.cs
index 15758e93c2836..57471567ee6da 100644
--- a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyComplex/Readonlyproperty.cs
+++ b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyComplex/Readonlyproperty.cs
@@ -221,9 +221,12 @@ public Readonlyproperty(AutoRestComplexTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(complexBody, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(complexBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(complexBody, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
diff --git a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyDate/Date.cs b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyDate/Date.cs
index 509781fe382c5..0a4c07170740d 100644
--- a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyDate/Date.cs
+++ b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyDate/Date.cs
@@ -574,9 +574,12 @@ public Date(AutoRestDateTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(dateBody, new DateJsonConverter());
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(dateBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(dateBody, new DateJsonConverter());
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -800,9 +803,12 @@ public Date(AutoRestDateTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(dateBody, new DateJsonConverter());
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(dateBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(dateBody, new DateJsonConverter());
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
diff --git a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyDateTime/Datetime.cs b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyDateTime/Datetime.cs
index a46a03a8ae9b4..2248d4263b000 100644
--- a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyDateTime/Datetime.cs
+++ b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyDateTime/Datetime.cs
@@ -574,9 +574,12 @@ public Datetime(AutoRestDateTimeTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(datetimeBody, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(datetimeBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(datetimeBody, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -920,9 +923,12 @@ public Datetime(AutoRestDateTimeTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(datetimeBody, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(datetimeBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(datetimeBody, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -1268,9 +1274,12 @@ public Datetime(AutoRestDateTimeTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(datetimeBody, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(datetimeBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(datetimeBody, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -1615,9 +1624,12 @@ public Datetime(AutoRestDateTimeTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(datetimeBody, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(datetimeBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(datetimeBody, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -1841,9 +1853,12 @@ public Datetime(AutoRestDateTimeTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(datetimeBody, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(datetimeBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(datetimeBody, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -2067,9 +2082,12 @@ public Datetime(AutoRestDateTimeTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(datetimeBody, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(datetimeBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(datetimeBody, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
diff --git a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyDateTimeRfc1123/Datetimerfc1123.cs b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyDateTimeRfc1123/Datetimerfc1123.cs
index 2506c533d5633..068aced56df75 100644
--- a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyDateTimeRfc1123/Datetimerfc1123.cs
+++ b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyDateTimeRfc1123/Datetimerfc1123.cs
@@ -574,9 +574,12 @@ public Datetimerfc1123(AutoRestRFC1123DateTimeTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(datetimeBody, new DateTimeRfc1123JsonConverter());
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(datetimeBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(datetimeBody, new DateTimeRfc1123JsonConverter());
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -919,9 +922,12 @@ public Datetimerfc1123(AutoRestRFC1123DateTimeTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(datetimeBody, new DateTimeRfc1123JsonConverter());
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(datetimeBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(datetimeBody, new DateTimeRfc1123JsonConverter());
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
diff --git a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyDictionary/Dictionary.cs b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyDictionary/Dictionary.cs
index a370279790948..ec2b9dd872bd3 100644
--- a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyDictionary/Dictionary.cs
+++ b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyDictionary/Dictionary.cs
@@ -340,9 +340,12 @@ public Dictionary(AutoRestSwaggerBATdictionaryService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(arrayBody, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(arrayBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(arrayBody, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -1047,9 +1050,12 @@ public Dictionary(AutoRestSwaggerBATdictionaryService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(arrayBody, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(arrayBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(arrayBody, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -1515,9 +1521,12 @@ public Dictionary(AutoRestSwaggerBATdictionaryService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(arrayBody, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(arrayBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(arrayBody, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -1983,9 +1992,12 @@ public Dictionary(AutoRestSwaggerBATdictionaryService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(arrayBody, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(arrayBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(arrayBody, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -2451,9 +2463,12 @@ public Dictionary(AutoRestSwaggerBATdictionaryService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(arrayBody, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(arrayBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(arrayBody, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -2919,9 +2934,12 @@ public Dictionary(AutoRestSwaggerBATdictionaryService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(arrayBody, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(arrayBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(arrayBody, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -3387,9 +3405,12 @@ public Dictionary(AutoRestSwaggerBATdictionaryService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(arrayBody, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(arrayBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(arrayBody, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -3857,9 +3878,12 @@ public Dictionary(AutoRestSwaggerBATdictionaryService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(arrayBody, new DateJsonConverter());
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(arrayBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(arrayBody, new DateJsonConverter());
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -4327,9 +4351,12 @@ public Dictionary(AutoRestSwaggerBATdictionaryService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(arrayBody, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(arrayBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(arrayBody, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -4798,9 +4825,12 @@ public Dictionary(AutoRestSwaggerBATdictionaryService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(arrayBody, new DateTimeRfc1123JsonConverter());
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(arrayBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(arrayBody, new DateTimeRfc1123JsonConverter());
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -5029,9 +5059,12 @@ public Dictionary(AutoRestSwaggerBATdictionaryService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(arrayBody, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(arrayBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(arrayBody, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -5261,9 +5294,12 @@ public Dictionary(AutoRestSwaggerBATdictionaryService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(arrayBody, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(arrayBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(arrayBody, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -5438,6 +5474,126 @@ public Dictionary(AutoRestSwaggerBATdictionaryService client)
return _result;
}
+ ///
+ /// Get base64url dictionary value {"0": "a string that gets encoded with
+ /// base64url", "1": "test string", "2": "Lorem ipsum"}
+ ///
+ ///
+ /// Headers that will be added to request.
+ ///
+ ///
+ /// The cancellation token.
+ ///
+ ///
+ /// A response object containing the response body and response headers.
+ ///
+ public async Task>> GetBase64UrlWithHttpMessagesAsync(Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken))
+ {
+ // Tracing
+ bool _shouldTrace = ServiceClientTracing.IsEnabled;
+ string _invocationId = null;
+ if (_shouldTrace)
+ {
+ _invocationId = ServiceClientTracing.NextInvocationId.ToString();
+ Dictionary tracingParameters = new Dictionary();
+ tracingParameters.Add("cancellationToken", cancellationToken);
+ ServiceClientTracing.Enter(_invocationId, this, "GetBase64Url", tracingParameters);
+ }
+ // Construct URL
+ var _baseUrl = this.Client.BaseUri.AbsoluteUri;
+ var _url = new Uri(new Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "dictionary/prim/base64url/valid").ToString();
+ // Create HTTP transport objects
+ HttpRequestMessage _httpRequest = new HttpRequestMessage();
+ HttpResponseMessage _httpResponse = null;
+ _httpRequest.Method = new HttpMethod("GET");
+ _httpRequest.RequestUri = new Uri(_url);
+ // Set Headers
+ if (customHeaders != null)
+ {
+ foreach(var _header in customHeaders)
+ {
+ if (_httpRequest.Headers.Contains(_header.Key))
+ {
+ _httpRequest.Headers.Remove(_header.Key);
+ }
+ _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
+ }
+ }
+
+ // Serialize Request
+ string _requestContent = null;
+ // Send Request
+ if (_shouldTrace)
+ {
+ ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
+ }
+ cancellationToken.ThrowIfCancellationRequested();
+ _httpResponse = await this.Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
+ if (_shouldTrace)
+ {
+ ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
+ }
+ HttpStatusCode _statusCode = _httpResponse.StatusCode;
+ cancellationToken.ThrowIfCancellationRequested();
+ string _responseContent = null;
+ if ((int)_statusCode != 200)
+ {
+ var ex = new ErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusCode));
+ try
+ {
+ _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
+ Error _errorBody = SafeJsonConvert.DeserializeObject(_responseContent, this.Client.DeserializationSettings);
+ if (_errorBody != null)
+ {
+ ex.Body = _errorBody;
+ }
+ }
+ catch (JsonException)
+ {
+ // Ignore the exception
+ }
+ ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
+ ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
+ if (_shouldTrace)
+ {
+ ServiceClientTracing.Error(_invocationId, ex);
+ }
+ _httpRequest.Dispose();
+ if (_httpResponse != null)
+ {
+ _httpResponse.Dispose();
+ }
+ throw ex;
+ }
+ // Create Result
+ var _result = new HttpOperationResponse>();
+ _result.Request = _httpRequest;
+ _result.Response = _httpResponse;
+ // Deserialize Response
+ if ((int)_statusCode == 200)
+ {
+ _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
+ try
+ {
+ _result.Body = SafeJsonConvert.DeserializeObject>(_responseContent, new Base64UrlJsonConverter());
+ }
+ catch (JsonException ex)
+ {
+ _httpRequest.Dispose();
+ if (_httpResponse != null)
+ {
+ _httpResponse.Dispose();
+ }
+ throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
+ }
+ }
+ if (_shouldTrace)
+ {
+ ServiceClientTracing.Exit(_invocationId, _result);
+ }
+ return _result;
+ }
+
///
/// Get dictionary of complex type null value
///
@@ -6092,9 +6248,12 @@ public Dictionary(AutoRestSwaggerBATdictionaryService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(arrayBody, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(arrayBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(arrayBody, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -6802,9 +6961,12 @@ public Dictionary(AutoRestSwaggerBATdictionaryService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(arrayBody, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(arrayBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(arrayBody, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -7517,9 +7679,12 @@ public Dictionary(AutoRestSwaggerBATdictionaryService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(arrayBody, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(arrayBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(arrayBody, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
diff --git a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyDictionary/DictionaryExtensions.cs b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyDictionary/DictionaryExtensions.cs
index 890eea653ece8..081c30c09bcb2 100644
--- a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyDictionary/DictionaryExtensions.cs
+++ b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyDictionary/DictionaryExtensions.cs
@@ -1345,6 +1345,36 @@ public static IDictionary GetByteInvalidNull(this IDictionary op
}
}
+ ///
+ /// Get base64url dictionary value {"0": "a string that gets encoded with
+ /// base64url", "1": "test string", "2": "Lorem ipsum"}
+ ///
+ ///
+ /// The operations group for this extension method.
+ ///
+ public static IDictionary GetBase64Url(this IDictionary operations)
+ {
+ return Task.Factory.StartNew(s => ((IDictionary)s).GetBase64UrlAsync(), operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Get base64url dictionary value {"0": "a string that gets encoded with
+ /// base64url", "1": "test string", "2": "Lorem ipsum"}
+ ///
+ ///
+ /// The operations group for this extension method.
+ ///
+ ///
+ /// The cancellation token.
+ ///
+ public static async Task> GetBase64UrlAsync(this IDictionary operations, CancellationToken cancellationToken = default(CancellationToken))
+ {
+ using (var _result = await operations.GetBase64UrlWithHttpMessagesAsync(null, cancellationToken).ConfigureAwait(false))
+ {
+ return _result.Body;
+ }
+ }
+
///
/// Get dictionary of complex type null value
///
diff --git a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyDictionary/IDictionary.cs b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyDictionary/IDictionary.cs
index 53da3621b1eb1..8c5451a26f103 100644
--- a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyDictionary/IDictionary.cs
+++ b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyDictionary/IDictionary.cs
@@ -524,6 +524,17 @@ public partial interface IDictionary
///
Task>> GetByteInvalidNullWithHttpMessagesAsync(Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken));
///
+ /// Get base64url dictionary value {"0": "a string that gets encoded
+ /// with base64url", "1": "test string", "2": "Lorem ipsum"}
+ ///
+ ///
+ /// The headers that will be added to request.
+ ///
+ ///
+ /// The cancellation token.
+ ///
+ Task>> GetBase64UrlWithHttpMessagesAsync(Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken));
+ ///
/// Get dictionary of complex type null value
///
///
diff --git a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyDuration/Duration.cs b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyDuration/Duration.cs
index 7893ed1ee8506..42b50edf64d33 100644
--- a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyDuration/Duration.cs
+++ b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyDuration/Duration.cs
@@ -217,9 +217,12 @@ public Duration(AutoRestDurationTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(durationBody, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(durationBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(durationBody, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
diff --git a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyInteger/IIntModel.cs b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyInteger/IIntModel.cs
index 4b90323fef26b..7131504bb1855 100644
--- a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyInteger/IIntModel.cs
+++ b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyInteger/IIntModel.cs
@@ -129,5 +129,47 @@ public partial interface IIntModel
/// The cancellation token.
///
Task PutMin64WithHttpMessagesAsync(long intBody, Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken));
+ ///
+ /// Get datetime encoded as Unix time value
+ ///
+ ///
+ /// The headers that will be added to request.
+ ///
+ ///
+ /// The cancellation token.
+ ///
+ Task> GetUnixTimeWithHttpMessagesAsync(Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken));
+ ///
+ /// Put datetime encoded as Unix time
+ ///
+ ///
+ ///
+ ///
+ /// The headers that will be added to request.
+ ///
+ ///
+ /// The cancellation token.
+ ///
+ Task PutUnixTimeDateWithHttpMessagesAsync(DateTime intBody, Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken));
+ ///
+ /// Get invalid Unix time value
+ ///
+ ///
+ /// The headers that will be added to request.
+ ///
+ ///
+ /// The cancellation token.
+ ///
+ Task> GetInvalidUnixTimeWithHttpMessagesAsync(Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken));
+ ///
+ /// Get null Unix time value
+ ///
+ ///
+ /// The headers that will be added to request.
+ ///
+ ///
+ /// The cancellation token.
+ ///
+ Task> GetNullUnixTimeWithHttpMessagesAsync(Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken));
}
}
diff --git a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyInteger/IntModel.cs b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyInteger/IntModel.cs
index 7c65575d05ed7..9c9b57ebbb2a4 100644
--- a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyInteger/IntModel.cs
+++ b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyInteger/IntModel.cs
@@ -812,9 +812,12 @@ public IntModel(AutoRestIntegerTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(intBody, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(intBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(intBody, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -919,9 +922,12 @@ public IntModel(AutoRestIntegerTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(intBody, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(intBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(intBody, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -1026,9 +1032,12 @@ public IntModel(AutoRestIntegerTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(intBody, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(intBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(intBody, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -1133,9 +1142,12 @@ public IntModel(AutoRestIntegerTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(intBody, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(intBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(intBody, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -1190,5 +1202,472 @@ public IntModel(AutoRestIntegerTestService client)
return _result;
}
+ ///
+ /// Get datetime encoded as Unix time value
+ ///
+ ///
+ /// Headers that will be added to request.
+ ///
+ ///
+ /// The cancellation token.
+ ///
+ ///
+ /// A response object containing the response body and response headers.
+ ///
+ public async Task> GetUnixTimeWithHttpMessagesAsync(Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken))
+ {
+ // Tracing
+ bool _shouldTrace = ServiceClientTracing.IsEnabled;
+ string _invocationId = null;
+ if (_shouldTrace)
+ {
+ _invocationId = ServiceClientTracing.NextInvocationId.ToString();
+ Dictionary tracingParameters = new Dictionary();
+ tracingParameters.Add("cancellationToken", cancellationToken);
+ ServiceClientTracing.Enter(_invocationId, this, "GetUnixTime", tracingParameters);
+ }
+ // Construct URL
+ var _baseUrl = this.Client.BaseUri.AbsoluteUri;
+ var _url = new Uri(new Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "int/unixtime").ToString();
+ // Create HTTP transport objects
+ HttpRequestMessage _httpRequest = new HttpRequestMessage();
+ HttpResponseMessage _httpResponse = null;
+ _httpRequest.Method = new HttpMethod("GET");
+ _httpRequest.RequestUri = new Uri(_url);
+ // Set Headers
+ if (customHeaders != null)
+ {
+ foreach(var _header in customHeaders)
+ {
+ if (_httpRequest.Headers.Contains(_header.Key))
+ {
+ _httpRequest.Headers.Remove(_header.Key);
+ }
+ _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
+ }
+ }
+
+ // Serialize Request
+ string _requestContent = null;
+ // Send Request
+ if (_shouldTrace)
+ {
+ ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
+ }
+ cancellationToken.ThrowIfCancellationRequested();
+ _httpResponse = await this.Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
+ if (_shouldTrace)
+ {
+ ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
+ }
+ HttpStatusCode _statusCode = _httpResponse.StatusCode;
+ cancellationToken.ThrowIfCancellationRequested();
+ string _responseContent = null;
+ if ((int)_statusCode != 200)
+ {
+ var ex = new ErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusCode));
+ try
+ {
+ _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
+ Error _errorBody = SafeJsonConvert.DeserializeObject(_responseContent, this.Client.DeserializationSettings);
+ if (_errorBody != null)
+ {
+ ex.Body = _errorBody;
+ }
+ }
+ catch (JsonException)
+ {
+ // Ignore the exception
+ }
+ ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
+ ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
+ if (_shouldTrace)
+ {
+ ServiceClientTracing.Error(_invocationId, ex);
+ }
+ _httpRequest.Dispose();
+ if (_httpResponse != null)
+ {
+ _httpResponse.Dispose();
+ }
+ throw ex;
+ }
+ // Create Result
+ var _result = new HttpOperationResponse();
+ _result.Request = _httpRequest;
+ _result.Response = _httpResponse;
+ // Deserialize Response
+ if ((int)_statusCode == 200)
+ {
+ _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
+ try
+ {
+ _result.Body = SafeJsonConvert.DeserializeObject(_responseContent, new UnixTimeJsonConverter());
+ }
+ catch (JsonException ex)
+ {
+ _httpRequest.Dispose();
+ if (_httpResponse != null)
+ {
+ _httpResponse.Dispose();
+ }
+ throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
+ }
+ }
+ if (_shouldTrace)
+ {
+ ServiceClientTracing.Exit(_invocationId, _result);
+ }
+ return _result;
+ }
+
+ ///
+ /// Put datetime encoded as Unix time
+ ///
+ ///
+ ///
+ ///
+ /// Headers that will be added to request.
+ ///
+ ///
+ /// The cancellation token.
+ ///
+ ///
+ /// A response object containing the response body and response headers.
+ ///
+ public async Task PutUnixTimeDateWithHttpMessagesAsync(DateTime intBody, Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken))
+ {
+ // Tracing
+ bool _shouldTrace = ServiceClientTracing.IsEnabled;
+ string _invocationId = null;
+ if (_shouldTrace)
+ {
+ _invocationId = ServiceClientTracing.NextInvocationId.ToString();
+ Dictionary tracingParameters = new Dictionary();
+ tracingParameters.Add("intBody", intBody);
+ tracingParameters.Add("cancellationToken", cancellationToken);
+ ServiceClientTracing.Enter(_invocationId, this, "PutUnixTimeDate", tracingParameters);
+ }
+ // Construct URL
+ var _baseUrl = this.Client.BaseUri.AbsoluteUri;
+ var _url = new Uri(new Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "int/unixtime").ToString();
+ // Create HTTP transport objects
+ HttpRequestMessage _httpRequest = new HttpRequestMessage();
+ HttpResponseMessage _httpResponse = null;
+ _httpRequest.Method = new HttpMethod("PUT");
+ _httpRequest.RequestUri = new Uri(_url);
+ // Set Headers
+ if (customHeaders != null)
+ {
+ foreach(var _header in customHeaders)
+ {
+ if (_httpRequest.Headers.Contains(_header.Key))
+ {
+ _httpRequest.Headers.Remove(_header.Key);
+ }
+ _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
+ }
+ }
+
+ // Serialize Request
+ string _requestContent = null;
+ if(intBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(intBody, new UnixTimeJsonConverter());
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
+ // Send Request
+ if (_shouldTrace)
+ {
+ ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
+ }
+ cancellationToken.ThrowIfCancellationRequested();
+ _httpResponse = await this.Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
+ if (_shouldTrace)
+ {
+ ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
+ }
+ HttpStatusCode _statusCode = _httpResponse.StatusCode;
+ cancellationToken.ThrowIfCancellationRequested();
+ string _responseContent = null;
+ if ((int)_statusCode != 200)
+ {
+ var ex = new ErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusCode));
+ try
+ {
+ _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
+ Error _errorBody = SafeJsonConvert.DeserializeObject(_responseContent, this.Client.DeserializationSettings);
+ if (_errorBody != null)
+ {
+ ex.Body = _errorBody;
+ }
+ }
+ catch (JsonException)
+ {
+ // Ignore the exception
+ }
+ ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
+ ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
+ if (_shouldTrace)
+ {
+ ServiceClientTracing.Error(_invocationId, ex);
+ }
+ _httpRequest.Dispose();
+ if (_httpResponse != null)
+ {
+ _httpResponse.Dispose();
+ }
+ throw ex;
+ }
+ // Create Result
+ var _result = new HttpOperationResponse();
+ _result.Request = _httpRequest;
+ _result.Response = _httpResponse;
+ if (_shouldTrace)
+ {
+ ServiceClientTracing.Exit(_invocationId, _result);
+ }
+ return _result;
+ }
+
+ ///
+ /// Get invalid Unix time value
+ ///
+ ///
+ /// Headers that will be added to request.
+ ///
+ ///
+ /// The cancellation token.
+ ///
+ ///
+ /// A response object containing the response body and response headers.
+ ///
+ public async Task> GetInvalidUnixTimeWithHttpMessagesAsync(Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken))
+ {
+ // Tracing
+ bool _shouldTrace = ServiceClientTracing.IsEnabled;
+ string _invocationId = null;
+ if (_shouldTrace)
+ {
+ _invocationId = ServiceClientTracing.NextInvocationId.ToString();
+ Dictionary tracingParameters = new Dictionary();
+ tracingParameters.Add("cancellationToken", cancellationToken);
+ ServiceClientTracing.Enter(_invocationId, this, "GetInvalidUnixTime", tracingParameters);
+ }
+ // Construct URL
+ var _baseUrl = this.Client.BaseUri.AbsoluteUri;
+ var _url = new Uri(new Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "int/invalidunixtime").ToString();
+ // Create HTTP transport objects
+ HttpRequestMessage _httpRequest = new HttpRequestMessage();
+ HttpResponseMessage _httpResponse = null;
+ _httpRequest.Method = new HttpMethod("GET");
+ _httpRequest.RequestUri = new Uri(_url);
+ // Set Headers
+ if (customHeaders != null)
+ {
+ foreach(var _header in customHeaders)
+ {
+ if (_httpRequest.Headers.Contains(_header.Key))
+ {
+ _httpRequest.Headers.Remove(_header.Key);
+ }
+ _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
+ }
+ }
+
+ // Serialize Request
+ string _requestContent = null;
+ // Send Request
+ if (_shouldTrace)
+ {
+ ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
+ }
+ cancellationToken.ThrowIfCancellationRequested();
+ _httpResponse = await this.Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
+ if (_shouldTrace)
+ {
+ ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
+ }
+ HttpStatusCode _statusCode = _httpResponse.StatusCode;
+ cancellationToken.ThrowIfCancellationRequested();
+ string _responseContent = null;
+ if ((int)_statusCode != 200)
+ {
+ var ex = new ErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusCode));
+ try
+ {
+ _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
+ Error _errorBody = SafeJsonConvert.DeserializeObject(_responseContent, this.Client.DeserializationSettings);
+ if (_errorBody != null)
+ {
+ ex.Body = _errorBody;
+ }
+ }
+ catch (JsonException)
+ {
+ // Ignore the exception
+ }
+ ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
+ ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
+ if (_shouldTrace)
+ {
+ ServiceClientTracing.Error(_invocationId, ex);
+ }
+ _httpRequest.Dispose();
+ if (_httpResponse != null)
+ {
+ _httpResponse.Dispose();
+ }
+ throw ex;
+ }
+ // Create Result
+ var _result = new HttpOperationResponse();
+ _result.Request = _httpRequest;
+ _result.Response = _httpResponse;
+ // Deserialize Response
+ if ((int)_statusCode == 200)
+ {
+ _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
+ try
+ {
+ _result.Body = SafeJsonConvert.DeserializeObject(_responseContent, new UnixTimeJsonConverter());
+ }
+ catch (JsonException ex)
+ {
+ _httpRequest.Dispose();
+ if (_httpResponse != null)
+ {
+ _httpResponse.Dispose();
+ }
+ throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
+ }
+ }
+ if (_shouldTrace)
+ {
+ ServiceClientTracing.Exit(_invocationId, _result);
+ }
+ return _result;
+ }
+
+ ///
+ /// Get null Unix time value
+ ///
+ ///
+ /// Headers that will be added to request.
+ ///
+ ///
+ /// The cancellation token.
+ ///
+ ///
+ /// A response object containing the response body and response headers.
+ ///
+ public async Task> GetNullUnixTimeWithHttpMessagesAsync(Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken))
+ {
+ // Tracing
+ bool _shouldTrace = ServiceClientTracing.IsEnabled;
+ string _invocationId = null;
+ if (_shouldTrace)
+ {
+ _invocationId = ServiceClientTracing.NextInvocationId.ToString();
+ Dictionary tracingParameters = new Dictionary();
+ tracingParameters.Add("cancellationToken", cancellationToken);
+ ServiceClientTracing.Enter(_invocationId, this, "GetNullUnixTime", tracingParameters);
+ }
+ // Construct URL
+ var _baseUrl = this.Client.BaseUri.AbsoluteUri;
+ var _url = new Uri(new Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "int/nullunixtime").ToString();
+ // Create HTTP transport objects
+ HttpRequestMessage _httpRequest = new HttpRequestMessage();
+ HttpResponseMessage _httpResponse = null;
+ _httpRequest.Method = new HttpMethod("GET");
+ _httpRequest.RequestUri = new Uri(_url);
+ // Set Headers
+ if (customHeaders != null)
+ {
+ foreach(var _header in customHeaders)
+ {
+ if (_httpRequest.Headers.Contains(_header.Key))
+ {
+ _httpRequest.Headers.Remove(_header.Key);
+ }
+ _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
+ }
+ }
+
+ // Serialize Request
+ string _requestContent = null;
+ // Send Request
+ if (_shouldTrace)
+ {
+ ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
+ }
+ cancellationToken.ThrowIfCancellationRequested();
+ _httpResponse = await this.Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
+ if (_shouldTrace)
+ {
+ ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
+ }
+ HttpStatusCode _statusCode = _httpResponse.StatusCode;
+ cancellationToken.ThrowIfCancellationRequested();
+ string _responseContent = null;
+ if ((int)_statusCode != 200)
+ {
+ var ex = new ErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusCode));
+ try
+ {
+ _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
+ Error _errorBody = SafeJsonConvert.DeserializeObject(_responseContent, this.Client.DeserializationSettings);
+ if (_errorBody != null)
+ {
+ ex.Body = _errorBody;
+ }
+ }
+ catch (JsonException)
+ {
+ // Ignore the exception
+ }
+ ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
+ ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
+ if (_shouldTrace)
+ {
+ ServiceClientTracing.Error(_invocationId, ex);
+ }
+ _httpRequest.Dispose();
+ if (_httpResponse != null)
+ {
+ _httpResponse.Dispose();
+ }
+ throw ex;
+ }
+ // Create Result
+ var _result = new HttpOperationResponse();
+ _result.Request = _httpRequest;
+ _result.Response = _httpResponse;
+ // Deserialize Response
+ if ((int)_statusCode == 200)
+ {
+ _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
+ try
+ {
+ _result.Body = SafeJsonConvert.DeserializeObject(_responseContent, new UnixTimeJsonConverter());
+ }
+ catch (JsonException ex)
+ {
+ _httpRequest.Dispose();
+ if (_httpResponse != null)
+ {
+ _httpResponse.Dispose();
+ }
+ throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
+ }
+ }
+ if (_shouldTrace)
+ {
+ ServiceClientTracing.Exit(_invocationId, _result);
+ }
+ return _result;
+ }
+
}
}
diff --git a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyInteger/IntModelExtensions.cs b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyInteger/IntModelExtensions.cs
index 0c57e20b0aade..c0bc0812ebde8 100644
--- a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyInteger/IntModelExtensions.cs
+++ b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyInteger/IntModelExtensions.cs
@@ -305,5 +305,118 @@ public static void PutMin64(this IIntModel operations, long intBody)
await operations.PutMin64WithHttpMessagesAsync(intBody, null, cancellationToken).ConfigureAwait(false);
}
+ ///
+ /// Get datetime encoded as Unix time value
+ ///
+ ///
+ /// The operations group for this extension method.
+ ///
+ public static DateTime? GetUnixTime(this IIntModel operations)
+ {
+ return Task.Factory.StartNew(s => ((IIntModel)s).GetUnixTimeAsync(), operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Get datetime encoded as Unix time value
+ ///
+ ///
+ /// The operations group for this extension method.
+ ///
+ ///
+ /// The cancellation token.
+ ///
+ public static async Task GetUnixTimeAsync(this IIntModel operations, CancellationToken cancellationToken = default(CancellationToken))
+ {
+ using (var _result = await operations.GetUnixTimeWithHttpMessagesAsync(null, cancellationToken).ConfigureAwait(false))
+ {
+ return _result.Body;
+ }
+ }
+
+ ///
+ /// Put datetime encoded as Unix time
+ ///
+ ///
+ /// The operations group for this extension method.
+ ///
+ ///
+ ///
+ public static void PutUnixTimeDate(this IIntModel operations, DateTime intBody)
+ {
+ Task.Factory.StartNew(s => ((IIntModel)s).PutUnixTimeDateAsync(intBody), operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Put datetime encoded as Unix time
+ ///
+ ///
+ /// The operations group for this extension method.
+ ///
+ ///
+ ///
+ ///
+ /// The cancellation token.
+ ///
+ public static async Task PutUnixTimeDateAsync(this IIntModel operations, DateTime intBody, CancellationToken cancellationToken = default(CancellationToken))
+ {
+ await operations.PutUnixTimeDateWithHttpMessagesAsync(intBody, null, cancellationToken).ConfigureAwait(false);
+ }
+
+ ///
+ /// Get invalid Unix time value
+ ///
+ ///
+ /// The operations group for this extension method.
+ ///
+ public static DateTime? GetInvalidUnixTime(this IIntModel operations)
+ {
+ return Task.Factory.StartNew(s => ((IIntModel)s).GetInvalidUnixTimeAsync(), operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Get invalid Unix time value
+ ///
+ ///
+ /// The operations group for this extension method.
+ ///
+ ///
+ /// The cancellation token.
+ ///
+ public static async Task GetInvalidUnixTimeAsync(this IIntModel operations, CancellationToken cancellationToken = default(CancellationToken))
+ {
+ using (var _result = await operations.GetInvalidUnixTimeWithHttpMessagesAsync(null, cancellationToken).ConfigureAwait(false))
+ {
+ return _result.Body;
+ }
+ }
+
+ ///
+ /// Get null Unix time value
+ ///
+ ///
+ /// The operations group for this extension method.
+ ///
+ public static DateTime? GetNullUnixTime(this IIntModel operations)
+ {
+ return Task.Factory.StartNew(s => ((IIntModel)s).GetNullUnixTimeAsync(), operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Get null Unix time value
+ ///
+ ///
+ /// The operations group for this extension method.
+ ///
+ ///
+ /// The cancellation token.
+ ///
+ public static async Task GetNullUnixTimeAsync(this IIntModel operations, CancellationToken cancellationToken = default(CancellationToken))
+ {
+ using (var _result = await operations.GetNullUnixTimeWithHttpMessagesAsync(null, cancellationToken).ConfigureAwait(false))
+ {
+ return _result.Body;
+ }
+ }
+
}
}
diff --git a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyNumber/Number.cs b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyNumber/Number.cs
index dc98d33d86449..4b60b5582025a 100644
--- a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyNumber/Number.cs
+++ b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyNumber/Number.cs
@@ -574,9 +574,12 @@ public Number(AutoRestNumberTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(numberBody, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(numberBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(numberBody, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -800,9 +803,12 @@ public Number(AutoRestNumberTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(numberBody, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(numberBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(numberBody, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -1026,9 +1032,12 @@ public Number(AutoRestNumberTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(numberBody, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(numberBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(numberBody, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -1252,9 +1261,12 @@ public Number(AutoRestNumberTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(numberBody, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(numberBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(numberBody, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -1478,9 +1490,12 @@ public Number(AutoRestNumberTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(numberBody, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(numberBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(numberBody, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -1704,9 +1719,12 @@ public Number(AutoRestNumberTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(numberBody, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(numberBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(numberBody, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -1930,9 +1948,12 @@ public Number(AutoRestNumberTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(numberBody, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(numberBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(numberBody, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -2156,9 +2177,12 @@ public Number(AutoRestNumberTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(numberBody, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(numberBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(numberBody, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -2382,9 +2406,12 @@ public Number(AutoRestNumberTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(numberBody, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(numberBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(numberBody, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -2608,9 +2635,12 @@ public Number(AutoRestNumberTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(numberBody, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(numberBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(numberBody, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
diff --git a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyString/EnumModel.cs b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyString/EnumModel.cs
index c1701bfb31ad1..8861a350c04b9 100644
--- a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyString/EnumModel.cs
+++ b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyString/EnumModel.cs
@@ -220,9 +220,12 @@ public EnumModel(AutoRestSwaggerBATService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(stringBody, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(stringBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(stringBody, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
diff --git a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyString/IStringModel.cs b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyString/IStringModel.cs
index ead7a87735a93..e1823d0463b87 100644
--- a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyString/IStringModel.cs
+++ b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyString/IStringModel.cs
@@ -136,5 +136,47 @@ public partial interface IStringModel
/// The cancellation token.
///
Task> GetNotProvidedWithHttpMessagesAsync(Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken));
+ ///
+ /// Get value that is base64 encoded
+ ///
+ ///
+ /// The headers that will be added to request.
+ ///
+ ///
+ /// The cancellation token.
+ ///
+ Task> GetBase64EncodedWithHttpMessagesAsync(Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken));
+ ///
+ /// Get value that is base64url encoded
+ ///
+ ///
+ /// The headers that will be added to request.
+ ///
+ ///
+ /// The cancellation token.
+ ///
+ Task> GetBase64UrlEncodedWithHttpMessagesAsync(Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken));
+ ///
+ /// Put value that is base64url encoded
+ ///
+ ///
+ ///
+ ///
+ /// The headers that will be added to request.
+ ///
+ ///
+ /// The cancellation token.
+ ///
+ Task PutBase64UrlEncodedWithHttpMessagesAsync(byte[] stringBody, Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken));
+ ///
+ /// Get null value that is expected to be base64url encoded
+ ///
+ ///
+ /// The headers that will be added to request.
+ ///
+ ///
+ /// The cancellation token.
+ ///
+ Task> GetNullBase64UrlEncodedWithHttpMessagesAsync(Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken));
}
}
diff --git a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyString/StringModel.cs b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyString/StringModel.cs
index 61557a3917295..e32308ac6f570 100644
--- a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyString/StringModel.cs
+++ b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyString/StringModel.cs
@@ -218,9 +218,12 @@ public StringModel(AutoRestSwaggerBATService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(stringBody, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(stringBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(stringBody, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -449,9 +452,12 @@ public StringModel(AutoRestSwaggerBATService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(stringBody, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(stringBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(stringBody, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -683,9 +689,12 @@ public StringModel(AutoRestSwaggerBATService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(stringBody, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(stringBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(stringBody, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -919,9 +928,12 @@ public StringModel(AutoRestSwaggerBATService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(stringBody, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(stringBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(stringBody, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -1095,5 +1107,476 @@ public StringModel(AutoRestSwaggerBATService client)
return _result;
}
+ ///
+ /// Get value that is base64 encoded
+ ///
+ ///
+ /// Headers that will be added to request.
+ ///
+ ///
+ /// The cancellation token.
+ ///
+ ///
+ /// A response object containing the response body and response headers.
+ ///
+ public async Task> GetBase64EncodedWithHttpMessagesAsync(Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken))
+ {
+ // Tracing
+ bool _shouldTrace = ServiceClientTracing.IsEnabled;
+ string _invocationId = null;
+ if (_shouldTrace)
+ {
+ _invocationId = ServiceClientTracing.NextInvocationId.ToString();
+ Dictionary tracingParameters = new Dictionary();
+ tracingParameters.Add("cancellationToken", cancellationToken);
+ ServiceClientTracing.Enter(_invocationId, this, "GetBase64Encoded", tracingParameters);
+ }
+ // Construct URL
+ var _baseUrl = this.Client.BaseUri.AbsoluteUri;
+ var _url = new Uri(new Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "string/base64Encoding").ToString();
+ // Create HTTP transport objects
+ HttpRequestMessage _httpRequest = new HttpRequestMessage();
+ HttpResponseMessage _httpResponse = null;
+ _httpRequest.Method = new HttpMethod("GET");
+ _httpRequest.RequestUri = new Uri(_url);
+ // Set Headers
+ if (customHeaders != null)
+ {
+ foreach(var _header in customHeaders)
+ {
+ if (_httpRequest.Headers.Contains(_header.Key))
+ {
+ _httpRequest.Headers.Remove(_header.Key);
+ }
+ _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
+ }
+ }
+
+ // Serialize Request
+ string _requestContent = null;
+ // Send Request
+ if (_shouldTrace)
+ {
+ ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
+ }
+ cancellationToken.ThrowIfCancellationRequested();
+ _httpResponse = await this.Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
+ if (_shouldTrace)
+ {
+ ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
+ }
+ HttpStatusCode _statusCode = _httpResponse.StatusCode;
+ cancellationToken.ThrowIfCancellationRequested();
+ string _responseContent = null;
+ if ((int)_statusCode != 200)
+ {
+ var ex = new ErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusCode));
+ try
+ {
+ _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
+ Error _errorBody = SafeJsonConvert.DeserializeObject(_responseContent, this.Client.DeserializationSettings);
+ if (_errorBody != null)
+ {
+ ex.Body = _errorBody;
+ }
+ }
+ catch (JsonException)
+ {
+ // Ignore the exception
+ }
+ ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
+ ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
+ if (_shouldTrace)
+ {
+ ServiceClientTracing.Error(_invocationId, ex);
+ }
+ _httpRequest.Dispose();
+ if (_httpResponse != null)
+ {
+ _httpResponse.Dispose();
+ }
+ throw ex;
+ }
+ // Create Result
+ var _result = new HttpOperationResponse();
+ _result.Request = _httpRequest;
+ _result.Response = _httpResponse;
+ // Deserialize Response
+ if ((int)_statusCode == 200)
+ {
+ _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
+ try
+ {
+ _result.Body = SafeJsonConvert.DeserializeObject(_responseContent, new Base64UrlJsonConverter());
+ }
+ catch (JsonException ex)
+ {
+ _httpRequest.Dispose();
+ if (_httpResponse != null)
+ {
+ _httpResponse.Dispose();
+ }
+ throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
+ }
+ }
+ if (_shouldTrace)
+ {
+ ServiceClientTracing.Exit(_invocationId, _result);
+ }
+ return _result;
+ }
+
+ ///
+ /// Get value that is base64url encoded
+ ///
+ ///
+ /// Headers that will be added to request.
+ ///
+ ///
+ /// The cancellation token.
+ ///
+ ///
+ /// A response object containing the response body and response headers.
+ ///
+ public async Task> GetBase64UrlEncodedWithHttpMessagesAsync(Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken))
+ {
+ // Tracing
+ bool _shouldTrace = ServiceClientTracing.IsEnabled;
+ string _invocationId = null;
+ if (_shouldTrace)
+ {
+ _invocationId = ServiceClientTracing.NextInvocationId.ToString();
+ Dictionary tracingParameters = new Dictionary();
+ tracingParameters.Add("cancellationToken", cancellationToken);
+ ServiceClientTracing.Enter(_invocationId, this, "GetBase64UrlEncoded", tracingParameters);
+ }
+ // Construct URL
+ var _baseUrl = this.Client.BaseUri.AbsoluteUri;
+ var _url = new Uri(new Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "string/base64UrlEncoding").ToString();
+ // Create HTTP transport objects
+ HttpRequestMessage _httpRequest = new HttpRequestMessage();
+ HttpResponseMessage _httpResponse = null;
+ _httpRequest.Method = new HttpMethod("GET");
+ _httpRequest.RequestUri = new Uri(_url);
+ // Set Headers
+ if (customHeaders != null)
+ {
+ foreach(var _header in customHeaders)
+ {
+ if (_httpRequest.Headers.Contains(_header.Key))
+ {
+ _httpRequest.Headers.Remove(_header.Key);
+ }
+ _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
+ }
+ }
+
+ // Serialize Request
+ string _requestContent = null;
+ // Send Request
+ if (_shouldTrace)
+ {
+ ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
+ }
+ cancellationToken.ThrowIfCancellationRequested();
+ _httpResponse = await this.Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
+ if (_shouldTrace)
+ {
+ ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
+ }
+ HttpStatusCode _statusCode = _httpResponse.StatusCode;
+ cancellationToken.ThrowIfCancellationRequested();
+ string _responseContent = null;
+ if ((int)_statusCode != 200)
+ {
+ var ex = new ErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusCode));
+ try
+ {
+ _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
+ Error _errorBody = SafeJsonConvert.DeserializeObject(_responseContent, this.Client.DeserializationSettings);
+ if (_errorBody != null)
+ {
+ ex.Body = _errorBody;
+ }
+ }
+ catch (JsonException)
+ {
+ // Ignore the exception
+ }
+ ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
+ ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
+ if (_shouldTrace)
+ {
+ ServiceClientTracing.Error(_invocationId, ex);
+ }
+ _httpRequest.Dispose();
+ if (_httpResponse != null)
+ {
+ _httpResponse.Dispose();
+ }
+ throw ex;
+ }
+ // Create Result
+ var _result = new HttpOperationResponse();
+ _result.Request = _httpRequest;
+ _result.Response = _httpResponse;
+ // Deserialize Response
+ if ((int)_statusCode == 200)
+ {
+ _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
+ try
+ {
+ _result.Body = SafeJsonConvert.DeserializeObject(_responseContent, new Base64UrlJsonConverter());
+ }
+ catch (JsonException ex)
+ {
+ _httpRequest.Dispose();
+ if (_httpResponse != null)
+ {
+ _httpResponse.Dispose();
+ }
+ throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
+ }
+ }
+ if (_shouldTrace)
+ {
+ ServiceClientTracing.Exit(_invocationId, _result);
+ }
+ return _result;
+ }
+
+ ///
+ /// Put value that is base64url encoded
+ ///
+ ///
+ ///
+ ///
+ /// Headers that will be added to request.
+ ///
+ ///
+ /// The cancellation token.
+ ///
+ ///
+ /// A response object containing the response body and response headers.
+ ///
+ public async Task PutBase64UrlEncodedWithHttpMessagesAsync(byte[] stringBody, Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken))
+ {
+ if (stringBody == null)
+ {
+ throw new ValidationException(ValidationRules.CannotBeNull, "stringBody");
+ }
+ // Tracing
+ bool _shouldTrace = ServiceClientTracing.IsEnabled;
+ string _invocationId = null;
+ if (_shouldTrace)
+ {
+ _invocationId = ServiceClientTracing.NextInvocationId.ToString();
+ Dictionary tracingParameters = new Dictionary();
+ tracingParameters.Add("stringBody", stringBody);
+ tracingParameters.Add("cancellationToken", cancellationToken);
+ ServiceClientTracing.Enter(_invocationId, this, "PutBase64UrlEncoded", tracingParameters);
+ }
+ // Construct URL
+ var _baseUrl = this.Client.BaseUri.AbsoluteUri;
+ var _url = new Uri(new Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "string/base64UrlEncoding").ToString();
+ // Create HTTP transport objects
+ HttpRequestMessage _httpRequest = new HttpRequestMessage();
+ HttpResponseMessage _httpResponse = null;
+ _httpRequest.Method = new HttpMethod("PUT");
+ _httpRequest.RequestUri = new Uri(_url);
+ // Set Headers
+ if (customHeaders != null)
+ {
+ foreach(var _header in customHeaders)
+ {
+ if (_httpRequest.Headers.Contains(_header.Key))
+ {
+ _httpRequest.Headers.Remove(_header.Key);
+ }
+ _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
+ }
+ }
+
+ // Serialize Request
+ string _requestContent = null;
+ if(stringBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(stringBody, new Base64UrlJsonConverter());
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
+ // Send Request
+ if (_shouldTrace)
+ {
+ ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
+ }
+ cancellationToken.ThrowIfCancellationRequested();
+ _httpResponse = await this.Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
+ if (_shouldTrace)
+ {
+ ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
+ }
+ HttpStatusCode _statusCode = _httpResponse.StatusCode;
+ cancellationToken.ThrowIfCancellationRequested();
+ string _responseContent = null;
+ if ((int)_statusCode != 200)
+ {
+ var ex = new ErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusCode));
+ try
+ {
+ _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
+ Error _errorBody = SafeJsonConvert.DeserializeObject(_responseContent, this.Client.DeserializationSettings);
+ if (_errorBody != null)
+ {
+ ex.Body = _errorBody;
+ }
+ }
+ catch (JsonException)
+ {
+ // Ignore the exception
+ }
+ ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
+ ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
+ if (_shouldTrace)
+ {
+ ServiceClientTracing.Error(_invocationId, ex);
+ }
+ _httpRequest.Dispose();
+ if (_httpResponse != null)
+ {
+ _httpResponse.Dispose();
+ }
+ throw ex;
+ }
+ // Create Result
+ var _result = new HttpOperationResponse();
+ _result.Request = _httpRequest;
+ _result.Response = _httpResponse;
+ if (_shouldTrace)
+ {
+ ServiceClientTracing.Exit(_invocationId, _result);
+ }
+ return _result;
+ }
+
+ ///
+ /// Get null value that is expected to be base64url encoded
+ ///
+ ///
+ /// Headers that will be added to request.
+ ///
+ ///
+ /// The cancellation token.
+ ///
+ ///
+ /// A response object containing the response body and response headers.
+ ///
+ public async Task> GetNullBase64UrlEncodedWithHttpMessagesAsync(Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken))
+ {
+ // Tracing
+ bool _shouldTrace = ServiceClientTracing.IsEnabled;
+ string _invocationId = null;
+ if (_shouldTrace)
+ {
+ _invocationId = ServiceClientTracing.NextInvocationId.ToString();
+ Dictionary tracingParameters = new Dictionary();
+ tracingParameters.Add("cancellationToken", cancellationToken);
+ ServiceClientTracing.Enter(_invocationId, this, "GetNullBase64UrlEncoded", tracingParameters);
+ }
+ // Construct URL
+ var _baseUrl = this.Client.BaseUri.AbsoluteUri;
+ var _url = new Uri(new Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "string/nullBase64UrlEncoding").ToString();
+ // Create HTTP transport objects
+ HttpRequestMessage _httpRequest = new HttpRequestMessage();
+ HttpResponseMessage _httpResponse = null;
+ _httpRequest.Method = new HttpMethod("GET");
+ _httpRequest.RequestUri = new Uri(_url);
+ // Set Headers
+ if (customHeaders != null)
+ {
+ foreach(var _header in customHeaders)
+ {
+ if (_httpRequest.Headers.Contains(_header.Key))
+ {
+ _httpRequest.Headers.Remove(_header.Key);
+ }
+ _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
+ }
+ }
+
+ // Serialize Request
+ string _requestContent = null;
+ // Send Request
+ if (_shouldTrace)
+ {
+ ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
+ }
+ cancellationToken.ThrowIfCancellationRequested();
+ _httpResponse = await this.Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
+ if (_shouldTrace)
+ {
+ ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
+ }
+ HttpStatusCode _statusCode = _httpResponse.StatusCode;
+ cancellationToken.ThrowIfCancellationRequested();
+ string _responseContent = null;
+ if ((int)_statusCode != 200)
+ {
+ var ex = new ErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusCode));
+ try
+ {
+ _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
+ Error _errorBody = SafeJsonConvert.DeserializeObject(_responseContent, this.Client.DeserializationSettings);
+ if (_errorBody != null)
+ {
+ ex.Body = _errorBody;
+ }
+ }
+ catch (JsonException)
+ {
+ // Ignore the exception
+ }
+ ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
+ ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
+ if (_shouldTrace)
+ {
+ ServiceClientTracing.Error(_invocationId, ex);
+ }
+ _httpRequest.Dispose();
+ if (_httpResponse != null)
+ {
+ _httpResponse.Dispose();
+ }
+ throw ex;
+ }
+ // Create Result
+ var _result = new HttpOperationResponse();
+ _result.Request = _httpRequest;
+ _result.Response = _httpResponse;
+ // Deserialize Response
+ if ((int)_statusCode == 200)
+ {
+ _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
+ try
+ {
+ _result.Body = SafeJsonConvert.DeserializeObject(_responseContent, new Base64UrlJsonConverter());
+ }
+ catch (JsonException ex)
+ {
+ _httpRequest.Dispose();
+ if (_httpResponse != null)
+ {
+ _httpResponse.Dispose();
+ }
+ throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
+ }
+ }
+ if (_shouldTrace)
+ {
+ ServiceClientTracing.Exit(_invocationId, _result);
+ }
+ return _result;
+ }
+
}
}
diff --git a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyString/StringModelExtensions.cs b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyString/StringModelExtensions.cs
index aaa2faa66b405..7e028f2034390 100644
--- a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyString/StringModelExtensions.cs
+++ b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyString/StringModelExtensions.cs
@@ -301,5 +301,118 @@ public static string GetNotProvided(this IStringModel operations)
}
}
+ ///
+ /// Get value that is base64 encoded
+ ///
+ ///
+ /// The operations group for this extension method.
+ ///
+ public static byte[] GetBase64Encoded(this IStringModel operations)
+ {
+ return Task.Factory.StartNew(s => ((IStringModel)s).GetBase64EncodedAsync(), operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Get value that is base64 encoded
+ ///
+ ///
+ /// The operations group for this extension method.
+ ///
+ ///
+ /// The cancellation token.
+ ///
+ public static async Task GetBase64EncodedAsync(this IStringModel operations, CancellationToken cancellationToken = default(CancellationToken))
+ {
+ using (var _result = await operations.GetBase64EncodedWithHttpMessagesAsync(null, cancellationToken).ConfigureAwait(false))
+ {
+ return _result.Body;
+ }
+ }
+
+ ///
+ /// Get value that is base64url encoded
+ ///
+ ///
+ /// The operations group for this extension method.
+ ///
+ public static byte[] GetBase64UrlEncoded(this IStringModel operations)
+ {
+ return Task.Factory.StartNew(s => ((IStringModel)s).GetBase64UrlEncodedAsync(), operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Get value that is base64url encoded
+ ///
+ ///
+ /// The operations group for this extension method.
+ ///
+ ///
+ /// The cancellation token.
+ ///
+ public static async Task GetBase64UrlEncodedAsync(this IStringModel operations, CancellationToken cancellationToken = default(CancellationToken))
+ {
+ using (var _result = await operations.GetBase64UrlEncodedWithHttpMessagesAsync(null, cancellationToken).ConfigureAwait(false))
+ {
+ return _result.Body;
+ }
+ }
+
+ ///
+ /// Put value that is base64url encoded
+ ///
+ ///
+ /// The operations group for this extension method.
+ ///
+ ///
+ ///
+ public static void PutBase64UrlEncoded(this IStringModel operations, byte[] stringBody)
+ {
+ Task.Factory.StartNew(s => ((IStringModel)s).PutBase64UrlEncodedAsync(stringBody), operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Put value that is base64url encoded
+ ///
+ ///
+ /// The operations group for this extension method.
+ ///
+ ///
+ ///
+ ///
+ /// The cancellation token.
+ ///
+ public static async Task PutBase64UrlEncodedAsync(this IStringModel operations, byte[] stringBody, CancellationToken cancellationToken = default(CancellationToken))
+ {
+ await operations.PutBase64UrlEncodedWithHttpMessagesAsync(stringBody, null, cancellationToken).ConfigureAwait(false);
+ }
+
+ ///
+ /// Get null value that is expected to be base64url encoded
+ ///
+ ///
+ /// The operations group for this extension method.
+ ///
+ public static byte[] GetNullBase64UrlEncoded(this IStringModel operations)
+ {
+ return Task.Factory.StartNew(s => ((IStringModel)s).GetNullBase64UrlEncodedAsync(), operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Get null value that is expected to be base64url encoded
+ ///
+ ///
+ /// The operations group for this extension method.
+ ///
+ ///
+ /// The cancellation token.
+ ///
+ public static async Task GetNullBase64UrlEncodedAsync(this IStringModel operations, CancellationToken cancellationToken = default(CancellationToken))
+ {
+ using (var _result = await operations.GetNullBase64UrlEncodedWithHttpMessagesAsync(null, cancellationToken).ConfigureAwait(false))
+ {
+ return _result.Body;
+ }
+ }
+
}
}
diff --git a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/CompositeBoolIntClient/BoolModel.cs b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/CompositeBoolIntClient/BoolModel.cs
index 9c761510fc304..22ff99e128385 100644
--- a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/CompositeBoolIntClient/BoolModel.cs
+++ b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/CompositeBoolIntClient/BoolModel.cs
@@ -217,9 +217,12 @@ public BoolModel(CompositeBoolInt client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(boolBody, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(boolBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(boolBody, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -443,9 +446,12 @@ public BoolModel(CompositeBoolInt client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(boolBody, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(boolBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(boolBody, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
diff --git a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/CompositeBoolIntClient/IIntModel.cs b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/CompositeBoolIntClient/IIntModel.cs
index 4917e355224d7..d0b518478669c 100644
--- a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/CompositeBoolIntClient/IIntModel.cs
+++ b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/CompositeBoolIntClient/IIntModel.cs
@@ -129,5 +129,47 @@ public partial interface IIntModel
/// The cancellation token.
///
Task PutMin64WithHttpMessagesAsync(long intBody, Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken));
+ ///
+ /// Get datetime encoded as Unix time value
+ ///
+ ///
+ /// The headers that will be added to request.
+ ///
+ ///
+ /// The cancellation token.
+ ///
+ Task> GetUnixTimeWithHttpMessagesAsync(Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken));
+ ///
+ /// Put datetime encoded as Unix time
+ ///
+ ///
+ ///
+ ///
+ /// The headers that will be added to request.
+ ///
+ ///
+ /// The cancellation token.
+ ///
+ Task PutUnixTimeDateWithHttpMessagesAsync(DateTime intBody, Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken));
+ ///
+ /// Get invalid Unix time value
+ ///
+ ///
+ /// The headers that will be added to request.
+ ///
+ ///
+ /// The cancellation token.
+ ///
+ Task> GetInvalidUnixTimeWithHttpMessagesAsync(Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken));
+ ///
+ /// Get null Unix time value
+ ///
+ ///
+ /// The headers that will be added to request.
+ ///
+ ///
+ /// The cancellation token.
+ ///
+ Task> GetNullUnixTimeWithHttpMessagesAsync(Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken));
}
}
diff --git a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/CompositeBoolIntClient/IntModel.cs b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/CompositeBoolIntClient/IntModel.cs
index 6932d90778be5..2047fd860871e 100644
--- a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/CompositeBoolIntClient/IntModel.cs
+++ b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/CompositeBoolIntClient/IntModel.cs
@@ -812,9 +812,12 @@ public IntModel(CompositeBoolInt client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(intBody, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(intBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(intBody, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -919,9 +922,12 @@ public IntModel(CompositeBoolInt client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(intBody, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(intBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(intBody, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -1026,9 +1032,12 @@ public IntModel(CompositeBoolInt client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(intBody, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(intBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(intBody, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -1133,9 +1142,12 @@ public IntModel(CompositeBoolInt client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(intBody, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(intBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(intBody, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -1190,5 +1202,472 @@ public IntModel(CompositeBoolInt client)
return _result;
}
+ ///
+ /// Get datetime encoded as Unix time value
+ ///
+ ///
+ /// Headers that will be added to request.
+ ///
+ ///
+ /// The cancellation token.
+ ///
+ ///
+ /// A response object containing the response body and response headers.
+ ///
+ public async Task> GetUnixTimeWithHttpMessagesAsync(Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken))
+ {
+ // Tracing
+ bool _shouldTrace = ServiceClientTracing.IsEnabled;
+ string _invocationId = null;
+ if (_shouldTrace)
+ {
+ _invocationId = ServiceClientTracing.NextInvocationId.ToString();
+ Dictionary tracingParameters = new Dictionary();
+ tracingParameters.Add("cancellationToken", cancellationToken);
+ ServiceClientTracing.Enter(_invocationId, this, "GetUnixTime", tracingParameters);
+ }
+ // Construct URL
+ var _baseUrl = this.Client.BaseUri.AbsoluteUri;
+ var _url = new Uri(new Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "int/unixtime").ToString();
+ // Create HTTP transport objects
+ HttpRequestMessage _httpRequest = new HttpRequestMessage();
+ HttpResponseMessage _httpResponse = null;
+ _httpRequest.Method = new HttpMethod("GET");
+ _httpRequest.RequestUri = new Uri(_url);
+ // Set Headers
+ if (customHeaders != null)
+ {
+ foreach(var _header in customHeaders)
+ {
+ if (_httpRequest.Headers.Contains(_header.Key))
+ {
+ _httpRequest.Headers.Remove(_header.Key);
+ }
+ _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
+ }
+ }
+
+ // Serialize Request
+ string _requestContent = null;
+ // Send Request
+ if (_shouldTrace)
+ {
+ ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
+ }
+ cancellationToken.ThrowIfCancellationRequested();
+ _httpResponse = await this.Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
+ if (_shouldTrace)
+ {
+ ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
+ }
+ HttpStatusCode _statusCode = _httpResponse.StatusCode;
+ cancellationToken.ThrowIfCancellationRequested();
+ string _responseContent = null;
+ if ((int)_statusCode != 200)
+ {
+ var ex = new ErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusCode));
+ try
+ {
+ _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
+ Error _errorBody = SafeJsonConvert.DeserializeObject(_responseContent, this.Client.DeserializationSettings);
+ if (_errorBody != null)
+ {
+ ex.Body = _errorBody;
+ }
+ }
+ catch (JsonException)
+ {
+ // Ignore the exception
+ }
+ ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
+ ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
+ if (_shouldTrace)
+ {
+ ServiceClientTracing.Error(_invocationId, ex);
+ }
+ _httpRequest.Dispose();
+ if (_httpResponse != null)
+ {
+ _httpResponse.Dispose();
+ }
+ throw ex;
+ }
+ // Create Result
+ var _result = new HttpOperationResponse();
+ _result.Request = _httpRequest;
+ _result.Response = _httpResponse;
+ // Deserialize Response
+ if ((int)_statusCode == 200)
+ {
+ _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
+ try
+ {
+ _result.Body = SafeJsonConvert.DeserializeObject(_responseContent, new UnixTimeJsonConverter());
+ }
+ catch (JsonException ex)
+ {
+ _httpRequest.Dispose();
+ if (_httpResponse != null)
+ {
+ _httpResponse.Dispose();
+ }
+ throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
+ }
+ }
+ if (_shouldTrace)
+ {
+ ServiceClientTracing.Exit(_invocationId, _result);
+ }
+ return _result;
+ }
+
+ ///
+ /// Put datetime encoded as Unix time
+ ///
+ ///
+ ///
+ ///
+ /// Headers that will be added to request.
+ ///
+ ///
+ /// The cancellation token.
+ ///
+ ///
+ /// A response object containing the response body and response headers.
+ ///
+ public async Task PutUnixTimeDateWithHttpMessagesAsync(DateTime intBody, Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken))
+ {
+ // Tracing
+ bool _shouldTrace = ServiceClientTracing.IsEnabled;
+ string _invocationId = null;
+ if (_shouldTrace)
+ {
+ _invocationId = ServiceClientTracing.NextInvocationId.ToString();
+ Dictionary tracingParameters = new Dictionary();
+ tracingParameters.Add("intBody", intBody);
+ tracingParameters.Add("cancellationToken", cancellationToken);
+ ServiceClientTracing.Enter(_invocationId, this, "PutUnixTimeDate", tracingParameters);
+ }
+ // Construct URL
+ var _baseUrl = this.Client.BaseUri.AbsoluteUri;
+ var _url = new Uri(new Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "int/unixtime").ToString();
+ // Create HTTP transport objects
+ HttpRequestMessage _httpRequest = new HttpRequestMessage();
+ HttpResponseMessage _httpResponse = null;
+ _httpRequest.Method = new HttpMethod("PUT");
+ _httpRequest.RequestUri = new Uri(_url);
+ // Set Headers
+ if (customHeaders != null)
+ {
+ foreach(var _header in customHeaders)
+ {
+ if (_httpRequest.Headers.Contains(_header.Key))
+ {
+ _httpRequest.Headers.Remove(_header.Key);
+ }
+ _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
+ }
+ }
+
+ // Serialize Request
+ string _requestContent = null;
+ if(intBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(intBody, new UnixTimeJsonConverter());
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
+ // Send Request
+ if (_shouldTrace)
+ {
+ ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
+ }
+ cancellationToken.ThrowIfCancellationRequested();
+ _httpResponse = await this.Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
+ if (_shouldTrace)
+ {
+ ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
+ }
+ HttpStatusCode _statusCode = _httpResponse.StatusCode;
+ cancellationToken.ThrowIfCancellationRequested();
+ string _responseContent = null;
+ if ((int)_statusCode != 200)
+ {
+ var ex = new ErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusCode));
+ try
+ {
+ _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
+ Error _errorBody = SafeJsonConvert.DeserializeObject(_responseContent, this.Client.DeserializationSettings);
+ if (_errorBody != null)
+ {
+ ex.Body = _errorBody;
+ }
+ }
+ catch (JsonException)
+ {
+ // Ignore the exception
+ }
+ ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
+ ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
+ if (_shouldTrace)
+ {
+ ServiceClientTracing.Error(_invocationId, ex);
+ }
+ _httpRequest.Dispose();
+ if (_httpResponse != null)
+ {
+ _httpResponse.Dispose();
+ }
+ throw ex;
+ }
+ // Create Result
+ var _result = new HttpOperationResponse();
+ _result.Request = _httpRequest;
+ _result.Response = _httpResponse;
+ if (_shouldTrace)
+ {
+ ServiceClientTracing.Exit(_invocationId, _result);
+ }
+ return _result;
+ }
+
+ ///
+ /// Get invalid Unix time value
+ ///
+ ///
+ /// Headers that will be added to request.
+ ///
+ ///
+ /// The cancellation token.
+ ///
+ ///
+ /// A response object containing the response body and response headers.
+ ///
+ public async Task> GetInvalidUnixTimeWithHttpMessagesAsync(Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken))
+ {
+ // Tracing
+ bool _shouldTrace = ServiceClientTracing.IsEnabled;
+ string _invocationId = null;
+ if (_shouldTrace)
+ {
+ _invocationId = ServiceClientTracing.NextInvocationId.ToString();
+ Dictionary tracingParameters = new Dictionary();
+ tracingParameters.Add("cancellationToken", cancellationToken);
+ ServiceClientTracing.Enter(_invocationId, this, "GetInvalidUnixTime", tracingParameters);
+ }
+ // Construct URL
+ var _baseUrl = this.Client.BaseUri.AbsoluteUri;
+ var _url = new Uri(new Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "int/invalidunixtime").ToString();
+ // Create HTTP transport objects
+ HttpRequestMessage _httpRequest = new HttpRequestMessage();
+ HttpResponseMessage _httpResponse = null;
+ _httpRequest.Method = new HttpMethod("GET");
+ _httpRequest.RequestUri = new Uri(_url);
+ // Set Headers
+ if (customHeaders != null)
+ {
+ foreach(var _header in customHeaders)
+ {
+ if (_httpRequest.Headers.Contains(_header.Key))
+ {
+ _httpRequest.Headers.Remove(_header.Key);
+ }
+ _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
+ }
+ }
+
+ // Serialize Request
+ string _requestContent = null;
+ // Send Request
+ if (_shouldTrace)
+ {
+ ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
+ }
+ cancellationToken.ThrowIfCancellationRequested();
+ _httpResponse = await this.Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
+ if (_shouldTrace)
+ {
+ ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
+ }
+ HttpStatusCode _statusCode = _httpResponse.StatusCode;
+ cancellationToken.ThrowIfCancellationRequested();
+ string _responseContent = null;
+ if ((int)_statusCode != 200)
+ {
+ var ex = new ErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusCode));
+ try
+ {
+ _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
+ Error _errorBody = SafeJsonConvert.DeserializeObject(_responseContent, this.Client.DeserializationSettings);
+ if (_errorBody != null)
+ {
+ ex.Body = _errorBody;
+ }
+ }
+ catch (JsonException)
+ {
+ // Ignore the exception
+ }
+ ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
+ ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
+ if (_shouldTrace)
+ {
+ ServiceClientTracing.Error(_invocationId, ex);
+ }
+ _httpRequest.Dispose();
+ if (_httpResponse != null)
+ {
+ _httpResponse.Dispose();
+ }
+ throw ex;
+ }
+ // Create Result
+ var _result = new HttpOperationResponse();
+ _result.Request = _httpRequest;
+ _result.Response = _httpResponse;
+ // Deserialize Response
+ if ((int)_statusCode == 200)
+ {
+ _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
+ try
+ {
+ _result.Body = SafeJsonConvert.DeserializeObject(_responseContent, new UnixTimeJsonConverter());
+ }
+ catch (JsonException ex)
+ {
+ _httpRequest.Dispose();
+ if (_httpResponse != null)
+ {
+ _httpResponse.Dispose();
+ }
+ throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
+ }
+ }
+ if (_shouldTrace)
+ {
+ ServiceClientTracing.Exit(_invocationId, _result);
+ }
+ return _result;
+ }
+
+ ///
+ /// Get null Unix time value
+ ///
+ ///
+ /// Headers that will be added to request.
+ ///
+ ///
+ /// The cancellation token.
+ ///
+ ///
+ /// A response object containing the response body and response headers.
+ ///
+ public async Task> GetNullUnixTimeWithHttpMessagesAsync(Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken))
+ {
+ // Tracing
+ bool _shouldTrace = ServiceClientTracing.IsEnabled;
+ string _invocationId = null;
+ if (_shouldTrace)
+ {
+ _invocationId = ServiceClientTracing.NextInvocationId.ToString();
+ Dictionary tracingParameters = new Dictionary();
+ tracingParameters.Add("cancellationToken", cancellationToken);
+ ServiceClientTracing.Enter(_invocationId, this, "GetNullUnixTime", tracingParameters);
+ }
+ // Construct URL
+ var _baseUrl = this.Client.BaseUri.AbsoluteUri;
+ var _url = new Uri(new Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "int/nullunixtime").ToString();
+ // Create HTTP transport objects
+ HttpRequestMessage _httpRequest = new HttpRequestMessage();
+ HttpResponseMessage _httpResponse = null;
+ _httpRequest.Method = new HttpMethod("GET");
+ _httpRequest.RequestUri = new Uri(_url);
+ // Set Headers
+ if (customHeaders != null)
+ {
+ foreach(var _header in customHeaders)
+ {
+ if (_httpRequest.Headers.Contains(_header.Key))
+ {
+ _httpRequest.Headers.Remove(_header.Key);
+ }
+ _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
+ }
+ }
+
+ // Serialize Request
+ string _requestContent = null;
+ // Send Request
+ if (_shouldTrace)
+ {
+ ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
+ }
+ cancellationToken.ThrowIfCancellationRequested();
+ _httpResponse = await this.Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
+ if (_shouldTrace)
+ {
+ ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
+ }
+ HttpStatusCode _statusCode = _httpResponse.StatusCode;
+ cancellationToken.ThrowIfCancellationRequested();
+ string _responseContent = null;
+ if ((int)_statusCode != 200)
+ {
+ var ex = new ErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusCode));
+ try
+ {
+ _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
+ Error _errorBody = SafeJsonConvert.DeserializeObject(_responseContent, this.Client.DeserializationSettings);
+ if (_errorBody != null)
+ {
+ ex.Body = _errorBody;
+ }
+ }
+ catch (JsonException)
+ {
+ // Ignore the exception
+ }
+ ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
+ ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
+ if (_shouldTrace)
+ {
+ ServiceClientTracing.Error(_invocationId, ex);
+ }
+ _httpRequest.Dispose();
+ if (_httpResponse != null)
+ {
+ _httpResponse.Dispose();
+ }
+ throw ex;
+ }
+ // Create Result
+ var _result = new HttpOperationResponse();
+ _result.Request = _httpRequest;
+ _result.Response = _httpResponse;
+ // Deserialize Response
+ if ((int)_statusCode == 200)
+ {
+ _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
+ try
+ {
+ _result.Body = SafeJsonConvert.DeserializeObject(_responseContent, new UnixTimeJsonConverter());
+ }
+ catch (JsonException ex)
+ {
+ _httpRequest.Dispose();
+ if (_httpResponse != null)
+ {
+ _httpResponse.Dispose();
+ }
+ throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
+ }
+ }
+ if (_shouldTrace)
+ {
+ ServiceClientTracing.Exit(_invocationId, _result);
+ }
+ return _result;
+ }
+
}
}
diff --git a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/CompositeBoolIntClient/IntModelExtensions.cs b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/CompositeBoolIntClient/IntModelExtensions.cs
index a203d3cee39e7..009277ea5077b 100644
--- a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/CompositeBoolIntClient/IntModelExtensions.cs
+++ b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/CompositeBoolIntClient/IntModelExtensions.cs
@@ -305,5 +305,118 @@ public static void PutMin64(this IIntModel operations, long intBody)
await operations.PutMin64WithHttpMessagesAsync(intBody, null, cancellationToken).ConfigureAwait(false);
}
+ ///
+ /// Get datetime encoded as Unix time value
+ ///
+ ///
+ /// The operations group for this extension method.
+ ///
+ public static DateTime? GetUnixTime(this IIntModel operations)
+ {
+ return Task.Factory.StartNew(s => ((IIntModel)s).GetUnixTimeAsync(), operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Get datetime encoded as Unix time value
+ ///
+ ///
+ /// The operations group for this extension method.
+ ///
+ ///
+ /// The cancellation token.
+ ///
+ public static async Task GetUnixTimeAsync(this IIntModel operations, CancellationToken cancellationToken = default(CancellationToken))
+ {
+ using (var _result = await operations.GetUnixTimeWithHttpMessagesAsync(null, cancellationToken).ConfigureAwait(false))
+ {
+ return _result.Body;
+ }
+ }
+
+ ///
+ /// Put datetime encoded as Unix time
+ ///
+ ///
+ /// The operations group for this extension method.
+ ///
+ ///
+ ///
+ public static void PutUnixTimeDate(this IIntModel operations, DateTime intBody)
+ {
+ Task.Factory.StartNew(s => ((IIntModel)s).PutUnixTimeDateAsync(intBody), operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Put datetime encoded as Unix time
+ ///
+ ///
+ /// The operations group for this extension method.
+ ///
+ ///
+ ///
+ ///
+ /// The cancellation token.
+ ///
+ public static async Task PutUnixTimeDateAsync(this IIntModel operations, DateTime intBody, CancellationToken cancellationToken = default(CancellationToken))
+ {
+ await operations.PutUnixTimeDateWithHttpMessagesAsync(intBody, null, cancellationToken).ConfigureAwait(false);
+ }
+
+ ///
+ /// Get invalid Unix time value
+ ///
+ ///
+ /// The operations group for this extension method.
+ ///
+ public static DateTime? GetInvalidUnixTime(this IIntModel operations)
+ {
+ return Task.Factory.StartNew(s => ((IIntModel)s).GetInvalidUnixTimeAsync(), operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Get invalid Unix time value
+ ///
+ ///
+ /// The operations group for this extension method.
+ ///
+ ///
+ /// The cancellation token.
+ ///
+ public static async Task GetInvalidUnixTimeAsync(this IIntModel operations, CancellationToken cancellationToken = default(CancellationToken))
+ {
+ using (var _result = await operations.GetInvalidUnixTimeWithHttpMessagesAsync(null, cancellationToken).ConfigureAwait(false))
+ {
+ return _result.Body;
+ }
+ }
+
+ ///
+ /// Get null Unix time value
+ ///
+ ///
+ /// The operations group for this extension method.
+ ///
+ public static DateTime? GetNullUnixTime(this IIntModel operations)
+ {
+ return Task.Factory.StartNew(s => ((IIntModel)s).GetNullUnixTimeAsync(), operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Get null Unix time value
+ ///
+ ///
+ /// The operations group for this extension method.
+ ///
+ ///
+ /// The cancellation token.
+ ///
+ public static async Task GetNullUnixTimeAsync(this IIntModel operations, CancellationToken cancellationToken = default(CancellationToken))
+ {
+ using (var _result = await operations.GetNullUnixTimeWithHttpMessagesAsync(null, cancellationToken).ConfigureAwait(false))
+ {
+ return _result.Body;
+ }
+ }
+
}
}
diff --git a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/CustomBaseUriMoreOptions/AutoRestParameterizedCustomHostTestClient.cs b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/CustomBaseUriMoreOptions/AutoRestParameterizedCustomHostTestClient.cs
new file mode 100644
index 0000000000000..e680cbe6a8731
--- /dev/null
+++ b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/CustomBaseUriMoreOptions/AutoRestParameterizedCustomHostTestClient.cs
@@ -0,0 +1,128 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License. See License.txt in the project root for
+// license information.
+//
+// Code generated by Microsoft (R) AutoRest Code Generator.
+// Changes may cause incorrect behavior and will be lost if the code is
+// regenerated.
+
+namespace Fixtures.AcceptanceTestsCustomBaseUriMoreOptions
+{
+ using System;
+ using System.Linq;
+ using System.Collections.Generic;
+ using System.Diagnostics;
+ using System.Net;
+ using System.Net.Http;
+ using System.Net.Http.Headers;
+ using System.Text;
+ using System.Text.RegularExpressions;
+ using System.Threading;
+ using System.Threading.Tasks;
+ using Microsoft.Rest;
+ using Microsoft.Rest.Serialization;
+ using Newtonsoft.Json;
+ using Models;
+
+ ///
+ /// Test Infrastructure for AutoRest
+ ///
+ public partial class AutoRestParameterizedCustomHostTestClient : ServiceClient, IAutoRestParameterizedCustomHostTestClient
+ {
+ ///
+ /// The base URI of the service.
+ ///
+ internal string BaseUri {get; set;}
+
+ ///
+ /// Gets or sets json serialization settings.
+ ///
+ public JsonSerializerSettings SerializationSettings { get; private set; }
+
+ ///
+ /// Gets or sets json deserialization settings.
+ ///
+ public JsonSerializerSettings DeserializationSettings { get; private set; }
+
+ ///
+ /// The subscription id with value 'test12'.
+ ///
+ public string SubscriptionId { get; set; }
+
+ ///
+ /// A string value that is used as a global part of the parameterized host.
+ /// Default value 'host'.
+ ///
+ public string DnsSuffix { get; set; }
+
+ ///
+ /// Gets the IPaths.
+ ///
+ public virtual IPaths Paths { get; private set; }
+
+ ///
+ /// Initializes a new instance of the AutoRestParameterizedCustomHostTestClient class.
+ ///
+ ///
+ /// Optional. The delegating handlers to add to the http client pipeline.
+ ///
+ public AutoRestParameterizedCustomHostTestClient(params DelegatingHandler[] handlers) : base(handlers)
+ {
+ this.Initialize();
+ }
+
+ ///
+ /// Initializes a new instance of the AutoRestParameterizedCustomHostTestClient class.
+ ///
+ ///
+ /// Optional. The http client handler used to handle http transport.
+ ///
+ ///
+ /// Optional. The delegating handlers to add to the http client pipeline.
+ ///
+ public AutoRestParameterizedCustomHostTestClient(HttpClientHandler rootHandler, params DelegatingHandler[] handlers) : base(rootHandler, handlers)
+ {
+ this.Initialize();
+ }
+
+ ///
+ /// An optional partial-method to perform custom initialization.
+ ///
+ partial void CustomInitialize();
+ ///
+ /// Initializes client properties.
+ ///
+ private void Initialize()
+ {
+ this.Paths = new Paths(this);
+ this.BaseUri = "{vault}{secret}{dnsSuffix}";
+ this.DnsSuffix = "host";
+ SerializationSettings = new JsonSerializerSettings
+ {
+ Formatting = Formatting.Indented,
+ DateFormatHandling = DateFormatHandling.IsoDateFormat,
+ DateTimeZoneHandling = DateTimeZoneHandling.Utc,
+ NullValueHandling = NullValueHandling.Ignore,
+ ReferenceLoopHandling = ReferenceLoopHandling.Serialize,
+ ContractResolver = new ReadOnlyJsonContractResolver(),
+ Converters = new List
+ {
+ new Iso8601TimeSpanConverter()
+ }
+ };
+ DeserializationSettings = new JsonSerializerSettings
+ {
+ DateFormatHandling = DateFormatHandling.IsoDateFormat,
+ DateTimeZoneHandling = DateTimeZoneHandling.Utc,
+ NullValueHandling = NullValueHandling.Ignore,
+ ReferenceLoopHandling = ReferenceLoopHandling.Serialize,
+ ContractResolver = new ReadOnlyJsonContractResolver(),
+ Converters = new List
+ {
+ new Iso8601TimeSpanConverter()
+ }
+ };
+ CustomInitialize();
+ }
+ }
+}
diff --git a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/CustomBaseUriMoreOptions/IAutoRestParameterizedCustomHostTestClient.cs b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/CustomBaseUriMoreOptions/IAutoRestParameterizedCustomHostTestClient.cs
new file mode 100644
index 0000000000000..87db999d81c42
--- /dev/null
+++ b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/CustomBaseUriMoreOptions/IAutoRestParameterizedCustomHostTestClient.cs
@@ -0,0 +1,57 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License. See License.txt in the project root for
+// license information.
+//
+// Code generated by Microsoft (R) AutoRest Code Generator.
+// Changes may cause incorrect behavior and will be lost if the code is
+// regenerated.
+
+namespace Fixtures.AcceptanceTestsCustomBaseUriMoreOptions
+{
+ using System;
+ using System.Collections.Generic;
+ using System.Net.Http;
+ using System.Threading;
+ using System.Threading.Tasks;
+ using Newtonsoft.Json;
+ using Microsoft.Rest;
+ using Models;
+
+ ///
+ /// Test Infrastructure for AutoRest
+ ///
+ public partial interface IAutoRestParameterizedCustomHostTestClient : IDisposable
+ {
+ ///
+ /// The base URI of the service.
+ ///
+
+ ///
+ /// Gets or sets json serialization settings.
+ ///
+ JsonSerializerSettings SerializationSettings { get; }
+
+ ///
+ /// Gets or sets json deserialization settings.
+ ///
+ JsonSerializerSettings DeserializationSettings { get; }
+
+ ///
+ /// The subscription id with value 'test12'.
+ ///
+ string SubscriptionId { get; set; }
+
+ ///
+ /// A string value that is used as a global part of the parameterized
+ /// host. Default value 'host'.
+ ///
+ string DnsSuffix { get; set; }
+
+
+ ///
+ /// Gets the IPaths.
+ ///
+ IPaths Paths { get; }
+
+ }
+}
diff --git a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/CustomBaseUriMoreOptions/IPaths.cs b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/CustomBaseUriMoreOptions/IPaths.cs
new file mode 100644
index 0000000000000..a117b914e7526
--- /dev/null
+++ b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/CustomBaseUriMoreOptions/IPaths.cs
@@ -0,0 +1,47 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License. See License.txt in the project root for
+// license information.
+//
+// Code generated by Microsoft (R) AutoRest Code Generator.
+// Changes may cause incorrect behavior and will be lost if the code is
+// regenerated.
+
+namespace Fixtures.AcceptanceTestsCustomBaseUriMoreOptions
+{
+ using System;
+ using System.Collections.Generic;
+ using System.Net.Http;
+ using System.Threading;
+ using System.Threading.Tasks;
+ using Microsoft.Rest;
+ using Models;
+
+ ///
+ /// Paths operations.
+ ///
+ public partial interface IPaths
+ {
+ ///
+ /// Get a 200 to test a valid base uri
+ ///
+ ///
+ /// The vault name, e.g. https://myvault
+ ///
+ ///
+ /// Secret value.
+ ///
+ ///
+ /// The key name with value 'key1'.
+ ///
+ ///
+ /// The key version. Default value 'v1'.
+ ///
+ ///
+ /// The headers that will be added to request.
+ ///
+ ///
+ /// The cancellation token.
+ ///
+ Task GetEmptyWithHttpMessagesAsync(string vault, string secret, string keyName, string keyVersion = "v1", Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken));
+ }
+}
diff --git a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/CustomBaseUriMoreOptions/Models/Error.cs b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/CustomBaseUriMoreOptions/Models/Error.cs
new file mode 100644
index 0000000000000..82a4873e61389
--- /dev/null
+++ b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/CustomBaseUriMoreOptions/Models/Error.cs
@@ -0,0 +1,45 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License. See License.txt in the project root for
+// license information.
+//
+// Code generated by Microsoft (R) AutoRest Code Generator.
+// Changes may cause incorrect behavior and will be lost if the code is
+// regenerated.
+
+namespace Fixtures.AcceptanceTestsCustomBaseUriMoreOptions.Models
+{
+ using System;
+ using System.Linq;
+ using System.Collections.Generic;
+ using Newtonsoft.Json;
+ using Microsoft.Rest;
+ using Microsoft.Rest.Serialization;
+
+ public partial class Error
+ {
+ ///
+ /// Initializes a new instance of the Error class.
+ ///
+ public Error() { }
+
+ ///
+ /// Initializes a new instance of the Error class.
+ ///
+ public Error(int? status = default(int?), string message = default(string))
+ {
+ Status = status;
+ Message = message;
+ }
+
+ ///
+ ///
+ [JsonProperty(PropertyName = "status")]
+ public int? Status { get; set; }
+
+ ///
+ ///
+ [JsonProperty(PropertyName = "message")]
+ public string Message { get; set; }
+
+ }
+}
diff --git a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/CustomBaseUriMoreOptions/Models/ErrorException.cs b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/CustomBaseUriMoreOptions/Models/ErrorException.cs
new file mode 100644
index 0000000000000..e3ab1c0a08abc
--- /dev/null
+++ b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/CustomBaseUriMoreOptions/Models/ErrorException.cs
@@ -0,0 +1,99 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License. See License.txt in the project root for
+// license information.
+//
+// Code generated by Microsoft (R) AutoRest Code Generator.
+// Changes may cause incorrect behavior and will be lost if the code is
+// regenerated.
+
+namespace Fixtures.AcceptanceTestsCustomBaseUriMoreOptions.Models
+{
+ using Microsoft.Rest;
+ using System;
+ using System.Net.Http;
+ using System.Runtime.Serialization;
+#if !PORTABLE && !DNXCORE50
+ using System.Security.Permissions;
+#endif
+
+ ///
+ /// Exception thrown for an invalid response with Error information.
+ ///
+#if !PORTABLE && !DNXCORE50
+ [Serializable]
+#endif
+ public class ErrorException : RestException
+ {
+ ///
+ /// Gets information about the associated HTTP request.
+ ///
+ public HttpRequestMessageWrapper Request { get; set; }
+
+ ///
+ /// Gets information about the associated HTTP response.
+ ///
+ public HttpResponseMessageWrapper Response { get; set; }
+
+ ///
+ /// Gets or sets the body object.
+ ///
+ public Error Body { get; set; }
+
+ ///
+ /// Initializes a new instance of the ErrorException class.
+ ///
+ public ErrorException()
+ {
+ }
+
+ ///
+ /// Initializes a new instance of the ErrorException class.
+ ///
+ /// The exception message.
+ public ErrorException(string message)
+ : this(message, null)
+ {
+ }
+
+ ///
+ /// Initializes a new instance of the ErrorException class.
+ ///
+ /// The exception message.
+ /// Inner exception.
+ public ErrorException(string message, Exception innerException)
+ : base(message, innerException)
+ {
+ }
+
+#if !PORTABLE && !DNXCORE50
+ ///
+ /// Initializes a new instance of the ErrorException class.
+ ///
+ /// Serialization info.
+ /// Streaming context.
+ protected ErrorException(SerializationInfo info, StreamingContext context)
+ : base(info, context)
+ {
+ }
+
+ ///
+ /// Serializes content of the exception.
+ ///
+ /// Serialization info.
+ /// Streaming context.
+ [SecurityPermission(SecurityAction.Demand, SerializationFormatter = true)]
+ public override void GetObjectData(SerializationInfo info, StreamingContext context)
+ {
+ base.GetObjectData(info, context);
+ if (info == null)
+ {
+ throw new ArgumentNullException("info");
+ }
+
+ info.AddValue("Request", Request);
+ info.AddValue("Response", Response);
+ info.AddValue("Body", Body);
+ }
+#endif
+ }
+}
diff --git a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/CustomBaseUriMoreOptions/Paths.cs b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/CustomBaseUriMoreOptions/Paths.cs
new file mode 100644
index 0000000000000..a8599cf083382
--- /dev/null
+++ b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/CustomBaseUriMoreOptions/Paths.cs
@@ -0,0 +1,203 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License. See License.txt in the project root for
+// license information.
+//
+// Code generated by Microsoft (R) AutoRest Code Generator.
+// Changes may cause incorrect behavior and will be lost if the code is
+// regenerated.
+
+namespace Fixtures.AcceptanceTestsCustomBaseUriMoreOptions
+{
+ using System;
+ using System.Linq;
+ using System.Collections.Generic;
+ using System.Net;
+ using System.Net.Http;
+ using System.Net.Http.Headers;
+ using System.Text;
+ using System.Text.RegularExpressions;
+ using System.Threading;
+ using System.Threading.Tasks;
+ using Microsoft.Rest;
+ using Microsoft.Rest.Serialization;
+ using Newtonsoft.Json;
+ using Models;
+
+ ///
+ /// Paths operations.
+ ///
+ public partial class Paths : IServiceOperations, IPaths
+ {
+ ///
+ /// Initializes a new instance of the Paths class.
+ ///
+ ///
+ /// Reference to the service client.
+ ///
+ public Paths(AutoRestParameterizedCustomHostTestClient client)
+ {
+ if (client == null)
+ {
+ throw new ArgumentNullException("client");
+ }
+ this.Client = client;
+ }
+
+ ///
+ /// Gets a reference to the AutoRestParameterizedCustomHostTestClient
+ ///
+ public AutoRestParameterizedCustomHostTestClient Client { get; private set; }
+
+ ///
+ /// Get a 200 to test a valid base uri
+ ///
+ ///
+ /// The vault name, e.g. https://myvault
+ ///
+ ///
+ /// Secret value.
+ ///
+ ///
+ /// The key name with value 'key1'.
+ ///
+ ///
+ /// The key version. Default value 'v1'.
+ ///
+ ///
+ /// Headers that will be added to request.
+ ///
+ ///
+ /// The cancellation token.
+ ///
+ ///
+ /// A response object containing the response body and response headers.
+ ///
+ public async Task GetEmptyWithHttpMessagesAsync(string vault, string secret, string keyName, string keyVersion = "v1", Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken))
+ {
+ if (vault == null)
+ {
+ throw new ValidationException(ValidationRules.CannotBeNull, "vault");
+ }
+ if (secret == null)
+ {
+ throw new ValidationException(ValidationRules.CannotBeNull, "secret");
+ }
+ if (this.Client.DnsSuffix == null)
+ {
+ throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.DnsSuffix");
+ }
+ if (keyName == null)
+ {
+ throw new ValidationException(ValidationRules.CannotBeNull, "keyName");
+ }
+ if (this.Client.SubscriptionId == null)
+ {
+ throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.SubscriptionId");
+ }
+ // Tracing
+ bool _shouldTrace = ServiceClientTracing.IsEnabled;
+ string _invocationId = null;
+ if (_shouldTrace)
+ {
+ _invocationId = ServiceClientTracing.NextInvocationId.ToString();
+ Dictionary tracingParameters = new Dictionary();
+ tracingParameters.Add("vault", vault);
+ tracingParameters.Add("secret", secret);
+ tracingParameters.Add("keyName", keyName);
+ tracingParameters.Add("keyVersion", keyVersion);
+ tracingParameters.Add("cancellationToken", cancellationToken);
+ ServiceClientTracing.Enter(_invocationId, this, "GetEmpty", tracingParameters);
+ }
+ // Construct URL
+ var _baseUrl = this.Client.BaseUri;
+ var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "customuri/{subscriptionId}/{keyName}";
+ _url = _url.Replace("{vault}", vault);
+ _url = _url.Replace("{secret}", secret);
+ _url = _url.Replace("{dnsSuffix}", this.Client.DnsSuffix);
+ _url = _url.Replace("{keyName}", Uri.EscapeDataString(keyName));
+ _url = _url.Replace("{subscriptionId}", Uri.EscapeDataString(this.Client.SubscriptionId));
+ List _queryParameters = new List();
+ if (keyVersion != null)
+ {
+ _queryParameters.Add(string.Format("keyVersion={0}", Uri.EscapeDataString(keyVersion)));
+ }
+ if (_queryParameters.Count > 0)
+ {
+ _url += "?" + string.Join("&", _queryParameters);
+ }
+ // Create HTTP transport objects
+ HttpRequestMessage _httpRequest = new HttpRequestMessage();
+ HttpResponseMessage _httpResponse = null;
+ _httpRequest.Method = new HttpMethod("GET");
+ _httpRequest.RequestUri = new Uri(_url);
+ // Set Headers
+ if (customHeaders != null)
+ {
+ foreach(var _header in customHeaders)
+ {
+ if (_httpRequest.Headers.Contains(_header.Key))
+ {
+ _httpRequest.Headers.Remove(_header.Key);
+ }
+ _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
+ }
+ }
+
+ // Serialize Request
+ string _requestContent = null;
+ // Send Request
+ if (_shouldTrace)
+ {
+ ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
+ }
+ cancellationToken.ThrowIfCancellationRequested();
+ _httpResponse = await this.Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
+ if (_shouldTrace)
+ {
+ ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
+ }
+ HttpStatusCode _statusCode = _httpResponse.StatusCode;
+ cancellationToken.ThrowIfCancellationRequested();
+ string _responseContent = null;
+ if ((int)_statusCode != 200)
+ {
+ var ex = new ErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusCode));
+ try
+ {
+ _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
+ Error _errorBody = SafeJsonConvert.DeserializeObject(_responseContent, this.Client.DeserializationSettings);
+ if (_errorBody != null)
+ {
+ ex.Body = _errorBody;
+ }
+ }
+ catch (JsonException)
+ {
+ // Ignore the exception
+ }
+ ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
+ ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
+ if (_shouldTrace)
+ {
+ ServiceClientTracing.Error(_invocationId, ex);
+ }
+ _httpRequest.Dispose();
+ if (_httpResponse != null)
+ {
+ _httpResponse.Dispose();
+ }
+ throw ex;
+ }
+ // Create Result
+ var _result = new HttpOperationResponse();
+ _result.Request = _httpRequest;
+ _result.Response = _httpResponse;
+ if (_shouldTrace)
+ {
+ ServiceClientTracing.Exit(_invocationId, _result);
+ }
+ return _result;
+ }
+
+ }
+}
diff --git a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/CustomBaseUriMoreOptions/PathsExtensions.cs b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/CustomBaseUriMoreOptions/PathsExtensions.cs
new file mode 100644
index 0000000000000..c553414304ed0
--- /dev/null
+++ b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/CustomBaseUriMoreOptions/PathsExtensions.cs
@@ -0,0 +1,74 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License. See License.txt in the project root for
+// license information.
+//
+// Code generated by Microsoft (R) AutoRest Code Generator.
+// Changes may cause incorrect behavior and will be lost if the code is
+// regenerated.
+
+namespace Fixtures.AcceptanceTestsCustomBaseUriMoreOptions
+{
+ using System;
+ using System.Collections;
+ using System.Collections.Generic;
+ using System.Threading;
+ using System.Threading.Tasks;
+ using Microsoft.Rest;
+ using Models;
+
+ ///
+ /// Extension methods for Paths.
+ ///
+ public static partial class PathsExtensions
+ {
+ ///
+ /// Get a 200 to test a valid base uri
+ ///
+ ///
+ /// The operations group for this extension method.
+ ///
+ ///
+ /// The vault name, e.g. https://myvault
+ ///
+ ///
+ /// Secret value.
+ ///
+ ///
+ /// The key name with value 'key1'.
+ ///
+ ///
+ /// The key version. Default value 'v1'.
+ ///
+ public static void GetEmpty(this IPaths operations, string vault, string secret, string keyName, string keyVersion = "v1")
+ {
+ Task.Factory.StartNew(s => ((IPaths)s).GetEmptyAsync(vault, secret, keyName, keyVersion), operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Get a 200 to test a valid base uri
+ ///
+ ///
+ /// The operations group for this extension method.
+ ///
+ ///
+ /// The vault name, e.g. https://myvault
+ ///
+ ///
+ /// Secret value.
+ ///
+ ///
+ /// The key name with value 'key1'.
+ ///
+ ///
+ /// The key version. Default value 'v1'.
+ ///
+ ///
+ /// The cancellation token.
+ ///
+ public static async Task GetEmptyAsync(this IPaths operations, string vault, string secret, string keyName, string keyVersion = "v1", CancellationToken cancellationToken = default(CancellationToken))
+ {
+ await operations.GetEmptyWithHttpMessagesAsync(vault, secret, keyName, keyVersion, null, cancellationToken).ConfigureAwait(false);
+ }
+
+ }
+}
diff --git a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/Http/HttpClientFailure.cs b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/Http/HttpClientFailure.cs
index 60a652f2efb7e..3df1107bea40c 100644
--- a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/Http/HttpClientFailure.cs
+++ b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/Http/HttpClientFailure.cs
@@ -329,9 +329,12 @@ public HttpClientFailure(AutoRestHttpInfrastructureTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(booleanValue, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(booleanValue != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(booleanValue, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -451,9 +454,12 @@ public HttpClientFailure(AutoRestHttpInfrastructureTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(booleanValue, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(booleanValue != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(booleanValue, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -573,9 +579,12 @@ public HttpClientFailure(AutoRestHttpInfrastructureTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(booleanValue, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(booleanValue != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(booleanValue, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -695,9 +704,12 @@ public HttpClientFailure(AutoRestHttpInfrastructureTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(booleanValue, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(booleanValue != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(booleanValue, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -1162,9 +1174,12 @@ public HttpClientFailure(AutoRestHttpInfrastructureTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(booleanValue, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(booleanValue != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(booleanValue, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -1284,9 +1299,12 @@ public HttpClientFailure(AutoRestHttpInfrastructureTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(booleanValue, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(booleanValue != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(booleanValue, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -1406,9 +1424,12 @@ public HttpClientFailure(AutoRestHttpInfrastructureTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(booleanValue, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(booleanValue != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(booleanValue, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -1528,9 +1549,12 @@ public HttpClientFailure(AutoRestHttpInfrastructureTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(booleanValue, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(booleanValue != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(booleanValue, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -1650,9 +1674,12 @@ public HttpClientFailure(AutoRestHttpInfrastructureTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(booleanValue, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(booleanValue != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(booleanValue, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -2117,9 +2144,12 @@ public HttpClientFailure(AutoRestHttpInfrastructureTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(booleanValue, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(booleanValue != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(booleanValue, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -2239,9 +2269,12 @@ public HttpClientFailure(AutoRestHttpInfrastructureTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(booleanValue, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(booleanValue != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(booleanValue, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -2361,9 +2394,12 @@ public HttpClientFailure(AutoRestHttpInfrastructureTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(booleanValue, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(booleanValue != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(booleanValue, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -2598,9 +2634,12 @@ public HttpClientFailure(AutoRestHttpInfrastructureTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(booleanValue, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(booleanValue != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(booleanValue, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
diff --git a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/Http/HttpRedirects.cs b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/Http/HttpRedirects.cs
index 7759c53c1e4d5..01747fbf1dd29 100644
--- a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/Http/HttpRedirects.cs
+++ b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/Http/HttpRedirects.cs
@@ -575,9 +575,12 @@ public HttpRedirects(AutoRestHttpInfrastructureTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(booleanValue, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(booleanValue != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(booleanValue, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -926,9 +929,12 @@ public HttpRedirects(AutoRestHttpInfrastructureTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(booleanValue, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(booleanValue != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(booleanValue, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -1049,9 +1055,12 @@ public HttpRedirects(AutoRestHttpInfrastructureTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(booleanValue, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(booleanValue != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(booleanValue, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -1398,9 +1407,12 @@ public HttpRedirects(AutoRestHttpInfrastructureTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(booleanValue, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(booleanValue != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(booleanValue, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -1519,9 +1531,12 @@ public HttpRedirects(AutoRestHttpInfrastructureTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(booleanValue, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(booleanValue != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(booleanValue, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -1640,9 +1655,12 @@ public HttpRedirects(AutoRestHttpInfrastructureTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(booleanValue, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(booleanValue != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(booleanValue, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -1761,9 +1779,12 @@ public HttpRedirects(AutoRestHttpInfrastructureTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(booleanValue, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(booleanValue != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(booleanValue, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
diff --git a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/Http/HttpRetry.cs b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/Http/HttpRetry.cs
index ac964e2f0c42b..6fe19ef0d1e25 100644
--- a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/Http/HttpRetry.cs
+++ b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/Http/HttpRetry.cs
@@ -200,9 +200,12 @@ public HttpRetry(AutoRestHttpInfrastructureTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(booleanValue, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(booleanValue != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(booleanValue, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -308,9 +311,12 @@ public HttpRetry(AutoRestHttpInfrastructureTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(booleanValue, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(booleanValue != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(booleanValue, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -517,9 +523,12 @@ public HttpRetry(AutoRestHttpInfrastructureTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(booleanValue, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(booleanValue != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(booleanValue, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -625,9 +634,12 @@ public HttpRetry(AutoRestHttpInfrastructureTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(booleanValue, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(booleanValue != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(booleanValue, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -733,9 +745,12 @@ public HttpRetry(AutoRestHttpInfrastructureTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(booleanValue, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(booleanValue != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(booleanValue, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -841,9 +856,12 @@ public HttpRetry(AutoRestHttpInfrastructureTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(booleanValue, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(booleanValue != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(booleanValue, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
diff --git a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/Http/HttpServerFailure.cs b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/Http/HttpServerFailure.cs
index a26c0148f8ec9..425c90bf3f141 100644
--- a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/Http/HttpServerFailure.cs
+++ b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/Http/HttpServerFailure.cs
@@ -329,9 +329,12 @@ public HttpServerFailure(AutoRestHttpInfrastructureTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(booleanValue, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(booleanValue != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(booleanValue, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -451,9 +454,12 @@ public HttpServerFailure(AutoRestHttpInfrastructureTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(booleanValue, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(booleanValue != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(booleanValue, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
diff --git a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/Http/HttpSuccess.cs b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/Http/HttpSuccess.cs
index 550bfeb440a1e..9cef952542266 100644
--- a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/Http/HttpSuccess.cs
+++ b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/Http/HttpSuccess.cs
@@ -319,9 +319,12 @@ public HttpSuccess(AutoRestHttpInfrastructureTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(booleanValue, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(booleanValue != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(booleanValue, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -427,9 +430,12 @@ public HttpSuccess(AutoRestHttpInfrastructureTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(booleanValue, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(booleanValue != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(booleanValue, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -535,9 +541,12 @@ public HttpSuccess(AutoRestHttpInfrastructureTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(booleanValue, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(booleanValue != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(booleanValue, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -643,9 +652,12 @@ public HttpSuccess(AutoRestHttpInfrastructureTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(booleanValue, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(booleanValue != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(booleanValue, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -751,9 +763,12 @@ public HttpSuccess(AutoRestHttpInfrastructureTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(booleanValue, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(booleanValue != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(booleanValue, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -859,9 +874,12 @@ public HttpSuccess(AutoRestHttpInfrastructureTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(booleanValue, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(booleanValue != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(booleanValue, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -967,9 +985,12 @@ public HttpSuccess(AutoRestHttpInfrastructureTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(booleanValue, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(booleanValue != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(booleanValue, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -1075,9 +1096,12 @@ public HttpSuccess(AutoRestHttpInfrastructureTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(booleanValue, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(booleanValue != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(booleanValue, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -1183,9 +1207,12 @@ public HttpSuccess(AutoRestHttpInfrastructureTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(booleanValue, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(booleanValue != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(booleanValue, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -1291,9 +1318,12 @@ public HttpSuccess(AutoRestHttpInfrastructureTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(booleanValue, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(booleanValue != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(booleanValue, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -1500,9 +1530,12 @@ public HttpSuccess(AutoRestHttpInfrastructureTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(booleanValue, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(booleanValue != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(booleanValue, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -1608,9 +1641,12 @@ public HttpSuccess(AutoRestHttpInfrastructureTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(booleanValue, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(booleanValue != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(booleanValue, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -1716,9 +1752,12 @@ public HttpSuccess(AutoRestHttpInfrastructureTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(booleanValue, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(booleanValue != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(booleanValue, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -1824,9 +1863,12 @@ public HttpSuccess(AutoRestHttpInfrastructureTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(booleanValue, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(booleanValue != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(booleanValue, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
diff --git a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/ModelFlattening/AutoRestResourceFlatteningTestService.cs b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/ModelFlattening/AutoRestResourceFlatteningTestService.cs
index 111c67ef2ea6f..507c54acd120f 100644
--- a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/ModelFlattening/AutoRestResourceFlatteningTestService.cs
+++ b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/ModelFlattening/AutoRestResourceFlatteningTestService.cs
@@ -198,9 +198,12 @@ private void Initialize()
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(resourceArray, this.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(resourceArray != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(resourceArray, this.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -425,9 +428,12 @@ private void Initialize()
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(resourceDictionary, this.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(resourceDictionary != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(resourceDictionary, this.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -652,9 +658,12 @@ private void Initialize()
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(resourceComplexObject, this.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(resourceComplexObject != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(resourceComplexObject, this.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -883,9 +892,12 @@ private void Initialize()
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(simpleBodyProduct, this.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(simpleBodyProduct != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(simpleBodyProduct, this.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -972,6 +984,9 @@ private void Initialize()
///
/// Description of product.
///
+ ///
+ /// Generic URL value.
+ ///
///
/// URL value.
///
@@ -984,7 +999,7 @@ private void Initialize()
///
/// A response object containing the response body and response headers.
///
- public async Task> PostFlattenedSimpleProductWithHttpMessagesAsync(string productId, string maxProductDisplayName, string description = default(string), string odatavalue = default(string), Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken))
+ public async Task> PostFlattenedSimpleProductWithHttpMessagesAsync(string productId, string maxProductDisplayName, string description = default(string), string genericValue = default(string), string odatavalue = default(string), Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken))
{
if (productId == null)
{
@@ -995,12 +1010,13 @@ private void Initialize()
throw new ValidationException(ValidationRules.CannotBeNull, "maxProductDisplayName");
}
SimpleProduct simpleBodyProduct = default(SimpleProduct);
- if (productId != null || description != null || maxProductDisplayName != null || odatavalue != null)
+ if (productId != null || description != null || maxProductDisplayName != null || genericValue != null || odatavalue != null)
{
simpleBodyProduct = new SimpleProduct();
simpleBodyProduct.ProductId = productId;
simpleBodyProduct.Description = description;
simpleBodyProduct.MaxProductDisplayName = maxProductDisplayName;
+ simpleBodyProduct.GenericValue = genericValue;
simpleBodyProduct.Odatavalue = odatavalue;
}
// Tracing
@@ -1037,9 +1053,12 @@ private void Initialize()
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(simpleBodyProduct, this.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(simpleBodyProduct != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(simpleBodyProduct, this.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -1157,18 +1176,24 @@ private void Initialize()
{
maxProductDisplayName = flattenParameterGroup.MaxProductDisplayName;
}
+ string genericValue = default(string);
+ if (flattenParameterGroup != null)
+ {
+ genericValue = flattenParameterGroup.GenericValue;
+ }
string odatavalue = default(string);
if (flattenParameterGroup != null)
{
odatavalue = flattenParameterGroup.Odatavalue;
}
SimpleProduct simpleBodyProduct = default(SimpleProduct);
- if (productId != null || description != null || maxProductDisplayName != null || odatavalue != null)
+ if (productId != null || description != null || maxProductDisplayName != null || genericValue != null || odatavalue != null)
{
simpleBodyProduct = new SimpleProduct();
simpleBodyProduct.ProductId = productId;
simpleBodyProduct.Description = description;
simpleBodyProduct.MaxProductDisplayName = maxProductDisplayName;
+ simpleBodyProduct.GenericValue = genericValue;
simpleBodyProduct.Odatavalue = odatavalue;
}
// Tracing
@@ -1182,6 +1207,7 @@ private void Initialize()
tracingParameters.Add("productId", productId);
tracingParameters.Add("description", description);
tracingParameters.Add("maxProductDisplayName", maxProductDisplayName);
+ tracingParameters.Add("genericValue", genericValue);
tracingParameters.Add("odatavalue", odatavalue);
tracingParameters.Add("simpleBodyProduct", simpleBodyProduct);
tracingParameters.Add("cancellationToken", cancellationToken);
@@ -1211,9 +1237,12 @@ private void Initialize()
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(simpleBodyProduct, this.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(simpleBodyProduct != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(simpleBodyProduct, this.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
diff --git a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/ModelFlattening/AutoRestResourceFlatteningTestServiceExtensions.cs b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/ModelFlattening/AutoRestResourceFlatteningTestServiceExtensions.cs
index 89debcadba39f..d2ab8e3efe09e 100644
--- a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/ModelFlattening/AutoRestResourceFlatteningTestServiceExtensions.cs
+++ b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/ModelFlattening/AutoRestResourceFlatteningTestServiceExtensions.cs
@@ -249,12 +249,15 @@ public static ResourceCollection GetResourceCollection(this IAutoRestResourceFla
///
/// Description of product.
///
+ ///
+ /// Generic URL value.
+ ///
///
/// URL value.
///
- public static SimpleProduct PostFlattenedSimpleProduct(this IAutoRestResourceFlatteningTestService operations, string productId, string maxProductDisplayName, string description = default(string), string odatavalue = default(string))
+ public static SimpleProduct PostFlattenedSimpleProduct(this IAutoRestResourceFlatteningTestService operations, string productId, string maxProductDisplayName, string description = default(string), string genericValue = default(string), string odatavalue = default(string))
{
- return Task.Factory.StartNew(s => ((IAutoRestResourceFlatteningTestService)s).PostFlattenedSimpleProductAsync(productId, maxProductDisplayName, description, odatavalue), operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
+ return Task.Factory.StartNew(s => ((IAutoRestResourceFlatteningTestService)s).PostFlattenedSimpleProductAsync(productId, maxProductDisplayName, description, genericValue, odatavalue), operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
}
///
@@ -274,15 +277,18 @@ public static ResourceCollection GetResourceCollection(this IAutoRestResourceFla
///
/// Description of product.
///
+ ///
+ /// Generic URL value.
+ ///
///
/// URL value.
///
///
/// The cancellation token.
///
- public static async Task PostFlattenedSimpleProductAsync(this IAutoRestResourceFlatteningTestService operations, string productId, string maxProductDisplayName, string description = default(string), string odatavalue = default(string), CancellationToken cancellationToken = default(CancellationToken))
+ public static async Task PostFlattenedSimpleProductAsync(this IAutoRestResourceFlatteningTestService operations, string productId, string maxProductDisplayName, string description = default(string), string genericValue = default(string), string odatavalue = default(string), CancellationToken cancellationToken = default(CancellationToken))
{
- using (var _result = await operations.PostFlattenedSimpleProductWithHttpMessagesAsync(productId, maxProductDisplayName, description, odatavalue, null, cancellationToken).ConfigureAwait(false))
+ using (var _result = await operations.PostFlattenedSimpleProductWithHttpMessagesAsync(productId, maxProductDisplayName, description, genericValue, odatavalue, null, cancellationToken).ConfigureAwait(false))
{
return _result.Body;
}
diff --git a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/ModelFlattening/IAutoRestResourceFlatteningTestService.cs b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/ModelFlattening/IAutoRestResourceFlatteningTestService.cs
index c2b0e8724c57e..e7cdeadf98fdc 100644
--- a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/ModelFlattening/IAutoRestResourceFlatteningTestService.cs
+++ b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/ModelFlattening/IAutoRestResourceFlatteningTestService.cs
@@ -142,6 +142,9 @@ public partial interface IAutoRestResourceFlatteningTestService : IDisposable
///
/// Description of product.
///
+ ///
+ /// Generic URL value.
+ ///
///
/// URL value.
///
@@ -151,7 +154,7 @@ public partial interface IAutoRestResourceFlatteningTestService : IDisposable
///
/// The cancellation token.
///
- Task> PostFlattenedSimpleProductWithHttpMessagesAsync(string productId, string maxProductDisplayName, string description = default(string), string odatavalue = default(string), Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken));
+ Task> PostFlattenedSimpleProductWithHttpMessagesAsync(string productId, string maxProductDisplayName, string description = default(string), string genericValue = default(string), string odatavalue = default(string), Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken));
///
/// Put Simple Product with client flattening true on the model
diff --git a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/ModelFlattening/Models/FlattenParameterGroup.cs b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/ModelFlattening/Models/FlattenParameterGroup.cs
index 315e5db4ea53f..db9785813c55c 100644
--- a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/ModelFlattening/Models/FlattenParameterGroup.cs
+++ b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/ModelFlattening/Models/FlattenParameterGroup.cs
@@ -29,12 +29,13 @@ public FlattenParameterGroup() { }
///
/// Initializes a new instance of the FlattenParameterGroup class.
///
- public FlattenParameterGroup(string name, string productId, string maxProductDisplayName, string description = default(string), string odatavalue = default(string))
+ public FlattenParameterGroup(string name, string productId, string maxProductDisplayName, string description = default(string), string genericValue = default(string), string odatavalue = default(string))
{
Name = name;
ProductId = productId;
Description = description;
MaxProductDisplayName = maxProductDisplayName;
+ GenericValue = genericValue;
Odatavalue = odatavalue;
}
@@ -64,6 +65,12 @@ public FlattenParameterGroup() { }
[JsonProperty(PropertyName = "")]
public string MaxProductDisplayName { get; set; }
+ ///
+ /// Generic URL value.
+ ///
+ [JsonProperty(PropertyName = "")]
+ public string GenericValue { get; set; }
+
///
/// URL value.
///
diff --git a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/ModelFlattening/Models/GenericUrl.cs b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/ModelFlattening/Models/GenericUrl.cs
new file mode 100644
index 0000000000000..309028eb12669
--- /dev/null
+++ b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/ModelFlattening/Models/GenericUrl.cs
@@ -0,0 +1,43 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License. See License.txt in the project root for
+// license information.
+//
+// Code generated by Microsoft (R) AutoRest Code Generator.
+// Changes may cause incorrect behavior and will be lost if the code is
+// regenerated.
+
+namespace Fixtures.AcceptanceTestsModelFlattening.Models
+{
+ using System;
+ using System.Linq;
+ using System.Collections.Generic;
+ using Newtonsoft.Json;
+ using Microsoft.Rest;
+ using Microsoft.Rest.Serialization;
+
+ ///
+ /// The Generic URL.
+ ///
+ public partial class GenericUrl
+ {
+ ///
+ /// Initializes a new instance of the GenericUrl class.
+ ///
+ public GenericUrl() { }
+
+ ///
+ /// Initializes a new instance of the GenericUrl class.
+ ///
+ public GenericUrl(string genericValue = default(string))
+ {
+ GenericValue = genericValue;
+ }
+
+ ///
+ /// Generic URL value.
+ ///
+ [JsonProperty(PropertyName = "generic_value")]
+ public string GenericValue { get; set; }
+
+ }
+}
diff --git a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/ModelFlattening/Models/SimpleProduct.cs b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/ModelFlattening/Models/SimpleProduct.cs
index 4c69296ee9335..5ee2fa897a5ea 100644
--- a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/ModelFlattening/Models/SimpleProduct.cs
+++ b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/ModelFlattening/Models/SimpleProduct.cs
@@ -29,10 +29,11 @@ public SimpleProduct() { }
///
/// Initializes a new instance of the SimpleProduct class.
///
- public SimpleProduct(string productId, string maxProductDisplayName, string description = default(string), string odatavalue = default(string))
+ public SimpleProduct(string productId, string maxProductDisplayName, string description = default(string), string genericValue = default(string), string odatavalue = default(string))
: base(productId, description)
{
MaxProductDisplayName = maxProductDisplayName;
+ GenericValue = genericValue;
Odatavalue = odatavalue;
}
///
@@ -49,6 +50,12 @@ static SimpleProduct()
[JsonProperty(PropertyName = "details.max_product_display_name")]
public string MaxProductDisplayName { get; set; }
+ ///
+ /// Generic URL value.
+ ///
+ [JsonProperty(PropertyName = "details.max_product_image.generic_value")]
+ public string GenericValue { get; set; }
+
///
/// URL value.
///
diff --git a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/ParameterFlattening/AvailabilitySets.cs b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/ParameterFlattening/AvailabilitySets.cs
index a2ff4eb31d0f1..119563378110a 100644
--- a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/ParameterFlattening/AvailabilitySets.cs
+++ b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/ParameterFlattening/AvailabilitySets.cs
@@ -132,9 +132,12 @@ public AvailabilitySets(AutoRestParameterFlattening client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(tags1, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(tags1 != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(tags1, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
diff --git a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/RequiredOptional/ExplicitModel.cs b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/RequiredOptional/ExplicitModel.cs
index 6d1908994fb20..f0e42c1bf7fc9 100644
--- a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/RequiredOptional/ExplicitModel.cs
+++ b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/RequiredOptional/ExplicitModel.cs
@@ -99,9 +99,12 @@ public ExplicitModel(AutoRestRequiredOptionalTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(bodyParameter, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(bodyParameter != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(bodyParameter, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -220,9 +223,12 @@ public ExplicitModel(AutoRestRequiredOptionalTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(bodyParameter, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(bodyParameter != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(bodyParameter, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -331,9 +337,12 @@ public ExplicitModel(AutoRestRequiredOptionalTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(bodyParameter, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(bodyParameter != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(bodyParameter, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -456,9 +465,12 @@ public ExplicitModel(AutoRestRequiredOptionalTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(bodyParameter, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(bodyParameter != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(bodyParameter, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -805,9 +817,12 @@ public ExplicitModel(AutoRestRequiredOptionalTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(bodyParameter, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(bodyParameter != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(bodyParameter, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -926,9 +941,12 @@ public ExplicitModel(AutoRestRequiredOptionalTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(bodyParameter, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(bodyParameter != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(bodyParameter, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -1044,9 +1062,12 @@ public ExplicitModel(AutoRestRequiredOptionalTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(bodyParameter, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(bodyParameter != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(bodyParameter, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -1172,9 +1193,12 @@ public ExplicitModel(AutoRestRequiredOptionalTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(bodyParameter, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(bodyParameter != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(bodyParameter, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -1532,9 +1556,12 @@ public ExplicitModel(AutoRestRequiredOptionalTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(bodyParameter, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(bodyParameter != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(bodyParameter, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -1657,9 +1684,12 @@ public ExplicitModel(AutoRestRequiredOptionalTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(bodyParameter, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(bodyParameter != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(bodyParameter, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -1779,9 +1809,12 @@ public ExplicitModel(AutoRestRequiredOptionalTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(bodyParameter, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(bodyParameter != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(bodyParameter, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -1911,9 +1944,12 @@ public ExplicitModel(AutoRestRequiredOptionalTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(bodyParameter, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(bodyParameter != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(bodyParameter, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -2023,9 +2059,12 @@ public ExplicitModel(AutoRestRequiredOptionalTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(bodyParameter, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(bodyParameter != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(bodyParameter, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -2144,9 +2183,12 @@ public ExplicitModel(AutoRestRequiredOptionalTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(bodyParameter, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(bodyParameter != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(bodyParameter, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -2262,9 +2304,12 @@ public ExplicitModel(AutoRestRequiredOptionalTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(bodyParameter, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(bodyParameter != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(bodyParameter, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -2390,9 +2435,12 @@ public ExplicitModel(AutoRestRequiredOptionalTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(bodyParameter, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(bodyParameter != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(bodyParameter, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
diff --git a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/RequiredOptional/ImplicitModel.cs b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/RequiredOptional/ImplicitModel.cs
index e07c894c0febb..52a2bd5e9c8a0 100644
--- a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/RequiredOptional/ImplicitModel.cs
+++ b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/RequiredOptional/ImplicitModel.cs
@@ -446,9 +446,12 @@ public ImplicitModel(AutoRestRequiredOptionalTestService client)
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(bodyParameter, this.Client.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(bodyParameter != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(bodyParameter, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
diff --git a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/Url/IPaths.cs b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/Url/IPaths.cs
index 518a34aeade57..d8f9e2c761579 100644
--- a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/Url/IPaths.cs
+++ b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/Url/IPaths.cs
@@ -277,5 +277,46 @@ public partial interface IPaths
/// The cancellation token.
///
Task DateTimeNullWithHttpMessagesAsync(DateTime dateTimePath, Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken));
+ ///
+ /// Get 'lorem' encoded value as 'bG9yZW0' (base64url)
+ ///
+ ///
+ /// base64url encoded value
+ ///
+ ///
+ /// The headers that will be added to request.
+ ///
+ ///
+ /// The cancellation token.
+ ///
+ Task Base64UrlWithHttpMessagesAsync(byte[] base64UrlPath, Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken));
+ ///
+ /// Get an array of string ['ArrayPath1', 'begin!*'();:@
+ /// &=+$,/?#[]end' , null, ''] using the csv-array format
+ ///
+ ///
+ /// an array of string ['ArrayPath1', 'begin!*'();:@
+ /// &=+$,/?#[]end' , null, ''] using the csv-array format
+ ///
+ ///
+ /// The headers that will be added to request.
+ ///
+ ///
+ /// The cancellation token.
+ ///
+ Task ArrayCsvInPathWithHttpMessagesAsync(IList arrayPath, Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken));
+ ///
+ /// Get the date 2016-04-13 encoded value as '1460505600' (Unix time)
+ ///
+ ///
+ /// Unix time encoded value
+ ///
+ ///
+ /// The headers that will be added to request.
+ ///
+ ///
+ /// The cancellation token.
+ ///
+ Task UnixTimeUrlWithHttpMessagesAsync(DateTime unixTimeUrlPath, Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken));
}
}
diff --git a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/Url/Paths.cs b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/Url/Paths.cs
index b68b6a5103255..3892f728ba11b 100644
--- a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/Url/Paths.cs
+++ b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/Url/Paths.cs
@@ -2470,5 +2470,333 @@ public Paths(AutoRestUrlTestService client)
return _result;
}
+ ///
+ /// Get 'lorem' encoded value as 'bG9yZW0' (base64url)
+ ///
+ ///
+ /// base64url encoded value
+ ///
+ ///
+ /// Headers that will be added to request.
+ ///
+ ///
+ /// The cancellation token.
+ ///
+ ///
+ /// A response object containing the response body and response headers.
+ ///
+ public async Task Base64UrlWithHttpMessagesAsync(byte[] base64UrlPath, Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken))
+ {
+ if (base64UrlPath == null)
+ {
+ throw new ValidationException(ValidationRules.CannotBeNull, "base64UrlPath");
+ }
+ // Tracing
+ bool _shouldTrace = ServiceClientTracing.IsEnabled;
+ string _invocationId = null;
+ if (_shouldTrace)
+ {
+ _invocationId = ServiceClientTracing.NextInvocationId.ToString();
+ Dictionary tracingParameters = new Dictionary();
+ tracingParameters.Add("base64UrlPath", base64UrlPath);
+ tracingParameters.Add("cancellationToken", cancellationToken);
+ ServiceClientTracing.Enter(_invocationId, this, "Base64Url", tracingParameters);
+ }
+ // Construct URL
+ var _baseUrl = this.Client.BaseUri.AbsoluteUri;
+ var _url = new Uri(new Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "paths/string/bG9yZW0/{base64UrlPath}").ToString();
+ _url = _url.Replace("{base64UrlPath}", Uri.EscapeDataString(SafeJsonConvert.SerializeObject(base64UrlPath, new Base64UrlJsonConverter()).Trim('"')));
+ // Create HTTP transport objects
+ HttpRequestMessage _httpRequest = new HttpRequestMessage();
+ HttpResponseMessage _httpResponse = null;
+ _httpRequest.Method = new HttpMethod("GET");
+ _httpRequest.RequestUri = new Uri(_url);
+ // Set Headers
+ if (customHeaders != null)
+ {
+ foreach(var _header in customHeaders)
+ {
+ if (_httpRequest.Headers.Contains(_header.Key))
+ {
+ _httpRequest.Headers.Remove(_header.Key);
+ }
+ _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
+ }
+ }
+
+ // Serialize Request
+ string _requestContent = null;
+ // Send Request
+ if (_shouldTrace)
+ {
+ ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
+ }
+ cancellationToken.ThrowIfCancellationRequested();
+ _httpResponse = await this.Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
+ if (_shouldTrace)
+ {
+ ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
+ }
+ HttpStatusCode _statusCode = _httpResponse.StatusCode;
+ cancellationToken.ThrowIfCancellationRequested();
+ string _responseContent = null;
+ if ((int)_statusCode != 200)
+ {
+ var ex = new ErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusCode));
+ try
+ {
+ _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
+ Error _errorBody = SafeJsonConvert.DeserializeObject(_responseContent, this.Client.DeserializationSettings);
+ if (_errorBody != null)
+ {
+ ex.Body = _errorBody;
+ }
+ }
+ catch (JsonException)
+ {
+ // Ignore the exception
+ }
+ ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
+ ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
+ if (_shouldTrace)
+ {
+ ServiceClientTracing.Error(_invocationId, ex);
+ }
+ _httpRequest.Dispose();
+ if (_httpResponse != null)
+ {
+ _httpResponse.Dispose();
+ }
+ throw ex;
+ }
+ // Create Result
+ var _result = new HttpOperationResponse();
+ _result.Request = _httpRequest;
+ _result.Response = _httpResponse;
+ if (_shouldTrace)
+ {
+ ServiceClientTracing.Exit(_invocationId, _result);
+ }
+ return _result;
+ }
+
+ ///
+ /// Get an array of string ['ArrayPath1', 'begin!*'();:@ &=+$,/?#[]end' ,
+ /// null, ''] using the csv-array format
+ ///
+ ///
+ /// an array of string ['ArrayPath1', 'begin!*'();:@ &=+$,/?#[]end' ,
+ /// null, ''] using the csv-array format
+ ///
+ ///
+ /// Headers that will be added to request.
+ ///
+ ///
+ /// The cancellation token.
+ ///
+ ///
+ /// A response object containing the response body and response headers.
+ ///
+ public async Task ArrayCsvInPathWithHttpMessagesAsync(IList arrayPath, Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken))
+ {
+ if (arrayPath == null)
+ {
+ throw new ValidationException(ValidationRules.CannotBeNull, "arrayPath");
+ }
+ // Tracing
+ bool _shouldTrace = ServiceClientTracing.IsEnabled;
+ string _invocationId = null;
+ if (_shouldTrace)
+ {
+ _invocationId = ServiceClientTracing.NextInvocationId.ToString();
+ Dictionary tracingParameters = new Dictionary();
+ tracingParameters.Add("arrayPath", arrayPath);
+ tracingParameters.Add("cancellationToken", cancellationToken);
+ ServiceClientTracing.Enter(_invocationId, this, "ArrayCsvInPath", tracingParameters);
+ }
+ // Construct URL
+ var _baseUrl = this.Client.BaseUri.AbsoluteUri;
+ var _url = new Uri(new Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "paths/array/ArrayPath1%2cbegin%21%2A%27%28%29%3B%3A%40%20%26%3D%2B%24%2C%2F%3F%23%5B%5Dend%2c%2c/{arrayPath:commaSeparated}").ToString();
+ _url = _url.Replace("{arrayPath:commaSeparated}", Uri.EscapeDataString(string.Join(",", arrayPath)));
+ // Create HTTP transport objects
+ HttpRequestMessage _httpRequest = new HttpRequestMessage();
+ HttpResponseMessage _httpResponse = null;
+ _httpRequest.Method = new HttpMethod("GET");
+ _httpRequest.RequestUri = new Uri(_url);
+ // Set Headers
+ if (customHeaders != null)
+ {
+ foreach(var _header in customHeaders)
+ {
+ if (_httpRequest.Headers.Contains(_header.Key))
+ {
+ _httpRequest.Headers.Remove(_header.Key);
+ }
+ _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
+ }
+ }
+
+ // Serialize Request
+ string _requestContent = null;
+ // Send Request
+ if (_shouldTrace)
+ {
+ ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
+ }
+ cancellationToken.ThrowIfCancellationRequested();
+ _httpResponse = await this.Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
+ if (_shouldTrace)
+ {
+ ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
+ }
+ HttpStatusCode _statusCode = _httpResponse.StatusCode;
+ cancellationToken.ThrowIfCancellationRequested();
+ string _responseContent = null;
+ if ((int)_statusCode != 200)
+ {
+ var ex = new ErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusCode));
+ try
+ {
+ _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
+ Error _errorBody = SafeJsonConvert.DeserializeObject(_responseContent, this.Client.DeserializationSettings);
+ if (_errorBody != null)
+ {
+ ex.Body = _errorBody;
+ }
+ }
+ catch (JsonException)
+ {
+ // Ignore the exception
+ }
+ ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
+ ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
+ if (_shouldTrace)
+ {
+ ServiceClientTracing.Error(_invocationId, ex);
+ }
+ _httpRequest.Dispose();
+ if (_httpResponse != null)
+ {
+ _httpResponse.Dispose();
+ }
+ throw ex;
+ }
+ // Create Result
+ var _result = new HttpOperationResponse();
+ _result.Request = _httpRequest;
+ _result.Response = _httpResponse;
+ if (_shouldTrace)
+ {
+ ServiceClientTracing.Exit(_invocationId, _result);
+ }
+ return _result;
+ }
+
+ ///
+ /// Get the date 2016-04-13 encoded value as '1460505600' (Unix time)
+ ///
+ ///
+ /// Unix time encoded value
+ ///
+ ///
+ /// Headers that will be added to request.
+ ///
+ ///
+ /// The cancellation token.
+ ///
+ ///
+ /// A response object containing the response body and response headers.
+ ///
+ public async Task UnixTimeUrlWithHttpMessagesAsync(DateTime unixTimeUrlPath, Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken))
+ {
+ // Tracing
+ bool _shouldTrace = ServiceClientTracing.IsEnabled;
+ string _invocationId = null;
+ if (_shouldTrace)
+ {
+ _invocationId = ServiceClientTracing.NextInvocationId.ToString();
+ Dictionary tracingParameters = new Dictionary();
+ tracingParameters.Add("unixTimeUrlPath", unixTimeUrlPath);
+ tracingParameters.Add("cancellationToken", cancellationToken);
+ ServiceClientTracing.Enter(_invocationId, this, "UnixTimeUrl", tracingParameters);
+ }
+ // Construct URL
+ var _baseUrl = this.Client.BaseUri.AbsoluteUri;
+ var _url = new Uri(new Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "paths/int/1460505600/{unixTimeUrlPath}").ToString();
+ _url = _url.Replace("{unixTimeUrlPath}", Uri.EscapeDataString(SafeJsonConvert.SerializeObject(unixTimeUrlPath, new UnixTimeJsonConverter()).Trim('"')));
+ // Create HTTP transport objects
+ HttpRequestMessage _httpRequest = new HttpRequestMessage();
+ HttpResponseMessage _httpResponse = null;
+ _httpRequest.Method = new HttpMethod("GET");
+ _httpRequest.RequestUri = new Uri(_url);
+ // Set Headers
+ if (customHeaders != null)
+ {
+ foreach(var _header in customHeaders)
+ {
+ if (_httpRequest.Headers.Contains(_header.Key))
+ {
+ _httpRequest.Headers.Remove(_header.Key);
+ }
+ _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
+ }
+ }
+
+ // Serialize Request
+ string _requestContent = null;
+ // Send Request
+ if (_shouldTrace)
+ {
+ ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
+ }
+ cancellationToken.ThrowIfCancellationRequested();
+ _httpResponse = await this.Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
+ if (_shouldTrace)
+ {
+ ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
+ }
+ HttpStatusCode _statusCode = _httpResponse.StatusCode;
+ cancellationToken.ThrowIfCancellationRequested();
+ string _responseContent = null;
+ if ((int)_statusCode != 200)
+ {
+ var ex = new ErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusCode));
+ try
+ {
+ _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
+ Error _errorBody = SafeJsonConvert.DeserializeObject(_responseContent, this.Client.DeserializationSettings);
+ if (_errorBody != null)
+ {
+ ex.Body = _errorBody;
+ }
+ }
+ catch (JsonException)
+ {
+ // Ignore the exception
+ }
+ ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
+ ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
+ if (_shouldTrace)
+ {
+ ServiceClientTracing.Error(_invocationId, ex);
+ }
+ _httpRequest.Dispose();
+ if (_httpResponse != null)
+ {
+ _httpResponse.Dispose();
+ }
+ throw ex;
+ }
+ // Create Result
+ var _result = new HttpOperationResponse();
+ _result.Request = _httpRequest;
+ _result.Response = _httpResponse;
+ if (_shouldTrace)
+ {
+ ServiceClientTracing.Exit(_invocationId, _result);
+ }
+ return _result;
+ }
+
}
}
diff --git a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/Url/PathsExtensions.cs b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/Url/PathsExtensions.cs
index 253b845261892..b4e8d2ce268e6 100644
--- a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/Url/PathsExtensions.cs
+++ b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/Url/PathsExtensions.cs
@@ -646,5 +646,102 @@ public static void DateTimeNull(this IPaths operations, DateTime dateTimePath)
await operations.DateTimeNullWithHttpMessagesAsync(dateTimePath, null, cancellationToken).ConfigureAwait(false);
}
+ ///
+ /// Get 'lorem' encoded value as 'bG9yZW0' (base64url)
+ ///
+ ///
+ /// The operations group for this extension method.
+ ///
+ ///
+ /// base64url encoded value
+ ///
+ public static void Base64Url(this IPaths operations, byte[] base64UrlPath)
+ {
+ Task.Factory.StartNew(s => ((IPaths)s).Base64UrlAsync(base64UrlPath), operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Get 'lorem' encoded value as 'bG9yZW0' (base64url)
+ ///
+ ///
+ /// The operations group for this extension method.
+ ///
+ ///
+ /// base64url encoded value
+ ///
+ ///
+ /// The cancellation token.
+ ///
+ public static async Task Base64UrlAsync(this IPaths operations, byte[] base64UrlPath, CancellationToken cancellationToken = default(CancellationToken))
+ {
+ await operations.Base64UrlWithHttpMessagesAsync(base64UrlPath, null, cancellationToken).ConfigureAwait(false);
+ }
+
+ ///
+ /// Get an array of string ['ArrayPath1', 'begin!*'();:@ &=+$,/?#[]end' ,
+ /// null, ''] using the csv-array format
+ ///
+ ///
+ /// The operations group for this extension method.
+ ///
+ ///
+ /// an array of string ['ArrayPath1', 'begin!*'();:@ &=+$,/?#[]end' ,
+ /// null, ''] using the csv-array format
+ ///
+ public static void ArrayCsvInPath(this IPaths operations, IList arrayPath)
+ {
+ Task.Factory.StartNew(s => ((IPaths)s).ArrayCsvInPathAsync(arrayPath), operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Get an array of string ['ArrayPath1', 'begin!*'();:@ &=+$,/?#[]end' ,
+ /// null, ''] using the csv-array format
+ ///
+ ///
+ /// The operations group for this extension method.
+ ///
+ ///
+ /// an array of string ['ArrayPath1', 'begin!*'();:@ &=+$,/?#[]end' ,
+ /// null, ''] using the csv-array format
+ ///
+ ///
+ /// The cancellation token.
+ ///
+ public static async Task ArrayCsvInPathAsync(this IPaths operations, IList arrayPath, CancellationToken cancellationToken = default(CancellationToken))
+ {
+ await operations.ArrayCsvInPathWithHttpMessagesAsync(arrayPath, null, cancellationToken).ConfigureAwait(false);
+ }
+
+ ///
+ /// Get the date 2016-04-13 encoded value as '1460505600' (Unix time)
+ ///
+ ///
+ /// The operations group for this extension method.
+ ///
+ ///
+ /// Unix time encoded value
+ ///
+ public static void UnixTimeUrl(this IPaths operations, DateTime unixTimeUrlPath)
+ {
+ Task.Factory.StartNew(s => ((IPaths)s).UnixTimeUrlAsync(unixTimeUrlPath), operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Get the date 2016-04-13 encoded value as '1460505600' (Unix time)
+ ///
+ ///
+ /// The operations group for this extension method.
+ ///
+ ///
+ /// Unix time encoded value
+ ///
+ ///
+ /// The cancellation token.
+ ///
+ public static async Task UnixTimeUrlAsync(this IPaths operations, DateTime unixTimeUrlPath, CancellationToken cancellationToken = default(CancellationToken))
+ {
+ await operations.UnixTimeUrlWithHttpMessagesAsync(unixTimeUrlPath, null, cancellationToken).ConfigureAwait(false);
+ }
+
}
}
diff --git a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/Validation/AutoRestValidationTest.cs b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/Validation/AutoRestValidationTest.cs
index dd33131940bbd..73459ebb73386 100644
--- a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/Validation/AutoRestValidationTest.cs
+++ b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/Validation/AutoRestValidationTest.cs
@@ -461,9 +461,12 @@ private void Initialize()
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(body, this.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(body != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(body, this.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -679,9 +682,12 @@ private void Initialize()
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(body, this.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(body != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(body, this.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
diff --git a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/DateTimeOffset/SwaggerDateTimeOffsetClient.cs b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/DateTimeOffset/SwaggerDateTimeOffsetClient.cs
index b59cf0b0fe805..3bd502e2cd4ac 100644
--- a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/DateTimeOffset/SwaggerDateTimeOffsetClient.cs
+++ b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/DateTimeOffset/SwaggerDateTimeOffsetClient.cs
@@ -208,9 +208,12 @@ private void Initialize()
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(product, this.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(product != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(product, this.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -346,9 +349,12 @@ private void Initialize()
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(product, this.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(product != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(product, this.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -484,9 +490,12 @@ private void Initialize()
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(product, this.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(product != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(product, this.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
@@ -622,9 +631,12 @@ private void Initialize()
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(product, this.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(product != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(product, this.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
diff --git a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/Mirror.Polymorphic/PolymorphicAnimalStore.cs b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/Mirror.Polymorphic/PolymorphicAnimalStore.cs
index 9dbebd699667a..86bf0ccd5653a 100644
--- a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/Mirror.Polymorphic/PolymorphicAnimalStore.cs
+++ b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/Mirror.Polymorphic/PolymorphicAnimalStore.cs
@@ -202,9 +202,12 @@ private void Initialize()
// Serialize Request
string _requestContent = null;
- _requestContent = SafeJsonConvert.SerializeObject(animalCreateOrUpdateParameter, this.SerializationSettings);
- _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
- _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ if(animalCreateOrUpdateParameter != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(animalCreateOrUpdateParameter, this.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
// Send Request
if (_shouldTrace)
{
diff --git a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/Mirror.Primitives/Models/Product.cs b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/Mirror.Primitives/Models/Product.cs
index 2c3e2bafc98f6..d2ea149e267a9 100644
--- a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/Mirror.Primitives/Models/Product.cs
+++ b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/Mirror.Primitives/Models/Product.cs
@@ -25,7 +25,7 @@ public Product() { }
///
/// Initializes a new instance of the Product class.
///
- public Product(int? integer = default(int?), int? intProperty = default(int?), long? longProperty = default(long?), double? number = default(double?), double? floatProperty = default(double?), double? doubleProperty = default(double?), byte[] byteProperty = default(byte[]), string stringProperty = default(string), Guid? uuid = default(Guid?), string enumProperty = default(string), bool? boolean = default(bool?), DateTime? date = default(DateTime?), DateTime? dateTime = default(DateTime?), IList integerArray = default(IList), IList intArray = default(IList), IList longArray = default(IList), IList numberArray = default(IList), IList floatArray = default(IList), IList doubleArray = default(IList), IList byteArray = default(IList), IList booleanArray = default(IList), IList