Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Xunit;

namespace Microsoft.TemplateEngine.Utils.UnitTests
{
[TestClass]
public class CombinedListTests
{
[Theory(DisplayName = nameof(VerifyCombinedListCombinesCorrectly))]
[InlineData(new int[] { }, new int[] { })]
[InlineData(new int[] { 5 }, new int[] { })]
[InlineData(new int[] { }, new int[] { 3 })]
[InlineData(new int[] { 1, 2 }, new int[] { })]
[InlineData(new int[] { }, new int[] { 1, 2 })]
[InlineData(new int[] { 1 }, new int[] { 1 })]
[InlineData(new int[] { 1 }, new int[] { 1, 2, 3 })]
[InlineData(new int[] { 1, 2, 3 }, new int[] { 1 })]
[InlineData(new int[] { 1, 2 }, new int[] { 1, 2, 3 })]
[InlineData(new int[] { 1, 2, 3, 4, 5 }, new int[] { 1, 2, 3 })]

[TestMethod]
[DataRow(new int[] { }, new int[] { })]
[DataRow(new int[] { 5 }, new int[] { })]
[DataRow(new int[] { }, new int[] { 3 })]
[DataRow(new int[] { 1, 2 }, new int[] { })]
[DataRow(new int[] { }, new int[] { 1, 2 })]
[DataRow(new int[] { 1 }, new int[] { 1 })]
[DataRow(new int[] { 1 }, new int[] { 1, 2, 3 })]
[DataRow(new int[] { 1, 2, 3 }, new int[] { 1 })]
[DataRow(new int[] { 1, 2 }, new int[] { 1, 2, 3 })]
[DataRow(new int[] { 1, 2, 3, 4, 5 }, new int[] { 1, 2, 3 })]
public void VerifyCombinedListCombinesCorrectly(IReadOnlyList<int> listOne, IReadOnlyList<int> listTwo)
{
CombinedList<int> combined = new CombinedList<int>(listOne, listTwo);
Expand All @@ -27,15 +25,15 @@ public void VerifyCombinedListCombinesCorrectly(IReadOnlyList<int> listOne, IRea
manuallyAppended.AddRange(listOne);
manuallyAppended.AddRange(listTwo);

Assert.Equal(combined.Count, manuallyAppended.Count);
Assert.AreEqual(combined.Count, manuallyAppended.Count);

int enumerationCount = 0;
foreach (int value in combined)
{
enumerationCount++;
}

Assert.Equal(enumerationCount, combined.Count);
Assert.AreEqual(enumerationCount, combined.Count);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,23 +1,42 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Microsoft.NET.TestFramework;
using Microsoft.TemplateEngine.Abstractions;
using Microsoft.TemplateEngine.TestHelper;
using Xunit;

namespace Microsoft.TemplateEngine.Utils.UnitTests
{
public class DefaultTemplatePackageProviderTests : IClassFixture<EnvironmentSettingsHelper>
[TestClass]
public class DefaultTemplatePackageProviderTests
{
private readonly IEngineEnvironmentSettings _engineEnvironmentSettings;
// MSTest has no IClassFixture equivalent; a lazily-initialized static helper
// mirrors the per-class lifetime that xUnit's IClassFixture provides.
private static readonly Lazy<EnvironmentSettingsHelper> s_environmentSettingsHelper =
new(() => new EnvironmentSettingsHelper(NullMessageSink.Instance));

public DefaultTemplatePackageProviderTests(EnvironmentSettingsHelper environmentSettingsHelper)
private IEngineEnvironmentSettings _engineEnvironmentSettings = null!;

public TestContext TestContext { get; set; } = null!;

[TestInitialize]
public void TestInitialize()
{
_engineEnvironmentSettings = s_environmentSettingsHelper.Value.CreateEnvironment(
hostIdentifier: GetType().Name,
virtualize: true);
}

[ClassCleanup]
public static void ClassCleanup()
{
_engineEnvironmentSettings = environmentSettingsHelper.CreateEnvironment(hostIdentifier: this.GetType().Name, virtualize: true);
if (s_environmentSettingsHelper.IsValueCreated)
{
s_environmentSettingsHelper.Value.Dispose();
}
}

[Fact]
[TestMethod]
public async Task ReturnsFoldersAndNuPkgs()
{
string testAssetsDir = SdkTestContext.Current.TestAssetsDirectory;
Expand All @@ -29,14 +48,14 @@ public async Task ReturnsFoldersAndNuPkgs()
var nupkgs = new[] { Path.Combine(templateEngineTestAssets, "nupkg_templates", "*.nupkg") };

var provider = new DefaultTemplatePackageProvider(null!, _engineEnvironmentSettings, nupkgs, folders);
var sources = await provider.GetAllTemplatePackagesAsync(TestContext.Current.CancellationToken);
var sources = await provider.GetAllTemplatePackagesAsync(TestContext.CancellationToken);

Comment thread
Evangelink marked this conversation as resolved.
//Total should be 7
Assert.Equal(7, sources.Count);
Assert.AreEqual(7, sources.Count);

Assert.True(sources[0].LastChangeTime > new DateTime(2000, 1, 1));
Assert.False(string.IsNullOrWhiteSpace(sources[0].MountPointUri));
Assert.Equal(provider, sources[0].Provider);
Assert.IsTrue(sources[0].LastChangeTime > new DateTime(2000, 1, 1));
Assert.IsFalse(string.IsNullOrWhiteSpace(sources[0].MountPointUri));
Assert.AreEqual(provider, sources[0].Provider);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using FluentAssertions;
using Xunit;

namespace Microsoft.TemplateEngine.Utils.UnitTests
{
[TestClass]
public class DirectedGraphTests
{
public static IEnumerable<object?[]> DirectedGraphHasCycleData()
Expand Down Expand Up @@ -83,23 +83,20 @@ public class DirectedGraphTests
};
}

[Theory]
[MemberData(nameof(DirectedGraphHasCycleData))]
#pragma warning disable xUnit1026 // Theory methods should use all of their parameters
[TestMethod]
[DynamicData(nameof(DirectedGraphHasCycleData))]
public void HasCycleTests(Dictionary<int, HashSet<int>> dependencies, bool shouldHaveCycle, IReadOnlyList<int> expectedCycle, IReadOnlyList<int> unused)
#pragma warning restore xUnit1026 // Theory methods should use all of their parameters
{
_ = unused;
new DirectedGraph<int>(dependencies).HasCycle(out IReadOnlyList<int> cycle).Should().Be(shouldHaveCycle);
cycle.Should().BeEquivalentTo(expectedCycle, options => options.WithStrictOrdering());
//cycle.SequenceEqual(expectedCycle).Should().BeTrue();
}

[Theory]
[MemberData(nameof(DirectedGraphHasCycleData))]
#pragma warning disable xUnit1026 // Theory methods should use all of their parameters
[TestMethod]
[DynamicData(nameof(DirectedGraphHasCycleData))]
public void EnumerateTopologicalSortTests(Dictionary<int, HashSet<int>> dependencies, bool shouldHaveCycle, IReadOnlyList<int> unused, IReadOnlyList<int> expectedOrder)
#pragma warning restore xUnit1026 // Theory methods should use all of their parameters
{
_ = unused;
new DirectedGraph<int>(dependencies).TryGetTopologicalSort(out IReadOnlyList<int> order).Should().Be(!shouldHaveCycle);
if (!shouldHaveCycle)
{
Expand Down Expand Up @@ -211,8 +208,8 @@ public void EnumerateTopologicalSortTests(Dictionary<int, HashSet<int>> dependen
yield return new object?[] { graphB, new List<int>() { 20 }, false, new Dictionary<int, HashSet<int>>() { { 1, empty } } };
}

[Theory]
[MemberData(nameof(DirectedGraphSubgraphData))]
[TestMethod]
[DynamicData(nameof(DirectedGraphSubgraphData))]
public void GetSubGraphDependandOnVerticesTests(Dictionary<int, HashSet<int>> dependencies, IReadOnlyList<int> vertices, bool includeSeedVertices, Dictionary<int, HashSet<int>> expectedResult)
{
var result = new DirectedGraph<int>(dependencies).GetSubGraphDependentOnVertices(vertices, includeSeedVertices);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Xunit;

namespace Microsoft.TemplateEngine.Utils.UnitTests
{
[TestClass]
public class EqualityExtensionsTests
{
[Fact(DisplayName = "AllAreTheSameDefaultComparerTrueTest")]
[TestMethod]
public void AllAreTheSameDefaultComparerTrueTest()
{
IDictionary<int, string> items = new Dictionary<int, string>()
Expand All @@ -19,10 +18,10 @@ public void AllAreTheSameDefaultComparerTrueTest()
};
static string Selector(KeyValuePair<int, string> x) => x.Value;

Assert.True(items.AllAreTheSame(Selector));
Assert.IsTrue(items.AllAreTheSame(Selector));
}

[Fact(DisplayName = "AllAreTheSameDefaultComparerFailsTest")]
[TestMethod]
public void AllAreTheSameDefaultComparerFailsTest()
{
IDictionary<int, string> items = new Dictionary<int, string>()
Expand All @@ -34,10 +33,10 @@ public void AllAreTheSameDefaultComparerFailsTest()
};
static string Selector(KeyValuePair<int, string> x) => x.Value;

Assert.False(items.AllAreTheSame(Selector));
Assert.IsFalse(items.AllAreTheSame(Selector));
}

[Fact(DisplayName = "AllAreTheSameCustomComparerTest")]
[TestMethod]
public void AllAreTheSameCustomComparerTest()
{
IDictionary<int, string> items = new Dictionary<int, string>()
Expand All @@ -52,10 +51,10 @@ public void AllAreTheSameCustomComparerTest()
static bool LengthComparer(string? x, string? y) => x!.Length == y!.Length;

// they're all the same length
Assert.True(items.AllAreTheSame(Selector, LengthComparer));
Assert.IsTrue(items.AllAreTheSame(Selector, LengthComparer));

static bool UpperComparer(string? x, string? y) => x!.ToUpper() == y!.ToUpper();
Assert.False(items.AllAreTheSame(Selector, UpperComparer));
Assert.IsFalse(items.AllAreTheSame(Selector, UpperComparer));
}
}
}
Loading
Loading