public void Apply_PushEachToExisting() { var update = Updater.PushEach(e => e.Books, new string[] { "A", "B", "C" }); var entity = new MyEntity { Books = new List <string> { "X", "Y", "Z" } }; var docs = ToBson(entity); var updater = new Updater(); updater.Apply(update, docs); var array = docs[0]["Books"].AsBsonArray; array.Count.Should().Be(6); array[0].Should().Be("X"); array[1].Should().Be("Y"); array[2].Should().Be("Z"); array[3].Should().Be("A"); array[4].Should().Be("B"); array[5].Should().Be("C"); /* * */ }
/// <summary> /// Apply changes on the WorkspaceContainer, the update event handler will get trigger if anything was changed /// </summary> /// <param name="pType"></param> /// <param name="pEvents"></param> private void Monitor_Updated(WorkspaceType pType, List <FSEventInfo> pEvents) { try { Updater.Apply(Container, VideoInfoProvider, pType, pEvents); } catch (Exception) { ReloadRequired?.Invoke(this, new EventArgs()); } }
public void Apply_FieldOnChildWhenChildNOTExists_FieldChanged() { var update = Updater .Set(e => e.TheThings.ThingA, "A"); var docs = ToBson(new MyEntity { }); var updater = new Updater(); updater.Apply(update, docs); docs[0]["TheThings"]["ThingA"].Should().Be("A"); }
public void Apply_PushToEmpty() { var update = Updater.Push(e => e.Books, "My Book"); var entity = new MyEntity(); var docs = ToBson(entity); var updater = new Updater(); updater.Apply(update, docs); var array = docs[0]["Books"].AsBsonArray; array.Count.Should().Be(1); array[0].Should().Be("My Book"); }
public void Apply_ReplaceArrayElement_ValueIsChanged() { var update = Updater .Set(e => e.Books[1], "A"); var docs = ToBson(new MyEntity { Books = new List <string> { "X", "Y", "Z" } }); var updater = new Updater(); updater.Apply(update, docs); docs[0]["Books"][1].Should().Be("A"); }
public void Apply_UnsetSimple_RemovesItem() { //var col = GetCollection<MyEntity>(); var update = Updater .Unset(e => e.Name); var docs = ToBson(new MyEntity { Name = "Mark" }); var updater = new Updater(); updater.Apply(update, docs); docs[0].Any(e => e.Name == "Mark").Should().BeFalse(); }
public void Apply_ReplaceArrayWhenArrayIsNull_ValueIsChanged() { var update = Updater .Set(e => e.Books, new List <string> { "A" }); var docs = ToBson(new MyEntity { }); var updater = new Updater(); updater.Apply(update, docs); docs[0]["Books"].IsBsonArray.Should().BeTrue(); docs[0]["Books"][0].Should().Be("A"); }
public void Apply_PlainSets_NewValuesShouldExist() { //var col = GetCollection<MyEntity>(); var update = Updater .Set(e => e.Name, "Mark") .Set(e => e.Number, 10); var docs = ToBson(new MyEntity { }); var updater = new Updater(); updater.Apply(update, docs); docs[0].GetValue("Name").Should().Be("Mark"); docs[0].GetValue("Number").Should().Be(10); }
public void Apply_PushEachToEmpty() { var update = Updater.PushEach(e => e.Books, new string[] { "A", "B", "C" }); var entity = new MyEntity(); var docs = ToBson(entity); var updater = new Updater(); updater.Apply(update, docs); var array = docs[0]["Books"].AsBsonArray; array.Count.Should().Be(3); array[0].Should().Be("A"); array[1].Should().Be("B"); array[2].Should().Be("C"); }
public long Apply_MultipleInts_MultipliesAndSetsCorrectType(string entityValue, int by) { var update = Updater .Mul(e => e.NullableLong, by); var entity = new MyEntity(); if (!string.IsNullOrWhiteSpace(entityValue)) { entity.NullableLong = int.Parse(entityValue); } var docs = ToBson(entity); var updater = new Updater(); updater.Apply(update, docs); return(docs[0]["NullableLong"].AsInt64); }
public void Apply_PushToExisting() { var update = Updater.Push(e => e.Books, "My Book"); var entity = new MyEntity { Books = new List <string> { "Your Book" } }; var docs = ToBson(entity); var updater = new Updater(); updater.Apply(update, docs); var array = docs[0]["Books"].AsBsonArray; array.Count.Should().Be(2); array[0].Should().Be("Your Book"); array[1].Should().Be("My Book"); }