public void ShouldGenerateValidEventsForMapFields() { var allTypes = new TestAllTypes(); allTypes.MapInt32TestAllTypesMessage.Add(1, GenerateMapTestAllTypes(100)); allTypes.MapInt32TestAllTypesMessage[1].SingleNestedMessage.Bb += 1; allTypes.MapInt32TestAllTypesMessage[1].SingleNestedMessage.Bb += 1; allTypes.MapInt32TestAllTypesMessage.Remove(1); allTypes.MapInt32TestAllTypesMessage.Add(2, GenerateMapTestAllTypes(101)); allTypes.MapInt32TestAllTypesMessage.Add(3, GenerateMapTestAllTypes(102)); allTypes.MapInt32TestAllTypesMessage.Add(4, GenerateMapTestAllTypes(103)); allTypes.MapInt32TestAllTypesMessage[2].SingleNestedMessage.Bb += 1; allTypes.MapInt32TestAllTypesMessage[2].SingleNestedMessage.Bb += 1; allTypes.MapInt32TestAllTypesMessage.Remove(2); allTypes.MapInt32TestAllTypesMessage.Add(5, GenerateMapTestAllTypes(104)); allTypes.MapInt32TestAllTypesMessage[3].SingleNestedMessage.Bb += 1; allTypes.MapInt32TestAllTypesMessage[3].SingleNestedMessage.Bb += 1; var events = allTypes.GenerateEvents(); var target = new TestAllTypes(); target.ApplyEvents(events); Assert.Equal(allTypes, target); }
public void ShouldGenerateEventsInSnapshotBasedInstance() { var allTypes = new TestAllTypes(); ApplyAllChanges(allTypes); var snapshot = allTypes.GenerateSnapshot(); var target = new TestAllTypes(); target.ApplyEvents(snapshot); UpdateNestedMessages(target, 2); UpdateNestedMessages(target.OneofAllTypes, 5); UpdateNestedMessages(target.AllTypes, 6); // verify events are stable var targetEvents = target.GenerateEvents(); var target2 = new TestAllTypes(); target2.ApplyEvents(snapshot); target2.ApplyEvents(targetEvents); Assert.Equal(target, target2); Assert.NotEqual(allTypes, target2); // verify snapshot is stable var targetSnapshot = target.GenerateSnapshot(); var target3 = new TestAllTypes(); target3.ApplyEvents(targetSnapshot); Assert.Equal(target, target3); Assert.NotEqual(allTypes, target3); }
public void ShouldGenerateEventsInDeeplyNestedSnapshotBasedInstance() { var root = DeeplyNested(); root.AllTypes.AllTypes.AllTypes.MapInt32TestAllTypesMessage[1] = DeeplyNested(); root.AllTypes.AllTypes.AllTypes.MapInt32TestAllTypesMessage[3] = DeeplyNested(); root.AllTypes.AllTypes.AllTypes.MapInt32TestAllTypesMessage[1].AllTypes.AllTypes.AllTypes.RepeatedTestAllTypesMessage.Add(DeeplyNested()); root.AllTypes.AllTypes.AllTypes.MapInt32TestAllTypesMessage[1].AllTypes.AllTypes.AllTypes.RepeatedTestAllTypesMessage.Add(DeeplyNested()); var allTypes = root.AllTypes.AllTypes.AllTypes.MapInt32TestAllTypesMessage[1].AllTypes.AllTypes.AllTypes.RepeatedTestAllTypesMessage[1].AllTypes.AllTypes.AllTypes; ApplyAllChanges(allTypes); var snapshot = root.GenerateSnapshot(); var target = new TestAllTypes(); target.ApplyEvents(snapshot); var nested = target.AllTypes.AllTypes.AllTypes.MapInt32TestAllTypesMessage[1].AllTypes.AllTypes.AllTypes.RepeatedTestAllTypesMessage[1].AllTypes.AllTypes.AllTypes; UpdateNestedMessages(nested, 2); UpdateNestedMessages(nested.OneofAllTypes, 5); UpdateNestedMessages(nested.AllTypes, 6); // verify events are stable var targetEvents = target.GenerateEvents(); var target2 = new TestAllTypes(); target2.ApplyEvents(snapshot); target2.ApplyEvents(targetEvents); Assert.Equal(target, target2); Assert.NotEqual(allTypes, target2); // verify snapshot is stable var targetSnapshot = target.GenerateSnapshot(); var target3 = new TestAllTypes(); target3.ApplyEvents(targetSnapshot); Assert.Equal(target, target3); Assert.NotEqual(allTypes, target3); }
public void ShouldGenerateValidEventsForRepeatedFields() { var allTypes = new TestAllTypes(); allTypes.RepeatedNestedMessage.Add(new TestAllTypes.Types.NestedMessage { Bb = 10 }); allTypes.RepeatedNestedMessage[0].Bb = 11; allTypes.RepeatedNestedMessage[0].Bb = 12; allTypes.RepeatedNestedMessage.RemoveAt(0); allTypes.RepeatedNestedMessage.Add(new TestAllTypes.Types.NestedMessage { Bb = 13 }); allTypes.RepeatedNestedMessage.Add(new TestAllTypes.Types.NestedMessage { Bb = 14 }); allTypes.RepeatedNestedMessage.Add(new TestAllTypes.Types.NestedMessage { Bb = 15 }); allTypes.RepeatedNestedMessage[0].Bb = 16; allTypes.RepeatedNestedMessage[0].Bb = 17; allTypes.RepeatedNestedMessage.RemoveAt(0); allTypes.RepeatedNestedMessage.Add(new TestAllTypes.Types.NestedMessage { Bb = 18 }); allTypes.RepeatedNestedMessage[0].Bb = 19; allTypes.RepeatedNestedMessage[0].Bb = 20; var events = allTypes.GenerateEvents(); var target = new TestAllTypes(); target.ApplyEvents(events); Assert.Equal(allTypes, target); }