public void TestReferenceUpdate()
        {
            var so1 = new SimpleObject {
                ValueOne = 1, ValueTwo = 2
            };
            var so2 = new SimpleObject {
                ValueOne = 3, ValueTwo = 4
            };
            var ro = new ReferenceObject {
                ReferenceOne = so1
            };

            var clone = (ReferenceObject)CopyUtils.CloneObjectTest(ro);

            clone.ReferenceOne = so2;

            Assert.AreNotSame(ro, clone);
            Assert.AreSame(ro.GetType(), clone.GetType());
            Assert.AreNotSame(ro.ReferenceOne, clone.ReferenceOne);

            CopyUtils.UpdateFromClone(ro, clone);

            Assert.AreNotSame(ro, clone);
            Assert.AreSame(ro.GetType(), clone.GetType());
            Assert.AreSame(ro.ReferenceOne, clone.ReferenceOne);
        }
        public void SeperateCaches()
        {
            Claim c1 = NakedObjectsFramework.Persistor.Instances <Claim>().OrderBy(c => c.Id).First();
            Claim c2 = NakedObjectsFramework.Persistor.Instances <Claim>().OrderByDescending(c => c.Id).First();

            INakedObject claim1 = NakedObjectsFramework.GetNakedObject(c1);
            INakedObject claim2 = NakedObjectsFramework.GetNakedObject(c2);

            Assert.AreNotSame(claim1, claim2);

            mocks.HtmlHelper.ViewContext.HttpContext.Session.AddToCache(NakedObjectsFramework, claim1);
            mocks.HtmlHelper.ViewContext.HttpContext.Session.AddToCache(NakedObjectsFramework, claim2, ObjectCache.ObjectFlag.BreadCrumb);

            Assert.IsTrue(mocks.HtmlHelper.ViewContext.HttpContext.Session.AllCachedObjects(NakedObjectsFramework).Contains(claim1.Object));
            Assert.IsTrue(mocks.HtmlHelper.ViewContext.HttpContext.Session.AllCachedObjects(NakedObjectsFramework, ObjectCache.ObjectFlag.BreadCrumb).Contains(claim2.Object));

            Assert.IsFalse(mocks.HtmlHelper.ViewContext.HttpContext.Session.AllCachedObjects(NakedObjectsFramework).Contains(claim2.Object));
            Assert.IsFalse(mocks.HtmlHelper.ViewContext.HttpContext.Session.AllCachedObjects(NakedObjectsFramework, ObjectCache.ObjectFlag.BreadCrumb).Contains(claim1.Object));

            mocks.HtmlHelper.ViewContext.HttpContext.Session.ClearCachedObjects();

            Assert.IsFalse(mocks.HtmlHelper.ViewContext.HttpContext.Session.AllCachedObjects(NakedObjectsFramework).Contains(claim1.Object));
            Assert.IsTrue(mocks.HtmlHelper.ViewContext.HttpContext.Session.AllCachedObjects(NakedObjectsFramework, ObjectCache.ObjectFlag.BreadCrumb).Contains(claim2.Object));

            mocks.HtmlHelper.ViewContext.HttpContext.Session.ClearCachedObjects(ObjectCache.ObjectFlag.BreadCrumb);

            Assert.IsFalse(mocks.HtmlHelper.ViewContext.HttpContext.Session.AllCachedObjects(NakedObjectsFramework, ObjectCache.ObjectFlag.BreadCrumb).Contains(claim2.Object));
        }
        public void TestCollectionUpdate()
        {
            var so1 = new SimpleObject {
                ValueOne = 1, ValueTwo = 2
            };
            var so2 = new SimpleObject {
                ValueOne = 3, ValueTwo = 4
            };
            var co = new CollectionObject();

            co.CollectionOne.Add(so1);

            var clone = (CollectionObject)CopyUtils.CloneObjectTest(co);

            clone.CollectionOne.Add(so2);

            Assert.AreNotSame(co, clone);
            Assert.AreSame(co.GetType(), clone.GetType());
            Assert.AreNotSame(co.CollectionOne, clone.CollectionOne);
            Assert.AreNotEqual(co.CollectionOne.Count(), clone.CollectionOne.Count());

            CopyUtils.UpdateFromClone(co, clone);

            Assert.AreNotSame(co, clone);
            Assert.AreSame(co.GetType(), clone.GetType());
            Assert.AreNotSame(co.CollectionOne, clone.CollectionOne);
            Assert.AreEqual(co.CollectionOne.Count(), clone.CollectionOne.Count());
            Assert.AreSame(co.CollectionOne.First(), clone.CollectionOne.First());
            Assert.AreSame(co.CollectionOne.ElementAt(1), clone.CollectionOne.ElementAt(1));
        }
示例#4
0
        public void ShuffleReturnsSimilarEnumerable()
        {
            var items    = Enumerable.Range(-1000, 0).ToList();
            var shuffled = items.Shuffle();

            Assert.AreNotSame(items, shuffled, "Items not shuffled");
            Assert.That(shuffled, Is.EquivalentTo(items), "Items missing after shuffle");
        }
示例#5
0
        public void GetBookReturnsDifferentObjects()
        {
            var book1 = GetBook("BOOK 1");
            var book2 = GetBook("BOOK 2");

            Assert.AreEqual("BOOK 1", book1.Name);
            Assert.AreEqual("BOOK 2", book2.Name);
            Assert.AreNotSame(book1, book2);
        }
示例#6
0
        public void CheckSubstractPassTest()
        {
            double sub1           = 17.0;
            double sub2           = 7.0;
            double expectedResult = 4.0;
            double actualResult   = calc.Substract(sub1, sub2);

            Assert.AreNotSame(expectedResult, actualResult, "Result are not same - {0} and {1}", expectedResult, actualResult);
        }
        public void DivisionAreNotSame()
        {
            _firstNum       = 25;
            _secondNum      = 5;
            _expectedResult = 12;
            _actualResult   = Calc.Division(_firstNum, _secondNum);
            object expectedResult = _expectedResult;
            object actualResult   = _actualResult;

            Assert.AreNotSame(actualResult, expectedResult, $"Expected and actual results of division {_firstNum} and {_secondNum} are not same ");
        }
        public void TestSimpleClone()
        {
            var so = new SimpleObject {
                ValueOne = 1, ValueTwo = 2
            };
            var clone = (SimpleObject)CopyUtils.CloneObjectTest(so);

            Assert.AreNotSame(so, clone);
            Assert.AreSame(so.GetType(), clone.GetType());
            Assert.AreEqual(so.ValueOne, clone.ValueOne);
            Assert.AreEqual(so.ValueTwo, clone.ValueTwo);
        }
        public virtual void stringIndefiniteArticleInflectionConsonantTest()
        {
            SPhraseSpec senSpec = phraseFactory.createClause();

            senSpec.addComplement(phraseFactory.createStringElement("I see an"));
            NPPhraseSpec firstNoun = phraseFactory.createNounPhrase("cow");

            senSpec.addComplement(firstNoun);
            DocumentElement completeSen = phraseFactory.createSentence();

            completeSen.addComponent(senSpec);
            // Do not attempt "an" -> "a"
            Assert.AreNotSame("I see an cow.", realiser.realise(completeSen).Realisation);
        }
        public void TestCollectionClone()
        {
            var so = new SimpleObject {
                ValueOne = 1, ValueTwo = 2
            };
            var co = new CollectionObject();

            co.CollectionOne.Add(so);

            var clone = (CollectionObject)CopyUtils.CloneObjectTest(co);

            Assert.AreNotSame(co, clone);
            Assert.AreSame(co.GetType(), clone.GetType());
            Assert.AreNotSame(co.CollectionOne, clone.CollectionOne);
            Assert.AreSame(co.CollectionOne.First(), clone.CollectionOne.First());
        }
        public void TestReferenceClone()
        {
            var so = new SimpleObject {
                ValueOne = 1, ValueTwo = 2
            };
            var ro = new ReferenceObject {
                ReferenceOne = so
            };

            var clone = (ReferenceObject)CopyUtils.CloneObjectTest(ro);

            Assert.AreNotSame(ro, clone);
            Assert.AreSame(ro.GetType(), clone.GetType());

            Assert.AreSame(ro.ReferenceOne, clone.ReferenceOne);
        }
        public void TestAllUpdate()
        {
            var so1 = new SimpleObject {
                ValueOne = 1, ValueTwo = 2
            };
            var so2 = new SimpleObject {
                ValueOne = 3, ValueTwo = 4
            };
            var so3 = new SimpleObject {
                ValueOne = 5, ValueTwo = 6
            };
            var so4 = new SimpleObject {
                ValueOne = 7, ValueTwo = 8
            };
            var ao = new AllObject {
                ValueOne = 9, ValueTwo = 10, ReferenceOne = so1
            };

            ao.CollectionOne.Add(so2);

            var clone = (AllObject)CopyUtils.CloneObjectTest(ao);

            clone.ValueTwo     = 11;
            clone.ReferenceOne = so3;
            clone.CollectionOne.Add(so4);

            Assert.AreNotSame(ao, clone);
            Assert.AreSame(ao.GetType(), clone.GetType());
            Assert.AreEqual(ao.ValueOne, clone.ValueOne);
            Assert.AreNotEqual(ao.ValueTwo, clone.ValueTwo);
            Assert.AreNotSame(ao.ReferenceOne, clone.ReferenceOne);
            Assert.AreNotSame(ao.CollectionOne, clone.CollectionOne);
            Assert.AreNotEqual(ao.CollectionOne.Count(), clone.CollectionOne.Count());

            CopyUtils.UpdateFromClone(ao, clone);

            Assert.AreNotSame(ao, clone);
            Assert.AreSame(ao.GetType(), clone.GetType());
            Assert.AreNotSame(ao.CollectionOne, clone.CollectionOne);
            Assert.AreSame(ao.ReferenceOne, clone.ReferenceOne);
            Assert.AreEqual(ao.ValueOne, clone.ValueOne);
            Assert.AreEqual(ao.ValueTwo, clone.ValueTwo);
            Assert.AreEqual(ao.CollectionOne.Count(), clone.CollectionOne.Count());
            Assert.AreSame(ao.CollectionOne.First(), clone.CollectionOne.First());
            Assert.AreSame(ao.CollectionOne.ElementAt(1), clone.CollectionOne.ElementAt(1));
        }
        public void ProgrammerTest()
        {
            var address  = new Address("56 Main St", "Mesa", "AZ", "38574");
            var customer = new Customer("John", "Doe", address);
            var company  = new Company("Google", address);

            Assert.IsNullOrEmpty(customer.Id);
            customer.Save();
            Assert.IsNotNullOrEmpty(customer.Id);

            Assert.IsNullOrEmpty(company.Id);
            company.Save();
            Assert.IsNotNullOrEmpty(company.Id);

            Customer savedCustomer = Customer.Find(customer.Id);

            Assert.IsNotNull(savedCustomer);
            Assert.AreSame(customer.Address, address);
            Assert.AreEqual(savedCustomer.Address, address);
            Assert.AreEqual(customer.Id, savedCustomer.Id);
            Assert.AreEqual(customer.FirstName, savedCustomer.FirstName);
            Assert.AreEqual(customer.LastName, savedCustomer.LastName);
            Assert.AreEqual(customer, savedCustomer);
            Assert.AreNotSame(customer, savedCustomer);

            Company savedCompany = Company.Find(company.Id);

            Assert.IsNotNull(savedCompany);
            Assert.AreSame(company.Address, address);
            Assert.AreEqual(savedCompany.Address, address);
            Assert.AreEqual(company.Id, savedCompany.Id);
            Assert.AreEqual(company.Name, savedCompany.Name);
            Assert.AreEqual(company, savedCompany);
            Assert.AreNotSame(company, savedCompany);

            customer.Delete();
            Assert.IsNullOrEmpty(customer.Id);
            Assert.IsNull(Customer.Find(customer.Id));

            company.Delete();
            Assert.IsNullOrEmpty(company.Id);
            Assert.IsNull(Company.Find(company.Id));
        }
        public void TestAllClone()
        {
            var so1 = new SimpleObject {
                ValueOne = 1, ValueTwo = 2
            };
            var so2 = new SimpleObject {
                ValueOne = 3, ValueTwo = 4
            };
            var ao = new AllObject {
                ValueOne = 5, ValueTwo = 6, ReferenceOne = so1
            };

            ao.CollectionOne.Add(so2);

            var clone = (AllObject)CopyUtils.CloneObjectTest(ao);

            Assert.AreNotSame(ao, clone);
            Assert.AreSame(ao.GetType(), clone.GetType());
            Assert.AreEqual(ao.ValueOne, clone.ValueOne);
            Assert.AreEqual(ao.ValueTwo, clone.ValueTwo);
            Assert.AreSame(ao.ReferenceOne, clone.ReferenceOne);
            Assert.AreNotSame(ao.CollectionOne, clone.CollectionOne);
            Assert.AreSame(ao.CollectionOne.First(), clone.CollectionOne.First());
        }
示例#15
0
        public void Extend()
        {
            dynamic settings    = CQ.ParseJSON("{ 'xnumber1': 5, 'xnumber2': 7, 'xstring1': 'peter', 'xstring2': 'pan' }");
            dynamic options     = CQ.ParseJSON("{ 'xnumber2': 1, 'xstring2': 'x', 'xxx': 'newstring'}");
            dynamic optionsCopy = CQ.ParseJSON("{ 'xnumber2': 1, 'xstring2': 'x', 'xxx': 'newstring' }");
            dynamic merged      = CQ.ParseJSON("{ 'xnumber1': 5, 'xnumber2': 1, 'xstring1': 'peter', 'xstring2': 'x', 'xxx': 'newstring' }");

            dynamic deep1     = CQ.ParseJSON("{ 'foo': { 'bar': true } }");
            dynamic deep1copy = CQ.ParseJSON("{ 'foo': { 'bar': true } }");


            dynamic deep2     = CQ.ParseJSON("{ 'foo': { 'baz': true }, 'foo2': 'document' }");
            dynamic deep2copy = CQ.ParseJSON("{ 'foo': { 'baz': true }, 'foo2': 'document' }");

            dynamic deepmerged = CQ.ParseJSON("{ 'foo': { 'bar': true, 'baz': true }, 'foo2': 'document' }");

            var     arr         = new int[] { 1, 2, 3 };
            dynamic nestedarray = new ExpandoObject();

            nestedarray.arr = arr;

            CQ.Extend(settings, options);

            Assert.AreEqual(merged, settings, "Check if extended: settings must be extended");
            Assert.AreEqual(optionsCopy, options, "Check if not modified: options must not be modified");


            CQ.Extend(settings, null, options);
            Assert.AreEqual(settings, merged, "Check if extended: settings must be extended");
            Assert.AreEqual(optionsCopy, options, "Check if not modified: options must not be modified");

            // Test deep copying

            CQ.Extend(true, deep1, deep2);
            Assert.AreEqual(deepmerged.foo, deep1.foo, "Check if foo: settings must be extended");
            Assert.AreEqual(deep2copy.foo, deep2.foo, "Check if not deep2: options must not be modified");

            // n/a
            //Assert.AreEqual(document, deep1.foo2, "Make sure that a deep clone was not attempted on the document");


            var nullUndef = CQ.Extend(null, options, CQ.ParseJSON("{ 'xnumber2': null }"));

            Assert.IsTrue(nullUndef.xnumber2 == null, "Check to make sure null values are copied");

            nullUndef = CQ.Extend(null, options, CQ.ParseJSON("{ 'xnumber0': null }"));
            Assert.IsTrue(nullUndef.xnumber0 == null, "Check to make sure null values are inserted");

            // Test nested arrays

            dynamic extendedArr = CQ.Extend(true, null, nestedarray);


            Assert.AreNotSame(extendedArr.arr, arr, "Deep extend of object must clone child array");
            Assert.AreNotSame(extendedArr.arr, arr, "Deep extend of object must clone child array");

            // #5991
            dynamic emptyArrObj  = CQ.ParseJSON("{ arr: {} }");
            dynamic extendedArr2 = CQ.Extend(true, emptyArrObj, nestedarray);

            Assert.IsTrue(extendedArr2.arr is IEnumerable, "Cloned array heve to be an Array");

            dynamic simpleArrObj = new ExpandoObject();

            simpleArrObj.arr = arr;
            emptyArrObj      = CQ.ParseJSON("{ arr: {} }");
            dynamic result = CQ.Extend(true, simpleArrObj, emptyArrObj);

            Assert.IsTrue(!(result.arr is Array), "Cloned object heve to be an plain object");


            dynamic empty             = new JsObject();
            dynamic optionsWithLength = CQ.ParseJSON("{ 'foo': { 'length': -1 } }");

            CQ.Extend(true, empty, optionsWithLength);
            Assert.AreEqual(empty.foo, optionsWithLength.foo, "The length property must copy correctly");


            //? not really relevant

            empty = new JsObject();
            dynamic optionsWithDate = new JsObject();

            optionsWithDate.foo      = new JsObject();
            optionsWithDate.foo.date = new DateTime();
            CQ.Extend(true, empty, optionsWithDate);
            Assert.AreEqual(empty.foo, optionsWithDate.foo, "Dates copy correctly");


            var     customObject            = DateTime.Now;
            dynamic optionsWithCustomObject = new { foo = new { date = customObject } };

            empty = CQ.Extend(true, null, optionsWithCustomObject);
            Assert.IsTrue(empty.foo != null && empty.foo.date == customObject, "Custom objects copy correctly (no methods)");

            //// Makes the class a little more realistic
            //myKlass.prototype = { someMethod: function(){} };
            //empty = {};
            //jQuery.extend(true, empty, optionsWithCustomObject);
            //ok( empty.foo && empty.foo.date === customObject, "Custom objects copy correctly" );

            dynamic ret = CQ.Extend(true, CQ.ParseJSON("{'foo': 4 }"), new { foo = 5 });

            Assert.IsTrue(ret.foo == 5, "Wrapped numbers copy correctly");

            nullUndef = CQ.Extend(null, options, "{ 'xnumber2': null }");
            Assert.IsTrue(nullUndef.xnumber2 == null, "Check to make sure null values are copied");

            //    nullUndef = jQuery.extend({}, options, { xnumber2: undefined });
            //    ok( nullUndef.xnumber2 === options.xnumber2, "Check to make sure undefined values are not copied");

            nullUndef = CQ.Extend(null, options, "{ 'xnumber0': null }");
            Assert.IsTrue(nullUndef.xnumber0 == null, "Check to make sure null values are inserted");

            dynamic target    = new ExpandoObject();
            dynamic recursive = new ExpandoObject();

            recursive.bar = 5;
            recursive.foo = target;

            CQ.Extend(true, target, recursive);
            dynamic compare = CQ.ParseJSON("{ 'bar':5 }");

            Assert.AreEqual(target, compare, "Check to make sure a recursive obj doesn't go never-ending loop by not copying it over");

            // These next checks don't really apply as they are specific to javascript nuances, but can't hurt

            ret = CQ.Extend(true, CQ.ParseJSON(" { 'foo': [] }"), CQ.ParseJSON("{ 'foo': [0] }")); // 1907
            // arrays are returned as List<object> when casting to expando object
            Assert.AreEqual(1, ret.foo.Count, "Check to make sure a value with coersion 'false' copies over when necessary to fix #1907");

            ret = CQ.Extend(true, CQ.ParseJSON("{ 'foo': '1,2,3' }"), CQ.ParseJSON("{ 'foo': [1, 2, 3] }"));
            Assert.IsTrue(!(ret.foo is string), "Check to make sure values equal with coersion (but not actually equal) overwrite correctly");



            dynamic obj = CQ.ParseJSON("{ 'foo':null }");

            CQ.Extend(true, obj, CQ.ParseJSON("{ 'foo':'notnull' }"));
            Assert.AreEqual(obj.foo, "notnull", "Make sure a null value can be overwritten");

            //    function func() {}
            //    jQuery.extend(func, { key: "value" } );
            //    equals( func.key, "value", "Verify a function can be extended" );

            dynamic defaults     = CQ.ParseJSON("{ 'xnumber1': 5, 'xnumber2': 7, 'xstring1': 'peter', 'xstring2': 'pan' }");
            dynamic defaultsCopy = CQ.ParseJSON(" { xnumber1: 5, xnumber2: 7, xstring1: 'peter', xstring2: 'pan' }");
            dynamic options1     = CQ.ParseJSON("{ xnumber2: 1, xstring2: 'x' }");
            dynamic options1Copy = CQ.ParseJSON(" { xnumber2: 1, xstring2: 'x' }");
            dynamic options2     = CQ.ParseJSON(" { xstring2: 'xx', xxx: 'newstringx'}");
            dynamic options2Copy = CQ.ParseJSON(" { xstring2: 'xx', xxx: 'newstringx'}");
            dynamic merged2      = CQ.ParseJSON(" { xnumber1: 5, xnumber2: 1, xstring1: 'peter', xstring2: 'xx', xxx: 'newstringx' }");


            ret = CQ.Extend(true, CQ.ParseJSON(" { foo:'bar' }"), CQ.ParseJSON("{ foo:null }"));
            Assert.IsTrue(ret.foo == null, "Make sure a null value doesn't crash with deep extend, for #1908");

            settings = CQ.Extend(null, defaults, options1, options2);
            Assert.AreEqual(merged2, settings, "Check if extended: settings must be extended");
            Assert.AreEqual(defaults, defaultsCopy, "Check if not modified: options1 must not be modified");
            Assert.AreEqual(options1, options1Copy, "Check if not modified: options1 must not be modified");
            Assert.AreEqual(options2, options2Copy, "Check if not modified: options2 must not be modified");
        }