Skip to content

Commit

Permalink
Adopt http\encode\datetime from cadl ranch (#4252)
Browse files Browse the repository at this point in the history
Fixes: #3972

---------

Co-authored-by: ShivangiReja <[email protected]>
  • Loading branch information
ShivangiReja and ShivangiReja authored Aug 23, 2024
1 parent d932462 commit 142f44f
Show file tree
Hide file tree
Showing 24 changed files with 2,624 additions and 1 deletion.
1 change: 0 additions & 1 deletion packages/http-client-csharp/eng/scripts/Generate.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ $failingSpecs = @(
Join-Path 'http' 'client' 'structure' 'client-operation-group'
Join-Path 'http' 'client' 'structure' 'renamed-operation'
Join-Path 'http' 'client' 'structure' 'two-operation-group'
Join-Path 'http' 'encode' 'datetime'
Join-Path 'http' 'parameters' 'body-optionality'
Join-Path 'http' 'parameters' 'collection-format'
Join-Path 'http' 'parameters' 'spread'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@
"commandName": "Executable",
"executablePath": "$(SolutionDir)/../dist/generator/Microsoft.Generator.CSharp.exe"
},
"http-encode-datetime": {
"commandLineArgs": "$(SolutionDir)/TestProjects/CadlRanch/http/encode/datetime -p StubLibraryPlugin",
"commandName": "Executable",
"executablePath": "$(SolutionDir)/../dist/generator/Microsoft.Generator.CSharp.exe"
},
"http-encode-duration": {
"commandLineArgs": "$(SolutionDir)/TestProjects/CadlRanch/http/encode/duration -p StubLibraryPlugin",
"commandName": "Executable",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using System.Threading.Tasks;
using Encode.Datetime;
using Encode.Datetime.Models;
using NUnit.Framework;

namespace TestProjects.CadlRanch.Tests.Http.Encode.DateTime
{
public class DateTimeTests : CadlRanchTestBase
{
[CadlRanchTest]
public Task Encode_Datetime_ResponseHeader_default() => Test(async (host) =>
{
var response = await new DatetimeClient(host, null).GetResponseHeaderClient().DefaultAsync();
Assert.AreEqual(204, response.GetRawResponse().Status);

Assert.IsTrue(response.GetRawResponse().Headers.TryGetValue("value", out string? header));
Assert.AreEqual("Fri, 26 Aug 2022 14:38:00 GMT", header);
});

[CadlRanchTest]
public Task Encode_Datetime_ResponseHeader_rfc3339() => Test(async (host) =>
{
var response = await new DatetimeClient(host, null).GetResponseHeaderClient().Rfc3339Async();
Assert.AreEqual(204, response.GetRawResponse().Status);

Assert.IsTrue(response.GetRawResponse().Headers.TryGetValue("value", out string? header));
Assert.AreEqual("2022-08-26T18:38:00.000Z", header);
});

[CadlRanchTest]
public Task Encode_Datetime_ResponseHeader_rfc7231() => Test(async (host) =>
{
var response = await new DatetimeClient(host, null).GetResponseHeaderClient().Rfc7231Async();
Assert.AreEqual(204, response.GetRawResponse().Status);

Assert.IsTrue(response.GetRawResponse().Headers.TryGetValue("value", out string? header));
Assert.AreEqual("Fri, 26 Aug 2022 14:38:00 GMT", header);
});

[CadlRanchTest]
public Task Encode_Datetime_ResponseHeader_unixTimestamp() => Test(async (host) =>
{
var response = await new DatetimeClient(host, null).GetResponseHeaderClient().UnixTimestampAsync();
Assert.AreEqual(204, response.GetRawResponse().Status);

Assert.IsTrue(response.GetRawResponse().Headers.TryGetValue("value", out string? header));
Assert.AreEqual("1686566864", header);
});

[CadlRanchTest]
public Task Encode_DateTime_Header_Default() => Test(async (host) =>
{
DateTimeOffset data = DateTimeOffset.Parse("Fri, 26 Aug 2022 14:38:00 GMT");
var response = await new DatetimeClient(host, null).GetHeaderClient().DefaultAsync(data);
Assert.AreEqual(204, response.GetRawResponse().Status);
});

[CadlRanchTest]
public Task Encode_DateTime_Header_Rfc3339() => Test(async (host) =>
{
DateTimeOffset data = DateTimeOffset.Parse("2022-08-26T18:38:00.000Z");
var response = await new DatetimeClient(host, null).GetHeaderClient().Rfc3339Async(data);
Assert.AreEqual(204, response.GetRawResponse().Status);
});

[CadlRanchTest]
public Task Encode_DateTime_Header_Rfc7231() => Test(async (host) =>
{
DateTimeOffset data = DateTimeOffset.Parse("Fri, 26 Aug 2022 14:38:00 GMT");
var response = await new DatetimeClient(host, null).GetHeaderClient().Rfc7231Async(data);
Assert.AreEqual(204, response.GetRawResponse().Status);
});

[CadlRanchTest]
public Task Encode_DateTime_Header_unixTimestamp() => Test(async (host) =>
{
DateTimeOffset data = DateTimeOffset.FromUnixTimeSeconds(1686566864);
var response = await new DatetimeClient(host, null).GetHeaderClient().UnixTimestampAsync(data);
Assert.AreEqual(204, response.GetRawResponse().Status);
});

[CadlRanchTest]
public Task Encode_DateTime_Header_unixTimestampArray() => Test(async (host) =>
{
DateTimeOffset data1 = DateTimeOffset.FromUnixTimeSeconds(1686566864);
DateTimeOffset data2 = DateTimeOffset.FromUnixTimeSeconds(1686734256);
var response = await new DatetimeClient(host, null).GetHeaderClient().UnixTimestampArrayAsync(new[] { data1, data2 });
Assert.AreEqual(204, response.GetRawResponse().Status);
});

[CadlRanchTest]
public Task Encode_DateTime_Query_Default() => Test(async (host) =>
{
DateTimeOffset data = DateTimeOffset.Parse("2022-08-26T18:38:00.000Z");
var response = await new DatetimeClient(host, null).GetQueryClient().DefaultAsync(data);
Assert.AreEqual(204, response.GetRawResponse().Status);
});

[CadlRanchTest]
public Task Encode_DateTime_Query_Rfc3339() => Test(async (host) =>
{
DateTimeOffset data = DateTimeOffset.Parse("2022-08-26T18:38:00.000Z");
var response = await new DatetimeClient(host, null).GetQueryClient().Rfc3339Async(data);
Assert.AreEqual(204, response.GetRawResponse().Status);
});

[CadlRanchTest]
public Task Encode_DateTime_Query_Rfc7231() => Test(async (host) =>
{
DateTimeOffset data = DateTimeOffset.Parse("Fri, 26 Aug 2022 14:38:00 GMT");
var response = await new DatetimeClient(host, null).GetQueryClient().Rfc7231Async(data);
Assert.AreEqual(204, response.GetRawResponse().Status);
});

[CadlRanchTest]
public Task Encode_DateTime_Query_unixTimestamp() => Test(async (host) =>
{
DateTimeOffset data = DateTimeOffset.FromUnixTimeSeconds(1686566864);
var response = await new DatetimeClient(host, null).GetQueryClient().UnixTimestampAsync(data);
Assert.AreEqual(204, response.GetRawResponse().Status);
});

[CadlRanchTest]
public Task Encode_DateTime_Query_unixTimestampArray() => Test(async (host) =>
{
DateTimeOffset data1 = DateTimeOffset.FromUnixTimeSeconds(1686566864);
DateTimeOffset data2 = DateTimeOffset.FromUnixTimeSeconds(1686734256);
var response = await new DatetimeClient(host, null).GetQueryClient().UnixTimestampArrayAsync(new[] { data1, data2 });
Assert.AreEqual(204, response.GetRawResponse().Status);
});

[CadlRanchTest]
public Task Encode_DateTime_Property_Default() => Test(async (host) =>
{
DateTimeOffset data = DateTimeOffset.Parse("2022-08-26T18:38:00.000Z");
var body = new DefaultDatetimeProperty(data);
var response = await new DatetimeClient(host, null).GetPropertyClient().DefaultAsync(body);
Assert.AreEqual(body.Value, response.Value.Value);
});

[CadlRanchTest]
public Task Encode_DateTime_Property_Rfc3339() => Test(async (host) =>
{
DateTimeOffset data = DateTimeOffset.Parse("2022-08-26T18:38:00.000Z");
var body = new Rfc3339DatetimeProperty(data);
var response = await new DatetimeClient(host, null).GetPropertyClient().Rfc3339Async(body);
Assert.AreEqual(body.Value, response.Value.Value);
});

[CadlRanchTest]
public Task Encode_DateTime_Property_Rfc7231() => Test(async (host) =>
{
DateTimeOffset data = DateTimeOffset.Parse("Fri, 26 Aug 2022 14:38:00 GMT");
var body = new Rfc7231DatetimeProperty(data);
var response = await new DatetimeClient(host, null).GetPropertyClient().Rfc7231Async(body);
Assert.AreEqual(body.Value, response.Value.Value);
});


[CadlRanchTest]
public Task Encode_DateTime_Property_unixTimestamp() => Test(async (host) =>
{
DateTimeOffset data = DateTimeOffset.FromUnixTimeSeconds(1686566864);
var body = new UnixTimestampDatetimeProperty(data);
var response = await new DatetimeClient(host, null).GetPropertyClient().UnixTimestampAsync(body);
Assert.AreEqual(body.Value, response.Value.Value);
});

[CadlRanchTest]
public Task Encode_DateTime_Property_unixTimestampArray() => Test(async (host) =>
{
DateTimeOffset data1 = DateTimeOffset.FromUnixTimeSeconds(1686566864);
DateTimeOffset data2 = DateTimeOffset.FromUnixTimeSeconds(1686734256);
var body = new UnixTimestampArrayDatetimeProperty(new[] { data1, data2 });
var response = await new DatetimeClient(host, null).GetPropertyClient().UnixTimestampArrayAsync(body);
Assert.AreEqual(body.Value, response.Value.Value);
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"output-folder": ".",
"namespace": "Encode.Datetime",
"library-name": "Encode.Datetime",
"use-model-reader-writer": true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29709.97
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Encode.Datetime", "src\Encode.Datetime.csproj", "{28FF4005-4467-4E36-92E7-DEA27DEB1519}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{B0C276D1-2930-4887-B29A-D1A33E7009A2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B0C276D1-2930-4887-B29A-D1A33E7009A2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B0C276D1-2930-4887-B29A-D1A33E7009A2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B0C276D1-2930-4887-B29A-D1A33E7009A2}.Release|Any CPU.Build.0 = Release|Any CPU
{8E9A77AC-792A-4432-8320-ACFD46730401}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8E9A77AC-792A-4432-8320-ACFD46730401}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8E9A77AC-792A-4432-8320-ACFD46730401}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8E9A77AC-792A-4432-8320-ACFD46730401}.Release|Any CPU.Build.0 = Release|Any CPU
{A4241C1F-A53D-474C-9E4E-075054407E74}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A4241C1F-A53D-474C-9E4E-075054407E74}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A4241C1F-A53D-474C-9E4E-075054407E74}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A4241C1F-A53D-474C-9E4E-075054407E74}.Release|Any CPU.Build.0 = Release|Any CPU
{FA8BD3F1-8616-47B6-974C-7576CDF4717E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FA8BD3F1-8616-47B6-974C-7576CDF4717E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FA8BD3F1-8616-47B6-974C-7576CDF4717E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FA8BD3F1-8616-47B6-974C-7576CDF4717E}.Release|Any CPU.Build.0 = Release|Any CPU
{85677AD3-C214-42FA-AE6E-49B956CAC8DC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{85677AD3-C214-42FA-AE6E-49B956CAC8DC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{85677AD3-C214-42FA-AE6E-49B956CAC8DC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{85677AD3-C214-42FA-AE6E-49B956CAC8DC}.Release|Any CPU.Build.0 = Release|Any CPU
{28FF4005-4467-4E36-92E7-DEA27DEB1519}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{28FF4005-4467-4E36-92E7-DEA27DEB1519}.Debug|Any CPU.Build.0 = Debug|Any CPU
{28FF4005-4467-4E36-92E7-DEA27DEB1519}.Release|Any CPU.ActiveCfg = Release|Any CPU
{28FF4005-4467-4E36-92E7-DEA27DEB1519}.Release|Any CPU.Build.0 = Release|Any CPU
{1F1CD1D4-9932-4B73-99D8-C252A67D4B46}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1F1CD1D4-9932-4B73-99D8-C252A67D4B46}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1F1CD1D4-9932-4B73-99D8-C252A67D4B46}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1F1CD1D4-9932-4B73-99D8-C252A67D4B46}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {A97F4B90-2591-4689-B1F8-5F21FE6D6CAE}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Description>This is the Encode.Datetime client library for developing .NET applications with rich experience.</Description>
<AssemblyTitle>SDK Code Generation Encode.Datetime</AssemblyTitle>
<Version>1.0.0-beta.1</Version>
<PackageTags>Encode.Datetime</PackageTags>
<TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>latest</LangVersion>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="System.ClientModel" Version="1.1.0-beta.4" />
<PackageReference Include="System.Text.Json" Version="8.0.4" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// <auto-generated/>

#nullable disable

using System;
using System.ClientModel.Primitives;

namespace Encode.Datetime
{
public partial class DatetimeClient
{
public DatetimeClient() : this(new Uri("http://localhost:3000"), new DatetimeClientOptions()) => throw null;

public DatetimeClient(Uri endpoint, DatetimeClientOptions options) => throw null;

public ClientPipeline Pipeline => throw null;

public virtual Query GetQueryClient() => throw null;

public virtual Property GetPropertyClient() => throw null;

public virtual Header GetHeaderClient() => throw null;

public virtual ResponseHeader GetResponseHeaderClient() => throw null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// <auto-generated/>

#nullable disable

using System.ClientModel.Primitives;

namespace Encode.Datetime
{
public partial class DatetimeClientOptions : ClientPipelineOptions
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// <auto-generated/>

#nullable disable

using System;
using System.Collections.Generic;

namespace Encode.Datetime.Models
{
public static partial class EncodeDatetimeModelFactory
{
public static DefaultDatetimeProperty DefaultDatetimeProperty(DateTimeOffset value = default) => throw null;

public static Rfc3339DatetimeProperty Rfc3339DatetimeProperty(DateTimeOffset value = default) => throw null;

public static Rfc7231DatetimeProperty Rfc7231DatetimeProperty(DateTimeOffset value = default) => throw null;

public static UnixTimestampDatetimeProperty UnixTimestampDatetimeProperty(DateTimeOffset value = default) => throw null;

public static UnixTimestampArrayDatetimeProperty UnixTimestampArrayDatetimeProperty(IEnumerable<DateTimeOffset> value = default) => throw null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// <auto-generated/>

#nullable disable

using System;
using System.ClientModel;
using System.ClientModel.Primitives;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Encode.Datetime
{
public partial class Header
{
protected Header() => throw null;

public ClientPipeline Pipeline => throw null;

public virtual ClientResult Default(DateTimeOffset value, RequestOptions options) => throw null;

public virtual Task<ClientResult> DefaultAsync(DateTimeOffset value, RequestOptions options) => throw null;

public virtual ClientResult Default(DateTimeOffset value) => throw null;

public virtual Task<ClientResult> DefaultAsync(DateTimeOffset value) => throw null;

public virtual ClientResult Rfc3339(DateTimeOffset value, RequestOptions options) => throw null;

public virtual Task<ClientResult> Rfc3339Async(DateTimeOffset value, RequestOptions options) => throw null;

public virtual ClientResult Rfc3339(DateTimeOffset value) => throw null;

public virtual Task<ClientResult> Rfc3339Async(DateTimeOffset value) => throw null;

public virtual ClientResult Rfc7231(DateTimeOffset value, RequestOptions options) => throw null;

public virtual Task<ClientResult> Rfc7231Async(DateTimeOffset value, RequestOptions options) => throw null;

public virtual ClientResult Rfc7231(DateTimeOffset value) => throw null;

public virtual Task<ClientResult> Rfc7231Async(DateTimeOffset value) => throw null;

public virtual ClientResult UnixTimestamp(DateTimeOffset value, RequestOptions options) => throw null;

public virtual Task<ClientResult> UnixTimestampAsync(DateTimeOffset value, RequestOptions options) => throw null;

public virtual ClientResult UnixTimestamp(DateTimeOffset value) => throw null;

public virtual Task<ClientResult> UnixTimestampAsync(DateTimeOffset value) => throw null;

public virtual ClientResult UnixTimestampArray(IList<DateTimeOffset> value, RequestOptions options) => throw null;

public virtual Task<ClientResult> UnixTimestampArrayAsync(IList<DateTimeOffset> value, RequestOptions options) => throw null;

public virtual ClientResult UnixTimestampArray(IList<DateTimeOffset> value) => throw null;

public virtual Task<ClientResult> UnixTimestampArrayAsync(IList<DateTimeOffset> value) => throw null;
}
}
Loading

0 comments on commit 142f44f

Please sign in to comment.