Files
Sergio Pedri 12ae36b594 Refactor unit tests to use new assertion helpers
Replaces usages of Assert.AreEqual, Assert.IsTrue, and similar assertions with new helper methods such as Assert.HasCount, Assert.IsEmpty, Assert.IsNull, and Assert.IsGreaterThanOrEqualTo across multiple test files. This improves test readability and consistency with updated assertion APIs.
2025-11-09 18:34:09 -08:00

49 lines
1.6 KiB
C#

// 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.
using System;
using System.Collections.Generic;
using System.Linq;
using CommunityToolkit.Mvvm.Collections;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace CommunityToolkit.Mvvm.UnitTests.Collections;
[TestClass]
public class Test_ObservableGroupedCollection
{
[TestMethod]
public void Test_ObservableGroupedCollection_Ctor_ShouldHaveExpectedValues()
{
ObservableGroupedCollection<string, int> groupCollection = new();
Assert.IsEmpty(groupCollection);
}
[TestMethod]
public void Test_ObservableGroupedCollection_Ctor_WithGroups_ShouldHaveExpectedValues()
{
List<IGrouping<string, int>> groups = new()
{
new IntGroup("A", new[] { 1, 3, 5 }),
new IntGroup("B", new[] { 2, 4, 6 }),
};
ObservableGroupedCollection<string, int> groupCollection = new(groups);
Assert.HasCount(2, groupCollection);
Assert.AreEqual("A", groupCollection[0].Key);
CollectionAssert.AreEqual(groupCollection[0], new[] { 1, 3, 5 });
Assert.AreEqual("B", groupCollection[1].Key);
CollectionAssert.AreEqual(groupCollection[1], new[] { 2, 4, 6 });
}
[TestMethod]
public void Test_ObservableGroupedCollection_Ctor_NullCollection()
{
_ = Assert.ThrowsExactly<ArgumentNullException>(() => _ = new ObservableGroupedCollection<string, int>(null!));
}
}