Esempio n. 1
0
        public void TestAddUniqueToList()
        {
            AVObject obj = new AVObject("Corgi");

            obj.AddUniqueToList("emptyList", "gogo");
            obj["existingList"] = new List <string>()
            {
                "gogo"
            };

            Assert.True(obj.ContainsKey("emptyList"));
            Assert.AreEqual(1, obj.Get <List <object> >("emptyList").Count);

            obj.AddUniqueToList("existingList", "gogo");
            Assert.True(obj.ContainsKey("existingList"));
            Assert.AreEqual(1, obj.Get <List <object> >("existingList").Count);

            obj.AddUniqueToList("existingList", 1);
            Assert.AreEqual(2, obj.Get <List <object> >("existingList").Count);

            obj.AddRangeUniqueToList("newRange", new List <string>()
            {
                "anti", "anti"
            });
            Assert.AreEqual(1, obj.Get <List <object> >("newRange").Count);
        }
Esempio n. 2
0
        public void TestIndexGetterSetter()
        {
            AVObject obj = AVObject.Create("Corgi");

            obj["gogo"]    = true;
            obj["list"]    = new List <string>();
            obj["dict"]    = new Dictionary <string, object>();
            obj["fakeACL"] = new AVACL();
            obj["obj"]     = new AVObject("Corgi");

            Assert.True(obj.ContainsKey("gogo"));
            Assert.IsInstanceOf <bool>(obj["gogo"]);

            Assert.True(obj.ContainsKey("list"));
            Assert.IsInstanceOf <IList <string> >(obj["list"]);

            Assert.True(obj.ContainsKey("dict"));
            Assert.IsInstanceOf <IDictionary <string, object> >(obj["dict"]);

            Assert.True(obj.ContainsKey("fakeACL"));
            Assert.IsInstanceOf <AVACL>(obj["fakeACL"]);

            Assert.True(obj.ContainsKey("obj"));
            Assert.IsInstanceOf <AVObject>(obj["obj"]);

            Assert.Throws <KeyNotFoundException>(() => { var gogo = obj["missingItem"]; });
        }
Esempio n. 3
0
        public void TestRevert()
        {
            AVObject obj = AVObject.Create("Corgi");

            obj["gogo"] = true;

            Assert.True(obj.IsDirty);
            Assert.AreEqual(1, obj.GetCurrentOperations().Count);
            Assert.True(obj.ContainsKey("gogo"));

            obj.Revert();

            Assert.True(obj.IsDirty);
            Assert.AreEqual(0, obj.GetCurrentOperations().Count);
            Assert.False(obj.ContainsKey("gogo"));
        }
Esempio n. 4
0
        public void TestAddUniqueToList()
        {
            AVObject obj = new AVObject("Corgi");
            obj.AddUniqueToList("emptyList", "gogo");
            obj["existingList"] = new List<string>() { "gogo" };

            Assert.True(obj.ContainsKey("emptyList"));
            Assert.AreEqual(1, obj.Get<List<object>>("emptyList").Count);

            obj.AddUniqueToList("existingList", "gogo");
            Assert.True(obj.ContainsKey("existingList"));
            Assert.AreEqual(1, obj.Get<List<object>>("existingList").Count);

            obj.AddUniqueToList("existingList", 1);
            Assert.AreEqual(2, obj.Get<List<object>>("existingList").Count);

            obj.AddRangeUniqueToList("newRange", new List<string>() { "anti", "anti" });
            Assert.AreEqual(1, obj.Get<List<object>>("newRange").Count);
        }
Esempio n. 5
0
        public void TestRemove()
        {
            AVObject obj = AVObject.Create("Corgi");

            obj["gogo"] = true;
            Assert.True(obj.ContainsKey("gogo"));

            obj.Remove("gogo");
            Assert.False(obj.ContainsKey("gogo"));

            IObjectState state = new MutableObjectState
            {
                ObjectId   = "waGiManPutr4Pet1r",
                ClassName  = "Pagi",
                CreatedAt  = new DateTime(),
                ServerData = new Dictionary <string, object>()
                {
                    { "username", "kevin" },
                    { "sessionToken", "se551onT0k3n" }
                }
            };

            obj = AVObjectExtensions.FromState <AVObject>(state, "Corgi");
            Assert.True(obj.ContainsKey("username"));
            Assert.True(obj.ContainsKey("sessionToken"));

            obj.Remove("username");
            Assert.False(obj.ContainsKey("username"));
            Assert.True(obj.ContainsKey("sessionToken"));
        }
Esempio n. 6
0
        /// <summary>
        /// Gets the updated keys.
        /// </summary>
        /// <returns>The updated keys.</returns>
        /// <param name="obj">Object.</param>
        public static IEnumerable <string> GetUpdatedKeys(this AVObject obj)
        {
            var updatedKeys = new List <string>();

            if (obj.ContainsKey("_updatedKeys"))
            {
                if (obj["_updatedKeys"] is List <object> upKys)
                {
                    updatedKeys = upKys.Select(k => k.ToString()).ToList();
                }
            }
            return(updatedKeys);
        }