public void CatalogDelta_ToString_1() { CatalogDelta delta = new CatalogDelta(); Assert.AreEqual("", delta.ToString().DosToUnix()); delta = _GetDelta(); Assert.AreEqual("New: 101, 102, 103\nDeleted: 80, 81, 82\nAltered: 90, 91, 92\n", delta.ToString().DosToUnix()); }
public void CatalogDelta_ToJson_1() { CatalogDelta delta = new CatalogDelta(); Assert.AreEqual("{}", JsonUtility.SerializeShort(delta)); delta = _GetDelta(); Assert.AreEqual("{'firstDate':'2017-12-09T00:00:00','secondDate':'2017-12-10T00:00:00','database':'IBIS','new':[101,102,103],'deleted':[80,81,82],'altered':[90,91,92]}", JsonUtility.SerializeShort(delta)); }
public void CatalogDelta_ToXml_1() { CatalogDelta delta = new CatalogDelta(); Assert.AreEqual("<catalogDelta />", XmlUtility.SerializeShort(delta)); delta = _GetDelta(); Assert.AreEqual("<catalogDelta firstDate=\"2017-12-09T00:00:00\" secondDate=\"2017-12-10T00:00:00\" database=\"IBIS\"><new><mfn>101</mfn><mfn>102</mfn><mfn>103</mfn></new><deleted><mfn>80</mfn><mfn>81</mfn><mfn>82</mfn></deleted><altered><mfn>90</mfn><mfn>91</mfn><mfn>92</mfn></altered></catalogDelta>", XmlUtility.SerializeShort(delta)); }
public void CatalogDelta_Serialization_1() { CatalogDelta delta = new CatalogDelta(); _TestSerialization(delta); delta = _GetDelta(); _TestSerialization(delta); }
private void _TestSerialization ( [NotNull] CatalogDelta first ) { byte[] bytes = first.SaveToMemory(); CatalogDelta second = bytes.RestoreObjectFromMemory <CatalogDelta>(); _Compare(first, second); }
static void Main(string[] args) { if (args.Length != 1) { return; } try { string connectionString = args[0]; using (IrbisConnection connection = new IrbisConnection(connectionString)) { ConnectedClient provider = new ConnectedClient(connection); CatalogState first; if (File.Exists("first.state")) { first = SerializationUtility .RestoreObjectFromFile <CatalogState> ( "first.state" ); Console.WriteLine("Previous state restored from first.state"); } else { first = provider.GetCatalogState("ISTU"); first.SaveToFile("first.state"); Console.WriteLine("Initial state saved to first.state"); return; } CatalogState second = provider.GetCatalogState("ISTU"); second.SaveToFile("second.state"); Console.WriteLine("New state saved to second.state"); CatalogDelta delta = CatalogDelta.Create ( first, second ); delta.SaveToFile("state.delta"); Console.WriteLine("Difference saved to state.delta"); Console.WriteLine(delta); } } catch (Exception e) { Console.WriteLine(e); } }
public void CatalogDelta_Construciton_1() { CatalogDelta delta = new CatalogDelta(); Assert.AreEqual(0, delta.Id); Assert.AreEqual(DateTime.MinValue, delta.FirstDate); Assert.AreEqual(DateTime.MinValue, delta.SecondDate); Assert.IsNull(delta.Database); Assert.IsNull(delta.NewRecords); Assert.IsNull(delta.DeletedRecords); Assert.IsNull(delta.AlteredRecords); }
private void _Compare ( [NotNull] CatalogDelta first, [NotNull] CatalogDelta second ) { Assert.AreEqual(first.Id, second.Id); Assert.AreEqual(first.FirstDate, second.FirstDate); Assert.AreEqual(first.SecondDate, second.SecondDate); Assert.AreEqual(first.Database, second.Database); _Compare(first.NewRecords, second.NewRecords); _Compare(first.DeletedRecords, second.DeletedRecords); _Compare(first.AlteredRecords, second.AlteredRecords); }
public void CatalogDelta_Create_1() { CatalogState firstState = new CatalogState { Id = 1, Date = new DateTime(2017, 12, 8, 22, 42, 0), Database = "IBIS", MaxMfn = 4, LogicallyDeleted = new[] { 1, 2 }, Records = new[] { new RecordState { Id = 2, Mfn = 1, Status = RecordStatus.LogicallyDeleted, Version = 3 }, new RecordState { Id = 3, Mfn = 2, Status = RecordStatus.LogicallyDeleted, Version = 2 }, new RecordState { Id = 4, Mfn = 3, Status = RecordStatus.Last, Version = 1 }, new RecordState { Id = 5, Mfn = 4, Status = RecordStatus.Last, Version = 2 } } }; CatalogState secondState = new CatalogState { Id = 2, Date = new DateTime(2017, 12, 9, 22, 42, 0), Database = "IBIS", MaxMfn = 6, LogicallyDeleted = new[] { 1, 2, 3 }, Records = new[] { new RecordState { Id = 2, Mfn = 1, Status = RecordStatus.LogicallyDeleted, Version = 3 }, new RecordState { Id = 3, Mfn = 2, Status = RecordStatus.LogicallyDeleted, Version = 2 }, new RecordState { Id = 4, Mfn = 3, Status = RecordStatus.LogicallyDeleted, Version = 2 }, new RecordState { Id = 5, Mfn = 4, Status = RecordStatus.Last, Version = 4 }, new RecordState { Id = 6, Mfn = 5, Status = RecordStatus.Last, Version = 1 }, new RecordState { Id = 7, Mfn = 6, Status = RecordStatus.Last, Version = 1 } } }; CatalogDelta delta = CatalogDelta.Create ( firstState, secondState ); Assert.AreEqual(0, delta.Id); Assert.AreEqual(new DateTime(2017, 12, 8, 22, 42, 0, 0), delta.FirstDate); Assert.AreEqual(new DateTime(2017, 12, 9, 22, 42, 0, 0), delta.SecondDate); Assert.AreEqual("IBIS", delta.Database); Assert.IsNotNull(delta.NewRecords); Assert.AreEqual(2, delta.NewRecords.Length); Assert.AreEqual(5, delta.NewRecords[0]); Assert.AreEqual(6, delta.NewRecords[1]); Assert.IsNotNull(delta.DeletedRecords); Assert.AreEqual(1, delta.DeletedRecords.Length); Assert.AreEqual(3, delta.DeletedRecords[0]); Assert.IsNotNull(delta.AlteredRecords); Assert.AreEqual(1, delta.AlteredRecords.Length); Assert.AreEqual(4, delta.AlteredRecords[0]); }