Skip to content

Commit

Permalink
Merge branch 'dotliquid' into personal/boywu/unused-segments
Browse files Browse the repository at this point in the history
  • Loading branch information
BoyaWu10 authored Dec 8, 2020
2 parents cfc0e74 + 4168fdc commit 6fbfcb9
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// -------------------------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
// -------------------------------------------------------------------------------------------------

using System.IO;

namespace Microsoft.Health.Fhir.Liquid.Converter.FunctionalTests
{
public static class Constants
{
public static readonly string TemplateDirectory = Path.Join("..", "..", "data", "Templates");
public static readonly string SampleDataDirectory = Path.Join("..", "..", "data", "SampleData");
public static readonly string ExpectedDataFolder = Path.Join("TestData", "Expected");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ namespace Microsoft.Health.Fhir.Liquid.Converter.FunctionalTests
{
public class FunctionalTests
{
private static readonly string DataFolder = @"..\..\..\..\..\data\SampleData";
private static readonly string ExpectedDataFolder = @"TestData\Expected";
private static readonly string Hl7v2TemplateFolder = @"..\..\..\..\..\data\Templates\Hl7v2";

public static IEnumerable<object[]> GetDataForHl7v2()
{
var data = new List<object[]>
Expand All @@ -44,8 +40,8 @@ public static IEnumerable<object[]> GetDataForHl7v2()
return data.Select(item => new object[]
{
Convert.ToString(item[0]),
Path.Combine(DataFolder, "Hl7v2", Convert.ToString(item[1])),
Path.Combine(ExpectedDataFolder, "Hl7v2", Convert.ToString(item[0]), Convert.ToString(item[2])),
Path.Join(Constants.SampleDataDirectory, "Hl7v2", Convert.ToString(item[1])),
Path.Join(Constants.ExpectedDataFolder, "Hl7v2", Convert.ToString(item[0]), Convert.ToString(item[2])),
});
}

Expand All @@ -54,7 +50,7 @@ public static IEnumerable<object[]> GetDataForHl7v2()
public void GivenHl7v2Message_WhenConverting_ExpectedFhirResourceShouldBeReturned(string rootTemplate, string inputFile, string expectedFile)
{
var hl7v2Processor = new Hl7v2Processor();
var templateDirectory = Path.Join(AppDomain.CurrentDomain.BaseDirectory, Hl7v2TemplateFolder);
var templateDirectory = Path.Join(AppDomain.CurrentDomain.BaseDirectory, Constants.TemplateDirectory, "Hl7v2");

var inputContent = File.ReadAllText(inputFile);
var expectedContent = File.ReadAllText(expectedFile);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@

<IsPackable>false</IsPackable>
</PropertyGroup>

<PropertyGroup>
<OutputPath>..\..\bin\Microsoft.Health.Fhir.Liquid.Converter.FunctionalTests\</OutputPath>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,8 @@ namespace Microsoft.Health.Fhir.Liquid.Converter.FunctionalTests
{
public class RuleBasedTests
{
private static readonly string _templateBaseFolder = @"..\..\..\..\..\data\Templates";
private static readonly string _dataBaseFolder = @"..\..\..\..\..\data\SampleData";

private static readonly string _hl7TemplateFolder = Path.Combine(_templateBaseFolder, "Hl7v2");
private static readonly string _hl7DataFolder = Path.Combine(_dataBaseFolder, "Hl7v2");
private static readonly string _hl7TemplateFolder = Path.Combine(Constants.TemplateDirectory, "Hl7v2");
private static readonly string _hl7DataFolder = Path.Combine(Constants.SampleDataDirectory, "Hl7v2");

private static readonly Hl7v2TemplateProvider _hl7TemplateProvider = new Hl7v2TemplateProvider(_hl7TemplateFolder);

Expand Down
14 changes: 14 additions & 0 deletions src/Microsoft.Health.Fhir.Liquid.Converter.UnitTests/Constants.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// -------------------------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
// -------------------------------------------------------------------------------------------------

using System.IO;

namespace Microsoft.Health.Fhir.Liquid.Converter.UnitTests
{
public static class Constants
{
public static readonly string Hl7v2TemplateDirectory = Path.Join("..", "..", "data", "Templates", "Hl7v2");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static IEnumerable<object[]> GetInvalidEvaluateTemplateContents()
public void GivenValidEvaluateTemplateContent_WhenParseAndRender_CorrectResultShouldBeReturned(string templateContent)
{
// Template should be parsed correctly
var templateProvider = new Hl7v2TemplateProvider(@"..\..\..\..\..\data\Templates\Hl7v2");
var templateProvider = new Hl7v2TemplateProvider(Constants.Hl7v2TemplateDirectory);
var template = Template.Parse(templateContent);
Assert.True(template.Root.NodeList.Count > 0);

Expand All @@ -62,14 +62,14 @@ public void GivenValidEvaluateTemplateContent_WhenParseAndRender_CorrectResultSh
[MemberData(nameof(GetInvalidEvaluateTemplateContents))]
public void GivenInvalidEvaluateTemplateContent_WhenParse_ExceptionsShouldBeThrown(string templateContent)
{
var templateProvider = new Hl7v2TemplateProvider(@"..\..\..\..\..\data\Templates\Hl7v2");
var templateProvider = new Hl7v2TemplateProvider(Constants.Hl7v2TemplateDirectory);
Assert.Throws<SyntaxException>(() => Template.Parse(templateContent));
}

[Fact]
public void GivenInvalidSnippet_WhenRender_ExceptionsShouldBeThrown()
{
var templateProvider = new Hl7v2TemplateProvider(@"..\..\..\..\..\data\Templates\Hl7v2");
var templateProvider = new Hl7v2TemplateProvider(Constants.Hl7v2TemplateDirectory);

// No template file system
var template = Template.Parse(@"{% evaluate bundleId using 'ID/Bundle' Data: hl7v2Data -%}");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public class Hl7v2ProcessorTests
public void GivenAValidTemplateDirectory_WhenConvert_CorrectResultShouldBeReturned()
{
var processor = new Hl7v2Processor();
var templateProvider = new Hl7v2TemplateProvider(@"..\..\..\..\..\data\Templates\Hl7v2");
var templateProvider = new Hl7v2TemplateProvider(Constants.Hl7v2TemplateDirectory);
var result = processor.Convert(TestData, "ORU_R01", templateProvider);
Assert.True(result.Length > 0);
}
Expand Down Expand Up @@ -111,7 +111,7 @@ public void GivenProcessorSettings_WhenConvert_CorrectResultsShouldBeReturned()
{
// Null ProcessorSettings: no time out
var processor = new Hl7v2Processor(null);
var templateProvider = new Hl7v2TemplateProvider(@"..\..\..\..\..\data\Templates\Hl7v2");
var templateProvider = new Hl7v2TemplateProvider(Constants.Hl7v2TemplateDirectory);
var result = processor.Convert(TestData, "ORU_R01", templateProvider);
Assert.True(result.Length > 0);

Expand Down Expand Up @@ -146,7 +146,7 @@ public void GivenProcessorSettings_WhenConvert_CorrectResultsShouldBeReturned()
public void GivenCancellationToken_WhenConvert_CorrectResultsShouldBeReturned()
{
var processor = new Hl7v2Processor();
var templateProvider = new Hl7v2TemplateProvider(@"..\..\..\..\..\data\Templates\Hl7v2");
var templateProvider = new Hl7v2TemplateProvider(Constants.Hl7v2TemplateDirectory);
var cts = new CancellationTokenSource();
var result = processor.Convert(TestData, "ORU_R01", templateProvider, cts.Token);
Assert.True(result.Length > 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
// -------------------------------------------------------------------------------------------------

using System.IO;
using Microsoft.Health.Fhir.Liquid.Converter.Exceptions;
using Microsoft.Health.Fhir.Liquid.Converter.Hl7v2;
using Microsoft.Health.Fhir.Liquid.Converter.Models;
Expand All @@ -15,14 +16,14 @@ public class Hl7v2TemplateProviderTests
[Fact]
public void GivenATemplateDirectory_WhenLoadTemplates_CorrectResultsShouldBeReturned()
{
var templateProvider = new Hl7v2TemplateProvider(@"..\..\..\..\..\data\Templates\Hl7v2");
var templateProvider = new Hl7v2TemplateProvider(Constants.Hl7v2TemplateDirectory);
Assert.True(templateProvider.GetTemplate("ADT_A01").Root.NodeList.Count > 0);

Assert.Throws<ConverterInitializeException>(() => templateProvider.LoadTemplates(null));
Assert.Throws<ConverterInitializeException>(() => templateProvider.LoadTemplates(string.Empty));
Assert.Throws<ConverterInitializeException>(() => templateProvider.LoadTemplates(@"a\b\c"));
Assert.Throws<ConverterInitializeException>(() => templateProvider.LoadTemplates(Path.Join("a", "b", "c")));

var exception = Assert.Throws<ConverterInitializeException>(() => templateProvider.LoadTemplates(@"..\..\..\TestTemplates"));
var exception = Assert.Throws<ConverterInitializeException>(() => templateProvider.LoadTemplates(@"TestTemplates"));
Assert.Equal(FhirConverterErrorCode.TemplateLoadingError, exception.FhirConverterErrorCode);
var innerException = exception.InnerException as FhirConverterException;
Assert.Equal(FhirConverterErrorCode.TemplateSyntaxError, innerException.FhirConverterErrorCode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
<IsPackable>false</IsPackable>
</PropertyGroup>

<PropertyGroup>
<OutputPath>..\..\bin\Microsoft.Health.Fhir.Liquid.Converter.UnitTests\</OutputPath>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" />
<PackageReference Include="xunit" Version="2.4.1" />
Expand All @@ -23,4 +29,10 @@
<ProjectReference Include="..\Microsoft.Health.Fhir.Liquid.Converter\Microsoft.Health.Fhir.Liquid.Converter.csproj" />
</ItemGroup>

<ItemGroup>
<None Update="TestTemplates\InvalidDotLiquidTemplate.liquid">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>

0 comments on commit 6fbfcb9

Please sign in to comment.