|
3 | 3 | // See the LICENSE file in the project root for more information.
|
4 | 4 |
|
5 | 5 | using System;
|
| 6 | +using System.Collections.Generic; |
6 | 7 | using CommunityToolkit.Mvvm.Collections;
|
7 | 8 | using Microsoft.VisualStudio.TestTools.UnitTesting;
|
8 | 9 |
|
@@ -148,6 +149,38 @@ public void Test_ObservableGroupedCollectionExtensions_AddGroup_WithParamsCollec
|
148 | 149 | CollectionAssert.AreEqual(groupedCollection, new[] { addedGroup });
|
149 | 150 | }
|
150 | 151 |
|
| 152 | + [TestMethod] |
| 153 | + public void Test_ObservableGroupedCollectionExtensions_InsertGroup() |
| 154 | + { |
| 155 | + ObservableGroupedCollection<string, int> groupedCollection = new(); |
| 156 | + |
| 157 | + ObservableGroup<string, int> a = groupedCollection.InsertGroup("A", new[] { 1, 2, 3 }); |
| 158 | + ObservableGroup<string, int> d = groupedCollection.InsertGroup("D", new[] { 1, 2, 3 }); |
| 159 | + ObservableGroup<string, int> e = groupedCollection.InsertGroup("E", new[] { 1, 2, 3 }); |
| 160 | + ObservableGroup<string, int> b = groupedCollection.InsertGroup("B", new[] { 1, 2, 3 }); |
| 161 | + ObservableGroup<string, int> z = groupedCollection.InsertGroup("Z", new[] { 1, 2, 3 }); |
| 162 | + ObservableGroup<string, int> c = groupedCollection.InsertGroup("C", new[] { 1, 2, 3 }); |
| 163 | + |
| 164 | + CollectionAssert.AllItemsAreNotNull(new[] { a, d, e, b, z, c }); |
| 165 | + CollectionAssert.AreEqual(new[] { a, b, c, d, e, z }, groupedCollection); |
| 166 | + } |
| 167 | + |
| 168 | + [TestMethod] |
| 169 | + public void Test_ObservableGroupedCollectionExtensions_InsertGroup_WithGrouping() |
| 170 | + { |
| 171 | + ObservableGroupedCollection<string, int> groupedCollection = new(); |
| 172 | + |
| 173 | + ObservableGroup<string, int> a = groupedCollection.InsertGroup(new IntGroup("A", new[] { 1, 2, 3 })); |
| 174 | + ObservableGroup<string, int> d = groupedCollection.InsertGroup(new IntGroup("D", new[] { 1, 2, 3 })); |
| 175 | + ObservableGroup<string, int> e = groupedCollection.InsertGroup(new IntGroup("E", new[] { 1, 2, 3 })); |
| 176 | + ObservableGroup<string, int> b = groupedCollection.InsertGroup(new IntGroup("B", new[] { 1, 2, 3 })); |
| 177 | + ObservableGroup<string, int> z = groupedCollection.InsertGroup(new IntGroup("Z", new[] { 1, 2, 3 })); |
| 178 | + ObservableGroup<string, int> c = groupedCollection.InsertGroup(new IntGroup("C", new[] { 1, 2, 3 })); |
| 179 | + |
| 180 | + CollectionAssert.AllItemsAreNotNull(new[] { a, d, e, b, z, c }); |
| 181 | + CollectionAssert.AreEqual(new[] { a, b, c, d, e, z }, groupedCollection); |
| 182 | + } |
| 183 | + |
151 | 184 | [TestMethod]
|
152 | 185 | public void Test_ObservableGroupedCollectionExtensions_AddItem_WhenTargetGroupDoesNotExists_ShouldCreateAndAddNewGroup()
|
153 | 186 | {
|
@@ -223,6 +256,66 @@ public void Test_ObservableGroupedCollectionExtensions_AddItem_WhenSeveralTarget
|
223 | 256 | CollectionAssert.AreEqual(groupedCollection[3], new[] { 10, 11 });
|
224 | 257 | }
|
225 | 258 |
|
| 259 | + [TestMethod] |
| 260 | + public void Test_ObservableGroupedCollectionExtensions_InsertItem() |
| 261 | + { |
| 262 | + ObservableGroupedCollection<string, int> groupedCollection = new(); |
| 263 | + |
| 264 | + ObservableGroup<string, int> group1 = groupedCollection.InsertItem("A", 1); |
| 265 | + ObservableGroup<string, int> group2 = groupedCollection.InsertItem("A", 2); |
| 266 | + ObservableGroup<string, int> group6 = groupedCollection.InsertItem("A", 6); |
| 267 | + ObservableGroup<string, int> group4 = groupedCollection.InsertItem("A", 4); |
| 268 | + ObservableGroup<string, int> group3 = groupedCollection.InsertItem("A", 3); |
| 269 | + ObservableGroup<string, int> group99 = groupedCollection.InsertItem("A", 99); |
| 270 | + ObservableGroup<string, int> group8 = groupedCollection.InsertItem("B", 8); |
| 271 | + ObservableGroup<string, int> group7 = groupedCollection.InsertItem("B", 7); |
| 272 | + |
| 273 | + Assert.AreEqual(2, groupedCollection.Count); |
| 274 | + CollectionAssert.AllItemsAreNotNull(new[] { group1, group2, group6, group4, group3, group99, group8, group7 }); |
| 275 | + |
| 276 | + Assert.AreSame(group1, group2); |
| 277 | + Assert.AreSame(group1, group6); |
| 278 | + Assert.AreSame(group1, group4); |
| 279 | + Assert.AreSame(group1, group3); |
| 280 | + Assert.AreSame(group1, group2); |
| 281 | + Assert.AreSame(group1, group99); |
| 282 | + Assert.AreNotSame(group1, group8); |
| 283 | + Assert.AreSame(group8, group7); |
| 284 | + |
| 285 | + CollectionAssert.AreEqual(new[] { 1, 2, 3, 4, 6, 99 }, group1); |
| 286 | + CollectionAssert.AreEqual(new[] { 7, 8 }, group8); |
| 287 | + } |
| 288 | + |
| 289 | + [TestMethod] |
| 290 | + public void Test_ObservableGroupedCollectionExtensions_InsertItem_WithComparer() |
| 291 | + { |
| 292 | + ObservableGroupedCollection<string, int> groupedCollection = new(); |
| 293 | + |
| 294 | + ObservableGroup<string, int> group1 = groupedCollection.InsertItem("A", Comparer<string>.Default, 1, Comparer<int>.Default); |
| 295 | + ObservableGroup<string, int> group2 = groupedCollection.InsertItem("A", Comparer<string>.Default, 2, Comparer<int>.Default); |
| 296 | + ObservableGroup<string, int> group6 = groupedCollection.InsertItem("A", Comparer<string>.Default, 6, Comparer<int>.Default); |
| 297 | + ObservableGroup<string, int> group4 = groupedCollection.InsertItem("A", Comparer<string>.Default, 4, Comparer<int>.Default); |
| 298 | + ObservableGroup<string, int> group3 = groupedCollection.InsertItem("A", Comparer<string>.Default, 3, Comparer<int>.Default); |
| 299 | + ObservableGroup<string, int> group99 = groupedCollection.InsertItem("A", Comparer<string>.Default, 99, Comparer<int>.Default); |
| 300 | + ObservableGroup<string, int> group8 = groupedCollection.InsertItem("B", Comparer<string>.Default, 8, Comparer<int>.Default); |
| 301 | + ObservableGroup<string, int> group7 = groupedCollection.InsertItem("B", Comparer<string>.Default, 7, Comparer<int>.Default); |
| 302 | + |
| 303 | + Assert.AreEqual(2, groupedCollection.Count); |
| 304 | + CollectionAssert.AllItemsAreNotNull(new[] { group1, group2, group6, group4, group3, group99, group8, group7 }); |
| 305 | + |
| 306 | + Assert.AreSame(group1, group2); |
| 307 | + Assert.AreSame(group1, group6); |
| 308 | + Assert.AreSame(group1, group4); |
| 309 | + Assert.AreSame(group1, group3); |
| 310 | + Assert.AreSame(group1, group2); |
| 311 | + Assert.AreSame(group1, group99); |
| 312 | + Assert.AreNotSame(group1, group8); |
| 313 | + Assert.AreSame(group8, group7); |
| 314 | + |
| 315 | + CollectionAssert.AreEqual(new[] { 1, 2, 3, 4, 6, 99 }, group1); |
| 316 | + CollectionAssert.AreEqual(new[] { 7, 8 }, group8); |
| 317 | + } |
| 318 | + |
226 | 319 | [TestMethod]
|
227 | 320 | public void Test_ObservableGroupedCollectionExtensions_RemoveGroup_WhenGroupDoesNotExists_ShouldDoNothing()
|
228 | 321 | {
|
|
0 commit comments