CADbloke / CADtest

CADtest runs NUnitLite version 3 inside AutoCAD and/or the AutoCAD Core Console

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Fix the sample test - disposal model is broken. Maybe

CADbloke opened this issue · comments

edb7277 uncommented the code in question. It runs in AutoCAD 2013 but crashes in AutoCAD 2016. I think it is because of the way the objects are disposed, or not disposed. See https://www.theswamp.org/index.php?topic=42399.msg476621#msg476621 and that whole thread for a good debate on this.

I need to look into this further. Or you do. Let me know if you figure it out first.

I fixed this using the code in #Pull Request.

       [Test]
        public void Test_method_name()
        {
            Action<Database, Transaction> action1 = (db, trans) =>
            {
                DBText dbText = new DBText { TextString = "cat" };
                string testMe;

                ObjectId dbTextObjectId = DbEntity.AddToModelSpace(dbText, db);
                dbText.TextString = "dog";

                DBText testText =  trans.GetObject(dbTextObjectId, OpenMode.ForRead) as DBText;
                testMe = testText != null ? testText.TextString : string.Empty;

                // Assert
                StringAssert.AreEqualIgnoringCase("dog", testMe, "DBText string was not changed to \"dog\".");
                StringAssert.AreNotEqualIgnoringCase("cat", testMe, "DBText string was not changed.");
            };

            ExecuteActionDWG(null, action1);

        }