示例#1
0
        public void WithoutIdentifier()
        {
            var db = DatabaseGenerator.Get();
            Person person = new Person();
            var tracker = new DocumentTracker(db);

            tracker.TrackChanges(person, ObjectUtility.CreateJObject(person, db));

            Assert.Throws<KeyNotFoundException>(() => tracker.GetChanges(person));
        }
示例#2
0
        public void None()
        {
            var db = DatabaseGenerator.Get();
            Product product = new Product();
            var tracker = new DocumentTracker(db);

            tracker.TrackChanges(product, ObjectUtility.CreateJObject(product, db));

            var changed = tracker.GetChanges(product);

            Assert.Equal(changed.Count, 0);
        }
示例#3
0
        public void OnePropertyToNull()
        {
            var db = DatabaseGenerator.Get();
            Product product = new Product() { Title = "Pen" };
            var tracker = new DocumentTracker(db);

            tracker.TrackChanges(product, ObjectUtility.CreateJObject(product, db));

            product.Title = null;

            var changed = tracker.GetChanges(product);

            var expectedJson = JObject.Parse("{'Title':null}");
            Assert.Equal(JObject.DeepEquals(expectedJson, changed), true);
        }
示例#4
0
        public void OneProperty()
        {
            var db = DatabaseGenerator.Get();
            Product product = new Product();
            var tracker = new DocumentTracker(db);

            tracker.TrackChanges(product, ObjectUtility.CreateJObject(product, db));

            product.Quantity = 5;

            var changed = tracker.GetChanges(product);

            var expectedJson = JObject.Parse("{'Quantity':5}");
            Assert.Equal(JObject.DeepEquals(expectedJson, changed), true);
        }
示例#5
0
        public void NestedInNestedOneProperty()
        {
            var db = DatabaseGenerator.Get();
            Product product = new Product()
            {
                Category = new Category
                {
                    Seller = new Seller
                    {
                        TotalSells = 5000
                    }
                }
            };
            var tracker = new DocumentTracker(db);

            tracker.TrackChanges(product, ObjectUtility.CreateJObject(product, db));

            product.Category.Seller.TotalSells = 11000;

            var changed = tracker.GetChanges(product);

            var expectedJson = JObject.Parse("{'Category':{'Seller':{'TotalSells':11000}}}");
            Assert.Equal(JObject.DeepEquals(expectedJson, changed), true);
        }
示例#6
0
        public void NestedInNestedDictionary()
        {
            var db = DatabaseGenerator.Get();
            Product product = new Product()
            {
                Category = new Category
                {
                    Seller = new Seller
                    {
                        ProductSells = new Dictionary<string, int>() { { "Pen", 1 } }
                    }
                }
            };
            var tracker = new DocumentTracker(db);

            tracker.TrackChanges(product, ObjectUtility.CreateJObject(product, db));

            product.Category.Seller.ProductSells.Add("Pencil", 3);

            var changed = tracker.GetChanges(product);

            var expectedJson = JObject.Parse("{'Category':{'Seller':{'ProductSells':{'Pencil':3}}}}");
            Assert.Equal(JObject.DeepEquals(expectedJson, changed), true);
        }
示例#7
0
        public void NestedList()
        {
            var db = DatabaseGenerator.Get();
            Product product = new Product() { Category = new Category() { Tags = new List<string>() { "Soft" } } };
            var tracker = new DocumentTracker(db);

            tracker.TrackChanges(product, ObjectUtility.CreateJObject(product, db));

            product.Category.Tags.Add("Hard");

            var changed = tracker.GetChanges(product);

            var expectedJson = JObject.Parse("{'Category':{'Tags':['Soft','Hard']}}");
            Assert.Equal(JObject.DeepEquals(expectedJson, changed), true);
        }
示例#8
0
        public void NestedToNull()
        {
            var db = DatabaseGenerator.Get();
            Product product = new Product() { Category = new Category() { Title = "Featured" } };
            var tracker = new DocumentTracker(db);

            tracker.TrackChanges(product, ObjectUtility.CreateJObject(product, db));

            product.Category = null;

            var changed = tracker.GetChanges(product);

            var expectedJson = JObject.Parse("{'Category':null}");
            Assert.Equal(JObject.DeepEquals(expectedJson, changed), true);
        }
示例#9
0
        public void DictionaryTwoProperty()
        {
            var db = DatabaseGenerator.Get();
            Product product = new Product() { TypeQuantities = new Dictionary<string, int>() { { "Soft", 1 } } };
            var tracker = new DocumentTracker(db);

            tracker.TrackChanges(product, ObjectUtility.CreateJObject(product, db));

            product.TypeQuantities["Soft"] = 5;
            product.TypeQuantities.Add("Hard", 2);

            var changed = tracker.GetChanges(product);

            var expectedJson = JObject.Parse("{'TypeQuantities':{'Hard':2,'Soft':5}}");
            Assert.Equal(JObject.DeepEquals(expectedJson, changed), true);
        }
示例#10
0
        public void ListFromNull()
        {
            var db = DatabaseGenerator.Get();
            Product product = new Product();
            var tracker = new DocumentTracker(db);

            tracker.TrackChanges(product, ObjectUtility.CreateJObject(product, db));

            product.Tags = new List<string>() { "Soft" };

            var changed = tracker.GetChanges(product);

            var expectedJson = JObject.Parse("{'Tags':['Soft']}");
            Assert.Equal(JObject.DeepEquals(expectedJson, changed), true);
        }