コード例 #1
0
 private static void AssertClonedObject(CloneTest myCopy, CloneTest myObject)
 {
     foreach (var expression in GetComparisons())
     {
         Assert.That(expression.Invoke(myObject), Is.EqualTo(expression.Invoke(myCopy)));
     }
 }
コード例 #2
0
        public void WhenCopyingAnObject_UsingBinaryFormatter_CannotWorkInPartialTrust()
        {
            try
            {
                // Arrange
                var myObject = new CloneTest("root", 1, "protected-value", "private-value", new CloneTest("child", 2, "child-protected-value", "child-private-value"), new CloneTest("public-child", 3, "publicchild-protected-value", "publicchild-private-value"));

                // Act
                var myCopy = myObject.Clone();

                // Assert
                AssertClonedObject(myCopy, myObject);
            }
            catch (SecurityException)
            {
                if (AppDomain.CurrentDomain.FriendlyName.StartsWith(PartialTrustHelper <ObjectExtensionsTests> .PartialTrustAppDomainName))
                {
                    Assert.Pass();
                }
            }
            if (AppDomain.CurrentDomain.FriendlyName.StartsWith(PartialTrustHelper <ObjectExtensionsTests> .PartialTrustAppDomainName))
            {
                Assert.Fail("Did not throw an exception");
            }
        }
コード例 #3
0
ファイル: CloneTest.cs プロジェクト: honglux/UnityTests
    public CloneTest(CloneTest other_CT)
    {
        Debug.Log("constructor called!!!");
        Debug.Log("other_CT.counter " + other_CT.counter);

        this.timer   = other_CT.timer;
        this.counter = other_CT.counter;
    }
コード例 #4
0
        private static void AssertClonedObjectIsDifferent(CloneTest myCopy, CloneTest myObject)
        {
            var allAreSame = GetComparisons().All(expression => expression.Invoke(myObject) == expression.Invoke(myCopy));

            if (allAreSame)
            {
                Assert.Fail("All properties are equal comparing a changed cloned object with its original");
            }
        }
コード例 #5
0
ファイル: CloneTest.cs プロジェクト: honglux/UnityTests
 private void spawn()
 {
     if (timer < 0.0f)
     {
         GameObject obj = Instantiate(gameObject);
         CloneTest  CT  = obj.GetComponent <CloneTest>();
         timer = 5.0f;
         CT.set_para(this);
         //CT = new CloneTest(this);
     }
 }
コード例 #6
0
        public void WhenCopyingAnObject_ObjectIsCloned()
        {
            // Arrange
            var myObject = new CloneTest("root", 1, "protected-value", "private-value", new CloneTest("child", 2, "child-protected-value", "child-private-value"), new CloneTest("public-child", 3, "publicchild-protected-value", "publicchild-private-value"));

            // Act
            CloneTest myCopy = myObject.DeepCopy(); // We don't use var because the return type is CloneOf<T>

            AssertClonedObject(myCopy, myObject);

            // Assert
            myCopy.Integer = 5;
            myCopy.ProtectedDeep.Integer = 6;
            myCopy.PublicDeep            = new CloneTest("brand-new", 2, "new-protected-value", "new-private-value");
            myCopy.AssertTestSetPrivateFieldBackedProperty("new-private-value");
            myCopy.AssertTestSetProtectedFieldBackedProperty("new-protected-value");

            AssertClonedObjectIsDifferent(myCopy, myObject);
        }
コード例 #7
0
ファイル: CloneTest.cs プロジェクト: honglux/UnityTests
 public void set_para(CloneTest other_CT)
 {
     this.timer   = other_CT.timer;
     this.counter = other_CT.counter;
 }