Skip to content

Commit 9904e05

Browse files
authored
LastSyncTime can be empty (Azure#21829)
* LastSyncTime can be empty
1 parent 7397225 commit 9904e05

File tree

3 files changed

+80
-27
lines changed

3 files changed

+80
-27
lines changed

sdk/tables/Azure.Data.Tables/src/Generated/Models/TableGeoReplicationInfo.Serialization.cs

Lines changed: 0 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
using System;
5+
using System.Text;
6+
using System.Xml.Linq;
7+
using Azure.Core;
8+
9+
namespace Azure.Data.Tables.Models
10+
{
11+
public partial class TableGeoReplicationInfo
12+
{
13+
internal static TableGeoReplicationInfo DeserializeTableGeoReplicationInfo(XElement element)
14+
{
15+
TableGeoReplicationStatus status = default;
16+
DateTimeOffset lastSyncedOn = default;
17+
if (element.Element("Status") is XElement statusElement)
18+
{
19+
status = new TableGeoReplicationStatus(statusElement.Value);
20+
}
21+
if (element.Element("LastSyncTime") is XElement lastSyncTimeElement)
22+
{
23+
// LastSyncTime can be empty (see https://docs.microsoft.com/en-us/rest/api/storageservices/get-table-service-stats#response-body)
24+
lastSyncedOn = (lastSyncTimeElement.Value.Length == 0) switch
25+
{
26+
true => DateTimeOffset.MinValue,
27+
false => lastSyncTimeElement.GetDateTimeOffsetValue("R")
28+
};
29+
}
30+
return new TableGeoReplicationInfo(status, lastSyncedOn);
31+
}
32+
}
33+
}

sdk/tables/Azure.Data.Tables/tests/TableServiceClientTests.cs

Lines changed: 47 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the MIT License.
33

44
using System;
5+
using System.Threading.Tasks;
56
using Azure.Core.TestFramework;
67
using Azure.Data.Tables.Sas;
78
using NUnit.Framework;
@@ -11,19 +12,20 @@ namespace Azure.Data.Tables.Tests
1112
public class TableServiceClientTests : ClientTestBase
1213
{
1314
public TableServiceClientTests(bool isAsync) : base(isAsync)
14-
{
15-
}
15+
{ }
1616

1717
/// <summary>
1818
/// The table account name.
1919
/// </summary>
2020
private readonly string _accountName = "someaccount";
21+
2122
private const string Secret = "Kg==";
2223

2324
/// <summary>
2425
/// The table endpoint.
2526
/// </summary>
2627
private readonly Uri _url = new Uri($"https://someaccount.table.core.windows.net");
28+
2729
private readonly Uri _urlHttp = new Uri($"http://someaccount.table.core.windows.net");
2830

2931
private TableServiceClient service_Instrumented { get; set; }
@@ -40,17 +42,35 @@ public void TestSetup()
4042
[Test]
4143
public void ConstructorValidatesArguments()
4244
{
43-
Assert.That(() => new TableServiceClient(null, new TableSharedKeyCredential(_accountName, string.Empty)), Throws.InstanceOf<ArgumentNullException>(), "The constructor should validate the url.");
44-
45-
Assert.That(() => new TableServiceClient(_url, credential: default(TableSharedKeyCredential)), Throws.InstanceOf<ArgumentNullException>(), "The constructor should validate the TablesSharedKeyCredential.");
46-
47-
Assert.That(() => new TableServiceClient(_urlHttp, new AzureSasCredential("sig")), Throws.InstanceOf<ArgumentException>(), "The constructor should validate the Uri is https when using a SAS token.");
48-
49-
Assert.That(() => new TableServiceClient(_url, default(AzureSasCredential)), Throws.InstanceOf<ArgumentNullException>(), "The constructor should not accept a null credential");
50-
51-
Assert.That(() => new TableServiceClient(_url, new TableSharedKeyCredential(_accountName, string.Empty)), Throws.Nothing, "The constructor should accept valid arguments.");
52-
53-
Assert.That(() => new TableServiceClient(_urlHttp, new TableSharedKeyCredential(_accountName, string.Empty)), Throws.Nothing, "The constructor should accept an http url.");
45+
Assert.That(
46+
() => new TableServiceClient(null, new TableSharedKeyCredential(_accountName, string.Empty)),
47+
Throws.InstanceOf<ArgumentNullException>(),
48+
"The constructor should validate the url.");
49+
50+
Assert.That(
51+
() => new TableServiceClient(_url, credential: default(TableSharedKeyCredential)),
52+
Throws.InstanceOf<ArgumentNullException>(),
53+
"The constructor should validate the TablesSharedKeyCredential.");
54+
55+
Assert.That(
56+
() => new TableServiceClient(_urlHttp, new AzureSasCredential("sig")),
57+
Throws.InstanceOf<ArgumentException>(),
58+
"The constructor should validate the Uri is https when using a SAS token.");
59+
60+
Assert.That(
61+
() => new TableServiceClient(_url, default(AzureSasCredential)),
62+
Throws.InstanceOf<ArgumentNullException>(),
63+
"The constructor should not accept a null credential");
64+
65+
Assert.That(
66+
() => new TableServiceClient(_url, new TableSharedKeyCredential(_accountName, string.Empty)),
67+
Throws.Nothing,
68+
"The constructor should accept valid arguments.");
69+
70+
Assert.That(
71+
() => new TableServiceClient(_urlHttp, new TableSharedKeyCredential(_accountName, string.Empty)),
72+
Throws.Nothing,
73+
"The constructor should accept an http url.");
5474
}
5575

5676
/// <summary>
@@ -111,5 +131,19 @@ public void GenerateSasUri()
111131

112132
Assert.AreEqual("?" + expectedSas, actualSas.Query);
113133
}
134+
135+
[Test]
136+
public async Task GetStatisticsHandlesEmptyLAstUpdatedTime(
137+
[Values("Tue, 23 Mar 2021 18:29:21 GMT", "")]
138+
string date)
139+
{
140+
var response = new MockResponse(200);
141+
response.SetContent(
142+
$"<?xml version=\"1.0\" encoding=\"utf-8\"?><StorageServiceStats><GeoReplication><Status>live</Status><LastSyncTime>{date}</LastSyncTime></GeoReplication></StorageServiceStats>");
143+
var mockTransport = new MockTransport(response);
144+
var service = InstrumentClient(new TableServiceClient(_url, new AzureSasCredential("sig"), new TableClientOptions { Transport = mockTransport }));
145+
146+
await service.GetStatisticsAsync();
147+
}
114148
}
115149
}

0 commit comments

Comments
 (0)