diff --git a/Microsoft.Toolkit.Parsers/Markdown/Blocks/ListBlock.cs b/Microsoft.Toolkit.Parsers/Markdown/Blocks/ListBlock.cs index ba44b0e6664..f1e90403d3a 100644 --- a/Microsoft.Toolkit.Parsers/Markdown/Blocks/ListBlock.cs +++ b/Microsoft.Toolkit.Parsers/Markdown/Blocks/ListBlock.cs @@ -11,7 +11,7 @@ using Microsoft.Toolkit.Parsers.Core; using Microsoft.Toolkit.Parsers.Markdown.Helpers; -[assembly: InternalsVisibleTo("UnitTests, PublicKey=002400000480000094000000060200000024000052534131000400000100010041753af735ae6140c9508567666c51c6ab929806adb0d210694b30ab142a060237bc741f9682e7d8d4310364b4bba4ee89cc9d3d5ce7e5583587e8ea44dca09977996582875e71fb54fa7b170798d853d5d8010b07219633bdb761d01ac924da44576d6180cdceae537973982bb461c541541d58417a3794e34f45e6f2d129e2")] +[assembly: InternalsVisibleTo("UnitTests.UWP, PublicKey=002400000480000094000000060200000024000052534131000400000100010041753af735ae6140c9508567666c51c6ab929806adb0d210694b30ab142a060237bc741f9682e7d8d4310364b4bba4ee89cc9d3d5ce7e5583587e8ea44dca09977996582875e71fb54fa7b170798d853d5d8010b07219633bdb761d01ac924da44576d6180cdceae537973982bb461c541541d58417a3794e34f45e6f2d129e2")] namespace Microsoft.Toolkit.Parsers.Markdown.Blocks { diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.DataGrid/Properties/AssemblyInfo.cs b/Microsoft.Toolkit.Uwp.UI.Controls.DataGrid/Properties/AssemblyInfo.cs index 64a4e43ebc0..22ad66eb095 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls.DataGrid/Properties/AssemblyInfo.cs +++ b/Microsoft.Toolkit.Uwp.UI.Controls.DataGrid/Properties/AssemblyInfo.cs @@ -8,5 +8,5 @@ // General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information // associated with an assembly. -[assembly: InternalsVisibleTo("UnitTests")] +[assembly: InternalsVisibleTo("UnitTests.UWP")] [assembly: NeutralResourcesLanguage("en-US")] \ No newline at end of file diff --git a/Microsoft.Toolkit.Uwp.UI.Controls/Properties/AssemblyInfo.cs b/Microsoft.Toolkit.Uwp.UI.Controls/Properties/AssemblyInfo.cs index 64a4e43ebc0..22ad66eb095 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls/Properties/AssemblyInfo.cs +++ b/Microsoft.Toolkit.Uwp.UI.Controls/Properties/AssemblyInfo.cs @@ -8,5 +8,5 @@ // General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information // associated with an assembly. -[assembly: InternalsVisibleTo("UnitTests")] +[assembly: InternalsVisibleTo("UnitTests.UWP")] [assembly: NeutralResourcesLanguage("en-US")] \ No newline at end of file diff --git a/Microsoft.Toolkit/Diagnostics/Attributes/DoesNotReturnIfAttribute.cs b/Microsoft.Toolkit/Diagnostics/Attributes/DoesNotReturnIfAttribute.cs new file mode 100644 index 00000000000..bde310c41bd --- /dev/null +++ b/Microsoft.Toolkit/Diagnostics/Attributes/DoesNotReturnIfAttribute.cs @@ -0,0 +1,36 @@ +// 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 more information. + +#if !NETSTANDARD2_1 + +namespace System.Diagnostics.CodeAnalysis +{ + /// + /// Specifies that a given also indicates + /// whether the method will not return (eg. throw an exception). + /// + /// Internal copy of the .NET Standard 2.1 attribute. + [AttributeUsage(AttributeTargets.Parameter)] + internal sealed class DoesNotReturnIfAttribute : Attribute + { + /// + /// Initializes a new instance of the class. + /// + /// + /// The condition parameter value. Code after the method will be considered unreachable + /// by diagnostics if the argument to the associated parameter matches this value. + /// + public DoesNotReturnIfAttribute(bool parameterValue) + { + ParameterValue = parameterValue; + } + + /// + /// Gets a value indicating whether the parameter value should be . + /// + public bool ParameterValue { get; } + } +} + +#endif \ No newline at end of file diff --git a/Microsoft.Toolkit/Diagnostics/Attributes/NotNullAttribute.cs b/Microsoft.Toolkit/Diagnostics/Attributes/NotNullAttribute.cs new file mode 100644 index 00000000000..80a3342c478 --- /dev/null +++ b/Microsoft.Toolkit/Diagnostics/Attributes/NotNullAttribute.cs @@ -0,0 +1,26 @@ +// 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 more information. + +#if !NETSTANDARD2_1 + +namespace System.Diagnostics.CodeAnalysis +{ + /// + /// Specifies that an output will not be even if the corresponding type allows it. + /// Specifies that an input argument was not when the call returns. + /// + /// Internal copy of the .NET Standard 2.1 attribute. + [AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.ReturnValue)] + internal sealed class NotNullAttribute : Attribute + { + /// + /// Initializes a new instance of the class. + /// + public NotNullAttribute() + { + } + } +} + +#endif \ No newline at end of file diff --git a/Microsoft.Toolkit/Diagnostics/Generated/Guard.Collection.g.cs b/Microsoft.Toolkit/Diagnostics/Generated/Guard.Collection.g.cs index 346241db8cc..6ccd58b3c5f 100644 --- a/Microsoft.Toolkit/Diagnostics/Generated/Guard.Collection.g.cs +++ b/Microsoft.Toolkit/Diagnostics/Generated/Guard.Collection.g.cs @@ -1,10 +1,9 @@ // 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 more information. - -/* ======================== - * Auto generated file - * ===================== */ +// ===================== +// Auto generated file +// ===================== using System; using System.Collections.Generic; @@ -94,11 +93,11 @@ public static void HasSizeNotEqualTo(Span span, int size, string name) /// The name of the input parameter being tested. /// Thrown if the size of is <= . [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void HasSizeOver(Span span, int size, string name) + public static void HasSizeGreaterThan(Span span, int size, string name) { if (span.Length <= size) { - ThrowHelper.ThrowArgumentExceptionForHasSizeOver(span, size, name); + ThrowHelper.ThrowArgumentExceptionForHasSizeGreaterThan(span, size, name); } } @@ -111,11 +110,11 @@ public static void HasSizeOver(Span span, int size, string name) /// The name of the input parameter being tested. /// Thrown if the size of is < . [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void HasSizeAtLeast(Span span, int size, string name) + public static void HasSizeGreaterThanOrEqualTo(Span span, int size, string name) { if (span.Length < size) { - ThrowHelper.ThrowArgumentExceptionForHasSizeAtLeast(span, size, name); + ThrowHelper.ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(span, size, name); } } @@ -296,11 +295,11 @@ public static void HasSizeNotEqualTo(ReadOnlySpan span, int size, string n /// The name of the input parameter being tested. /// Thrown if the size of is <= . [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void HasSizeOver(ReadOnlySpan span, int size, string name) + public static void HasSizeGreaterThan(ReadOnlySpan span, int size, string name) { if (span.Length <= size) { - ThrowHelper.ThrowArgumentExceptionForHasSizeOver(span, size, name); + ThrowHelper.ThrowArgumentExceptionForHasSizeGreaterThan(span, size, name); } } @@ -313,11 +312,11 @@ public static void HasSizeOver(ReadOnlySpan span, int size, string name) /// The name of the input parameter being tested. /// Thrown if the size of is < . [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void HasSizeAtLeast(ReadOnlySpan span, int size, string name) + public static void HasSizeGreaterThanOrEqualTo(ReadOnlySpan span, int size, string name) { if (span.Length < size) { - ThrowHelper.ThrowArgumentExceptionForHasSizeAtLeast(span, size, name); + ThrowHelper.ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(span, size, name); } } @@ -498,11 +497,11 @@ public static void HasSizeNotEqualTo(Memory memory, int size, string name) /// The name of the input parameter being tested. /// Thrown if the size of is <= . [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void HasSizeOver(Memory memory, int size, string name) + public static void HasSizeGreaterThan(Memory memory, int size, string name) { if (memory.Length <= size) { - ThrowHelper.ThrowArgumentExceptionForHasSizeOver(memory, size, name); + ThrowHelper.ThrowArgumentExceptionForHasSizeGreaterThan(memory, size, name); } } @@ -515,11 +514,11 @@ public static void HasSizeOver(Memory memory, int size, string name) /// The name of the input parameter being tested. /// Thrown if the size of is < . [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void HasSizeAtLeast(Memory memory, int size, string name) + public static void HasSizeGreaterThanOrEqualTo(Memory memory, int size, string name) { if (memory.Length < size) { - ThrowHelper.ThrowArgumentExceptionForHasSizeAtLeast(memory, size, name); + ThrowHelper.ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(memory, size, name); } } @@ -700,11 +699,11 @@ public static void HasSizeNotEqualTo(ReadOnlyMemory memory, int size, stri /// The name of the input parameter being tested. /// Thrown if the size of is <= . [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void HasSizeOver(ReadOnlyMemory memory, int size, string name) + public static void HasSizeGreaterThan(ReadOnlyMemory memory, int size, string name) { if (memory.Length <= size) { - ThrowHelper.ThrowArgumentExceptionForHasSizeOver(memory, size, name); + ThrowHelper.ThrowArgumentExceptionForHasSizeGreaterThan(memory, size, name); } } @@ -717,11 +716,11 @@ public static void HasSizeOver(ReadOnlyMemory memory, int size, string nam /// The name of the input parameter being tested. /// Thrown if the size of is < . [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void HasSizeAtLeast(ReadOnlyMemory memory, int size, string name) + public static void HasSizeGreaterThanOrEqualTo(ReadOnlyMemory memory, int size, string name) { if (memory.Length < size) { - ThrowHelper.ThrowArgumentExceptionForHasSizeAtLeast(memory, size, name); + ThrowHelper.ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(memory, size, name); } } @@ -902,11 +901,11 @@ public static void HasSizeNotEqualTo(T[] array, int size, string name) /// The name of the input parameter being tested. /// Thrown if the size of is <= . [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void HasSizeOver(T[] array, int size, string name) + public static void HasSizeGreaterThan(T[] array, int size, string name) { if (array.Length <= size) { - ThrowHelper.ThrowArgumentExceptionForHasSizeOver(array, size, name); + ThrowHelper.ThrowArgumentExceptionForHasSizeGreaterThan(array, size, name); } } @@ -919,11 +918,11 @@ public static void HasSizeOver(T[] array, int size, string name) /// The name of the input parameter being tested. /// Thrown if the size of is < . [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void HasSizeAtLeast(T[] array, int size, string name) + public static void HasSizeGreaterThanOrEqualTo(T[] array, int size, string name) { if (array.Length < size) { - ThrowHelper.ThrowArgumentExceptionForHasSizeAtLeast(array, size, name); + ThrowHelper.ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(array, size, name); } } @@ -1104,11 +1103,11 @@ public static void HasSizeNotEqualTo(List list, int size, string name) /// The name of the input parameter being tested. /// Thrown if the size of is <= . [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void HasSizeOver(List list, int size, string name) + public static void HasSizeGreaterThan(List list, int size, string name) { if (list.Count <= size) { - ThrowHelper.ThrowArgumentExceptionForHasSizeOver((ICollection)list, size, name); + ThrowHelper.ThrowArgumentExceptionForHasSizeGreaterThan((ICollection)list, size, name); } } @@ -1121,11 +1120,11 @@ public static void HasSizeOver(List list, int size, string name) /// The name of the input parameter being tested. /// Thrown if the size of is < . [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void HasSizeAtLeast(List list, int size, string name) + public static void HasSizeGreaterThanOrEqualTo(List list, int size, string name) { if (list.Count < size) { - ThrowHelper.ThrowArgumentExceptionForHasSizeAtLeast((ICollection)list, size, name); + ThrowHelper.ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo((ICollection)list, size, name); } } @@ -1306,11 +1305,11 @@ public static void HasSizeNotEqualTo(ICollection collection, int size, str /// The name of the input parameter being tested. /// Thrown if the size of is <= . [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void HasSizeOver(ICollection collection, int size, string name) + public static void HasSizeGreaterThan(ICollection collection, int size, string name) { if (collection.Count <= size) { - ThrowHelper.ThrowArgumentExceptionForHasSizeOver(collection, size, name); + ThrowHelper.ThrowArgumentExceptionForHasSizeGreaterThan(collection, size, name); } } @@ -1323,11 +1322,11 @@ public static void HasSizeOver(ICollection collection, int size, string na /// The name of the input parameter being tested. /// Thrown if the size of is < . [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void HasSizeAtLeast(ICollection collection, int size, string name) + public static void HasSizeGreaterThanOrEqualTo(ICollection collection, int size, string name) { if (collection.Count < size) { - ThrowHelper.ThrowArgumentExceptionForHasSizeAtLeast(collection, size, name); + ThrowHelper.ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(collection, size, name); } } @@ -1508,11 +1507,11 @@ public static void HasSizeNotEqualTo(IReadOnlyCollection collection, int s /// The name of the input parameter being tested. /// Thrown if the size of is <= . [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void HasSizeOver(IReadOnlyCollection collection, int size, string name) + public static void HasSizeGreaterThan(IReadOnlyCollection collection, int size, string name) { if (collection.Count <= size) { - ThrowHelper.ThrowArgumentExceptionForHasSizeOver(collection, size, name); + ThrowHelper.ThrowArgumentExceptionForHasSizeGreaterThan(collection, size, name); } } @@ -1525,11 +1524,11 @@ public static void HasSizeOver(IReadOnlyCollection collection, int size, s /// The name of the input parameter being tested. /// Thrown if the size of is < . [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void HasSizeAtLeast(IReadOnlyCollection collection, int size, string name) + public static void HasSizeGreaterThanOrEqualTo(IReadOnlyCollection collection, int size, string name) { if (collection.Count < size) { - ThrowHelper.ThrowArgumentExceptionForHasSizeAtLeast(collection, size, name); + ThrowHelper.ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(collection, size, name); } } diff --git a/Microsoft.Toolkit/Diagnostics/Generated/Guard.Collection.tt b/Microsoft.Toolkit/Diagnostics/Generated/Guard.Collection.tt index 37430fced50..20e46530a30 100644 --- a/Microsoft.Toolkit/Diagnostics/Generated/Guard.Collection.tt +++ b/Microsoft.Toolkit/Diagnostics/Generated/Guard.Collection.tt @@ -2,10 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. <#@include file="TypeInfo.ttinclude" #> -/* ======================== - * Auto generated file - * ===================== */ - using System; using System.Collections.Generic; using System.Runtime.CompilerServices; @@ -117,11 +113,11 @@ GenerateTextForItems(EnumerableTypes, item => /// The name of the input parameter being tested. /// Thrown if the size of is <= . [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void HasSizeOver(<#=item.Type#> <#=item.Name#>, int size, string name) + public static void HasSizeGreaterThan(<#=item.Type#> <#=item.Name#>, int size, string name) { if (<#=item.Name#>.<#=item.Size#> <= size) { - ThrowHelper.ThrowArgumentExceptionForHasSizeOver(<#=item.Cast#><#=item.Name#>, size, name); + ThrowHelper.ThrowArgumentExceptionForHasSizeGreaterThan(<#=item.Cast#><#=item.Name#>, size, name); } } @@ -134,11 +130,11 @@ GenerateTextForItems(EnumerableTypes, item => /// The name of the input parameter being tested. /// Thrown if the size of is < . [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void HasSizeAtLeast(<#=item.Type#> <#=item.Name#>, int size, string name) + public static void HasSizeGreaterThanOrEqualTo(<#=item.Type#> <#=item.Name#>, int size, string name) { if (<#=item.Name#>.<#=item.Size#> < size) { - ThrowHelper.ThrowArgumentExceptionForHasSizeAtLeast(<#=item.Cast#><#=item.Name#>, size, name); + ThrowHelper.ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(<#=item.Cast#><#=item.Name#>, size, name); } } @@ -248,11 +244,11 @@ GenerateTextForItems(EnumerableTypes, item => public static void IsInRangeFor(int index, <#=item.Type#> <#=item.Name#>, string name) { <# - /* Here we're leveraging the fact that signed integers are represented - * in 2-complement to perform the bounds check with a single compare operation. - * This is the same trick used throughout CoreCLR as well. - * For more info and code sample, see the original conversation here: - * https://github.com/windows-toolkit/WindowsCommunityToolkit/pull/3131#discussion_r390682835 */ + // Here we're leveraging the fact that signed integers are represented + // in 2-complement to perform the bounds check with a single compare operation. + // This is the same trick used throughout CoreCLR as well. + // For more info and code sample, see the original conversation here: + // https://github.com/windows-toolkit/WindowsCommunityToolkit/pull/3131#discussion_r390682835 #> if ((uint)index >= (uint)<#=item.Name#>.<#=item.Size#>) { diff --git a/Microsoft.Toolkit/Diagnostics/Generated/Guard.Comparable.Numeric.g.cs b/Microsoft.Toolkit/Diagnostics/Generated/Guard.Comparable.Numeric.g.cs index ec0d08fd788..5da28215540 100644 --- a/Microsoft.Toolkit/Diagnostics/Generated/Guard.Comparable.Numeric.g.cs +++ b/Microsoft.Toolkit/Diagnostics/Generated/Guard.Comparable.Numeric.g.cs @@ -1,10 +1,9 @@ // 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 more information. - -/* ======================== - * Auto generated file - * ===================== */ +// ===================== +// Auto generated file +// ===================== using System; using System.Runtime.CompilerServices; diff --git a/Microsoft.Toolkit/Diagnostics/Generated/Guard.Comparable.Numeric.tt b/Microsoft.Toolkit/Diagnostics/Generated/Guard.Comparable.Numeric.tt index 3cb7ee32093..aeb86f9c700 100644 --- a/Microsoft.Toolkit/Diagnostics/Generated/Guard.Comparable.Numeric.tt +++ b/Microsoft.Toolkit/Diagnostics/Generated/Guard.Comparable.Numeric.tt @@ -2,10 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. <#@include file="TypeInfo.ttinclude" #> -/* ======================== - * Auto generated file - * ===================== */ - using System; using System.Runtime.CompilerServices; diff --git a/Microsoft.Toolkit/Diagnostics/Generated/ThrowHelper.Collection.g.cs b/Microsoft.Toolkit/Diagnostics/Generated/ThrowHelper.Collection.g.cs index e40c0d94fe5..f6ee371e87f 100644 --- a/Microsoft.Toolkit/Diagnostics/Generated/ThrowHelper.Collection.g.cs +++ b/Microsoft.Toolkit/Diagnostics/Generated/ThrowHelper.Collection.g.cs @@ -1,14 +1,12 @@ // 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 more information. - -/* ======================== - * Auto generated file - * ===================== */ +// ===================== +// Auto generated file +// ===================== using System; using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using Microsoft.Toolkit.Extensions; @@ -19,7 +17,6 @@ namespace Microsoft.Toolkit.Diagnostics /// /// Helper methods to throw exceptions /// - [SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1618", Justification = "Internal helper methods")] internal static partial class ThrowHelper { /// @@ -50,19 +47,19 @@ public static void ThrowArgumentExceptionForHasSizeNotEqualTo(Span span, i } /// - /// Throws an when (or an overload) fails. + /// Throws an when (or an overload) fails. /// [MethodImpl(MethodImplOptions.NoInlining)] - public static void ThrowArgumentExceptionForHasSizeOver(Span span, int size, string name) + public static void ThrowArgumentExceptionForHasSizeGreaterThan(Span span, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(Span).ToTypeString()}) must have a size over {size}, had a size of {span.Length.ToAssertString()}"); } /// - /// Throws an when (or an overload) fails. + /// Throws an when (or an overload) fails. /// [MethodImpl(MethodImplOptions.NoInlining)] - public static void ThrowArgumentExceptionForHasSizeAtLeast(Span span, int size, string name) + public static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(Span span, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(Span).ToTypeString()}) must have a size of at least {size}, had a size of {span.Length.ToAssertString()}"); } @@ -149,19 +146,19 @@ public static void ThrowArgumentExceptionForHasSizeNotEqualTo(ReadOnlySpan } /// - /// Throws an when (or an overload) fails. + /// Throws an when (or an overload) fails. /// [MethodImpl(MethodImplOptions.NoInlining)] - public static void ThrowArgumentExceptionForHasSizeOver(ReadOnlySpan span, int size, string name) + public static void ThrowArgumentExceptionForHasSizeGreaterThan(ReadOnlySpan span, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ReadOnlySpan).ToTypeString()}) must have a size over {size}, had a size of {span.Length.ToAssertString()}"); } /// - /// Throws an when (or an overload) fails. + /// Throws an when (or an overload) fails. /// [MethodImpl(MethodImplOptions.NoInlining)] - public static void ThrowArgumentExceptionForHasSizeAtLeast(ReadOnlySpan span, int size, string name) + public static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(ReadOnlySpan span, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ReadOnlySpan).ToTypeString()}) must have a size of at least {size}, had a size of {span.Length.ToAssertString()}"); } @@ -248,19 +245,19 @@ public static void ThrowArgumentExceptionForHasSizeNotEqualTo(Memory memor } /// - /// Throws an when (or an overload) fails. + /// Throws an when (or an overload) fails. /// [MethodImpl(MethodImplOptions.NoInlining)] - public static void ThrowArgumentExceptionForHasSizeOver(Memory memory, int size, string name) + public static void ThrowArgumentExceptionForHasSizeGreaterThan(Memory memory, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(Memory).ToTypeString()}) must have a size over {size}, had a size of {memory.Length.ToAssertString()}"); } /// - /// Throws an when (or an overload) fails. + /// Throws an when (or an overload) fails. /// [MethodImpl(MethodImplOptions.NoInlining)] - public static void ThrowArgumentExceptionForHasSizeAtLeast(Memory memory, int size, string name) + public static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(Memory memory, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(Memory).ToTypeString()}) must have a size of at least {size}, had a size of {memory.Length.ToAssertString()}"); } @@ -347,19 +344,19 @@ public static void ThrowArgumentExceptionForHasSizeNotEqualTo(ReadOnlyMemory< } /// - /// Throws an when (or an overload) fails. + /// Throws an when (or an overload) fails. /// [MethodImpl(MethodImplOptions.NoInlining)] - public static void ThrowArgumentExceptionForHasSizeOver(ReadOnlyMemory memory, int size, string name) + public static void ThrowArgumentExceptionForHasSizeGreaterThan(ReadOnlyMemory memory, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ReadOnlyMemory).ToTypeString()}) must have a size over {size}, had a size of {memory.Length.ToAssertString()}"); } /// - /// Throws an when (or an overload) fails. + /// Throws an when (or an overload) fails. /// [MethodImpl(MethodImplOptions.NoInlining)] - public static void ThrowArgumentExceptionForHasSizeAtLeast(ReadOnlyMemory memory, int size, string name) + public static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(ReadOnlyMemory memory, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ReadOnlyMemory).ToTypeString()}) must have a size of at least {size}, had a size of {memory.Length.ToAssertString()}"); } @@ -446,19 +443,19 @@ public static void ThrowArgumentExceptionForHasSizeNotEqualTo(T[] array, int } /// - /// Throws an when (or an overload) fails. + /// Throws an when (or an overload) fails. /// [MethodImpl(MethodImplOptions.NoInlining)] - public static void ThrowArgumentExceptionForHasSizeOver(T[] array, int size, string name) + public static void ThrowArgumentExceptionForHasSizeGreaterThan(T[] array, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(T[]).ToTypeString()}) must have a size over {size}, had a size of {array.Length.ToAssertString()}"); } /// - /// Throws an when (or an overload) fails. + /// Throws an when (or an overload) fails. /// [MethodImpl(MethodImplOptions.NoInlining)] - public static void ThrowArgumentExceptionForHasSizeAtLeast(T[] array, int size, string name) + public static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(T[] array, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(T[]).ToTypeString()}) must have a size of at least {size}, had a size of {array.Length.ToAssertString()}"); } @@ -545,19 +542,19 @@ public static void ThrowArgumentExceptionForHasSizeNotEqualTo(List list, i } /// - /// Throws an when (or an overload) fails. + /// Throws an when (or an overload) fails. /// [MethodImpl(MethodImplOptions.NoInlining)] - public static void ThrowArgumentExceptionForHasSizeOver(List list, int size, string name) + public static void ThrowArgumentExceptionForHasSizeGreaterThan(List list, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(List).ToTypeString()}) must have a size over {size}, had a size of {list.Count.ToAssertString()}"); } /// - /// Throws an when (or an overload) fails. + /// Throws an when (or an overload) fails. /// [MethodImpl(MethodImplOptions.NoInlining)] - public static void ThrowArgumentExceptionForHasSizeAtLeast(List list, int size, string name) + public static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(List list, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(List).ToTypeString()}) must have a size of at least {size}, had a size of {list.Count.ToAssertString()}"); } @@ -644,19 +641,19 @@ public static void ThrowArgumentExceptionForHasSizeNotEqualTo(ICollection } /// - /// Throws an when (or an overload) fails. + /// Throws an when (or an overload) fails. /// [MethodImpl(MethodImplOptions.NoInlining)] - public static void ThrowArgumentExceptionForHasSizeOver(ICollection collection, int size, string name) + public static void ThrowArgumentExceptionForHasSizeGreaterThan(ICollection collection, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ICollection).ToTypeString()}) must have a size over {size}, had a size of {collection.Count.ToAssertString()}"); } /// - /// Throws an when (or an overload) fails. + /// Throws an when (or an overload) fails. /// [MethodImpl(MethodImplOptions.NoInlining)] - public static void ThrowArgumentExceptionForHasSizeAtLeast(ICollection collection, int size, string name) + public static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(ICollection collection, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ICollection).ToTypeString()}) must have a size of at least {size}, had a size of {collection.Count.ToAssertString()}"); } @@ -743,19 +740,19 @@ public static void ThrowArgumentExceptionForHasSizeNotEqualTo(IReadOnlyCollec } /// - /// Throws an when (or an overload) fails. + /// Throws an when (or an overload) fails. /// [MethodImpl(MethodImplOptions.NoInlining)] - public static void ThrowArgumentExceptionForHasSizeOver(IReadOnlyCollection collection, int size, string name) + public static void ThrowArgumentExceptionForHasSizeGreaterThan(IReadOnlyCollection collection, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(IReadOnlyCollection).ToTypeString()}) must have a size over {size}, had a size of {collection.Count.ToAssertString()}"); } /// - /// Throws an when (or an overload) fails. + /// Throws an when (or an overload) fails. /// [MethodImpl(MethodImplOptions.NoInlining)] - public static void ThrowArgumentExceptionForHasSizeAtLeast(IReadOnlyCollection collection, int size, string name) + public static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(IReadOnlyCollection collection, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(IReadOnlyCollection).ToTypeString()}) must have a size of at least {size}, had a size of {collection.Count.ToAssertString()}"); } diff --git a/Microsoft.Toolkit/Diagnostics/Generated/ThrowHelper.Collection.tt b/Microsoft.Toolkit/Diagnostics/Generated/ThrowHelper.Collection.tt index 4aaac7f607a..c27e68efbca 100644 --- a/Microsoft.Toolkit/Diagnostics/Generated/ThrowHelper.Collection.tt +++ b/Microsoft.Toolkit/Diagnostics/Generated/ThrowHelper.Collection.tt @@ -2,13 +2,8 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. <#@include file="TypeInfo.ttinclude" #> -/* ======================== - * Auto generated file - * ===================== */ - using System; using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using Microsoft.Toolkit.Extensions; @@ -19,7 +14,6 @@ namespace Microsoft.Toolkit.Diagnostics /// /// Helper methods to throw exceptions /// - [SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1618", Justification = "Internal helper methods")] internal static partial class ThrowHelper { <# @@ -54,19 +48,19 @@ GenerateTextForItems(EnumerableTypes, item => } /// - /// Throws an when (or an overload) fails. + /// Throws an when (or an overload) fails. /// [MethodImpl(MethodImplOptions.NoInlining)] - public static void ThrowArgumentExceptionForHasSizeOver(<#=item.Type#> <#=item.Name#>, int size, string name) + public static void ThrowArgumentExceptionForHasSizeGreaterThan(<#=item.Type#> <#=item.Name#>, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(<#=item.Type#>).ToTypeString()}) must have a size over {size}, had a size of {<#=item.Name#>.<#=item.Size#>.ToAssertString()}"); } /// - /// Throws an when (or an overload) fails. + /// Throws an when (or an overload) fails. /// [MethodImpl(MethodImplOptions.NoInlining)] - public static void ThrowArgumentExceptionForHasSizeAtLeast(<#=item.Type#> <#=item.Name#>, int size, string name) + public static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(<#=item.Type#> <#=item.Name#>, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(<#=item.Type#>).ToTypeString()}) must have a size of at least {size}, had a size of {<#=item.Name#>.<#=item.Size#>.ToAssertString()}"); } diff --git a/Microsoft.Toolkit/Diagnostics/Generated/TypeInfo.ttinclude b/Microsoft.Toolkit/Diagnostics/Generated/TypeInfo.ttinclude index 04e29500538..1bcffa5513f 100644 --- a/Microsoft.Toolkit/Diagnostics/Generated/TypeInfo.ttinclude +++ b/Microsoft.Toolkit/Diagnostics/Generated/TypeInfo.ttinclude @@ -2,6 +2,9 @@ <#@ assembly name="System.Core" #> <#@ import namespace="System.Collections.Generic" #> <#@ output extension=".g.cs"#> +// ===================== +// Auto generated file +// ===================== <#+ /// /// A model representing the info on an enumerable type diff --git a/Microsoft.Toolkit/Diagnostics/Guard.Comparable.Generic.cs b/Microsoft.Toolkit/Diagnostics/Guard.Comparable.Generic.cs index 1c974232ecd..f07d3297a2b 100644 --- a/Microsoft.Toolkit/Diagnostics/Guard.Comparable.Generic.cs +++ b/Microsoft.Toolkit/Diagnostics/Guard.Comparable.Generic.cs @@ -98,11 +98,11 @@ public static void IsNotEqualTo(T value, T target, string name) public static void IsBitwiseEqualTo(T value, T target, string name) where T : unmanaged { - /* Include some fast paths if the input type is of size 1, 2, 4 or 8. - * In those cases, just reinterpret the bytes as values of an integer type, - * and compare them directly, which is much faster than having a loop over each byte. - * The conditional branches below are known at compile time by the JIT compiler, - * so that only the right one will actually be translated into native code. */ + // Include some fast paths if the input type is of size 1, 2, 4 or 8. + // In those cases, just reinterpret the bytes as values of an integer type, + // and compare them directly, which is much faster than having a loop over each byte. + // The conditional branches below are known at compile time by the JIT compiler, + // so that only the right one will actually be translated into native code. if (typeof(T) == typeof(byte) || typeof(T) == typeof(sbyte) || typeof(T) == typeof(bool)) diff --git a/Microsoft.Toolkit/Diagnostics/Guard.Comparable.Numeric.cs b/Microsoft.Toolkit/Diagnostics/Guard.Comparable.Numeric.cs index 712b5fa6784..0e23e7fbaf6 100644 --- a/Microsoft.Toolkit/Diagnostics/Guard.Comparable.Numeric.cs +++ b/Microsoft.Toolkit/Diagnostics/Guard.Comparable.Numeric.cs @@ -25,17 +25,17 @@ public static partial class Guard [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void IsCloseTo(int value, int target, uint delta, string name) { - /* Cast to long before calculating the difference to avoid overflows - * when the values are at the two extremes of the supported range. - * Then cast to double to calculate the absolute value: this allows - * the JIT compiler to use AVX instructions on X64 CPUs instead of - * conditional jumps, which results in more efficient assembly code. - * The IEEE 754 specs guarantees that a 32 bit integer value can - * be stored within a double precision floating point value with - * no loss of precision, so the result will always be correct here. - * The difference is then cast to uint as that's the maximum possible - * value it can have, and comparing two 32 bit integer values - * results in shorter and slightly faster code than using doubles. */ + // Cast to long before calculating the difference to avoid overflows + // when the values are at the two extremes of the supported range. + // Then cast to double to calculate the absolute value: this allows + // the JIT compiler to use AVX instructions on X64 CPUs instead of + // conditional jumps, which results in more efficient assembly code. + // The IEEE 754 specs guarantees that a 32 bit integer value can + // be stored within a double precision floating point value with + // no loss of precision, so the result will always be correct here. + // The difference is then cast to uint as that's the maximum possible + // value it can have, and comparing two 32 bit integer values + // results in shorter and slightly faster code than using doubles. if ((uint)Math.Abs((double)((long)value - target)) > delta) { ThrowHelper.ThrowArgumentExceptionForIsCloseTo(value, target, delta, name); @@ -70,8 +70,8 @@ public static void IsNotCloseTo(int value, int target, uint delta, string name) [MethodImpl(MethodImplOptions.NoInlining)] public static void IsCloseTo(long value, long target, ulong delta, string name) { - /* This method and the one below are not inlined because - * using the decimal type results in quite a bit of code. */ + // This method and the one below are not inlined because + // using the decimal type results in quite a bit of code. if ((ulong)Math.Abs((decimal)value - target) > delta) { ThrowHelper.ThrowArgumentExceptionForIsCloseTo(value, target, delta, name); diff --git a/Microsoft.Toolkit/Diagnostics/Guard.String.cs b/Microsoft.Toolkit/Diagnostics/Guard.String.cs index 05286bee164..bf4f56beb3b 100644 --- a/Microsoft.Toolkit/Diagnostics/Guard.String.cs +++ b/Microsoft.Toolkit/Diagnostics/Guard.String.cs @@ -3,6 +3,7 @@ // See the LICENSE file in the project root for more information. using System; +using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; #nullable enable @@ -36,7 +37,7 @@ public static void IsNullOrEmpty(string? text, string name) /// The name of the input parameter being tested. /// Thrown if is or empty. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void IsNotNullOrEmpty(string? text, string name) + public static void IsNotNullOrEmpty([NotNull] string? text, string name) { if (string.IsNullOrEmpty(text)) { @@ -66,7 +67,7 @@ public static void IsNullOrWhitespace(string? text, string name) /// The name of the input parameter being tested. /// Thrown if is or whitespace. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void IsNotNullOrWhitespace(string? text, string name) + public static void IsNotNullOrWhitespace([NotNull] string? text, string name) { if (string.IsNullOrWhiteSpace(text)) { @@ -174,11 +175,11 @@ public static void HasSizeNotEqualTo(string text, int size, string name) /// The name of the input parameter being tested. /// Thrown if the size of is <= . [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void HasSizeOver(string text, int size, string name) + public static void HasSizeGreaterThan(string text, int size, string name) { if (text.Length <= size) { - ThrowHelper.ThrowArgumentExceptionForHasSizeOver(text, size, name); + ThrowHelper.ThrowArgumentExceptionForHasSizeGreaterThan(text, size, name); } } @@ -190,11 +191,11 @@ public static void HasSizeOver(string text, int size, string name) /// The name of the input parameter being tested. /// Thrown if the size of is < . [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void HasSizeAtLeast(string text, int size, string name) + public static void HasSizeGreaterThanOrEqualTo(string text, int size, string name) { if (text.Length < size) { - ThrowHelper.ThrowArgumentExceptionForHasSizeAtLeast(text, size, name); + ThrowHelper.ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(text, size, name); } } @@ -229,5 +230,71 @@ public static void HasSizeLessThanOrEqualTo(string text, int size, string name) ThrowHelper.ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(text, size, name); } } + + /// + /// Asserts that the source instance must have the same size of a destination instance. + /// + /// The source instance to check the size for. + /// The destination instance to check the size for. + /// The name of the input parameter being tested. + /// Thrown if the size of is != the one of . + /// The type is immutable, but the name of this API is kept for consistency with the other overloads. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static void HasSizeEqualTo(string source, string destination, string name) + { + if (source.Length != destination.Length) + { + ThrowHelper.ThrowArgumentExceptionForHasSizeEqualTo(source, destination, name); + } + } + + /// + /// Asserts that the source instance must have a size of less than or equal to that of a destination instance. + /// + /// The source instance to check the size for. + /// The destination instance to check the size for. + /// The name of the input parameter being tested. + /// Thrown if the size of is > the one of . + /// The type is immutable, but the name of this API is kept for consistency with the other overloads. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static void HasSizeLessThanOrEqualTo(string source, string destination, string name) + { + if (source.Length > destination.Length) + { + ThrowHelper.ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(source, destination, name); + } + } + + /// + /// Asserts that the input index is valid for a given instance. + /// + /// The input index to be used to access . + /// The input instance to use to validate . + /// The name of the input parameter being tested. + /// Thrown if is not valid to access . + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static void IsInRangeFor(int index, string text, string name) + { + if ((uint)index >= (uint)text.Length) + { + ThrowHelper.ThrowArgumentOutOfRangeExceptionForIsInRangeFor(index, text, name); + } + } + + /// + /// Asserts that the input index is not valid for a given instance. + /// + /// The input index to be used to access . + /// The input instance to use to validate . + /// The name of the input parameter being tested. + /// Thrown if is valid to access . + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static void IsNotInRangeFor(int index, string text, string name) + { + if ((uint)index < (uint)text.Length) + { + ThrowHelper.ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(index, text, name); + } + } } } diff --git a/Microsoft.Toolkit/Diagnostics/Guard.cs b/Microsoft.Toolkit/Diagnostics/Guard.cs index a8703a4c04a..fb57977ba2d 100644 --- a/Microsoft.Toolkit/Diagnostics/Guard.cs +++ b/Microsoft.Toolkit/Diagnostics/Guard.cs @@ -25,7 +25,6 @@ public static partial class Guard /// The name of the input parameter being tested. /// Thrown if is not . [MethodImpl(MethodImplOptions.AggressiveInlining)] - [SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1119", Justification = "Negated pattern match expression")] public static void IsNull(T? value, string name) where T : class { @@ -44,7 +43,6 @@ public static void IsNull(T? value, string name) /// Thrown if is not . /// The method is generic to avoid boxing the parameters, if they are value types. [MethodImpl(MethodImplOptions.AggressiveInlining)] - [SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1119", Justification = "Negated pattern match expression")] public static void IsNull(T? value, string name) where T : struct { @@ -62,7 +60,7 @@ public static void IsNull(T? value, string name) /// The name of the input parameter being tested. /// Thrown if is . [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void IsNotNull(T? value, string name) + public static void IsNotNull([NotNull] T? value, string name) where T : class { if (value is null) @@ -80,7 +78,7 @@ public static void IsNotNull(T? value, string name) /// Thrown if is . /// The method is generic to avoid boxing the parameters, if they are value types. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void IsNotNull(T? value, string name) + public static void IsNotNull([NotNull] T? value, string name) where T : struct { if (value is null) @@ -262,7 +260,7 @@ public static void IsReferenceNotEqualTo(T value, T target, string name) /// The name of the input parameter being tested. /// Thrown if is . [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void IsTrue(bool value, string name) + public static void IsTrue([DoesNotReturnIf(false)] bool value, string name) { if (!value) { @@ -270,6 +268,22 @@ public static void IsTrue(bool value, string name) } } + /// + /// Asserts that the input value must be . + /// + /// The input to test. + /// The name of the input parameter being tested. + /// A message to display if is . + /// Thrown if is . + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static void IsTrue([DoesNotReturnIf(false)] bool value, string name, string message) + { + if (!value) + { + ThrowHelper.ThrowArgumentExceptionForIsTrue(name, message); + } + } + /// /// Asserts that the input value must be . /// @@ -277,12 +291,28 @@ public static void IsTrue(bool value, string name) /// The name of the input parameter being tested. /// Thrown if is . [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void IsFalse(bool value, string name) + public static void IsFalse([DoesNotReturnIf(true)] bool value, string name) { if (value) { ThrowHelper.ThrowArgumentExceptionForIsFalse(name); } } + + /// + /// Asserts that the input value must be . + /// + /// The input to test. + /// The name of the input parameter being tested. + /// A message to display if is . + /// Thrown if is . + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static void IsFalse([DoesNotReturnIf(true)] bool value, string name, string message) + { + if (value) + { + ThrowHelper.ThrowArgumentExceptionForIsFalse(name, message); + } + } } } diff --git a/Microsoft.Toolkit/Diagnostics/ThrowHelper.Collection.Generic.cs b/Microsoft.Toolkit/Diagnostics/ThrowHelper.Collection.Generic.cs index 7f1a57d1b80..64a4ce44b48 100644 --- a/Microsoft.Toolkit/Diagnostics/ThrowHelper.Collection.Generic.cs +++ b/Microsoft.Toolkit/Diagnostics/ThrowHelper.Collection.Generic.cs @@ -3,7 +3,6 @@ // See the LICENSE file in the project root for more information. using System; -using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using Microsoft.Toolkit.Extensions; @@ -14,12 +13,12 @@ namespace Microsoft.Toolkit.Diagnostics /// /// Helper methods to throw exceptions /// - [SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1618", Justification = "Internal helper methods")] internal static partial class ThrowHelper { /// /// Throws an when fails. /// + /// The item of items in the input instance. /// This method is needed because can't be used as a generic type parameter. [MethodImpl(MethodImplOptions.NoInlining)] public static void ThrowArgumentExceptionForIsNotEmptyWithSpan(string name) @@ -30,7 +29,8 @@ public static void ThrowArgumentExceptionForIsNotEmptyWithSpan(string name) /// /// Throws an when fails. /// - /// This method is needed because can't be used as a generic type parameter. + /// The item of items in the input instance. + /// This method is needed because can't be used as a generic type parameter. [MethodImpl(MethodImplOptions.NoInlining)] public static void ThrowArgumentExceptionForIsNotEmptyWithReadOnlySpan(string name) { @@ -40,6 +40,7 @@ public static void ThrowArgumentExceptionForIsNotEmptyWithReadOnlySpan(string /// /// Throws an when (or an overload) fails. /// + /// The item of items in the input collection. [MethodImpl(MethodImplOptions.NoInlining)] public static void ThrowArgumentExceptionForIsNotEmpty(string name) { diff --git a/Microsoft.Toolkit/Diagnostics/ThrowHelper.Comparable.Generic.cs b/Microsoft.Toolkit/Diagnostics/ThrowHelper.Comparable.Generic.cs index 0dab8651f21..ef901c3d136 100644 --- a/Microsoft.Toolkit/Diagnostics/ThrowHelper.Comparable.Generic.cs +++ b/Microsoft.Toolkit/Diagnostics/ThrowHelper.Comparable.Generic.cs @@ -3,7 +3,6 @@ // See the LICENSE file in the project root for more information. using System; -using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using Microsoft.Toolkit.Extensions; @@ -14,12 +13,12 @@ namespace Microsoft.Toolkit.Diagnostics /// /// Helper methods to throw exceptions /// - [SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1618", Justification = "Internal helper methods")] internal static partial class ThrowHelper { /// /// Throws an when fails. /// + /// The type of value type being tested. [MethodImpl(MethodImplOptions.NoInlining)] public static void ThrowArgumentExceptionForIsDefault(T value, string name) where T : struct @@ -30,6 +29,7 @@ public static void ThrowArgumentExceptionForIsDefault(T value, string name) /// /// Throws an when fails. /// + /// The type of value type being tested. [MethodImpl(MethodImplOptions.NoInlining)] public static void ThrowArgumentExceptionForIsNotDefault(string name) where T : struct @@ -40,6 +40,7 @@ public static void ThrowArgumentExceptionForIsNotDefault(string name) /// /// Throws an when fails. /// + /// The type of values being tested. [MethodImpl(MethodImplOptions.NoInlining)] public static void ThrowArgumentExceptionForIsEqualTo(T value, T target, string name) { @@ -49,6 +50,7 @@ public static void ThrowArgumentExceptionForIsEqualTo(T value, T target, stri /// /// Throws an when fails. /// + /// The type of values being tested. [MethodImpl(MethodImplOptions.NoInlining)] public static void ThrowArgumentExceptionForIsNotEqualTo(T value, T target, string name) { @@ -58,6 +60,7 @@ public static void ThrowArgumentExceptionForIsNotEqualTo(T value, T target, s /// /// Throws an when fails. /// + /// The type of values being tested. [MethodImpl(MethodImplOptions.NoInlining)] public static void ThrowArgumentOutOfRangeExceptionForIsLessThan(T value, T maximum, string name) { @@ -67,6 +70,7 @@ public static void ThrowArgumentOutOfRangeExceptionForIsLessThan(T value, T m /// /// Throws an when fails. /// + /// The type of values being tested. [MethodImpl(MethodImplOptions.NoInlining)] public static void ThrowArgumentOutOfRangeExceptionForIsLessThanOrEqualTo(T value, T maximum, string name) { @@ -76,6 +80,7 @@ public static void ThrowArgumentOutOfRangeExceptionForIsLessThanOrEqualTo(T v /// /// Throws an when fails. /// + /// The type of values being tested. [MethodImpl(MethodImplOptions.NoInlining)] public static void ThrowArgumentOutOfRangeExceptionForIsGreaterThan(T value, T minimum, string name) { @@ -85,6 +90,7 @@ public static void ThrowArgumentOutOfRangeExceptionForIsGreaterThan(T value, /// /// Throws an when fails. /// + /// The type of values being tested. [MethodImpl(MethodImplOptions.NoInlining)] public static void ThrowArgumentOutOfRangeExceptionForIsGreaterThanOrEqualTo(T value, T minimum, string name) { @@ -94,6 +100,7 @@ public static void ThrowArgumentOutOfRangeExceptionForIsGreaterThanOrEqualTo( /// /// Throws an when fails. /// + /// The type of values being tested. [MethodImpl(MethodImplOptions.NoInlining)] public static void ThrowArgumentOutOfRangeExceptionForIsInRange(T value, T minimum, T maximum, string name) { @@ -103,6 +110,7 @@ public static void ThrowArgumentOutOfRangeExceptionForIsInRange(T value, T mi /// /// Throws an when fails. /// + /// The type of values being tested. [MethodImpl(MethodImplOptions.NoInlining)] public static void ThrowArgumentOutOfRangeExceptionForIsNotInRange(T value, T minimum, T maximum, string name) { @@ -112,6 +120,7 @@ public static void ThrowArgumentOutOfRangeExceptionForIsNotInRange(T value, T /// /// Throws an when fails. /// + /// The type of values being tested. [MethodImpl(MethodImplOptions.NoInlining)] public static void ThrowArgumentOutOfRangeExceptionForIsBetween(T value, T minimum, T maximum, string name) { @@ -121,6 +130,7 @@ public static void ThrowArgumentOutOfRangeExceptionForIsBetween(T value, T mi /// /// Throws an when fails. /// + /// The type of values being tested. [MethodImpl(MethodImplOptions.NoInlining)] public static void ThrowArgumentOutOfRangeExceptionForIsNotBetween(T value, T minimum, T maximum, string name) { @@ -130,6 +140,7 @@ public static void ThrowArgumentOutOfRangeExceptionForIsNotBetween(T value, T /// /// Throws an when fails. /// + /// The type of values being tested. [MethodImpl(MethodImplOptions.NoInlining)] public static void ThrowArgumentOutOfRangeExceptionForIsBetweenOrEqualTo(T value, T minimum, T maximum, string name) { @@ -139,6 +150,7 @@ public static void ThrowArgumentOutOfRangeExceptionForIsBetweenOrEqualTo(T va /// /// Throws an when fails. /// + /// The type of values being tested. [MethodImpl(MethodImplOptions.NoInlining)] public static void ThrowArgumentOutOfRangeExceptionForIsNotBetweenOrEqualTo(T value, T minimum, T maximum, string name) { diff --git a/Microsoft.Toolkit/Diagnostics/ThrowHelper.Comparable.Numeric.cs b/Microsoft.Toolkit/Diagnostics/ThrowHelper.Comparable.Numeric.cs index ab05318ad6c..2db1ef888ab 100644 --- a/Microsoft.Toolkit/Diagnostics/ThrowHelper.Comparable.Numeric.cs +++ b/Microsoft.Toolkit/Diagnostics/ThrowHelper.Comparable.Numeric.cs @@ -3,7 +3,6 @@ // See the LICENSE file in the project root for more information. using System; -using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using Microsoft.Toolkit.Extensions; @@ -14,7 +13,6 @@ namespace Microsoft.Toolkit.Diagnostics /// /// Helper methods to throw exceptions /// - [SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1618", Justification = "Internal helper methods")] internal static partial class ThrowHelper { /// diff --git a/Microsoft.Toolkit/Diagnostics/ThrowHelper.IO.cs b/Microsoft.Toolkit/Diagnostics/ThrowHelper.IO.cs index 5dada175c32..218c1527480 100644 --- a/Microsoft.Toolkit/Diagnostics/ThrowHelper.IO.cs +++ b/Microsoft.Toolkit/Diagnostics/ThrowHelper.IO.cs @@ -3,7 +3,6 @@ // See the LICENSE file in the project root for more information. using System; -using System.Diagnostics.CodeAnalysis; using System.IO; using System.Runtime.CompilerServices; using Microsoft.Toolkit.Extensions; @@ -15,7 +14,6 @@ namespace Microsoft.Toolkit.Diagnostics /// /// Helper methods to throw exceptions /// - [SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1618", Justification = "Internal helper methods")] internal static partial class ThrowHelper { /// diff --git a/Microsoft.Toolkit/Diagnostics/ThrowHelper.String.cs b/Microsoft.Toolkit/Diagnostics/ThrowHelper.String.cs index 496507b6dc1..2835d1c4c0c 100644 --- a/Microsoft.Toolkit/Diagnostics/ThrowHelper.String.cs +++ b/Microsoft.Toolkit/Diagnostics/ThrowHelper.String.cs @@ -3,7 +3,6 @@ // See the LICENSE file in the project root for more information. using System; -using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; #nullable enable @@ -13,7 +12,6 @@ namespace Microsoft.Toolkit.Diagnostics /// /// Helper methods to throw exceptions /// - [SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1618", Justification = "Internal helper methods")] internal static partial class ThrowHelper { /// @@ -89,7 +87,7 @@ public static void ThrowArgumentExceptionForIsNotWhitespace(string text, string } /// - /// Throws an when fails. + /// Throws an when fails. /// [MethodImpl(MethodImplOptions.NoInlining)] public static void ThrowArgumentExceptionForHasSizeEqualTo(string text, int size, string name) @@ -107,19 +105,19 @@ public static void ThrowArgumentExceptionForHasSizeNotEqualTo(string text, int s } /// - /// Throws an when fails. + /// Throws an when fails. /// [MethodImpl(MethodImplOptions.NoInlining)] - public static void ThrowArgumentExceptionForHasSizeOver(string text, int size, string name) + public static void ThrowArgumentExceptionForHasSizeGreaterThan(string text, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} (string) must have a size over {size}, had a size of {text.Length} and was {text.ToAssertString()}"); } /// - /// Throws an when fails. + /// Throws an when fails. /// [MethodImpl(MethodImplOptions.NoInlining)] - public static void ThrowArgumentExceptionForHasSizeAtLeast(string text, int size, string name) + public static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(string text, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} (string) must have a size of at least {size}, had a size of {text.Length} and was {text.ToAssertString()}"); } @@ -134,12 +132,48 @@ public static void ThrowArgumentExceptionForHasSizeLessThan(string text, int siz } /// - /// Throws an when fails. + /// Throws an when fails. /// [MethodImpl(MethodImplOptions.NoInlining)] public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(string text, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} (string) must have a size less than or equal to {size}, had a size of {text.Length} and was {text.ToAssertString()}"); } + + /// + /// Throws an when fails. + /// + [MethodImpl(MethodImplOptions.NoInlining)] + public static void ThrowArgumentExceptionForHasSizeEqualTo(string source, string destination, string name) + { + ThrowArgumentException(name, $"The source {name.ToAssertString()} (string) must have a size equal to {destination.Length.ToAssertString()} (the destination), had a size of {source.Length.ToAssertString()}"); + } + + /// + /// Throws an when fails. + /// + [MethodImpl(MethodImplOptions.NoInlining)] + public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(string source, string destination, string name) + { + ThrowArgumentException(name, $"The source {name.ToAssertString()} (string) must have a size less than or equal to {destination.Length.ToAssertString()} (the destination), had a size of {source.Length.ToAssertString()}"); + } + + /// + /// Throws an when fails. + /// + [MethodImpl(MethodImplOptions.NoInlining)] + public static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, string text, string name) + { + ThrowArgumentOutOfRangeException(name, $"Parameter {name.ToAssertString()} (int) must be in the range given by <0> and {text.Length.ToAssertString()} to be a valid index for the target string, was {index.ToAssertString()}"); + } + + /// + /// Throws an when fails. + /// + [MethodImpl(MethodImplOptions.NoInlining)] + public static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int index, string text, string name) + { + ThrowArgumentOutOfRangeException(name, $"Parameter {name.ToAssertString()} (int) must not be in the range given by <0> and {text.Length.ToAssertString()} to be an invalid index for the target string, was {index.ToAssertString()}"); + } } } diff --git a/Microsoft.Toolkit/Diagnostics/ThrowHelper.Tasks.cs b/Microsoft.Toolkit/Diagnostics/ThrowHelper.Tasks.cs index 9fad34ea8d1..8b5a144d5e0 100644 --- a/Microsoft.Toolkit/Diagnostics/ThrowHelper.Tasks.cs +++ b/Microsoft.Toolkit/Diagnostics/ThrowHelper.Tasks.cs @@ -3,7 +3,6 @@ // See the LICENSE file in the project root for more information. using System; -using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using System.Threading.Tasks; using Microsoft.Toolkit.Extensions; @@ -15,7 +14,6 @@ namespace Microsoft.Toolkit.Diagnostics /// /// Helper methods to throw exceptions /// - [SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1618", Justification = "Internal helper methods")] internal static partial class ThrowHelper { /// diff --git a/Microsoft.Toolkit/Diagnostics/ThrowHelper.cs b/Microsoft.Toolkit/Diagnostics/ThrowHelper.cs index 5436d9b48b4..bbc307deb9d 100644 --- a/Microsoft.Toolkit/Diagnostics/ThrowHelper.cs +++ b/Microsoft.Toolkit/Diagnostics/ThrowHelper.cs @@ -3,7 +3,6 @@ // See the LICENSE file in the project root for more information. using System; -using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using Microsoft.Toolkit.Extensions; @@ -14,13 +13,12 @@ namespace Microsoft.Toolkit.Diagnostics /// /// Helper methods to throw exceptions /// - [SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1618", Justification = "Internal helper methods")] internal static partial class ThrowHelper { -#pragma warning disable CS0419 /// - /// Throws an when fails. + /// Throws an when (where is ) fails. /// + /// The type of the input value. [MethodImpl(MethodImplOptions.NoInlining)] public static void ThrowArgumentExceptionForIsNull(T value, string name) where T : class @@ -29,8 +27,9 @@ public static void ThrowArgumentExceptionForIsNull(T value, string name) } /// - /// Throws an when fails. + /// Throws an when (where is ) fails. /// + /// The type of the input value. [MethodImpl(MethodImplOptions.NoInlining)] public static void ThrowArgumentExceptionForIsNull(T? value, string name) where T : struct @@ -39,18 +38,19 @@ public static void ThrowArgumentExceptionForIsNull(T? value, string name) } /// - /// Throws an when fails. + /// Throws an when fails. /// + /// The type of the input value. [MethodImpl(MethodImplOptions.NoInlining)] public static void ThrowArgumentNullExceptionForIsNotNull(string name) { ThrowArgumentNullException(name, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be not null)"); } -#pragma warning restore CS0419 /// /// Throws an when fails. /// + /// The type of the input value. [MethodImpl(MethodImplOptions.NoInlining)] public static void ThrowArgumentExceptionForIsOfType(object value, string name) { @@ -60,6 +60,7 @@ public static void ThrowArgumentExceptionForIsOfType(object value, string nam /// /// Throws an when fails. /// + /// The type of the input value. [MethodImpl(MethodImplOptions.NoInlining)] public static void ThrowArgumentExceptionForIsNotOfType(object value, string name) { @@ -87,6 +88,7 @@ public static void ThrowArgumentExceptionForIsNotOfType(object value, Type type, /// /// Throws an when fails. /// + /// The type being checked against. [MethodImpl(MethodImplOptions.NoInlining)] public static void ThrowArgumentExceptionForIsAssignableToType(object value, string name) { @@ -96,6 +98,7 @@ public static void ThrowArgumentExceptionForIsAssignableToType(object value, /// /// Throws an when fails. /// + /// The type being checked against. [MethodImpl(MethodImplOptions.NoInlining)] public static void ThrowArgumentExceptionForIsNotAssignableToType(object value, string name) { @@ -123,6 +126,7 @@ public static void ThrowArgumentExceptionForIsNotAssignableToType(object value, /// /// Throws an when fails. /// + /// The type of input values being compared. [MethodImpl(MethodImplOptions.NoInlining)] public static void ThrowArgumentExceptionForsBitwiseEqualTo(T value, T target, string name) where T : unmanaged @@ -133,6 +137,7 @@ public static void ThrowArgumentExceptionForsBitwiseEqualTo(T value, T target /// /// Throws an when fails. /// + /// The type of input value being compared. [MethodImpl(MethodImplOptions.NoInlining)] public static void ThrowArgumentExceptionForIsReferenceEqualTo(string name) where T : class @@ -143,6 +148,7 @@ public static void ThrowArgumentExceptionForIsReferenceEqualTo(string name) /// /// Throws an when fails. /// + /// The type of input value being compared. [MethodImpl(MethodImplOptions.NoInlining)] public static void ThrowArgumentExceptionForIsReferenceNotEqualTo(string name) where T : class @@ -151,7 +157,7 @@ public static void ThrowArgumentExceptionForIsReferenceNotEqualTo(string name } /// - /// Throws an when fails. + /// Throws an when fails. /// [MethodImpl(MethodImplOptions.NoInlining)] public static void ThrowArgumentExceptionForIsTrue(string name) @@ -160,12 +166,30 @@ public static void ThrowArgumentExceptionForIsTrue(string name) } /// - /// Throws an when fails. + /// Throws an when fails. + /// + [MethodImpl(MethodImplOptions.NoInlining)] + public static void ThrowArgumentExceptionForIsTrue(string name, string message) + { + ThrowArgumentException(name, $"Parameter {name.ToAssertString()} must be true, was false: {message.ToAssertString()}"); + } + + /// + /// Throws an when fails. /// [MethodImpl(MethodImplOptions.NoInlining)] public static void ThrowArgumentExceptionForIsFalse(string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} must be false, was true"); } + + /// + /// Throws an when fails. + /// + [MethodImpl(MethodImplOptions.NoInlining)] + public static void ThrowArgumentExceptionForIsFalse(string name, string message) + { + ThrowArgumentException(name, $"Parameter {name.ToAssertString()} must be false, was true: {message.ToAssertString()}"); + } } } diff --git a/Microsoft.Toolkit/Extensions/TypeExtensions.cs b/Microsoft.Toolkit/Extensions/TypeExtensions.cs index c012d085daf..bcc6cea4415 100644 --- a/Microsoft.Toolkit/Extensions/TypeExtensions.cs +++ b/Microsoft.Toolkit/Extensions/TypeExtensions.cs @@ -107,10 +107,10 @@ tokens[0] is { } genericName && return type.ToString(); } - /* Atomically get or build the display string for the current type. - * Manually create a static lambda here to enable caching of the generated closure. - * This is a workaround for the missing caching for method group conversions, and should - * be removed once this issue is resolved: https://github.com/dotnet/roslyn/issues/5835. */ + // Atomically get or build the display string for the current type. + // Manually create a static lambda here to enable caching of the generated closure. + // This is a workaround for the missing caching for method group conversions, and should + // be removed once this issue is resolved: https://github.com/dotnet/roslyn/issues/5835. return DisplayNames.GetValue(type, t => FormatDisplayString(t)); } } diff --git a/Microsoft.Toolkit/Microsoft.Toolkit.csproj b/Microsoft.Toolkit/Microsoft.Toolkit.csproj index 011f95377f7..f8ec09a5960 100644 --- a/Microsoft.Toolkit/Microsoft.Toolkit.csproj +++ b/Microsoft.Toolkit/Microsoft.Toolkit.csproj @@ -1,7 +1,7 @@  - netstandard2.0 + netstandard2.0;netstandard2.1 8.0 true Windows Community Toolkit .NET Standard @@ -16,8 +16,14 @@ Full - - + + + + + + + + diff --git a/UnitTests/UnitTests.NetCore/UnitTests.NetCore.csproj b/UnitTests/UnitTests.NetCore/UnitTests.NetCore.csproj new file mode 100644 index 00000000000..c16dbc80a03 --- /dev/null +++ b/UnitTests/UnitTests.NetCore/UnitTests.NetCore.csproj @@ -0,0 +1,21 @@ + + + + netcoreapp2.1;netcoreapp3.1 + false + + + + + + + + + + + + + + + + diff --git a/UnitTests/.editorconfig b/UnitTests/UnitTests.Shared/.editorconfig similarity index 100% rename from UnitTests/.editorconfig rename to UnitTests/UnitTests.Shared/.editorconfig diff --git a/UnitTests/Collections/IntGroup.cs b/UnitTests/UnitTests.Shared/Collections/IntGroup.cs similarity index 100% rename from UnitTests/Collections/IntGroup.cs rename to UnitTests/UnitTests.Shared/Collections/IntGroup.cs diff --git a/UnitTests/Collections/ObservableGroupTests.cs b/UnitTests/UnitTests.Shared/Collections/ObservableGroupTests.cs similarity index 100% rename from UnitTests/Collections/ObservableGroupTests.cs rename to UnitTests/UnitTests.Shared/Collections/ObservableGroupTests.cs index 92a08f5a68b..0d2809d2ebd 100644 --- a/UnitTests/Collections/ObservableGroupTests.cs +++ b/UnitTests/UnitTests.Shared/Collections/ObservableGroupTests.cs @@ -2,11 +2,11 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using System.Collections.Specialized; using System.Linq; using FluentAssertions; using Microsoft.Toolkit.Collections; using Microsoft.VisualStudio.TestTools.UnitTesting; -using System.Collections.Specialized; namespace UnitTests.Collections { diff --git a/UnitTests/Collections/ObservableGroupedCollectionExtensionsTests.cs b/UnitTests/UnitTests.Shared/Collections/ObservableGroupedCollectionExtensionsTests.cs similarity index 100% rename from UnitTests/Collections/ObservableGroupedCollectionExtensionsTests.cs rename to UnitTests/UnitTests.Shared/Collections/ObservableGroupedCollectionExtensionsTests.cs index 0c1128be410..78e99abce61 100644 --- a/UnitTests/Collections/ObservableGroupedCollectionExtensionsTests.cs +++ b/UnitTests/UnitTests.Shared/Collections/ObservableGroupedCollectionExtensionsTests.cs @@ -2,11 +2,11 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using System; +using System.Linq; using FluentAssertions; using Microsoft.Toolkit.Collections; using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; -using System.Linq; namespace UnitTests.Collections { diff --git a/UnitTests/Collections/ObservableGroupedCollectionTests.cs b/UnitTests/UnitTests.Shared/Collections/ObservableGroupedCollectionTests.cs similarity index 100% rename from UnitTests/Collections/ObservableGroupedCollectionTests.cs rename to UnitTests/UnitTests.Shared/Collections/ObservableGroupedCollectionTests.cs index 49b0634e982..fa64718e7ea 100644 --- a/UnitTests/Collections/ObservableGroupedCollectionTests.cs +++ b/UnitTests/UnitTests.Shared/Collections/ObservableGroupedCollectionTests.cs @@ -2,11 +2,11 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using System.Collections.Generic; +using System.Linq; using FluentAssertions; using Microsoft.Toolkit.Collections; using Microsoft.VisualStudio.TestTools.UnitTesting; -using System.Collections.Generic; -using System.Linq; namespace UnitTests.Collections { diff --git a/UnitTests/Collections/ReadOnlyObservableGroupTests.cs b/UnitTests/UnitTests.Shared/Collections/ReadOnlyObservableGroupTests.cs similarity index 100% rename from UnitTests/Collections/ReadOnlyObservableGroupTests.cs rename to UnitTests/UnitTests.Shared/Collections/ReadOnlyObservableGroupTests.cs diff --git a/UnitTests/Collections/ReadOnlyObservableGroupedCollectionTests.cs b/UnitTests/UnitTests.Shared/Collections/ReadOnlyObservableGroupedCollectionTests.cs similarity index 100% rename from UnitTests/Collections/ReadOnlyObservableGroupedCollectionTests.cs rename to UnitTests/UnitTests.Shared/Collections/ReadOnlyObservableGroupedCollectionTests.cs index 1e69d45246a..963d89ba432 100644 --- a/UnitTests/Collections/ReadOnlyObservableGroupedCollectionTests.cs +++ b/UnitTests/UnitTests.Shared/Collections/ReadOnlyObservableGroupedCollectionTests.cs @@ -2,9 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using FluentAssertions; -using Microsoft.Toolkit.Collections; -using Microsoft.VisualStudio.TestTools.UnitTesting; using System; using System.Collections; using System.Collections.Generic; @@ -12,6 +9,9 @@ using System.Collections.Specialized; using System.ComponentModel; using System.Linq; +using FluentAssertions; +using Microsoft.Toolkit.Collections; +using Microsoft.VisualStudio.TestTools.UnitTesting; namespace UnitTests.Collections { diff --git a/UnitTests/Diagnostics/Test_Guard.Array.cs b/UnitTests/UnitTests.Shared/Diagnostics/Test_Guard.Array.cs similarity index 84% rename from UnitTests/Diagnostics/Test_Guard.Array.cs rename to UnitTests/UnitTests.Shared/Diagnostics/Test_Guard.Array.cs index 326cbab049c..c7dee14f272 100644 --- a/UnitTests/Diagnostics/Test_Guard.Array.cs +++ b/UnitTests/UnitTests.Shared/Diagnostics/Test_Guard.Array.cs @@ -72,41 +72,41 @@ public void Test_Guard_HasSizeNotEqualTo_ArrayFail() [TestCategory("Guard")] [TestMethod] - public void Test_Guard_HasSizeOver_ArrayOk() + public void Test_Guard_HasSizeGreaterThan_ArrayOk() { - Guard.HasSizeOver(new int[5], 2, nameof(Test_Guard_HasSizeOver_ArrayOk)); + Guard.HasSizeGreaterThan(new int[5], 2, nameof(Test_Guard_HasSizeGreaterThan_ArrayOk)); } [TestCategory("Guard")] [TestMethod] [ExpectedException(typeof(ArgumentException))] - public void Test_Guard_HasSizeOver_ArrayEqualFail() + public void Test_Guard_HasSizeGreaterThan_ArrayEqualFail() { - Guard.HasSizeOver(new int[4], 4, nameof(Test_Guard_HasSizeOver_ArrayEqualFail)); + Guard.HasSizeGreaterThan(new int[4], 4, nameof(Test_Guard_HasSizeGreaterThan_ArrayEqualFail)); } [TestCategory("Guard")] [TestMethod] [ExpectedException(typeof(ArgumentException))] - public void Test_Guard_HasSizeOver_ArraSmallerFail() + public void Test_Guard_HasSizeGreaterThan_ArraSmallerFail() { - Guard.HasSizeOver(new int[1], 4, nameof(Test_Guard_HasSizeOver_ArraSmallerFail)); + Guard.HasSizeGreaterThan(new int[1], 4, nameof(Test_Guard_HasSizeGreaterThan_ArraSmallerFail)); } [TestCategory("Guard")] [TestMethod] - public void Test_Guard_HasSizeAtLeast_ArrayOk() + public void Test_Guard_HasSizeGreaterThanOrEqualTo_ArrayOk() { - Guard.HasSizeAtLeast(new int[5], 2, nameof(Test_Guard_HasSizeAtLeast_ArrayOk)); - Guard.HasSizeAtLeast(new int[2], 2, nameof(Test_Guard_HasSizeAtLeast_ArrayOk)); + Guard.HasSizeGreaterThanOrEqualTo(new int[5], 2, nameof(Test_Guard_HasSizeGreaterThanOrEqualTo_ArrayOk)); + Guard.HasSizeGreaterThanOrEqualTo(new int[2], 2, nameof(Test_Guard_HasSizeGreaterThanOrEqualTo_ArrayOk)); } [TestCategory("Guard")] [TestMethod] [ExpectedException(typeof(ArgumentException))] - public void Test_Guard_HasSizeAtLeast_ArrayFail() + public void Test_Guard_HasSizeGreaterThanOrEqualTo_ArrayFail() { - Guard.HasSizeOver(new int[1], 4, nameof(Test_Guard_HasSizeAtLeast_ArrayFail)); + Guard.HasSizeGreaterThan(new int[1], 4, nameof(Test_Guard_HasSizeGreaterThanOrEqualTo_ArrayFail)); } [TestCategory("Guard")] diff --git a/UnitTests/Diagnostics/Test_Guard.Comparable.Numeric.cs b/UnitTests/UnitTests.Shared/Diagnostics/Test_Guard.Comparable.Numeric.cs similarity index 100% rename from UnitTests/Diagnostics/Test_Guard.Comparable.Numeric.cs rename to UnitTests/UnitTests.Shared/Diagnostics/Test_Guard.Comparable.Numeric.cs diff --git a/UnitTests/Diagnostics/Test_Guard.cs b/UnitTests/UnitTests.Shared/Diagnostics/Test_Guard.cs similarity index 93% rename from UnitTests/Diagnostics/Test_Guard.cs rename to UnitTests/UnitTests.Shared/Diagnostics/Test_Guard.cs index 935c4e2a868..557245abdf7 100644 --- a/UnitTests/Diagnostics/Test_Guard.cs +++ b/UnitTests/UnitTests.Shared/Diagnostics/Test_Guard.cs @@ -216,6 +216,7 @@ public void Test_Guard_IsReferenceNotEqualTo_Fail() public void Test_Guard_IsTrue_Ok() { Guard.IsTrue(true, nameof(Test_Guard_IsTrue_Ok)); + Guard.IsTrue(true, nameof(Test_Guard_IsTrue_Ok), "Hello world"); } [TestCategory("Guard")] @@ -226,11 +227,32 @@ public void Test_Guard_IsTrue_Fail() Guard.IsTrue(false, nameof(Test_Guard_IsTrue_Fail)); } + [TestCategory("Guard")] + [TestMethod] + public void Test_Guard_IsTrue_Fail_WithMessage() + { + try + { + Guard.IsTrue(false, nameof(Test_Guard_IsTrue_Fail_WithMessage), "Hello world"); + } + catch (ArgumentException e) + { + Assert.IsTrue(e.Message.Contains("\"Hello world\"")); + + return; + } + + // Compiler detects this is unreachable from attribute, + // but we leave the assertion to double check that's valid + Assert.Fail(); + } + [TestCategory("Guard")] [TestMethod] public void Test_Guard_IsFalse_Ok() { Guard.IsFalse(false, nameof(Test_Guard_IsFalse_Ok)); + Guard.IsFalse(false, nameof(Test_Guard_IsFalse_Ok), "Hello world"); } [TestCategory("Guard")] @@ -241,6 +263,24 @@ public void Test_Guard_IsFalse_Fail() Guard.IsFalse(true, nameof(Test_Guard_IsFalse_Fail)); } + [TestCategory("Guard")] + [TestMethod] + public void Test_Guard_IsFalse_Fail_WithMessage() + { + try + { + Guard.IsFalse(true, nameof(Test_Guard_IsFalse_Fail_WithMessage), "Hello world"); + } + catch (ArgumentException e) + { + Assert.IsTrue(e.Message.Contains("\"Hello world\"")); + + return; + } + + Assert.Fail(); + } + [TestCategory("Guard")] [TestMethod] public void Test_Guard_IsLessThan_Ok() @@ -315,7 +355,7 @@ public void Test_Guard_IsGreaterThan_LowerFalse() [TestMethod] public void Test_Guard_IsGreaterThanOrEqualTo_Ok() { - Guard.IsGreaterThanOrEqualTo(2,1, nameof(Test_Guard_IsGreaterThanOrEqualTo_Ok)); + Guard.IsGreaterThanOrEqualTo(2, 1, nameof(Test_Guard_IsGreaterThanOrEqualTo_Ok)); Guard.IsGreaterThanOrEqualTo(1, 1, nameof(Test_Guard_IsGreaterThanOrEqualTo_Ok)); Guard.IsGreaterThanOrEqualTo(MathF.PI, 1, nameof(Test_Guard_IsGreaterThanOrEqualTo_Ok)); Guard.IsGreaterThanOrEqualTo(MathF.PI, MathF.PI, nameof(Test_Guard_IsGreaterThanOrEqualTo_Ok)); diff --git a/UnitTests/Extensions/Test_ArrayExtensions.cs b/UnitTests/UnitTests.Shared/Extensions/Test_ArrayExtensions.cs similarity index 98% rename from UnitTests/Extensions/Test_ArrayExtensions.cs rename to UnitTests/UnitTests.Shared/Extensions/Test_ArrayExtensions.cs index df17487dd19..9c7877dfd70 100644 --- a/UnitTests/Extensions/Test_ArrayExtensions.cs +++ b/UnitTests/UnitTests.Shared/Extensions/Test_ArrayExtensions.cs @@ -2,11 +2,11 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using Microsoft.Toolkit.Extensions; -using Microsoft.VisualStudio.TestTools.UnitTesting; using System; using System.Diagnostics; using System.Linq; +using Microsoft.Toolkit.Extensions; +using Microsoft.VisualStudio.TestTools.UnitTesting; namespace UnitTests.Extensions { @@ -174,9 +174,9 @@ public void Test_ArrayExtensions_Jagged_GetColumn() { int[][] array = { - new int[] { 5, 2, 4 }, - new int[] { 6, 3 }, - new int[] { 7 } + new int[] { 5, 2, 4 }, + new int[] { 6, 3 }, + new int[] { 7 } }; var col = array.GetColumn(1).ToArray(); @@ -188,7 +188,7 @@ public void Test_ArrayExtensions_Jagged_GetColumn() [TestMethod] public void Test_ArrayExtensions_Jagged_GetColumn_Exception() { - int[][] array = + int[][] array = { new int[] { 5, 2, 4 }, new int[] { 6, 3 }, diff --git a/UnitTests/Extensions/Test_TypeExtensions.cs b/UnitTests/UnitTests.Shared/Extensions/Test_TypeExtensions.cs similarity index 100% rename from UnitTests/Extensions/Test_TypeExtensions.cs rename to UnitTests/UnitTests.Shared/Extensions/Test_TypeExtensions.cs diff --git a/UnitTests/Extensions/Test_ValueTypeExtensions.cs b/UnitTests/UnitTests.Shared/Extensions/Test_ValueTypeExtensions.cs similarity index 100% rename from UnitTests/Extensions/Test_ValueTypeExtensions.cs rename to UnitTests/UnitTests.Shared/Extensions/Test_ValueTypeExtensions.cs diff --git a/UnitTests/UnitTests.Shared/UnitTests.Shared.projitems b/UnitTests/UnitTests.Shared/UnitTests.Shared.projitems new file mode 100644 index 00000000000..c281bd27bdf --- /dev/null +++ b/UnitTests/UnitTests.Shared/UnitTests.Shared.projitems @@ -0,0 +1,25 @@ + + + + $(MSBuildAllProjects);$(MSBuildThisFileFullPath) + true + 4e9466d1-d5aa-46ac-801b-c8fdab79f0d4 + + + UnitTests.Shared + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/UnitTests/UnitTests.Shared/UnitTests.Shared.shproj b/UnitTests/UnitTests.Shared/UnitTests.Shared.shproj new file mode 100644 index 00000000000..303509f4fd5 --- /dev/null +++ b/UnitTests/UnitTests.Shared/UnitTests.Shared.shproj @@ -0,0 +1,13 @@ + + + + 4e9466d1-d5aa-46ac-801b-c8fdab79f0d4 + 14.0 + + + + + + + + diff --git a/UnitTests/UnitTests.UWP/.editorconfig b/UnitTests/UnitTests.UWP/.editorconfig new file mode 100644 index 00000000000..68caad1b9dc --- /dev/null +++ b/UnitTests/UnitTests.UWP/.editorconfig @@ -0,0 +1,7 @@ +[*.{cs,vb}] + +# SA1601: Partial elements should be documented +dotnet_diagnostic.SA1601.severity = none +dotnet_diagnostic.CS1573.severity = none +dotnet_diagnostic.CS1591.severity = none +dotnet_diagnostic.CS1712.severity = none \ No newline at end of file diff --git a/UnitTests/Assets/LockScreenLogo.scale-200.png b/UnitTests/UnitTests.UWP/Assets/LockScreenLogo.scale-200.png similarity index 100% rename from UnitTests/Assets/LockScreenLogo.scale-200.png rename to UnitTests/UnitTests.UWP/Assets/LockScreenLogo.scale-200.png diff --git a/UnitTests/Assets/Samples/lorem.txt b/UnitTests/UnitTests.UWP/Assets/Samples/lorem.txt similarity index 100% rename from UnitTests/Assets/Samples/lorem.txt rename to UnitTests/UnitTests.UWP/Assets/Samples/lorem.txt diff --git a/UnitTests/Assets/SplashScreen.scale-200.png b/UnitTests/UnitTests.UWP/Assets/SplashScreen.scale-200.png similarity index 100% rename from UnitTests/Assets/SplashScreen.scale-200.png rename to UnitTests/UnitTests.UWP/Assets/SplashScreen.scale-200.png diff --git a/UnitTests/Assets/Square150x150Logo.scale-200.png b/UnitTests/UnitTests.UWP/Assets/Square150x150Logo.scale-200.png similarity index 100% rename from UnitTests/Assets/Square150x150Logo.scale-200.png rename to UnitTests/UnitTests.UWP/Assets/Square150x150Logo.scale-200.png diff --git a/UnitTests/Assets/Square44x44Logo.scale-200.png b/UnitTests/UnitTests.UWP/Assets/Square44x44Logo.scale-200.png similarity index 100% rename from UnitTests/Assets/Square44x44Logo.scale-200.png rename to UnitTests/UnitTests.UWP/Assets/Square44x44Logo.scale-200.png diff --git a/UnitTests/Assets/Square44x44Logo.targetsize-24_altform-unplated.png b/UnitTests/UnitTests.UWP/Assets/Square44x44Logo.targetsize-24_altform-unplated.png similarity index 100% rename from UnitTests/Assets/Square44x44Logo.targetsize-24_altform-unplated.png rename to UnitTests/UnitTests.UWP/Assets/Square44x44Logo.targetsize-24_altform-unplated.png diff --git a/UnitTests/Assets/StoreLogo.png b/UnitTests/UnitTests.UWP/Assets/StoreLogo.png similarity index 100% rename from UnitTests/Assets/StoreLogo.png rename to UnitTests/UnitTests.UWP/Assets/StoreLogo.png diff --git a/UnitTests/Assets/Wide310x150Logo.scale-200.png b/UnitTests/UnitTests.UWP/Assets/Wide310x150Logo.scale-200.png similarity index 100% rename from UnitTests/Assets/Wide310x150Logo.scale-200.png rename to UnitTests/UnitTests.UWP/Assets/Wide310x150Logo.scale-200.png diff --git a/UnitTests/Converters/Test_AdaptiveHeightValueConverter.cs b/UnitTests/UnitTests.UWP/Converters/Test_AdaptiveHeightValueConverter.cs similarity index 100% rename from UnitTests/Converters/Test_AdaptiveHeightValueConverter.cs rename to UnitTests/UnitTests.UWP/Converters/Test_AdaptiveHeightValueConverter.cs diff --git a/UnitTests/Converters/Test_BoolToObjectConverter.cs b/UnitTests/UnitTests.UWP/Converters/Test_BoolToObjectConverter.cs similarity index 100% rename from UnitTests/Converters/Test_BoolToObjectConverter.cs rename to UnitTests/UnitTests.UWP/Converters/Test_BoolToObjectConverter.cs diff --git a/UnitTests/Converters/Test_EmptyCollectionToObjectConverter.cs b/UnitTests/UnitTests.UWP/Converters/Test_EmptyCollectionToObjectConverter.cs similarity index 100% rename from UnitTests/Converters/Test_EmptyCollectionToObjectConverter.cs rename to UnitTests/UnitTests.UWP/Converters/Test_EmptyCollectionToObjectConverter.cs diff --git a/UnitTests/Converters/Test_EmptyStringToObjectConverter.cs b/UnitTests/UnitTests.UWP/Converters/Test_EmptyStringToObjectConverter.cs similarity index 100% rename from UnitTests/Converters/Test_EmptyStringToObjectConverter.cs rename to UnitTests/UnitTests.UWP/Converters/Test_EmptyStringToObjectConverter.cs diff --git a/UnitTests/Converters/Test_StringFormatConverter.cs b/UnitTests/UnitTests.UWP/Converters/Test_StringFormatConverter.cs similarity index 100% rename from UnitTests/Converters/Test_StringFormatConverter.cs rename to UnitTests/UnitTests.UWP/Converters/Test_StringFormatConverter.cs diff --git a/UnitTests/Extensions/Helpers/ObjectWithNullableBoolProperty.cs b/UnitTests/UnitTests.UWP/Extensions/Helpers/ObjectWithNullableBoolProperty.cs similarity index 100% rename from UnitTests/Extensions/Helpers/ObjectWithNullableBoolProperty.cs rename to UnitTests/UnitTests.UWP/Extensions/Helpers/ObjectWithNullableBoolProperty.cs diff --git a/UnitTests/Extensions/Test_NullableBoolMarkupExtension.cs b/UnitTests/UnitTests.UWP/Extensions/Test_NullableBoolMarkupExtension.cs similarity index 100% rename from UnitTests/Extensions/Test_NullableBoolMarkupExtension.cs rename to UnitTests/UnitTests.UWP/Extensions/Test_NullableBoolMarkupExtension.cs diff --git a/UnitTests/GlobalSuppressions.cs b/UnitTests/UnitTests.UWP/GlobalSuppressions.cs similarity index 100% rename from UnitTests/GlobalSuppressions.cs rename to UnitTests/UnitTests.UWP/GlobalSuppressions.cs diff --git a/UnitTests/Helpers/TestCollectionCapableDeepLinkParser.cs b/UnitTests/UnitTests.UWP/Helpers/TestCollectionCapableDeepLinkParser.cs similarity index 100% rename from UnitTests/Helpers/TestCollectionCapableDeepLinkParser.cs rename to UnitTests/UnitTests.UWP/Helpers/TestCollectionCapableDeepLinkParser.cs diff --git a/UnitTests/Helpers/TestDeepLinkParser.cs b/UnitTests/UnitTests.UWP/Helpers/TestDeepLinkParser.cs similarity index 100% rename from UnitTests/Helpers/TestDeepLinkParser.cs rename to UnitTests/UnitTests.UWP/Helpers/TestDeepLinkParser.cs diff --git a/UnitTests/Helpers/Test_AdvancedCollectionView.cs b/UnitTests/UnitTests.UWP/Helpers/Test_AdvancedCollectionView.cs similarity index 100% rename from UnitTests/Helpers/Test_AdvancedCollectionView.cs rename to UnitTests/UnitTests.UWP/Helpers/Test_AdvancedCollectionView.cs diff --git a/UnitTests/Helpers/Test_BackgroundTaskHelper.cs b/UnitTests/UnitTests.UWP/Helpers/Test_BackgroundTaskHelper.cs similarity index 100% rename from UnitTests/Helpers/Test_BackgroundTaskHelper.cs rename to UnitTests/UnitTests.UWP/Helpers/Test_BackgroundTaskHelper.cs diff --git a/UnitTests/Helpers/Test_CollectionCapableDeepLinkParser.cs b/UnitTests/UnitTests.UWP/Helpers/Test_CollectionCapableDeepLinkParser.cs similarity index 100% rename from UnitTests/Helpers/Test_CollectionCapableDeepLinkParser.cs rename to UnitTests/UnitTests.UWP/Helpers/Test_CollectionCapableDeepLinkParser.cs diff --git a/UnitTests/Helpers/Test_ColorHelper.cs b/UnitTests/UnitTests.UWP/Helpers/Test_ColorHelper.cs similarity index 100% rename from UnitTests/Helpers/Test_ColorHelper.cs rename to UnitTests/UnitTests.UWP/Helpers/Test_ColorHelper.cs diff --git a/UnitTests/Helpers/Test_ConnectionHelper.cs b/UnitTests/UnitTests.UWP/Helpers/Test_ConnectionHelper.cs similarity index 100% rename from UnitTests/Helpers/Test_ConnectionHelper.cs rename to UnitTests/UnitTests.UWP/Helpers/Test_ConnectionHelper.cs diff --git a/UnitTests/Helpers/Test_DeepLinkParser.cs b/UnitTests/UnitTests.UWP/Helpers/Test_DeepLinkParser.cs similarity index 100% rename from UnitTests/Helpers/Test_DeepLinkParser.cs rename to UnitTests/UnitTests.UWP/Helpers/Test_DeepLinkParser.cs diff --git a/UnitTests/Helpers/Test_ScreenUnitHelper.cs b/UnitTests/UnitTests.UWP/Helpers/Test_ScreenUnitHelper.cs similarity index 100% rename from UnitTests/Helpers/Test_ScreenUnitHelper.cs rename to UnitTests/UnitTests.UWP/Helpers/Test_ScreenUnitHelper.cs diff --git a/UnitTests/Helpers/Test_StorageFileHelper.cs b/UnitTests/UnitTests.UWP/Helpers/Test_StorageFileHelper.cs similarity index 100% rename from UnitTests/Helpers/Test_StorageFileHelper.cs rename to UnitTests/UnitTests.UWP/Helpers/Test_StorageFileHelper.cs diff --git a/UnitTests/Helpers/Test_StorageHelper.cs b/UnitTests/UnitTests.UWP/Helpers/Test_StorageHelper.cs similarity index 100% rename from UnitTests/Helpers/Test_StorageHelper.cs rename to UnitTests/UnitTests.UWP/Helpers/Test_StorageHelper.cs diff --git a/UnitTests/Helpers/Test_StreamHelper.cs b/UnitTests/UnitTests.UWP/Helpers/Test_StreamHelper.cs similarity index 100% rename from UnitTests/Helpers/Test_StreamHelper.cs rename to UnitTests/UnitTests.UWP/Helpers/Test_StreamHelper.cs diff --git a/UnitTests/Helpers/Test_WeakEventListener.cs b/UnitTests/UnitTests.UWP/Helpers/Test_WeakEventListener.cs similarity index 100% rename from UnitTests/Helpers/Test_WeakEventListener.cs rename to UnitTests/UnitTests.UWP/Helpers/Test_WeakEventListener.cs diff --git a/UnitTests/Markdown/Parse/BoldTests.cs b/UnitTests/UnitTests.UWP/Markdown/Parse/BoldTests.cs similarity index 100% rename from UnitTests/Markdown/Parse/BoldTests.cs rename to UnitTests/UnitTests.UWP/Markdown/Parse/BoldTests.cs diff --git a/UnitTests/Markdown/Parse/CodeTests.cs b/UnitTests/UnitTests.UWP/Markdown/Parse/CodeTests.cs similarity index 100% rename from UnitTests/Markdown/Parse/CodeTests.cs rename to UnitTests/UnitTests.UWP/Markdown/Parse/CodeTests.cs diff --git a/UnitTests/Markdown/Parse/HeaderTests.cs b/UnitTests/UnitTests.UWP/Markdown/Parse/HeaderTests.cs similarity index 100% rename from UnitTests/Markdown/Parse/HeaderTests.cs rename to UnitTests/UnitTests.UWP/Markdown/Parse/HeaderTests.cs diff --git a/UnitTests/Markdown/Parse/HorizontalRuleTests.cs b/UnitTests/UnitTests.UWP/Markdown/Parse/HorizontalRuleTests.cs similarity index 100% rename from UnitTests/Markdown/Parse/HorizontalRuleTests.cs rename to UnitTests/UnitTests.UWP/Markdown/Parse/HorizontalRuleTests.cs diff --git a/UnitTests/Markdown/Parse/HyperlinkTests.cs b/UnitTests/UnitTests.UWP/Markdown/Parse/HyperlinkTests.cs similarity index 100% rename from UnitTests/Markdown/Parse/HyperlinkTests.cs rename to UnitTests/UnitTests.UWP/Markdown/Parse/HyperlinkTests.cs diff --git a/UnitTests/Markdown/Parse/ImageInlineTests.cs b/UnitTests/UnitTests.UWP/Markdown/Parse/ImageInlineTests.cs similarity index 100% rename from UnitTests/Markdown/Parse/ImageInlineTests.cs rename to UnitTests/UnitTests.UWP/Markdown/Parse/ImageInlineTests.cs diff --git a/UnitTests/Markdown/Parse/ItalicTests.cs b/UnitTests/UnitTests.UWP/Markdown/Parse/ItalicTests.cs similarity index 100% rename from UnitTests/Markdown/Parse/ItalicTests.cs rename to UnitTests/UnitTests.UWP/Markdown/Parse/ItalicTests.cs diff --git a/UnitTests/Markdown/Parse/ListTests.cs b/UnitTests/UnitTests.UWP/Markdown/Parse/ListTests.cs similarity index 100% rename from UnitTests/Markdown/Parse/ListTests.cs rename to UnitTests/UnitTests.UWP/Markdown/Parse/ListTests.cs diff --git a/UnitTests/Markdown/Parse/MarkdownLinkTests.cs b/UnitTests/UnitTests.UWP/Markdown/Parse/MarkdownLinkTests.cs similarity index 100% rename from UnitTests/Markdown/Parse/MarkdownLinkTests.cs rename to UnitTests/UnitTests.UWP/Markdown/Parse/MarkdownLinkTests.cs diff --git a/UnitTests/Markdown/Parse/ParagraphTests.cs b/UnitTests/UnitTests.UWP/Markdown/Parse/ParagraphTests.cs similarity index 100% rename from UnitTests/Markdown/Parse/ParagraphTests.cs rename to UnitTests/UnitTests.UWP/Markdown/Parse/ParagraphTests.cs diff --git a/UnitTests/Markdown/Parse/ParseTestBase.cs b/UnitTests/UnitTests.UWP/Markdown/Parse/ParseTestBase.cs similarity index 100% rename from UnitTests/Markdown/Parse/ParseTestBase.cs rename to UnitTests/UnitTests.UWP/Markdown/Parse/ParseTestBase.cs diff --git a/UnitTests/Markdown/Parse/ParseTestExtensionMethods.cs b/UnitTests/UnitTests.UWP/Markdown/Parse/ParseTestExtensionMethods.cs similarity index 100% rename from UnitTests/Markdown/Parse/ParseTestExtensionMethods.cs rename to UnitTests/UnitTests.UWP/Markdown/Parse/ParseTestExtensionMethods.cs diff --git a/UnitTests/Markdown/Parse/QuoteTests.cs b/UnitTests/UnitTests.UWP/Markdown/Parse/QuoteTests.cs similarity index 100% rename from UnitTests/Markdown/Parse/QuoteTests.cs rename to UnitTests/UnitTests.UWP/Markdown/Parse/QuoteTests.cs diff --git a/UnitTests/Markdown/Parse/StrikethroughTests.cs b/UnitTests/UnitTests.UWP/Markdown/Parse/StrikethroughTests.cs similarity index 100% rename from UnitTests/Markdown/Parse/StrikethroughTests.cs rename to UnitTests/UnitTests.UWP/Markdown/Parse/StrikethroughTests.cs diff --git a/UnitTests/Markdown/Parse/SubscriptTests.cs b/UnitTests/UnitTests.UWP/Markdown/Parse/SubscriptTests.cs similarity index 100% rename from UnitTests/Markdown/Parse/SubscriptTests.cs rename to UnitTests/UnitTests.UWP/Markdown/Parse/SubscriptTests.cs diff --git a/UnitTests/Markdown/Parse/SuperscriptTests.cs b/UnitTests/UnitTests.UWP/Markdown/Parse/SuperscriptTests.cs similarity index 100% rename from UnitTests/Markdown/Parse/SuperscriptTests.cs rename to UnitTests/UnitTests.UWP/Markdown/Parse/SuperscriptTests.cs diff --git a/UnitTests/Markdown/Parse/TableTests.cs b/UnitTests/UnitTests.UWP/Markdown/Parse/TableTests.cs similarity index 100% rename from UnitTests/Markdown/Parse/TableTests.cs rename to UnitTests/UnitTests.UWP/Markdown/Parse/TableTests.cs diff --git a/UnitTests/Markdown/TestBase.cs b/UnitTests/UnitTests.UWP/Markdown/TestBase.cs similarity index 100% rename from UnitTests/Markdown/TestBase.cs rename to UnitTests/UnitTests.UWP/Markdown/TestBase.cs diff --git a/UnitTests/MarkdownTests.playlist b/UnitTests/UnitTests.UWP/MarkdownTests.playlist similarity index 100% rename from UnitTests/MarkdownTests.playlist rename to UnitTests/UnitTests.UWP/MarkdownTests.playlist diff --git a/UnitTests/Package.appxmanifest b/UnitTests/UnitTests.UWP/Package.appxmanifest similarity index 100% rename from UnitTests/Package.appxmanifest rename to UnitTests/UnitTests.UWP/Package.appxmanifest diff --git a/UnitTests/Properties/AssemblyInfo.cs b/UnitTests/UnitTests.UWP/Properties/AssemblyInfo.cs similarity index 100% rename from UnitTests/Properties/AssemblyInfo.cs rename to UnitTests/UnitTests.UWP/Properties/AssemblyInfo.cs diff --git a/UnitTests/Properties/UnitTestApp.rd.xml b/UnitTests/UnitTests.UWP/Properties/UnitTestApp.rd.xml similarity index 100% rename from UnitTests/Properties/UnitTestApp.rd.xml rename to UnitTests/UnitTests.UWP/Properties/UnitTestApp.rd.xml diff --git a/UnitTests/UI/Controls/Test_MasterDetailsView.cs b/UnitTests/UnitTests.UWP/UI/Controls/Test_MasterDetailsView.cs similarity index 96% rename from UnitTests/UI/Controls/Test_MasterDetailsView.cs rename to UnitTests/UnitTests.UWP/UI/Controls/Test_MasterDetailsView.cs index ce06802fd97..7108d74e020 100644 --- a/UnitTests/UI/Controls/Test_MasterDetailsView.cs +++ b/UnitTests/UnitTests.UWP/UI/Controls/Test_MasterDetailsView.cs @@ -5,11 +5,7 @@ using Microsoft.Toolkit.Uwp.UI.Controls; using Microsoft.VisualStudio.TestTools.UnitTesting; using Microsoft.VisualStudio.TestTools.UnitTesting.AppContainer; -using System; -using System.Collections.Generic; using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace UnitTests.UI.Controls { diff --git a/UnitTests/UI/Controls/Test_UniformGrid_AutoLayout.cs b/UnitTests/UnitTests.UWP/UI/Controls/Test_UniformGrid_AutoLayout.cs similarity index 100% rename from UnitTests/UI/Controls/Test_UniformGrid_AutoLayout.cs rename to UnitTests/UnitTests.UWP/UI/Controls/Test_UniformGrid_AutoLayout.cs diff --git a/UnitTests/UI/Controls/Test_UniformGrid_Dimensions.cs b/UnitTests/UnitTests.UWP/UI/Controls/Test_UniformGrid_Dimensions.cs similarity index 100% rename from UnitTests/UI/Controls/Test_UniformGrid_Dimensions.cs rename to UnitTests/UnitTests.UWP/UI/Controls/Test_UniformGrid_Dimensions.cs diff --git a/UnitTests/UI/Controls/Test_UniformGrid_FreeSpots.cs b/UnitTests/UnitTests.UWP/UI/Controls/Test_UniformGrid_FreeSpots.cs similarity index 100% rename from UnitTests/UI/Controls/Test_UniformGrid_FreeSpots.cs rename to UnitTests/UnitTests.UWP/UI/Controls/Test_UniformGrid_FreeSpots.cs diff --git a/UnitTests/UI/Controls/Test_UniformGrid_RowColDefinitions.cs b/UnitTests/UnitTests.UWP/UI/Controls/Test_UniformGrid_RowColDefinitions.cs similarity index 100% rename from UnitTests/UI/Controls/Test_UniformGrid_RowColDefinitions.cs rename to UnitTests/UnitTests.UWP/UI/Controls/Test_UniformGrid_RowColDefinitions.cs diff --git a/UnitTests/UI/Person.cs b/UnitTests/UnitTests.UWP/UI/Person.cs similarity index 100% rename from UnitTests/UI/Person.cs rename to UnitTests/UnitTests.UWP/UI/Person.cs diff --git a/UnitTests/UI/Test_AdvancedCollectionView.cs b/UnitTests/UnitTests.UWP/UI/Test_AdvancedCollectionView.cs similarity index 100% rename from UnitTests/UI/Test_AdvancedCollectionView.cs rename to UnitTests/UnitTests.UWP/UI/Test_AdvancedCollectionView.cs diff --git a/UnitTests/UnitTestApp.xaml b/UnitTests/UnitTests.UWP/UnitTestApp.xaml similarity index 100% rename from UnitTests/UnitTestApp.xaml rename to UnitTests/UnitTests.UWP/UnitTestApp.xaml diff --git a/UnitTests/UnitTestApp.xaml.cs b/UnitTests/UnitTests.UWP/UnitTestApp.xaml.cs similarity index 100% rename from UnitTests/UnitTestApp.xaml.cs rename to UnitTests/UnitTests.UWP/UnitTestApp.xaml.cs diff --git a/UnitTests/UnitTests.csproj b/UnitTests/UnitTests.UWP/UnitTests.UWP.csproj similarity index 93% rename from UnitTests/UnitTests.csproj rename to UnitTests/UnitTests.UWP/UnitTests.UWP.csproj index aa8b45ce03c..4ef9d4a130a 100644 --- a/UnitTests/UnitTests.csproj +++ b/UnitTests/UnitTests.UWP/UnitTests.UWP.csproj @@ -7,8 +7,8 @@ {A139968E-AD78-4E8C-93B8-9A5523BCAC89} AppContainerExe Properties - UnitTests - UnitTests + UnitTests.UWP + UnitTests.UWP en-US UAP 10.0.17763.0 @@ -123,19 +123,12 @@ - - - - - - - @@ -168,11 +161,6 @@ - - - - - @@ -210,31 +198,31 @@ - + {42ca4935-54be-42ea-ac19-992378c08de6} Microsoft.Toolkit.Parsers - + {34398053-fc70-4243-84f9-f355defff66d} Microsoft.Toolkit.Services - + {b1e850ff-dde6-44d5-a830-34250e97a687} Microsoft.Toolkit.Uwp.Connectivity - + {e9faabfb-d726-42c1-83c1-cb46a29fea81} Microsoft.Toolkit.Uwp.UI.Controls - + {3dd8aa7c-3569-4e51-992f-0c2257e8878e} Microsoft.Toolkit.Uwp.UI - + {805f80df-75c6-4c2f-8fd9-b47f6d0df5a3} Microsoft.Toolkit.Uwp - + {6fe128a8-cefa-4a61-a987-ec92de6b538e} Microsoft.Toolkit @@ -243,6 +231,7 @@ + 14.0 diff --git a/UnitTests/UnitTests_TemporaryKey.pfx b/UnitTests/UnitTests_TemporaryKey.pfx deleted file mode 100644 index d607f92beb7..00000000000 Binary files a/UnitTests/UnitTests_TemporaryKey.pfx and /dev/null differ diff --git a/Windows Community Toolkit.sln b/Windows Community Toolkit.sln index b963eda466f..18f0b2186ef 100644 --- a/Windows Community Toolkit.sln +++ b/Windows Community Toolkit.sln @@ -9,7 +9,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Toolkit.Uwp.Sampl EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Toolkit.Uwp", "Microsoft.Toolkit.Uwp\Microsoft.Toolkit.Uwp.csproj", "{805F80DF-75C6-4C2F-8FD9-B47F6D0DF5A3}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnitTests", "UnitTests\UnitTests.csproj", "{A139968E-AD78-4E8C-93B8-9A5523BCAC89}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnitTests.UWP", "UnitTests\UnitTests.UWP\UnitTests.UWP.csproj", "{A139968E-AD78-4E8C-93B8-9A5523BCAC89}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Toolkit.Uwp.UI", "Microsoft.Toolkit.Uwp.UI\Microsoft.Toolkit.Uwp.UI.csproj", "{3DD8AA7C-3569-4E51-992F-0C2257E8878E}" EndProject @@ -90,7 +90,12 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GazeInputTest", "GazeInputT EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Toolkit.Uwp.UI.Media", "Microsoft.Toolkit.Uwp.UI.Media\Microsoft.Toolkit.Uwp.UI.Media.csproj", "{75F9EE44-3EFA-47BC-AEDD-351B9834A0AF}" EndProject +Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "UnitTests.Shared", "UnitTests\UnitTests.Shared\UnitTests.Shared.shproj", "{4E9466D1-D5AA-46AC-801B-C8FDAB79F0D4}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UnitTests.NetCore", "UnitTests\UnitTests.NetCore\UnitTests.NetCore.csproj", "{7878CD00-85E8-4D02-9757-8A43DB4C6510}" +EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Toolkit.Uwp.UI.Controls.Layout", "Microsoft.Toolkit.Uwp.UI.Controls.Layout\Microsoft.Toolkit.Uwp.UI.Controls.Layout.csproj", "{CB444381-18BA-4A51-BB32-3A498BCC1E99}" +EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Toolkit.HighPerformance", "Microsoft.Toolkit.HighPerformance\Microsoft.Toolkit.HighPerformance.csproj", "{7E30D48C-4CD8-47BE-B557-10A20391DCC4}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UnitTests.HighPerformance.NetCore", "UnitTests\UnitTests.HighPerformance.NetCore\UnitTests.HighPerformance.NetCore.csproj", "{D9BDBC68-3D0A-47FC-9C88-0BF769101644}" @@ -103,6 +108,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnitTests.HighPerformance.U EndProject Global GlobalSection(SharedMSBuildProjectFiles) = preSolution + UnitTests\UnitTests.Shared\UnitTests.Shared.projitems*{4e9466d1-d5aa-46ac-801b-c8fdab79f0d4}*SharedItemsImports = 13 + UnitTests\UnitTests.Shared\UnitTests.Shared.projitems*{7878cd00-85e8-4d02-9757-8a43db4c6510}*SharedItemsImports = 5 + UnitTests\UnitTests.Notifications.Shared\UnitTests.Notifications.Shared.projitems*{982cc826-aacd-4855-9075-430bb6ce40a9}*SharedItemsImports = 13 + UnitTests\UnitTests.Shared\UnitTests.Shared.projitems*{a139968e-ad78-4e8c-93b8-9a5523bcac89}*SharedItemsImports = 4 UnitTests\UnitTests.HighPerformance.Shared\UnitTests.HighPerformance.Shared.projitems*{5524523e-db0f-41f7-a0d4-43128422a342}*SharedItemsImports = 4 UnitTests\UnitTests.Notifications.Shared\UnitTests.Notifications.Shared.projitems*{982cc826-aacd-4855-9075-430bb6ce40a9}*SharedItemsImports = 13 UnitTests\UnitTests.HighPerformance.Shared\UnitTests.HighPerformance.Shared.projitems*{9b3a94a6-0d29-4523-880b-6938e2efeef7}*SharedItemsImports = 13 @@ -814,6 +823,31 @@ Global {75F9EE44-3EFA-47BC-AEDD-351B9834A0AF}.Release|x64.Build.0 = Release|Any CPU {75F9EE44-3EFA-47BC-AEDD-351B9834A0AF}.Release|x86.ActiveCfg = Release|Any CPU {75F9EE44-3EFA-47BC-AEDD-351B9834A0AF}.Release|x86.Build.0 = Release|Any CPU + {7878CD00-85E8-4D02-9757-8A43DB4C6510}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7878CD00-85E8-4D02-9757-8A43DB4C6510}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7878CD00-85E8-4D02-9757-8A43DB4C6510}.Debug|ARM.ActiveCfg = Debug|Any CPU + {7878CD00-85E8-4D02-9757-8A43DB4C6510}.Debug|ARM.Build.0 = Debug|Any CPU + {7878CD00-85E8-4D02-9757-8A43DB4C6510}.Debug|ARM64.ActiveCfg = Debug|Any CPU + {7878CD00-85E8-4D02-9757-8A43DB4C6510}.Debug|ARM64.Build.0 = Debug|Any CPU + {7878CD00-85E8-4D02-9757-8A43DB4C6510}.Debug|x64.ActiveCfg = Debug|Any CPU + {7878CD00-85E8-4D02-9757-8A43DB4C6510}.Debug|x64.Build.0 = Debug|Any CPU + {7878CD00-85E8-4D02-9757-8A43DB4C6510}.Debug|x86.ActiveCfg = Debug|Any CPU + {7878CD00-85E8-4D02-9757-8A43DB4C6510}.Debug|x86.Build.0 = Debug|Any CPU + {7878CD00-85E8-4D02-9757-8A43DB4C6510}.Native|Any CPU.ActiveCfg = Debug|Any CPU + {7878CD00-85E8-4D02-9757-8A43DB4C6510}.Native|ARM.ActiveCfg = Debug|Any CPU + {7878CD00-85E8-4D02-9757-8A43DB4C6510}.Native|ARM64.ActiveCfg = Debug|Any CPU + {7878CD00-85E8-4D02-9757-8A43DB4C6510}.Native|x64.ActiveCfg = Debug|Any CPU + {7878CD00-85E8-4D02-9757-8A43DB4C6510}.Native|x86.ActiveCfg = Debug|Any CPU + {7878CD00-85E8-4D02-9757-8A43DB4C6510}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7878CD00-85E8-4D02-9757-8A43DB4C6510}.Release|Any CPU.Build.0 = Release|Any CPU + {7878CD00-85E8-4D02-9757-8A43DB4C6510}.Release|ARM.ActiveCfg = Release|Any CPU + {7878CD00-85E8-4D02-9757-8A43DB4C6510}.Release|ARM.Build.0 = Release|Any CPU + {7878CD00-85E8-4D02-9757-8A43DB4C6510}.Release|ARM64.ActiveCfg = Release|Any CPU + {7878CD00-85E8-4D02-9757-8A43DB4C6510}.Release|ARM64.Build.0 = Release|Any CPU + {7878CD00-85E8-4D02-9757-8A43DB4C6510}.Release|x64.ActiveCfg = Release|Any CPU + {7878CD00-85E8-4D02-9757-8A43DB4C6510}.Release|x64.Build.0 = Release|Any CPU + {7878CD00-85E8-4D02-9757-8A43DB4C6510}.Release|x86.ActiveCfg = Release|Any CPU + {7878CD00-85E8-4D02-9757-8A43DB4C6510}.Release|x86.Build.0 = Release|Any CPU {CB444381-18BA-4A51-BB32-3A498BCC1E99}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {CB444381-18BA-4A51-BB32-3A498BCC1E99}.Debug|Any CPU.Build.0 = Debug|Any CPU {CB444381-18BA-4A51-BB32-3A498BCC1E99}.Debug|ARM.ActiveCfg = Debug|Any CPU @@ -950,6 +984,8 @@ Global {262BB7CE-EF42-4BF7-B90C-107E6CBB57FF} = {096ECFD7-7035-4487-9C87-81DCE9389620} {A122EA02-4DE7-413D-BFBF-AF7DFC668DD6} = {B30036C4-D514-4E5B-A323-587A061772CE} {75F9EE44-3EFA-47BC-AEDD-351B9834A0AF} = {F1AFFFA7-28FE-4770-BA48-10D76F3E59BC} + {4E9466D1-D5AA-46AC-801B-C8FDAB79F0D4} = {B30036C4-D514-4E5B-A323-587A061772CE} + {7878CD00-85E8-4D02-9757-8A43DB4C6510} = {B30036C4-D514-4E5B-A323-587A061772CE} {CB444381-18BA-4A51-BB32-3A498BCC1E99} = {F1AFFFA7-28FE-4770-BA48-10D76F3E59BC} {D9BDBC68-3D0A-47FC-9C88-0BF769101644} = {262CDB74-CF21-47AC-8DD9-CBC33C73B7CF} {9B3A94A6-0D29-4523-880B-6938E2EFEEF7} = {262CDB74-CF21-47AC-8DD9-CBC33C73B7CF}