-
Notifications
You must be signed in to change notification settings - Fork 524
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds codegen for table-valued parameters (#454)
- Loading branch information
1 parent
4a5e030
commit 5a0b402
Showing
26 changed files
with
1,468 additions
and
406 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
src/Microsoft.Health.Fhir.SqlServer.UnitTests/EnumerableExtensionsTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// ------------------------------------------------------------------------------------------------- | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information. | ||
// ------------------------------------------------------------------------------------------------- | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using Xunit; | ||
|
||
namespace Microsoft.Health.Fhir.SqlServer.UnitTests | ||
{ | ||
public class EnumerableExtensionsTests | ||
{ | ||
[InlineData(null)] | ||
[InlineData("")] | ||
[Theory] | ||
public void GivenAnNullOrEmptyEnumerable_WhenCallingNullIfEmpty_ReturnsNull(string commaSeparatedInput) | ||
{ | ||
string[] input = commaSeparatedInput?.Split(',', StringSplitOptions.RemoveEmptyEntries); | ||
Assert.Null(input.NullIfEmpty()); | ||
} | ||
|
||
[InlineData("1")] | ||
[InlineData("1,2")] | ||
[InlineData("1,2,3")] | ||
[Theory] | ||
public void GivenANonEmptyEnumerable_WhenCallingNullIfEmpty_ReturnsTheExpectedSequence(string commaSeparatedInput) | ||
{ | ||
string[] inputSequence = commaSeparatedInput?.Split(',', StringSplitOptions.RemoveEmptyEntries); | ||
IEnumerable<string> wrappedSequence = inputSequence.NullIfEmpty(); | ||
Assert.Equal(commaSeparatedInput, string.Join(",", wrappedSequence)); | ||
Assert.Equal(commaSeparatedInput, string.Join(",", wrappedSequence)); | ||
} | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
...icrosoft.Health.Fhir.SqlServer.UnitTests/Microsoft.Health.Fhir.SqlServer.UnitTests.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netcoreapp2.2</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.0.1" /> | ||
<PackageReference Include="xunit" Version="2.4.1" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Microsoft.Health.Fhir.SqlServer\Microsoft.Health.Fhir.SqlServer.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// ------------------------------------------------------------------------------------------------- | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information. | ||
// ------------------------------------------------------------------------------------------------- | ||
|
||
using System.Resources; | ||
using System.Runtime.CompilerServices; | ||
|
||
[assembly: InternalsVisibleTo("Microsoft.Health.Fhir.SqlServer.UnitTests")] | ||
[assembly: NeutralResourcesLanguage("en-us")] |
81 changes: 81 additions & 0 deletions
81
src/Microsoft.Health.Fhir.SqlServer/EnumerableExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// ------------------------------------------------------------------------------------------------- | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information. | ||
// ------------------------------------------------------------------------------------------------- | ||
|
||
using System.Collections; | ||
using System.Collections.Generic; | ||
|
||
namespace Microsoft.Health.Fhir.SqlServer | ||
{ | ||
internal static class EnumerableExtensions | ||
{ | ||
/// <summary> | ||
/// If the given sequence is null or empty, returns null. Otherwise returns | ||
/// an equivalent sequence. | ||
/// </summary> | ||
/// <typeparam name="T">The element type</typeparam> | ||
/// <param name="enumerable">The input sequence</param> | ||
/// <returns>An equivalent sequence, or null if given one is empty or null.</returns> | ||
internal static IEnumerable<T> NullIfEmpty<T>(this IEnumerable<T> enumerable) | ||
{ | ||
if (enumerable == null) | ||
{ | ||
return null; | ||
} | ||
|
||
IEnumerator<T> enumerator = enumerable.GetEnumerator(); | ||
if (!enumerator.MoveNext()) | ||
{ | ||
return null; | ||
} | ||
|
||
return new EnumerableFromStartedEnumerator<T>(enumerator, enumerable); | ||
} | ||
|
||
private class EnumerableFromStartedEnumerator<T> : IEnumerable<T> | ||
{ | ||
private readonly IEnumerable<T> _original; | ||
private IEnumerator<T> _startedEnumerator; | ||
|
||
public EnumerableFromStartedEnumerator(IEnumerator<T> startedEnumerator, IEnumerable<T> original) | ||
{ | ||
_original = original; | ||
_startedEnumerator = startedEnumerator; | ||
} | ||
|
||
public IEnumerator<T> GetEnumerator() | ||
{ | ||
IEnumerable<T> Inner(IEnumerator<T> e) | ||
{ | ||
try | ||
{ | ||
do | ||
{ | ||
yield return e.Current; | ||
} | ||
while (e.MoveNext()); | ||
} | ||
finally | ||
{ | ||
e.Dispose(); | ||
} | ||
} | ||
|
||
if (_startedEnumerator != null) | ||
{ | ||
IEnumerator<T> e = _startedEnumerator; | ||
_startedEnumerator = null; | ||
return Inner(e).GetEnumerator(); | ||
} | ||
|
||
return _original.GetEnumerator(); | ||
} | ||
|
||
IEnumerator IEnumerable.GetEnumerator() | ||
{ | ||
return ((IEnumerable)this).GetEnumerator(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.