Ejemplo n.º 1
0
 public void TestMoreComplexClass()
 {
     AnOptionClass a = new AnOptionClass() { AnInt = 5, AString = "Test" };
     AnotherOptionClass c = new AnotherOptionClass(15.5) { PublicInt = 15, PublicString = "15", MoreOptions = a };
     AnotherOptionClass b = c.Clone() as AnotherOptionClass;
     Assert.That(b, Is.TypeOf(c.GetType()));
     Assert.That(b.PublicInt, Is.EqualTo(c.PublicInt));
     Assert.That(b.PublicString, Is.EqualTo(c.PublicString));
     Assert.That(a.AnInt, Is.EqualTo(b.MoreOptions.AnInt));
     Assert.That(a.AString, Is.EqualTo(b.MoreOptions.AString));
     Assert.That(b.PrivateVal, Is.Not.EqualTo(c.PrivateVal));
 }
Ejemplo n.º 2
0
 public void TestComplexClassAfterChange()
 {
     AnOptionClass a = new AnOptionClass() { AnInt = 5, AString = "Test" };
     AnotherOptionClass c = new AnotherOptionClass(15.5) { PublicInt = 15, PublicString = "15", MoreOptions = a };
     AnotherOptionClass b = c.Clone() as AnotherOptionClass;
     a.AnInt--;
     a.AString = "different now!";
     c.PublicInt--;
     c.PublicString = "public but different";
     Assert.That(b, Is.TypeOf(c.GetType()));
     Assert.That(b.PublicInt, Is.Not.EqualTo(c.PublicInt));
     Assert.That(b.PublicString, Is.Not.EqualTo(c.PublicString));
     Assert.That(a.AnInt, Is.Not.EqualTo(b.MoreOptions.AnInt));
     Assert.That(a.AString, Is.Not.EqualTo(b.MoreOptions.AString));
 }
Ejemplo n.º 3
0
        public void TestMoreComplexClass()
        {
            AnOptionClass a = new AnOptionClass()
            {
                AnInt = 5, AString = "Test"
            };
            AnotherOptionClass c = new AnotherOptionClass(15.5)
            {
                PublicInt = 15, PublicString = "15", MoreOptions = a
            };
            AnotherOptionClass b = c.Clone() as AnotherOptionClass;

            Assert.That(b, Is.TypeOf(c.GetType()));
            Assert.That(b.PublicInt, Is.EqualTo(c.PublicInt));
            Assert.That(b.PublicString, Is.EqualTo(c.PublicString));
            Assert.That(a.AnInt, Is.EqualTo(b.MoreOptions.AnInt));
            Assert.That(a.AString, Is.EqualTo(b.MoreOptions.AString));
            Assert.That(b.PrivateVal, Is.Not.EqualTo(c.PrivateVal));
        }
Ejemplo n.º 4
0
        public void TestComplexClassAfterChange()
        {
            AnOptionClass a = new AnOptionClass()
            {
                AnInt = 5, AString = "Test"
            };
            AnotherOptionClass c = new AnotherOptionClass(15.5)
            {
                PublicInt = 15, PublicString = "15", MoreOptions = a
            };
            AnotherOptionClass b = c.Clone() as AnotherOptionClass;

            a.AnInt--;
            a.AString = "different now!";
            c.PublicInt--;
            c.PublicString = "public but different";
            Assert.That(b, Is.TypeOf(c.GetType()));
            Assert.That(b.PublicInt, Is.Not.EqualTo(c.PublicInt));
            Assert.That(b.PublicString, Is.Not.EqualTo(c.PublicString));
            Assert.That(a.AnInt, Is.Not.EqualTo(b.MoreOptions.AnInt));
            Assert.That(a.AString, Is.Not.EqualTo(b.MoreOptions.AString));
        }
Ejemplo n.º 5
0
        // override object.Equals
        public override bool Equals(object obj)
        {
            if (obj == null || GetType() != obj.GetType())
            {
                return(false);
            }

            AnotherOptionClass a = obj as AnotherOptionClass;

            if (a.PublicInt != this.PublicInt)
            {
                return(false);
            }
            if (!a.PublicString.Equals(this.PublicString))
            {
                return(false);
            }
            if (!a.MoreOptions.Equals(this.MoreOptions))
            {
                return(false);
            }
            return(base.Equals(obj));
        }