Skip to content

Commit 720364e

Browse files
committed
make Data Sync schema parsing case insensitive
1 parent 9ee1941 commit 720364e

File tree

4 files changed

+104
-20
lines changed

4 files changed

+104
-20
lines changed

src/ResourceManager/Sql/ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
- Additional information about change #1
1919
-->
2020
## Current Release
21+
* Schema file parsing for Update-AzureRmSqlSyncGroup is now case insensitive.
2122

2223
## Version 3.2.1
2324

src/ResourceManager/Sql/Commands.Sql.Test/Commands.Sql.Test.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@
313313
<Compile Include="UnitTests\AzureSqlDatabaseServerAttributeTests.cs" />
314314
<Compile Include="UnitTests\AzureSqlDatabaseIndexRecommendationAttributeTests.cs" />
315315
<Compile Include="UnitTests\AzureSqlCapabilityAttributeTests.cs" />
316+
<Compile Include="UnitTests\AzureSqlDataSyncTests.cs" />
316317
<Compile Include="UnitTests\AzureSqlServerUpgradeAttributeTests.cs" />
317318
<Compile Include="UnitTests\AzureSqlServerDisasterRecoveryConfigurationTests.cs" />
318319
<Compile Include="UnitTests\AzureSqlServiceTierAdvisorAttributeTests.cs" />
@@ -828,7 +829,7 @@
828829
<None Include="SessionRecords\Microsoft.Azure.Commands.Sql.Test.ScenarioTests.TransparentDataEncryptionCrudTests\TestDatabaseTransparentDataEncryptionUpdate.json">
829830
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
830831
</None>
831-
<None Include="SessionRecords\Microsoft.Azure.Commands.Sql.Test.ScenarioTests.TransparentDataEncryptionCrudTests\TestServerTransparentDataEncryptionProtectorGet.json">
832+
<None Include="SessionRecords\Microsoft.Azure.Commands.Sql.Test.ScenarioTests.TransparentDataEncryptionCrudTests\TestServerTransparentDataEncryptionProtectorGet.json">
832833
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
833834
</None>
834835
<None Include="SessionRecords\Microsoft.Azure.Commands.Sql.Test.ScenarioTests.TransparentDataEncryptionCrudTests\TestServerTransparentDataEncryptionProtectorSet.json">
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using Microsoft.Azure.Commands.Sql.DataSync.Cmdlet;
16+
using Microsoft.Azure.Commands.Sql.DataSync.Model;
17+
using Microsoft.Azure.Commands.Sql.Test.Utilities;
18+
using Microsoft.Azure.ServiceManagemenet.Common.Models;
19+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
20+
using Newtonsoft.Json.Linq;
21+
using Xunit;
22+
using Xunit.Abstractions;
23+
24+
namespace Microsoft.Azure.Commands.Sql.Test.UnitTests
25+
{
26+
public class AzureSqlDataSyncTests
27+
{
28+
public AzureSqlDataSyncTests(ITestOutputHelper output)
29+
{
30+
XunitTracingInterceptor.AddToContext(new XunitTracingInterceptor(output));
31+
}
32+
33+
[Fact]
34+
[Trait(Category.AcceptanceType, Category.CheckIn)]
35+
public void ParseSyncGroupSchema()
36+
{
37+
string schema = @"{
38+
""mastersyncMemberNAME"": ""masterMember"",
39+
""Tables"": [
40+
{
41+
""QUOTEDNAME"": ""testTable"",
42+
""columns"": [
43+
{
44+
""QuotedName"": ""testColumn""
45+
}
46+
]
47+
}
48+
]
49+
}";
50+
51+
var cmdlet = new UpdateAzureSqlSyncGroup();
52+
AzureSqlSyncGroupSchemaModel schemaModel = AzureSqlSyncGroupCmdletBase.ConstructSchemaFromJObject(JObject.Parse(schema));
53+
54+
Assert.Equal("masterMember", schemaModel.MasterSyncMemberName);
55+
Assert.Equal(1, schemaModel.Tables.Count);
56+
Assert.Equal("testTable", schemaModel.Tables[0].QuotedName);
57+
Assert.Equal(1, schemaModel.Tables[0].Columns.Count);
58+
Assert.Equal("testColumn", schemaModel.Tables[0].Columns[0].QuotedName);
59+
}
60+
}
61+
}

src/ResourceManager/Sql/Commands.Sql/Data Sync/Cmdlet/AzureSqlSyncGroupCmdletBase.cs

Lines changed: 40 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15+
using System;
1516
using System.IO;
1617
using System.Collections.Generic;
1718
using System.Management.Automation;
@@ -45,43 +46,63 @@ protected override AzureSqlDataSyncAdapter InitModelAdapter(IAzureSubscription s
4546
/// </summary>
4647
/// <param name="filePath">The path of the schema file</param>
4748
/// <returns>A schema object of member database</returns>
48-
protected AzureSqlSyncGroupSchemaModel ConstructSchemaFromFile(string filePath)
49+
protected static AzureSqlSyncGroupSchemaModel ConstructSchemaFromFile(string filePath)
4950
{
50-
AzureSqlSyncGroupSchemaModel schema = new AzureSqlSyncGroupSchemaModel();
5151
try
5252
{
5353
JObject jSchema = JObject.Parse(File.ReadAllText(filePath));
54-
schema.MasterSyncMemberName = jSchema["masterSyncMemberName"] == null ? null : jSchema["masterSyncMemberName"].ToString();
55-
List<AzureSqlSyncGroupSchemaTableModel> tables = new List<AzureSqlSyncGroupSchemaTableModel>();
56-
JArray jTables = (JArray)jSchema["tables"];
57-
if (jTables != null)
54+
return ConstructSchemaFromJObject(jSchema);
55+
}
56+
catch (Newtonsoft.Json.JsonReaderException)
57+
{
58+
throw new PSArgumentException("The schema file is empty or invalid!", "SchemaFile");
59+
}
60+
}
61+
62+
/// <summary>
63+
/// Construct schema for schema object
64+
/// </summary>
65+
/// <param name="jSchema">JObject containing description of the schema</param>
66+
/// <returns>A schema object of member database</returns>
67+
public static AzureSqlSyncGroupSchemaModel ConstructSchemaFromJObject(JObject jSchema)
68+
{
69+
AzureSqlSyncGroupSchemaModel schema = new AzureSqlSyncGroupSchemaModel();
70+
JToken masterSyncMemberName = jSchema.GetValue("masterSyncMemberName", StringComparison.InvariantCultureIgnoreCase);
71+
schema.MasterSyncMemberName = masterSyncMemberName == null ? null : masterSyncMemberName.ToString();
72+
List<AzureSqlSyncGroupSchemaTableModel> tables = new List<AzureSqlSyncGroupSchemaTableModel>();
73+
JArray jTables = (JArray)jSchema.GetValue("tables", StringComparison.InvariantCultureIgnoreCase);
74+
if (jTables != null)
75+
{
76+
foreach (var jTableToken in jTables.Children())
5877
{
59-
foreach (var jTable in jTables.Children())
78+
if (jTableToken.Type == JTokenType.Object)
6079
{
80+
JObject jTable = (JObject)jTableToken;
6181
AzureSqlSyncGroupSchemaTableModel table = new AzureSqlSyncGroupSchemaTableModel();
62-
table.QuotedName = jTable["quotedName"] == null ? null : jTable["quotedName"].ToString();
82+
JToken tableQuotedNameToken = jTable.GetValue("quotedName", StringComparison.InvariantCultureIgnoreCase);
83+
table.QuotedName = tableQuotedNameToken == null ? null : tableQuotedNameToken.ToString();
6384
List<AzureSqlSyncGroupSchemaColumnModel> columns = new List<AzureSqlSyncGroupSchemaColumnModel>();
64-
JArray jColumns = (JArray)jTable["columns"];
85+
JArray jColumns = (JArray)jTable.GetValue("columns", StringComparison.InvariantCultureIgnoreCase);
6586
if (jColumns != null)
6687
{
67-
foreach (var jColumn in jColumns.Children())
88+
foreach (var jColumnToken in jColumns.Children())
6889
{
69-
AzureSqlSyncGroupSchemaColumnModel column = new AzureSqlSyncGroupSchemaColumnModel();
70-
column.QuotedName = jColumn["quotedName"] == null ? null : jColumn["quotedName"].ToString();
71-
columns.Add(column);
90+
if (jColumnToken.Type == JTokenType.Object)
91+
{
92+
AzureSqlSyncGroupSchemaColumnModel column = new AzureSqlSyncGroupSchemaColumnModel();
93+
JToken columnQuotedNameToken = ((JObject)jColumnToken).GetValue("quotedName", StringComparison.InvariantCultureIgnoreCase);
94+
column.QuotedName = columnQuotedNameToken == null ? null : columnQuotedNameToken.ToString();
95+
columns.Add(column);
96+
}
7297
}
7398
}
7499
table.Columns = columns;
75100
tables.Add(table);
76101
}
77102
}
78-
schema.Tables = tables;
79-
return schema;
80-
}
81-
catch (Newtonsoft.Json.JsonReaderException)
82-
{
83-
throw new PSArgumentException("The schema file is empty or invalid!", "SchemaFile");
84103
}
104+
schema.Tables = tables;
105+
return schema;
85106
}
86107
}
87108
}

0 commit comments

Comments
 (0)