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)); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }