|
| 1 | +using System; |
| 2 | +using CoreHelpers.WindowsAzure.Storage.Table.Backup; |
| 3 | +using CoreHelpers.WindowsAzure.Storage.Table.Tests.Contracts; |
| 4 | +using CoreHelpers.WindowsAzure.Storage.Table.Tests.Extensions; |
| 5 | +using CoreHelpers.WindowsAzure.Storage.Table.Tests.Models; |
| 6 | + |
| 7 | +namespace CoreHelpers.WindowsAzure.Storage.Table.Tests |
| 8 | +{ |
| 9 | + public class ITS22PartialUpates |
| 10 | + { |
| 11 | + private readonly IStorageContext _rootContext; |
| 12 | + |
| 13 | + public ITS22PartialUpates(IStorageContext context) |
| 14 | + { |
| 15 | + _rootContext = context; |
| 16 | + } |
| 17 | + |
| 18 | + [Fact] |
| 19 | + public async Task CreateAndVerifyBackup() |
| 20 | + { |
| 21 | + using (var scp = _rootContext.CreateChildContext()) |
| 22 | + { |
| 23 | + // set the tablename context |
| 24 | + scp.SetTableContext(); |
| 25 | + |
| 26 | + // configure the entity mapper |
| 27 | + scp.AddAttributeMapper<PartialUpdateModel>(); |
| 28 | + |
| 29 | + // verify we don't have any value |
| 30 | + Assert.Empty(await scp.EnableAutoCreateTable().Query<PartialUpdateModel>().InAllPartitions().Now()); |
| 31 | + |
| 32 | + |
| 33 | + // insert the value with just on optional integer |
| 34 | + await scp.MergeOrInsertAsync<PartialUpdateModel>(new PartialUpdateModel() { CustomerId = "C01", MeterId = "M01", Value01 = 1 }); |
| 35 | + |
| 36 | + var result = (await scp.EnableAutoCreateTable().Query<PartialUpdateModel>().Now()).First(); |
| 37 | + Assert.True(result.Value01.HasValue); |
| 38 | + Assert.Equal(result.Value01, 1); |
| 39 | + Assert.False(result.Value02.HasValue); |
| 40 | + Assert.False(result.Value03.HasValue); |
| 41 | + |
| 42 | + // add the second update with just Value02 and ensure that Value01 stays untouched |
| 43 | + await scp.MergeOrInsertAsync<PartialUpdateModel>(new PartialUpdateModel() { CustomerId = "C01", MeterId = "M01", Value02 = 2 }); |
| 44 | + |
| 45 | + result = (await scp.EnableAutoCreateTable().Query<PartialUpdateModel>().Now()).First(); |
| 46 | + Assert.True(result.Value01.HasValue); |
| 47 | + Assert.Equal(result.Value01, 1); |
| 48 | + Assert.True(result.Value02.HasValue); |
| 49 | + Assert.Equal(result.Value02, 2); |
| 50 | + Assert.False(result.Value03.HasValue); |
| 51 | + |
| 52 | + // replace the model with Value 03 |
| 53 | + await scp.InsertOrReplaceAsync<PartialUpdateModel>(new PartialUpdateModel() { CustomerId = "C01", MeterId = "M01", Value03 = 3 }); |
| 54 | + |
| 55 | + result = (await scp.EnableAutoCreateTable().Query<PartialUpdateModel>().Now()).First(); |
| 56 | + Assert.False(result.Value01.HasValue); |
| 57 | + Assert.False(result.Value02.HasValue); |
| 58 | + Assert.True(result.Value03.HasValue); |
| 59 | + Assert.Equal(result.Value03, 3); |
| 60 | + |
| 61 | + // clean up |
| 62 | + scp.DropTable<PartialUpdateModel>(); |
| 63 | + } |
| 64 | + } |
| 65 | + } |
| 66 | +} |
| 67 | + |
0 commit comments