コード例 #1
0
        public void TestContains()
        {
            HashedCollection<SampleClass> collection = new HashedCollection<SampleClass>((item) => item.Hash);

            var i1 = new SampleClass("XXX");
            var i2 = new SampleClass("YYY");
            var i3 = new SampleClass("ZZZ");

            collection.Add(i1);
            collection.Add(i2);

            Assert.IsFalse(collection.Contains(i3));
            Assert.IsTrue(collection.Contains(i1));
            Assert.IsTrue(collection.Contains(i2));
        }
コード例 #2
0
        public void TestClone()
        {
            SampleClass instance = new SampleClass();
            instance.String = "XYZ";
            instance.DateTimeOffset = new DateTimeOffset(2015, 1, 3, 0, 0, 0, new TimeSpan(1, 0, 0));
            instance.Int = 5;
            instance.Sample = new SampleClass() { String = "Test", DateTimeOffset = new DateTimeOffset(2015, 1, 4, 0, 0, 0, new TimeSpan(1, 0, 0)) };

            SampleClass deserialized = SerializationExtensions.Clone(instance);

            Assert.AreEqual(instance.String, deserialized.String);
            Assert.AreEqual(instance.DateTimeOffset, deserialized.DateTimeOffset);
            Assert.AreEqual(instance.Int, deserialized.Int);
            Assert.AreEqual(instance.Sample.String, deserialized.Sample.String);
            Assert.AreEqual(instance.Sample.DateTimeOffset, deserialized.Sample.DateTimeOffset);
        }
コード例 #3
0
        public void TestRemove()
        {
            HashedCollection<SampleClass> collection = new HashedCollection<SampleClass>((item) => item.Hash);

            var i1 = new SampleClass("XXX");
            var i2 = new SampleClass("YYY");

            collection.Add(i1);
            collection.Add(i2);

            Assert.AreEqual(2, collection.Count);

            collection.Remove(i1);
            collection.Remove(i2);

            Assert.AreEqual(0, collection.Count);
        }