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

Restructure the project of common testing libraries #60

Merged
merged 3 commits into from
Aug 21, 2020
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
23 changes: 15 additions & 8 deletions test/Microsoft.Health.Tests.Common/FileDataAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,37 @@

using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using Xunit.Sdk;

namespace Microsoft.Health.Tests.Common
{
public class FileDataAttribute : DataAttribute
{
private readonly string _filePath;
private readonly string[] _filePaths;

public FileDataAttribute(string filePath)
public FileDataAttribute(params string[] filePaths)
{
_filePath = filePath;
_filePaths = filePaths;
}

public override IEnumerable<object[]> GetData(MethodInfo testMethod)
{
var path = Path.IsPathRooted(_filePath) ? _filePath : Path.Combine(Directory.GetCurrentDirectory(), _filePath);

if (!File.Exists(path))
ICollection<string> fileContents = new List<string>();
foreach (string filePath in _filePaths)
{
throw new FileNotFoundException($"File {path} not found.");
var path = Path.IsPathRooted(filePath) ? filePath : Path.Combine(Directory.GetCurrentDirectory(), filePath);

if (!File.Exists(path))
{
throw new FileNotFoundException($"File {path} not found.");
}

fileContents.Add(File.ReadAllText(path));
}

yield return new[] { File.ReadAllText(path) };
yield return fileContents.ToArray();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<IsPackable>false</IsPackable>
<TargetFramework>netstandard2.0</TargetFramework>
<IsPackable>true</IsPackable>
<CodeAnalysisRuleSet>..\..\CustomAnalysisRules.Test.ruleset</CodeAnalysisRuleSet>
<HighEntropyVA>true</HighEntropyVA>
<GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
Expand All @@ -18,8 +18,8 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.4.0" />
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
<PackageReference Include="xunit" Version="2.4.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
<PackageReference Include="coverlet.collector" Version="1.0.1" />
<PackageReference Include="NSubstitute" Version="4.2.0" />
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.9.8">
Expand Down