コード例 #1
0
        public void ShouldApplyOverriddenEquals()
        {
            var cookie = new GuineaPig("Cookie", 800, 37.7);
            var clone  = cookie.DeepCopy();
            var other  = new GuineaPig("Cookie", 800, 37.7);

            Assert.That(cookie.Equals(clone), Is.True);
            Assert.That(cookie.Equals(other), Is.False);
            Assert.That(cookie == clone, Is.True);
            Assert.That(cookie != other, Is.True);
        }
コード例 #2
0
        public void ShouldPerformDeepCopy()
        {
            var pig   = new GuineaPig("Cookie", 800, 37.7);
            var clone = pig.DeepCopy();

            Assert.That(pig.Name, Is.EqualTo(clone.Name));
            Assert.That(pig.Weight, Is.EqualTo(clone.Weight));

            var prop = typeof(GuineaPig).GetProperty("BodyTemp", BindingFlags.NonPublic | BindingFlags.Instance);

            Assert.That(prop?.GetValue(pig), Is.EqualTo(prop?.GetValue(clone)));
        }
コード例 #3
0
        public void ShouldApplyOverriddenToString()
        {
            var cookie = new GuineaPig("Cookie", 800, 37.7);

            Assert.That(cookie.ToString(), Is.EqualTo($"GuineaPig {cookie.Id} 'Cookie'"));
        }