/
NamedCollectionTest.cs
44 lines (36 loc) · 1.31 KB
/
NamedCollectionTest.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Copyright Bastian Eicher
// Licensed under the MIT License
using System;
using System.Linq;
using FluentAssertions;
using Xunit;
namespace NanoByte.Common.Collections
{
/// <summary>
/// Contains test methods for <see cref="NamedCollection{T}"/>.
/// </summary>
public class NamedCollectionTest
{
private class TestElement : INamed<TestElement>
{
public string Name { get; set; }
public int CompareTo(TestElement other) => string.Compare(Name, other.Name, StringComparison.OrdinalIgnoreCase);
}
[Fact]
public void TestSort()
{
var collection = new NamedCollection<TestElement> {new TestElement {Name = "c"}, new TestElement {Name = "b"}, new TestElement {Name = "a"}};
collection.Select(x => x.Name).Should().Equal("a", "b", "c");
}
[Fact]
public void TestRename()
{
var element = new TestElement {Name = "Name1"};
var collection = new NamedCollection<TestElement> {element};
collection["Name1"].Should().BeSameAs(element);
collection.Rename(element, "Name2");
element.Name.Should().Be("Name2");
collection["Name2"].Should().BeSameAs(element);
}
}
}