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

Fix analyzer errors #19238

Merged
merged 10 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .globalconfig
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ dotnet_diagnostic.MSTEST0023.severity = warning
dotnet_diagnostic.MSTEST0025.severity = warning

# MSTEST0026: Avoid conditional access in assertions
dotnet_diagnostic.MSTEST0026.severity = warning
dotnet_diagnostic.MSTEST0026.severity = suggestion

# MSTEST0029: Public method should be test method
dotnet_diagnostic.MSTEST0029.severity = warning
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.ObjectModel;
using System.Linq;
using System.Threading;
Expand All @@ -13,6 +13,7 @@
using Windows.UI.Core;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace UITests.Windows_Storage
{
Expand Down Expand Up @@ -96,6 +97,7 @@ private async void RunFileIOTests()
}
}

#pragma warning disable MSTEST0030 // Type containing [TestMethod] should be marked with [TestClass] - instantiated explicitly.
public class Pickable_StorageFolder_Tests : Given_StorageFolder_Native_Base
{
private readonly StorageFolder _rootFolder;
Expand Down Expand Up @@ -131,4 +133,5 @@ public Pickable_FileIO_Tests(StorageFolder rootFolder)

protected override Task<StorageFolder> GetRootFolderAsync() => Task.FromResult(_rootFolder);
}
#pragma warning restore MSTEST0030
}
Original file line number Diff line number Diff line change
Expand Up @@ -561,8 +561,9 @@ await TestServices.RunOnUIThread(() =>
});
}

#if !__ANDROID__ && !__IOS__
[TestMethod]
#if __ANDROID__ || __IOS__
[Ignore]
#endif
public async Task CanZeroWeightedCellsShrinkToZeroSize()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,8 @@ public async Task EnsureReplaceOfAnchorDoesNotResetAllContainers()
});
}

//[TestMethod]
[TestMethod]
[Ignore]
public void ReplaceMultipleItems()
{
// TODO: Lower prioirty scenario. Tracked by work item: 9738020
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ void ItemsSourceView_CollectionChanged(object sender, NotifyCollectionChangedEve
}

//TODO Uno specific: This test is adjusted to pass on Android - UpdateLayout needs to be called twice.
public async Task ValidateSwitchingItemsSourceRefreshesElements(bool isVirtualLayout)
private async Task ValidateSwitchingItemsSourceRefreshesElements(bool isVirtualLayout)
{
const int numItems = 10;
ItemsRepeater repeater = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ await RunOnUIThread.ExecuteAsync(async () =>
});
}

public async Task ValidateTemplateSwitchingRefreshesElements(Layout layout)
private async Task ValidateTemplateSwitchingRefreshesElements(Layout layout)
{
var dataTemplate1 = (DataTemplate)XamlReader.Load(
@"<DataTemplate xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ namespace Microsoft.UI.Xaml.Tests.MUXControls.ApiTests.RepeaterTests
[TestClass]
public class RecyclePoolTests : MUXApiTestBase
{

[Ignore("https://github.com/unoplatform/uno/issues/9080")]
[TestMethod]
jeromelaban marked this conversation as resolved.
Show resolved Hide resolved
public void ValidateElementsHaveCorrectKeys()
{
RunOnUIThread.Execute(() =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ public void CanQueryElementFactory()
});
}

// [TestMethod] Issue #1018
[TestMethod] // Issue #1018
[Ignore]
public async Task CanPinFocusedElements()
{
// Setup a grouped repeater scenario with two groups each containing two items.
Expand Down Expand Up @@ -191,7 +192,8 @@ public async Task CanPinFocusedElements()
});
}

// [TestMethod] Issue 1018
[TestMethod] // Issue 1018
[Ignore]
public async Task CanReuseElementsDuringUniqueIdReset()
{
var data = new WinRTCollection(Enumerable.Range(0, 2).Select(i => string.Format("Item #{0}", i)));
Expand Down Expand Up @@ -678,7 +680,8 @@ public void ValidateDataContextGetsPropagated()
});
}

// [TestMethod] Issue 1018
[TestMethod] // Issue 1018
[Ignore]
public async Task ValidateFocusMoveOnElementCleared()
{
CustomItemsSource dataSource = null;
Expand Down Expand Up @@ -721,7 +724,8 @@ await SharedHelpers.RunActionsWithWait(
});
}

// [TestMethod] Issue 1018
[TestMethod] // Issue 1018
[Ignore]
public async Task ValidateFocusMoveOnElementClearedWithUniqueIds()
{
CustomItemsSource dataSource = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ public void ValidateNoScrollingSurfaceScenario()
});
}

// [TestMethod] Temporarily disabled for bug 18866003
[TestMethod] // Temporarily disabled for bug 18866003
[Ignore]
public async Task ValidateItemsRepeaterScrollHostScenario()
{
var realizationRects = new List<Rect>();
Expand Down Expand Up @@ -854,7 +855,8 @@ public void ValidateSuggestedElement()
});
}

// [TestMethod] Temporarily disabled for bug 18866003
[TestMethod] // Temporarily disabled for bug 18866003
[Ignore]
public async Task ValidateLoadUnload()
{
if (!PlatformConfiguration.IsOsVersionGreaterThan(OSVersion.Redstone2))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ await TestServices.RunOnUIThread(() =>
{
var timePickerFlyoutPresenter = TreeHelper.GetVisualChildByTypeFromOpenPopups<TimePickerFlyoutPresenter>(timePicker);
Assert.IsNotNull(timePickerFlyoutPresenter);
Assert.AreEqual(true, timePickerFlyoutPresenter.IsDefaultShadowEnabled);
Assert.IsTrue(timePickerFlyoutPresenter.IsDefaultShadowEnabled);
});
#endif
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,8 @@ await RunOnUIThread.ExecuteAsync(() =>
await TestServices.WindowHelper.WaitForIdle();
}

//[TestMethod] Disabled with issue number #1775 (WinUI issue)
[TestMethod] // Disabled with issue number #1775 (WinUI issue)
[Ignore]
public void TreeViewInheritanceTest()
{
StackPanel stackPanel = new StackPanel();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public async Task When_SelectedItem_Set_Before_Load_And_Theme_Changed()
#if __ANDROID__
// This is the meat of the test - we verify that the actual color of the TextBlock matches the managed Color, which will only be the
// case if it was correctly measured and arranged as requested after the theme changed.
Assert.AreEqual(false, iconTextBlock.IsLayoutRequested);
Assert.IsFalse(iconTextBlock.IsLayoutRequested);
Assert.AreEqual((Android.Graphics.Color)((iconTextBlock.Foreground as SolidColorBrush).Color), iconTextBlock.NativeArrangedColor);
#endif
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,11 @@ public async Task When_TreeViewItem_Dragged_Near_the_Edge()

mouse.MoveBy(0, 1);
await WindowHelper.WaitForIdle();
Assert.AreEqual(dragStartingCount, 0);
Assert.AreEqual(0, dragStartingCount);

mouse.MoveBy(0, 15); // move out of the tvi
await WindowHelper.WaitForIdle();
Assert.AreEqual(dragStartingCount, 1);
Assert.AreEqual(1, dragStartingCount);
}
#endif

Expand Down Expand Up @@ -703,8 +703,8 @@ public async Task When_SelectedItem_NotExpandedToExpanded()
// assert: before expanding
Assert.AreEqual(targetItem, tvm.SelectedItem, "[collapsed]invalid tvm.SelectedItem");
Assert.AreEqual(targetItem, SUT.SelectedItem, "[collapsed]invalid SUT.SelectedItem");
Assert.AreEqual(null, SUT.SelectedNode, "[collapsed]invalid SUT.SelectedNode should be null");
Assert.AreEqual(null, SUT.NodeFromContainer(SUT.ContainerFromItem(targetItem)), "[collapsed]selected node should not exist yet");
Assert.IsNull(SUT.SelectedNode, "[collapsed]invalid SUT.SelectedNode should be null");
Assert.IsNull(SUT.NodeFromContainer(SUT.ContainerFromItem(targetItem)), "[collapsed]selected node should not exist yet");

// expand the ancestry from top-down
for (int i = 1; i < targetItem.Label.Length; i++)
Expand Down Expand Up @@ -768,10 +768,10 @@ public async Task When_IsSelectedItem_NotExpandedToExpanded()
await UITestHelper.Load(setup);

// assert: before expanding
Assert.AreEqual(null, tvm.SelectedItem, "[collapsed]invalid tvm.SelectedItem");
Assert.AreEqual(null, SUT.SelectedItem, "[collapsed]invalid SUT.SelectedItem");
Assert.AreEqual(null, SUT.SelectedNode, "[collapsed]invalid SUT.SelectedNode should be null");
Assert.AreEqual(null, SUT.NodeFromContainer(SUT.ContainerFromItem(targetItem)), "[collapsed]selected node should not exist yet");
Assert.IsNull(tvm.SelectedItem, "[collapsed]invalid tvm.SelectedItem");
Assert.IsNull(SUT.SelectedItem, "[collapsed]invalid SUT.SelectedItem");
Assert.IsNull(SUT.SelectedNode, "[collapsed]invalid SUT.SelectedNode should be null");
Assert.IsNull(SUT.NodeFromContainer(SUT.ContainerFromItem(targetItem)), "[collapsed]selected node should not exist yet");

// expand the ancestry from top-down
for (int i = 1; i < targetItem.Label.Length; i++)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ public async Task ItemsControl_HeaderFooter_NoTP_DynamicXaml()
await ItemsControl_HeaderFooter_NoTP(sut, sut);
}

public async Task ItemsControl_HeaderFooter_NoTP(FrameworkElement setup, ItemsControl sut)
private async Task ItemsControl_HeaderFooter_NoTP(FrameworkElement setup, ItemsControl sut)
{
await UITestHelper.Load(setup, x => x.IsLoaded);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ public static IEnumerable<object[]> GetData()
yield return new object[] { 14, 1, 15 };
}

#pragma warning disable MSTEST0029 // Public methods should be test methods - https://github.com/microsoft/testfx/issues/4660
public void Dispose() =>
Assert.Equals(TestSucces_Count, 3);
#pragma warning restore MSTEST0029 // Public methods should be test methods
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ public static IEnumerable<object[]> Data
}
}

#pragma warning disable MSTEST0029 // Public methods should be test methods - https://github.com/microsoft/testfx/issues/4660
public void Dispose() =>
Assert.Equals(TestSucces_Count, 3);
#pragma warning restore MSTEST0029 // Public methods should be test methods
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public async Task When_ScheduleRepeatingWorkItem()
await Task.WhenAny(tcs.Task, Task.Delay(30000));

Assert.IsTrue(tcs.Task.IsCompleted);
Assert.AreEqual(count, 3);
Assert.AreEqual(3, count);
}
finally
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ public async Task When_Timer()

await Task.Delay(500);

Assert.AreEqual(handlerCount, 1);
Assert.AreEqual(1, handlerCount);

await Task.Delay(500);

Assert.AreEqual(handlerCount, 1);
Assert.AreEqual(1, handlerCount);
}

[TestMethod]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ public void When_Instance_Is_Created_Default_Values()
{
var item = JumpListItem.CreateWithArguments("Hello", "test");
Assert.AreEqual(string.Empty, item.Description);
Assert.AreEqual(null, item.Logo);
Assert.AreEqual(false, item.RemovedByUser);
Assert.IsNull(item.Logo);
Assert.IsFalse(item.RemovedByUser);
Assert.AreEqual(JumpListItemKind.Arguments, item.Kind);
}

Expand All @@ -93,7 +93,7 @@ public void When_Logo_Uri_Is_Set_To_Null()
{
var item = JumpListItem.CreateWithArguments("Hello", "Test");
item.Logo = null;
Assert.AreEqual(null, item.Logo);
Assert.IsNull(item.Logo);
}

[TestMethod]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ public void When_Template_Changes_Should_Not_Be_Materialized_Immediately()
Assert.AreEqual(0, ConstructorCounterControl.ConstructorCount);
Assert.AreEqual(0, ConstructorCounterControl.ApplyTemplateCount);
Assert.AreEqual(0, control.ApplyTemplateCount);
Assert.AreEqual(false, control.ApplyTemplate());
Assert.IsFalse(control.ApplyTemplate());
Assert.AreEqual(0, ConstructorCounterControl.ConstructorCount);
Assert.AreEqual(0, ConstructorCounterControl.ApplyTemplateCount);
Assert.AreEqual(0, control.ApplyTemplateCount);
Expand All @@ -254,7 +254,7 @@ public void When_Template_Changes_Should_Not_Be_Materialized_Immediately()
Assert.AreEqual(0, ConstructorCounterControl.ConstructorCount);
Assert.AreEqual(0, ConstructorCounterControl.ApplyTemplateCount);
Assert.AreEqual(0, control.ApplyTemplateCount);
Assert.AreEqual(true, control.ApplyTemplate());
Assert.IsTrue(control.ApplyTemplate());
Assert.AreEqual(1, ConstructorCounterControl.ConstructorCount);
Assert.AreEqual(0, ConstructorCounterControl.ApplyTemplateCount);
Assert.AreEqual(1, control.ApplyTemplateCount);
Expand Down Expand Up @@ -286,7 +286,7 @@ public void When_Measure_Should_Materialize_Template()
Assert.AreEqual(1, ConstructorCounterControl.ConstructorCount);
Assert.AreEqual(0, ConstructorCounterControl.ApplyTemplateCount);
Assert.AreEqual(1, control.ApplyTemplateCount);
Assert.AreEqual(false, control.ApplyTemplate());
Assert.IsFalse(control.ApplyTemplate());
Assert.AreEqual(1, ConstructorCounterControl.ConstructorCount);
Assert.AreEqual(0, ConstructorCounterControl.ApplyTemplateCount);
Assert.AreEqual(1, control.ApplyTemplateCount);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ void HandleException(object s, UnhandledExceptionEventArgs e)
await TestServices.WindowHelper.WaitFor(() => tickCounter > 0);
await Task.Delay(200);
// Second tick never happens
Assert.AreEqual(tickCounter, 1);
Assert.AreEqual(1, tickCounter);
// Even then, the timer still appears enabled
Assert.IsTrue(dispatcherTimer.IsEnabled);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml/Given_Panel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ public async Task When_Overriding_Measure_Arrange()
Assert.IsTrue(Math.Abs(parent.ActualSize.Y - lv.ActualSize.Y) < 1);

// MeasureOverride should be returning the default Size(0,0)
Assert.AreEqual(lv.DesiredSize.Width, 0);
Assert.AreEqual(lv.DesiredSize.Height, 0);
Assert.AreEqual(0, lv.DesiredSize.Width);
Assert.AreEqual(0, lv.DesiredSize.Height);

for (var i = 0; i < 4; i++)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,8 @@ public void When_LinkedResDict_ThemeUpdated()
var materialized4 = (SolidColorBrush)copy[TestBrush];

// validation
Assert.AreEqual(false, ReferenceEquals(materialized1, materialized2)); // we are expecting these to be different, as the CopyFrom should copy them as WeakResourceInitializer...
Assert.AreEqual(false, ReferenceEquals(materialized3, materialized4)); // ^same
Assert.IsFalse(ReferenceEquals(materialized1, materialized2)); // we are expecting these to be different, as the CopyFrom should copy them as WeakResourceInitializer...
Assert.IsFalse(ReferenceEquals(materialized3, materialized4)); // ^same
Assert.AreNotEqual(materialized2Color, materialized4.Color); // check the theme change is actually applied (otherwise it would void the next check)
Assert.AreEqual(materialized3.Color, materialized4.Color); // check the theme change is propagated to the source res-dict
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,29 +126,29 @@ void AssertItem(int index)
?? throw new NullReferenceException($"Cannot find the materialized border of item {index}");

var containerToListView = container.TransformToVisual(listView).TransformBounds(new Rect(0, 0, 42, 42));
Assert.AreEqual(containerToListView.X, 0, tolerance);
Assert.AreEqual(containerToListView.X, 0, tolerance);
Assert.AreEqual(0, containerToListView.X, tolerance);
Assert.AreEqual(0, containerToListView.X, tolerance);
Assert.AreEqual(containerToListView.Y, ((100 + 5 * 2) * index), tolerance);
Assert.AreEqual(containerToListView.Width, 42, tolerance);
Assert.AreEqual(containerToListView.Height, 42, tolerance);
Assert.AreEqual(42, containerToListView.Width, tolerance);
Assert.AreEqual(42, containerToListView.Height, tolerance);

var borderToListView = border.TransformToVisual(listView).TransformBounds(new Rect(0, 0, 42, 42));
Assert.AreEqual(borderToListView.X, 0, tolerance);
Assert.AreEqual(0, borderToListView.X, tolerance);
Assert.AreEqual(borderToListView.Y, ((100 + 5 * 2) * index + 5), tolerance);
Assert.AreEqual(borderToListView.Width, 42, tolerance);
Assert.AreEqual(borderToListView.Height, 42, tolerance);
Assert.AreEqual(42, borderToListView.Width, tolerance);
Assert.AreEqual(42, borderToListView.Height, tolerance);

var containerToSut = container.TransformToVisual(sut).TransformBounds(new Rect(0, 0, 42, 42));
Assert.AreEqual(containerToSut.X, 15, tolerance);
Assert.AreEqual(15, containerToSut.X, tolerance);
Assert.AreEqual(containerToSut.Y, (15 + (100 + 5 * 2) * index), tolerance);
Assert.AreEqual(containerToSut.Width, 42, tolerance);
Assert.AreEqual(containerToSut.Height, 42, tolerance);
Assert.AreEqual(42, containerToSut.Width, tolerance);
Assert.AreEqual(42, containerToSut.Height, tolerance);

var borderToSut = border.TransformToVisual(sut).TransformBounds(new Rect(0, 0, 42, 42));
Assert.AreEqual(borderToSut.X, 15, tolerance);
Assert.AreEqual(15, borderToSut.X, tolerance);
Assert.AreEqual(borderToSut.Y, (15 + (100 + 5 * 2) * index + 5), tolerance);
Assert.AreEqual(borderToSut.Width, 42, tolerance);
Assert.AreEqual(borderToSut.Height, 42, tolerance);
Assert.AreEqual(42, borderToSut.Width, tolerance);
Assert.AreEqual(42, borderToSut.Height, tolerance);
}
}
#endif
Expand Down
Loading
Loading