Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

test: Update to MSTest dogfooding version #19271

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .globalconfig
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ dotnet_diagnostic.IDE0051.severity = warning
# MSTEST0004: Public types should be test classes
# dotnet_diagnostic.MSTEST0004.severity = warning

# MSTEST0006: Avoid '[ExpectedException]'
dotnet_diagnostic.MSTEST0006.severity = warning
Comment on lines +157 to +158
Copy link
Member Author

@Youssef1313 Youssef1313 Jan 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI microsoft/testfx#135 so you have context why we implemented the analyzer and why to enable it.


# MSTEST0007: Use test attributes only on test methods
dotnet_diagnostic.MSTEST0007.severity = warning

Expand Down
10 changes: 7 additions & 3 deletions src/Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
<Product Condition="'$(UnoRuntimeIdentifier)' != ''">$(AssemblyName) ($(TargetFramework) $(UnoRuntimeIdentifier))</Product>
<CommunityToolkitMvvmVersion>8.2.2</CommunityToolkitMvvmVersion>
<TestingPlatformDotNetTestSupport Condition="'$(IsTestingPlatformApplication)' == 'true'">true</TestingPlatformDotNetTestSupport>

<!-- Dogfooding feed for MSTest -->
<RestoreAdditionalProjectSources>$(RestoreAdditionalProjectSources);https://dnceng.pkgs.visualstudio.com/public/_packaging/test-tools/nuget/v3/index.json</RestoreAdditionalProjectSources>
</PropertyGroup>

<PropertyGroup>
Expand Down Expand Up @@ -64,12 +67,13 @@
<PropertyGroup>
<!-- IMPORTANT!!! KEEP BOTH MSTest and MTP versions in sync -->
<!-- For a given MSTest version, go to https://www.nuget.org/packages/MSTest.TestAdapter/3.7.1#dependencies-body-tab -->
<!-- (replacing 3.7.1 in the url with the MSTest version in question) -->
<!-- (Or, for dogfooding versions, go to https://dnceng.visualstudio.com/public/_artifacts/feed/test-tools/NuGet/MSTest.TestAdapter/overview/3.8.0-preview.25067.5) -->
<!-- (replacing the version in the url with the MSTest version in question) -->
<!-- And look for MTP version in there, and make sure MicrosoftTestingPlatformVersion is the same -->
<!-- Alternatively, migrate to MSTest.Sdk and let it handle the MTP versioning for you -->
<!-- In case of MSTest.Sdk, the TrxReport package will not be needed. It will be added automatically -->
<MSTestVersion>3.7.1</MSTestVersion>
<MicrosoftTestingPlatformVersion>1.5.1</MicrosoftTestingPlatformVersion>
<MSTestVersion>3.8.0-preview.25067.5</MSTestVersion>
<MicrosoftTestingPlatformVersion>1.6.0-preview.25067.5</MicrosoftTestingPlatformVersion>

<SkiaSharpVersion>2.88.7</SkiaSharpVersion>
<!-- TODO: Uncomment when we're net8.0+ to have SamplesApp serve as a good test for SkiaSharp 3 support -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public void Parsed_Geometry_ToString_Should_Format_Value(string pathData, string
[DataRow("j")]
public void Throws_InvalidDataException_On_None_Defined_Command(string pathData)
{
Assert.ThrowsException<InvalidDataException>(() => Parse(pathData));
Assert.ThrowsExactly<InvalidDataException>(() => Parse(pathData));
}

[TestMethod]
Expand Down
4 changes: 2 additions & 2 deletions src/Uno.UI.RuntimeTests/MUX/Utilities/MSTestInterop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,12 @@ public static void Fail(string message, params object[] args)

public static void Throws<T>(Action action, string message) where T : Exception
{
Assert.ThrowsException<T>(action, message);
Assert.ThrowsExactly<T>(action, message);
}

public static void Throws<T>(Action action) where T : Exception
{
Assert.ThrowsException<T>(action);
Assert.ThrowsExactly<T>(action);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class Given_AppDataUriEvaluator
[TestMethod]
public void When_Uri_Is_Null()
{
Assert.ThrowsException<ArgumentNullException>(
Assert.ThrowsExactly<ArgumentNullException>(
() => AppDataUriEvaluator.ToPath(null));
}

Expand All @@ -27,7 +27,7 @@ public void When_Uri_Has_Different_Scheme()
{
var uri = new Uri("ms-appx:///local/test.txt");

Assert.ThrowsException<ArgumentOutOfRangeException>(
Assert.ThrowsExactly<ArgumentOutOfRangeException>(
() => AppDataUriEvaluator.ToPath(uri));
}

Expand All @@ -36,7 +36,7 @@ public void When_Uri_Is_Not_Absolute()
{
var uri = new Uri("local/test.txt", UriKind.Relative);

Assert.ThrowsException<ArgumentOutOfRangeException>(
Assert.ThrowsExactly<ArgumentOutOfRangeException>(
() => AppDataUriEvaluator.ToPath(uri));
}

Expand All @@ -45,7 +45,7 @@ public void When_Uri_Has_No_Path()
{
var uri = new Uri("ms-appdata:");

Assert.ThrowsException<ArgumentOutOfRangeException>(
Assert.ThrowsExactly<ArgumentOutOfRangeException>(
() => AppDataUriEvaluator.ToPath(uri));
}

Expand All @@ -54,7 +54,7 @@ public void When_Uri_Has_No_Subfolder_Specification()
{
var uri = new Uri("ms-appdata:///");

Assert.ThrowsException<ArgumentOutOfRangeException>(
Assert.ThrowsExactly<ArgumentOutOfRangeException>(
() => AppDataUriEvaluator.ToPath(uri));
}

Expand Down Expand Up @@ -93,7 +93,7 @@ public void When_Uri_Is_RoamingFolder_But_Has_Suffix()
{
var uri = new Uri("ms-appdata:///roamingfolder/");

Assert.ThrowsException<ArgumentOutOfRangeException>(
Assert.ThrowsExactly<ArgumentOutOfRangeException>(
() => AppDataUriEvaluator.ToPath(uri));
}

Expand All @@ -112,7 +112,7 @@ public void When_Uri_Starts_With_Invalid_Folder()
{
var uri = new Uri($"ms-appdata:///space/file.png");

Assert.ThrowsException<ArgumentOutOfRangeException>(
Assert.ThrowsExactly<ArgumentOutOfRangeException>(
() => AppDataUriEvaluator.ToPath(uri));
}

Expand Down Expand Up @@ -147,7 +147,7 @@ public void When_Uri_Contains_Package_Name_But_Has_Suffix()
var packageName = Package.Current.Id.Name;
var uri = new Uri($"ms-appdata://{packageName}abcd/local/file.png");

Assert.ThrowsException<ArgumentOutOfRangeException>(
Assert.ThrowsExactly<ArgumentOutOfRangeException>(
() => AppDataUriEvaluator.ToPath(uri));
}

Expand Down Expand Up @@ -195,7 +195,7 @@ public void When_Double_Dot_Backs_Out_Above_App_Data()
{
var uri = new Uri("ms-appdata:///local/../hello/logo.png");

Assert.ThrowsException<ArgumentOutOfRangeException>(
Assert.ThrowsExactly<ArgumentOutOfRangeException>(
() => AppDataUriEvaluator.ToPath(uri));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class Given_EmailManager
[TestMethod]
public async Task When_EmailMessage_Is_Null()
{
await Assert.ThrowsExceptionAsync<ArgumentNullException>(
await Assert.ThrowsExactlyAsync<ArgumentNullException>(
async () => await EmailManager.ShowComposeNewEmailAsync(null));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,15 @@ public void When_Body_Default()
public void When_Body_Set_Null()
{
var emailMessage = new EmailMessage();
Assert.ThrowsException<ArgumentNullException>(
Assert.ThrowsExactly<ArgumentNullException>(
() => emailMessage.Body = null);
}

[TestMethod]
public void When_Subject_Set_Null()
{
var emailMessage = new EmailMessage();
Assert.ThrowsException<ArgumentNullException>(
Assert.ThrowsExactly<ArgumentNullException>(
() => emailMessage.Subject = null);
}

Expand All @@ -83,23 +83,23 @@ public void When_Sender_Set_Null()
public void When_Null_To_Recipient_Is_Added()
{
var emailMessage = new EmailMessage();
Assert.ThrowsException<ArgumentNullException>(
Assert.ThrowsExactly<ArgumentNullException>(
() => emailMessage.To.Add(null));
}

[TestMethod]
public void When_Null_CC_Recipient_Is_Added()
{
var emailMessage = new EmailMessage();
Assert.ThrowsException<ArgumentNullException>(
Assert.ThrowsExactly<ArgumentNullException>(
() => emailMessage.CC.Add(null));
}

[TestMethod]
public void When_Null_Bcc_Recipient_Is_Added()
{
var emailMessage = new EmailMessage();
Assert.ThrowsException<ArgumentNullException>(
Assert.ThrowsExactly<ArgumentNullException>(
() => emailMessage.Bcc.Add(null));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,30 @@ public class Given_EmailRecipient
[TestMethod]
public void When_Address_Is_Null()
{
Assert.ThrowsException<ArgumentNullException>(
Assert.ThrowsExactly<ArgumentNullException>(
() => new EmailRecipient(null));
}

[TestMethod]
public void When_Name_Is_Null()
{
Assert.ThrowsException<ArgumentNullException>(
Assert.ThrowsExactly<ArgumentNullException>(
() => new EmailRecipient("[email protected]", null));
}

[TestMethod]
public void When_Address_Set_Null()
{
var emailRecipient = new EmailRecipient();
Assert.ThrowsException<ArgumentNullException>(
Assert.ThrowsExactly<ArgumentNullException>(
() => emailRecipient.Address = null);
}

[TestMethod]
public void When_Name_Set_Null()
{
var emailRecipient = new EmailRecipient();
Assert.ThrowsException<ArgumentNullException>(
Assert.ThrowsExactly<ArgumentNullException>(
() => emailRecipient.Name = null);
}

Expand Down
42 changes: 24 additions & 18 deletions src/Uno.UI.RuntimeTests/Tests/Windows_Data/Pdf/Given_PdfDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,31 +121,33 @@ public async Task When_LoadFromStreamAsync()
}

[TestMethod]
#if XAMARIN_ANDROID
[ExpectedException(typeof(NotImplementedException))]
#endif
public async Task When_LoadFromStreamAsync_With_Valid_Password()
{
var stream = GetSreamFromResource(PdfDocument_Name_Protected)?.AsRandomAccessStream();
Assert.IsNotNull(stream, "Not valid stream");

PdfDocument? pdfDocument = await PdfDocument.LoadFromStreamAsync(stream, PdfDocument_Password_Valid);
#if __ANDROID__
await Assert.ThrowsAsync<NotImplementedException>(() => await PdfDocument.LoadFromStreamAsync(stream, PdfDocument_Password_Valid));
#else
var pdfDocument = await PdfDocument.LoadFromStreamAsync(stream, PdfDocument_Password_Valid);
await CheckDocumentAsync(pdfDocument, ReferencePageImage_ProtectedUri, hasPassword: true);
#endif
}

[TestMethod]
#if XAMARIN_ANDROID
[ExpectedException(typeof(NotImplementedException))]
#elif !HAS_UNO
[ExpectedException(typeof(Exception))]
#endif
public async Task When_LoadFromStreamAsync_With_Wrong_Password()
{
var stream = GetSreamFromResource(PdfDocument_Name_Protected)?.AsRandomAccessStream();
Assert.IsNotNull(stream, "Not valid stream");

PdfDocument? pdfDocument = await PdfDocument.LoadFromStreamAsync(stream, PdfDocument_Password_Invalid);
#if __ANDROID__
await Assert.ThrowsAsync<NotImplementedException>(() => await PdfDocument.LoadFromStreamAsync(stream, PdfDocument_Password_Invalid));
#elif !HAS_UNO
await Assert.ThrowsAsync<Exception>(() => await PdfDocument.LoadFromStreamAsync(stream, PdfDocument_Password_Invalid));
#else
var pdfDocument = await PdfDocument.LoadFromStreamAsync(stream, PdfDocument_Password_Valid);
await CheckDocumentAsync(pdfDocument, ReferencePageImage_ProtectedUri, hasPassword: true);
#endif
}


Expand All @@ -166,9 +168,6 @@ public async Task When_LoadFromFileAsync()
}

[TestMethod]
#if XAMARIN_ANDROID
[ExpectedException(typeof(NotImplementedException))]
#endif
public async Task When_LoadFromFileAsync_Valid_Password()
{
var testFolderName = Guid.NewGuid().ToString();
Expand All @@ -180,16 +179,16 @@ public async Task When_LoadFromFileAsync_Valid_Password()
Assert.IsNotNull(source);
await source.CopyToAsync(ws);
}

#if __ANDROID__
await Assert.ThrowsAsync<NotImplementedException>(() => await PdfDocument.LoadFromStreamAsync(stream, PdfDocument_Password_Valid));
#else
var pdfDocument = await PdfDocument.LoadFromFileAsync(file, PdfDocument_Password_Valid);
await CheckDocumentAsync(pdfDocument, ReferencePageImage_ProtectedUri, hasPassword: true);
#endif
}

[TestMethod]
#if XAMARIN_ANDROID
[ExpectedException(typeof(NotImplementedException))]
#elif !HAS_UNO
[ExpectedException(typeof(Exception))]
#endif
public async Task When_LoadFromFileAsync_Wrong_Password()
{
var testFolderName = Guid.NewGuid().ToString();
Expand All @@ -201,8 +200,15 @@ public async Task When_LoadFromFileAsync_Wrong_Password()
Assert.IsNotNull(source);
await source.CopyToAsync(ws);
}

#if __ANDROID__
await Assert.ThrowsAsync<NotImplementedException>(() => await PdfDocument.LoadFromFileAsync(file, PdfDocument_Password_Invalid));
#elif !HAS_UNO
await Assert.ThrowsAsync<Exception>(() => await PdfDocument.LoadFromFileAsync(file, PdfDocument_Password_Invalid));
#else
var pdfDocument = await PdfDocument.LoadFromFileAsync(file, PdfDocument_Password_Invalid);
await CheckDocumentAsync(pdfDocument, ReferencePageImage_ProtectedUri, hasPassword: true);
#endif
}

[TestMethod]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ public void When_RawData()
[TestMethod]
public void When_Channel_Out_Of_Bounds()
{
Assert.ThrowsException<ArgumentException>(
Assert.ThrowsExactly<ArgumentException>(
() => new MidiChannelPressureMessage(16, 10));
}

[TestMethod]
public void When_Pressure_Out_Of_Bounds()
{
Assert.ThrowsException<ArgumentException>(
Assert.ThrowsExactly<ArgumentException>(
() => new MidiChannelPressureMessage(12, 128));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,21 @@ public void When_RawData()
[TestMethod]
public void When_Channel_Out_Of_Bounds()
{
Assert.ThrowsException<ArgumentException>(
Assert.ThrowsExactly<ArgumentException>(
() => new MidiControlChangeMessage(16, 10, 10));
}

[TestMethod]
public void When_Controller_Out_Of_Bounds()
{
Assert.ThrowsException<ArgumentException>(
Assert.ThrowsExactly<ArgumentException>(
() => new MidiControlChangeMessage(12, 128, 10));
}

[TestMethod]
public void When_ControlChange_Out_Of_Bounds()
{
Assert.ThrowsException<ArgumentException>(
Assert.ThrowsExactly<ArgumentException>(
() => new MidiControlChangeMessage(12, 10, 128));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,21 @@ public void When_RawData()
[TestMethod]
public void When_Channel_Out_Of_Bounds()
{
Assert.ThrowsException<ArgumentException>(
Assert.ThrowsExactly<ArgumentException>(
() => new MidiNoteOffMessage(16, 10, 10));
}

[TestMethod]
public void When_Note_Out_Of_Bounds()
{
Assert.ThrowsException<ArgumentException>(
Assert.ThrowsExactly<ArgumentException>(
() => new MidiNoteOffMessage(12, 128, 10));
}

[TestMethod]
public void When_Velocity_Out_Of_Bounds()
{
Assert.ThrowsException<ArgumentException>(
Assert.ThrowsExactly<ArgumentException>(
() => new MidiNoteOffMessage(12, 10, 128));
}
}
Expand Down
Loading
Loading