-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Now exclude the global prefix from built in types (#7)
- Loading branch information
1 parent
ed2272f
commit 8a49eb7
Showing
10 changed files
with
181 additions
and
158 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
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
92 changes: 92 additions & 0 deletions
92
src/Pharmacist.Tests/IntegrationTests/IntegrationTestHelper.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,92 @@ | ||
// Copyright (c) 2019 .NET Foundation and Contributors. All rights reserved. | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for full license information. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Runtime.CompilerServices; | ||
using System.Text; | ||
using System.Text.RegularExpressions; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
using NuGet.Configuration; | ||
using NuGet.Frameworks; | ||
using NuGet.LibraryModel; | ||
using NuGet.Packaging.Core; | ||
using NuGet.Protocol.Core.Types; | ||
|
||
using Pharmacist.Core; | ||
using Pharmacist.Core.NuGet; | ||
|
||
using Shouldly; | ||
|
||
namespace Pharmacist.Tests.IntegrationTests | ||
{ | ||
internal static class IntegrationTestHelper | ||
{ | ||
private static readonly Regex _whitespaceRegex = new Regex(@"\s"); | ||
|
||
public static async Task CheckResultsAgainstTemplate(PackageIdentity[] package, IReadOnlyCollection<NuGetFramework> frameworks, [CallerFilePath]string filePath = null) | ||
{ | ||
using (var memoryStream = new MemoryStream()) | ||
{ | ||
await ObservablesForEventGenerator.ExtractEventsFromNuGetPackages(memoryStream, package, frameworks).ConfigureAwait(false); | ||
CheckContents(memoryStream, package[0], filePath); | ||
} | ||
} | ||
|
||
public static async Task CheckResultsAgainstTemplate(LibraryRange[] package, IReadOnlyCollection<NuGetFramework> frameworks, [CallerFilePath]string filePath = null) | ||
{ | ||
var bestPackageIdentity = await NuGetPackageHelper.GetBestMatch(package[0], new SourceRepository(new PackageSource(NuGetPackageHelper.DefaultNuGetSource), NuGetPackageHelper.Providers), CancellationToken.None).ConfigureAwait(false); | ||
|
||
using (var memoryStream = new MemoryStream()) | ||
{ | ||
await ObservablesForEventGenerator.ExtractEventsFromNuGetPackages(memoryStream, package, frameworks).ConfigureAwait(false); | ||
CheckContents(memoryStream, bestPackageIdentity, filePath); | ||
} | ||
} | ||
|
||
private static void CheckContents(MemoryStream memoryStream, PackageIdentity bestPackageIdentity, string filePath) | ||
{ | ||
var sourceDirectory = Path.GetDirectoryName(filePath); | ||
|
||
var approvedFileName = Path.Combine(sourceDirectory, $"{bestPackageIdentity.Id}.{bestPackageIdentity.Version}.approved.txt"); | ||
var receivedFileName = Path.Combine(sourceDirectory, $"{bestPackageIdentity.Id}.{bestPackageIdentity.Version}.received.txt"); | ||
|
||
if (!File.Exists(approvedFileName)) | ||
{ | ||
File.Create(approvedFileName); | ||
} | ||
|
||
if (!File.Exists(receivedFileName)) | ||
{ | ||
File.Create(receivedFileName); | ||
} | ||
|
||
memoryStream.Flush(); | ||
|
||
memoryStream.Position = 0; | ||
using (var sr = new StreamReader(memoryStream)) | ||
{ | ||
var actualContents = sr.ReadToEnd().Trim('\n').Trim('\r'); | ||
var expectedContents = File.ReadAllText(approvedFileName); | ||
|
||
string normalizedActual = _whitespaceRegex.Replace(actualContents, string.Empty); | ||
string normalizedExpected = _whitespaceRegex.Replace(expectedContents, string.Empty); | ||
|
||
if (!string.Equals(normalizedActual, normalizedExpected, StringComparison.InvariantCulture)) | ||
{ | ||
File.WriteAllText(receivedFileName, actualContents); | ||
ShouldlyConfiguration.DiffTools.GetDiffTool().Open(receivedFileName, approvedFileName, true); | ||
} | ||
|
||
normalizedActual.ShouldNotBeEmpty(); | ||
|
||
normalizedActual.ShouldBe(normalizedExpected, StringCompareShould.IgnoreLineEndings); | ||
} | ||
} | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
src/Pharmacist.Tests/IntegrationTests/LibraryRangeIntegrationTests.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,54 @@ | ||
using System.Threading.Tasks; | ||
|
||
using NuGet.Frameworks; | ||
using NuGet.LibraryModel; | ||
using NuGet.Versioning; | ||
|
||
using Pharmacist.Core.NuGet; | ||
|
||
using Xunit; | ||
|
||
namespace Pharmacist.Tests.IntegrationTests | ||
{ | ||
public class LibraryRangeIntegrationTests | ||
{ | ||
/// <summary> | ||
/// Tests to make sure the Tizen platform produces the expected results. | ||
/// </summary> | ||
/// <returns>A task to monitor the progress.</returns> | ||
[Fact] | ||
public Task TizenNuGetTest() | ||
{ | ||
var package = new[] { new LibraryRange("Tizen.NET.API4", VersionRange.Parse("4.0.1.*"), LibraryDependencyTarget.Package) }; | ||
var frameworks = new[] { FrameworkConstants.CommonFrameworks.NetStandard20 }; | ||
|
||
return IntegrationTestHelper.CheckResultsAgainstTemplate(package, frameworks); | ||
} | ||
|
||
/// <summary> | ||
/// Tests to make sure the Xamarin.Essentials platform produces the expected results. | ||
/// </summary> | ||
/// <returns>A task to monitor the progress.</returns> | ||
[Fact] | ||
public Task XamarinEssentialsNuGetTest() | ||
{ | ||
var package = new[] { new LibraryRange("Xamarin.Essentials", VersionRange.Parse("1.1.*"), LibraryDependencyTarget.Package) }; | ||
var frameworks = "MonoAndroid81".ToFrameworks(); | ||
|
||
return IntegrationTestHelper.CheckResultsAgainstTemplate(package, frameworks); | ||
} | ||
|
||
/// <summary> | ||
/// Tests to make sure the Xamarin.Forms platform produces the expected results. | ||
/// </summary> | ||
/// <returns>A task to monitor the progress.</returns> | ||
[Fact] | ||
public Task XamarinFormsNuGetTest() | ||
{ | ||
var package = new[] { new LibraryRange("Xamarin.Forms", VersionRange.Parse("4.0.0.*"), LibraryDependencyTarget.Package) }; | ||
var frameworks = "MonoAndroid81".ToFrameworks(); | ||
|
||
return IntegrationTestHelper.CheckResultsAgainstTemplate(package, frameworks); | ||
} | ||
} | ||
} |
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
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
2 changes: 1 addition & 1 deletion
2
...ectedResults/Xamarin.Essentials.1.1.0.txt → ...sts/Xamarin.Essentials.1.1.0.approved.txt
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.