public void GetRepresentative() { var bag1 = new Bag <string>( new[] { "foo", null, "FOO", "Eric", "eric", "bar", null, "foO", "ERIC", "eric", null }, StringComparer.InvariantCultureIgnoreCase); string rep; var count = bag1.GetRepresentativeItem("Foo", out rep); Assert.AreEqual(3, count); Assert.AreEqual("foo", rep); count = bag1.GetRepresentativeItem(null, out rep); Assert.AreEqual(3, count); Assert.AreEqual(null, rep); count = bag1.GetRepresentativeItem("silly", out rep); Assert.AreEqual(0, count); Assert.AreEqual("silly", rep); count = bag1.GetRepresentativeItem("ERic", out rep); Assert.AreEqual(4, count); Assert.AreEqual("Eric", rep); count = bag1.GetRepresentativeItem("BAR", out rep); Assert.AreEqual(1, count); Assert.AreEqual("bar", rep); }