public async Task TestConflictReplace() { var ioc = TestUtils.GetTestIoc(); var dbOperations = ioc.GetRequiredService <DbOperations>(); var dbInstance = ioc.GetRequiredService <DbInstance>(); var table = dbInstance.CreateTableIfNotExists("mytable", false); var rawClass = new TestReplaceEntity { PartitionKey = "test", RowKey = "test", TimeStamp = "12:00:00", Value = "123" }; var memory = rawClass.ToMemory(); await dbOperations.InsertAsync(table, memory, DataSynchronizationPeriod.Sec1, DateTime.UtcNow); rawClass = table.GetEntity("test", "test").AsResult <TestReplaceEntity>(); rawClass.Value = "456"; rawClass.TimeStamp = "111"; memory = rawClass.ToMemory(); var opResult = await dbOperations.ReplaceAsync(table, memory, DataSynchronizationPeriod.Immediately, DateTime.UtcNow); Assert.AreEqual(OperationResult.RecordChangedConcurrently, opResult); }
public async Task TestOkReplace() { var ioc = TestUtils.GetTestIoc(); var dbOperations = ioc.GetRequiredService <DbOperations>(); var dbInstance = ioc.GetRequiredService <DbInstance>(); var table = dbInstance.CreateTableIfNotExists("mytable", false); var rawClass = new TestReplaceEntity { PartitionKey = "test", RowKey = "test", Value = "123" }; var dt = DateTime.UtcNow; await dbOperations.InsertAsync(table, rawClass.ToMemory(), DataSynchronizationPeriod.Sec1, dt); rawClass = table.GetEntity("test", "test").AsResult <TestReplaceEntity>(); rawClass.Value = "456"; dt = DateTime.UtcNow.AddSeconds(1); var opResult = await dbOperations.ReplaceAsync(table, rawClass.ToMemory(), DataSynchronizationPeriod.Immediately, dt); Assert.AreEqual(OperationResult.Ok, opResult); var result = table.GetEntity("test", "test").AsResult <TestReplaceEntity>(); Assert.AreEqual("456", result.Value); Assert.AreEqual(dt.ToTimeStampString(), result.TimeStamp); }