diff --git a/README.md b/README.md index 848ff98..97f6ad0 100644 --- a/README.md +++ b/README.md @@ -198,3 +198,10 @@ var records = tableStore.GetByPartitionKey(1, e=>e.Name == "Jim CEO"); ``` In this example we get all records in parition "1" where the name is "Jim CEO". + +#### Timestamp +Azure Table Storage entities always have a timestamp. If your POCO has a field named Timestamp, that is a `DateTimeOffset`, `DateTime` or `String`, then this property will automatically be hydrated wit the timestamp provided by Azure Table Storage. + +Modifications to the Timestamp property do not get persisited. This is exactly how it works with the Azure Table Storage SDK. + +Considerations for taking a similar approach to ETag are being considered. \ No newline at end of file diff --git a/src/TableStorage.Abstractions.POCO.Tests/Employee.cs b/src/TableStorage.Abstractions.POCO.Tests/Employee.cs index 1dd0674..277ef3f 100644 --- a/src/TableStorage.Abstractions.POCO.Tests/Employee.cs +++ b/src/TableStorage.Abstractions.POCO.Tests/Employee.cs @@ -1,4 +1,6 @@ -namespace TableStorage.Abstractions.POCO.Tests +using System; + +namespace TableStorage.Abstractions.POCO.Tests { public class Employee { @@ -6,5 +8,6 @@ public class Employee public int Id { get; set; } public string Name { get; set; } public Department Department { get; set; } + public DateTimeOffset Timestamp { get; set; } } } \ No newline at end of file diff --git a/src/TableStorage.Abstractions.POCO.Tests/PocoTableStoreTests.cs b/src/TableStorage.Abstractions.POCO.Tests/PocoTableStoreTests.cs index c8f4c44..9b09584 100644 --- a/src/TableStorage.Abstractions.POCO.Tests/PocoTableStoreTests.cs +++ b/src/TableStorage.Abstractions.POCO.Tests/PocoTableStoreTests.cs @@ -59,6 +59,25 @@ public void insert_record() Assert.AreEqual(4, tableStore.GetRecordCount()); } + [TestMethod] + public void insert_record_with_timestamp_ignores_user_provided_timestamp_value() + { + var employee = new Employee + { + Name = "Test", + CompanyId = 99445, + Id = 991122, + Department = new Department { Id = 5, Name = "Test" }, + Timestamp = new DateTimeOffset(2001, 1, 1, 1, 1, 1, TimeSpan.Zero) + }; + tableStore.Insert(employee); + + var fromDb = tableStore.GetRecord(99445, 991122); + + Assert.AreNotEqual(employee.Timestamp, fromDb.Timestamp); + + } + [TestMethod] public void insert_or_replace_record_inserts_when_record_is_new() @@ -211,6 +230,13 @@ public void get_record() Assert.IsNotNull(record); } + [TestMethod] + public void get_record_populates_timestamp() + { + var record = tableStore.GetRecord("1", "1"); + Assert.AreNotEqual(default(DateTimeOffset), record.Timestamp); + } + [TestMethod] public void get_record_with_no_results() { @@ -404,6 +430,16 @@ public void get_records_by_row_key() Assert.AreEqual(2, records.Count()); } + [TestMethod] + public void get_records_by_row_key_contain_hydrated_timestamp() + { + var records = tableStore.GetByRowKey("1"); + foreach (var record in records) + { + Assert.AreNotEqual(default(DateTimeOffset), record.Timestamp); + } + } + [TestMethod] public void get_records_by_row_key_and_filter() { @@ -635,6 +671,26 @@ public void update_record() Assert.AreEqual("Mr. Jim CEO", record.Name); } + [TestMethod] + public void update_record_updates_timestamp() + { + var employee = new Employee + { + CompanyId = 1, + Id = 1, + Name = "Mr. Jim CEO", + Department = new Department { Id = 22, Name = "Executive" } + }; + tableStore.Update(employee); + var record = tableStore.GetRecord(1, 1); + var timestamp1 = record.Timestamp; + Task.Delay(5).Wait(); + tableStore.Update(employee); + record = tableStore.GetRecord(1, 1); + var timestamp2 = record.Timestamp; + Assert.AreNotEqual(timestamp1, timestamp2); + } + [TestMethod] public void update_record_wildcard_etag() { diff --git a/src/TableStorage.Abstractions.POCO.Tests/TableStorage.Abstractions.POCO.Tests.csproj b/src/TableStorage.Abstractions.POCO.Tests/TableStorage.Abstractions.POCO.Tests.csproj index 50812ab..9410168 100644 --- a/src/TableStorage.Abstractions.POCO.Tests/TableStorage.Abstractions.POCO.Tests.csproj +++ b/src/TableStorage.Abstractions.POCO.Tests/TableStorage.Abstractions.POCO.Tests.csproj @@ -40,13 +40,13 @@ - ..\packages\FluentValidation.8.6.1\lib\net45\FluentValidation.dll + ..\packages\FluentValidation.8.6.2\lib\net45\FluentValidation.dll ..\packages\Microsoft.Azure.Cosmos.Table.1.0.6\lib\netstandard2.0\Microsoft.Azure.Cosmos.Table.dll - - ..\packages\Microsoft.Azure.DocumentDB.Core.2.9.3\lib\netstandard1.6\Microsoft.Azure.DocumentDB.Core.dll + + ..\packages\Microsoft.Azure.DocumentDB.Core.2.10.0\lib\netstandard1.6\Microsoft.Azure.DocumentDB.Core.dll ..\packages\Microsoft.Azure.KeyVault.Core.3.0.5\lib\net461\Microsoft.Azure.KeyVault.Core.dll @@ -305,8 +305,8 @@ ..\packages\TableStorage.Abstractions.3.1.0\lib\netstandard2.0\TableStorage.Abstractions.dll - - ..\packages\TableStorage.Abstractions.TableEntityConverters.1.1.8\lib\net462\TableStorage.Abstractions.TableEntityConverters.dll + + ..\packages\TableStorage.Abstractions.TableEntityConverters.1.2.0\lib\net462\TableStorage.Abstractions.TableEntityConverters.dll ..\packages\Useful.Extensions.3.0.1\lib\netstandard2.0\Useful.Extensions.dll @@ -339,9 +339,9 @@ - + - + \ No newline at end of file diff --git a/src/TableStorage.Abstractions.POCO.Tests/app.config b/src/TableStorage.Abstractions.POCO.Tests/app.config index 1c9437e..27b8bc3 100644 --- a/src/TableStorage.Abstractions.POCO.Tests/app.config +++ b/src/TableStorage.Abstractions.POCO.Tests/app.config @@ -125,7 +125,7 @@ - + diff --git a/src/TableStorage.Abstractions.POCO.Tests/packages.config b/src/TableStorage.Abstractions.POCO.Tests/packages.config index 980b0d8..ff2cd61 100644 --- a/src/TableStorage.Abstractions.POCO.Tests/packages.config +++ b/src/TableStorage.Abstractions.POCO.Tests/packages.config @@ -1,8 +1,8 @@  - + - + @@ -92,6 +92,6 @@ - + \ No newline at end of file diff --git a/src/TableStorage.Abstractions.POCO/TableStorage.Abstractions.POCO.csproj b/src/TableStorage.Abstractions.POCO/TableStorage.Abstractions.POCO.csproj index e72e68e..6b05b8e 100644 --- a/src/TableStorage.Abstractions.POCO/TableStorage.Abstractions.POCO.csproj +++ b/src/TableStorage.Abstractions.POCO/TableStorage.Abstractions.POCO.csproj @@ -2,7 +2,7 @@ netstandard2.0 - 2.3.1 + 2.4 Giovanni Galbo Giovanni Galbo A repository wrapper for Azure Table Storage that uses POCOs (Plain Old CLR Objects) instead of objects that implemeent ITableEntity. @@ -19,18 +19,18 @@ The library will convert simple properties to fields in Azure Table Storage. Com https://github.com/giometrix/TableStorage.Abstractions.POCO https://github.com/giometrix/TableStorage.Abstractions.POCO table-storage azure-table-storage poco table-entities tableentity - update nuget packages + auto-populate timestamp field true MIT - 2.3.1.0 - 2.3.1.0 + 2.4.0.0 + 2.4.0.0 xtensible-x.png - +