Skip to content

Commit ed80e9f

Browse files
committed
Fix mock issues with serialization fix
1 parent 753204a commit ed80e9f

File tree

12 files changed

+69
-12
lines changed

12 files changed

+69
-12
lines changed

src/Common/Commands.ScenarioTests.Common/Commands.ScenarioTests.Common.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@
117117
<ItemGroup>
118118
<Compile Include="Constants.cs" />
119119
<Compile Include="EnvironmentSetupHelper.cs" />
120+
<Compile Include="PermissiveRecordMatcher.cs" />
120121
<Compile Include="PowerShellExtensions.cs" />
121122
<Compile Include="Properties\AssemblyInfo.cs" />
122123
</ItemGroup>
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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 System;
16+
using System.Text;
17+
using Microsoft.Azure.Test.HttpRecorder;
18+
using Xunit;
19+
20+
namespace Microsoft.WindowsAzure.Commands.ScenarioTest
21+
{
22+
public class PermissiveRecordMatcher : IRecordMatcher
23+
{
24+
public string GetMatchingKey(System.Net.Http.HttpRequestMessage request)
25+
{
26+
var path = request.RequestUri.PathAndQuery;
27+
if (path.Contains("?&"))
28+
{
29+
path = path.Replace("?&", "?");
30+
}
31+
32+
var encodedPath = Convert.ToBase64String(Encoding.UTF8.GetBytes(path));
33+
return string.Format("{0} {1}", request.Method, encodedPath);
34+
}
35+
36+
public string GetMatchingKey(RecordEntry recordEntry)
37+
{
38+
var encodedPath = recordEntry.EncodedRequestUri;
39+
if (recordEntry.RequestUri.Contains("?&"))
40+
{
41+
var updatedPath = recordEntry.RequestUri.Replace("?&", "?");
42+
encodedPath = Convert.ToBase64String(Encoding.UTF8.GetBytes(updatedPath));
43+
}
44+
45+
return string.Format("{0} {1}", recordEntry.RequestMethod, encodedPath);
46+
}
47+
}
48+
}

src/ResourceManager/Batch/Commands.Batch.Test/ScenarioTests/BatchController.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
using Microsoft.Azure.Management.Batch;
1919
using Microsoft.Azure.Management.Resources;
2020
using Microsoft.Azure.Test;
21+
using Microsoft.Azure.Test.HttpRecorder;
2122
using Microsoft.WindowsAzure.Commands.ScenarioTest;
2223
using System;
2324
using System.Linq;
@@ -72,10 +73,10 @@ public void RunPsTestWorkflow(
7273
string callingClassType,
7374
string mockName)
7475
{
76+
HttpMockServer.Matcher = new PermissiveRecordMatcher();
7577
using (UndoContext context = UndoContext.Current)
7678
{
7779
context.Start(callingClassType, mockName);
78-
7980
this.csmTestFactory = SetupCSMTestEnvironmentFactory();
8081
SetupManagementClients();
8182

src/ResourceManager/Batch/Commands.Batch.Test/SessionRecords/Microsoft.Azure.Commands.Batch.Test.ScenarioTests.BatchAccountTests/TestBatchAccountKeys.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"Entries": [
33
{
4-
"RequestUri": "/subscriptions/4a06fe24-c197-4353-adc1-058d1a51924e/providers?&api-version=2014-04-01-preview",
4+
"RequestUri": "/subscriptions/4a06fe24-c197-4353-adc1-058d1a51924e/providers?api-version=2014-04-01-preview",
55
"EncodedRequestUri": "L3N1YnNjcmlwdGlvbnMvNGEwNmZlMjQtYzE5Ny00MzUzLWFkYzEtMDU4ZDFhNTE5MjRlL3Byb3ZpZGVycz8mYXBpLXZlcnNpb249MjAxNC0wNC0wMS1wcmV2aWV3",
66
"RequestMethod": "GET",
77
"RequestBody": "",
@@ -196,7 +196,7 @@
196196
"StatusCode": 201
197197
},
198198
{
199-
"RequestUri": "/subscriptions/4a06fe24-c197-4353-adc1-058d1a51924e/resourceGroups/onesdk6673/resources?&api-version=2014-04-01-preview",
199+
"RequestUri": "/subscriptions/4a06fe24-c197-4353-adc1-058d1a51924e/resourceGroups/onesdk6673/resources?api-version=2014-04-01-preview",
200200
"EncodedRequestUri": "L3N1YnNjcmlwdGlvbnMvNGEwNmZlMjQtYzE5Ny00MzUzLWFkYzEtMDU4ZDFhNTE5MjRlL3Jlc291cmNlR3JvdXBzL29uZXNkazY2NzMvcmVzb3VyY2VzPyZhcGktdmVyc2lvbj0yMDE0LTA0LTAxLXByZXZpZXc=",
201201
"RequestMethod": "GET",
202202
"RequestBody": "",

src/ResourceManager/Batch/Commands.Batch.Test/SessionRecords/Microsoft.Azure.Commands.Batch.Test.ScenarioTests.BatchAccountTests/TestCreateAndRemoveBatchAccountViaPiping.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"Entries": [
33
{
4-
"RequestUri": "/subscriptions/4a06fe24-c197-4353-adc1-058d1a51924e/providers?&api-version=2014-04-01-preview",
4+
"RequestUri": "/subscriptions/4a06fe24-c197-4353-adc1-058d1a51924e/providers?api-version=2014-04-01-preview",
55
"EncodedRequestUri": "L3N1YnNjcmlwdGlvbnMvNGEwNmZlMjQtYzE5Ny00MzUzLWFkYzEtMDU4ZDFhNTE5MjRlL3Byb3ZpZGVycz8mYXBpLXZlcnNpb249MjAxNC0wNC0wMS1wcmV2aWV3",
66
"RequestMethod": "GET",
77
"RequestBody": "",
@@ -196,7 +196,7 @@
196196
"StatusCode": 201
197197
},
198198
{
199-
"RequestUri": "/subscriptions/4a06fe24-c197-4353-adc1-058d1a51924e/resourceGroups/onesdk2788/resources?&api-version=2014-04-01-preview",
199+
"RequestUri": "/subscriptions/4a06fe24-c197-4353-adc1-058d1a51924e/resourceGroups/onesdk2788/resources?api-version=2014-04-01-preview",
200200
"EncodedRequestUri": "L3N1YnNjcmlwdGlvbnMvNGEwNmZlMjQtYzE5Ny00MzUzLWFkYzEtMDU4ZDFhNTE5MjRlL3Jlc291cmNlR3JvdXBzL29uZXNkazI3ODgvcmVzb3VyY2VzPyZhcGktdmVyc2lvbj0yMDE0LTA0LTAxLXByZXZpZXc=",
201201
"RequestMethod": "GET",
202202
"RequestBody": "",

src/ResourceManager/Batch/Commands.Batch.Test/SessionRecords/Microsoft.Azure.Commands.Batch.Test.ScenarioTests.BatchAccountTests/TestCreateExistingBatchAccount.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"Entries": [
33
{
4-
"RequestUri": "/subscriptions/4a06fe24-c197-4353-adc1-058d1a51924e/providers?&api-version=2014-04-01-preview",
4+
"RequestUri": "/subscriptions/4a06fe24-c197-4353-adc1-058d1a51924e/providers?api-version=2014-04-01-preview",
55
"EncodedRequestUri": "L3N1YnNjcmlwdGlvbnMvNGEwNmZlMjQtYzE5Ny00MzUzLWFkYzEtMDU4ZDFhNTE5MjRlL3Byb3ZpZGVycz8mYXBpLXZlcnNpb249MjAxNC0wNC0wMS1wcmV2aWV3",
66
"RequestMethod": "GET",
77
"RequestBody": "",
@@ -196,7 +196,7 @@
196196
"StatusCode": 201
197197
},
198198
{
199-
"RequestUri": "/subscriptions/4a06fe24-c197-4353-adc1-058d1a51924e/resourceGroups/onesdk4067/resources?&api-version=2014-04-01-preview",
199+
"RequestUri": "/subscriptions/4a06fe24-c197-4353-adc1-058d1a51924e/resourceGroups/onesdk4067/resources?api-version=2014-04-01-preview",
200200
"EncodedRequestUri": "L3N1YnNjcmlwdGlvbnMvNGEwNmZlMjQtYzE5Ny00MzUzLWFkYzEtMDU4ZDFhNTE5MjRlL3Jlc291cmNlR3JvdXBzL29uZXNkazQwNjcvcmVzb3VyY2VzPyZhcGktdmVyc2lvbj0yMDE0LTA0LTAxLXByZXZpZXc=",
201201
"RequestMethod": "GET",
202202
"RequestBody": "",

src/ResourceManager/Batch/Commands.Batch.Test/SessionRecords/Microsoft.Azure.Commands.Batch.Test.ScenarioTests.BatchAccountTests/TestCreatesNewBatchAccount.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"Entries": [
33
{
4-
"RequestUri": "/subscriptions/4a06fe24-c197-4353-adc1-058d1a51924e/providers?&api-version=2014-04-01-preview",
4+
"RequestUri": "/subscriptions/4a06fe24-c197-4353-adc1-058d1a51924e/providers?api-version=2014-04-01-preview",
55
"EncodedRequestUri": "L3N1YnNjcmlwdGlvbnMvNGEwNmZlMjQtYzE5Ny00MzUzLWFkYzEtMDU4ZDFhNTE5MjRlL3Byb3ZpZGVycz8mYXBpLXZlcnNpb249MjAxNC0wNC0wMS1wcmV2aWV3",
66
"RequestMethod": "GET",
77
"RequestBody": "",
@@ -196,7 +196,7 @@
196196
"StatusCode": 201
197197
},
198198
{
199-
"RequestUri": "/subscriptions/4a06fe24-c197-4353-adc1-058d1a51924e/resourceGroups/onesdk4630/resources?&api-version=2014-04-01-preview",
199+
"RequestUri": "/subscriptions/4a06fe24-c197-4353-adc1-058d1a51924e/resourceGroups/onesdk4630/resources?api-version=2014-04-01-preview",
200200
"EncodedRequestUri": "L3N1YnNjcmlwdGlvbnMvNGEwNmZlMjQtYzE5Ny00MzUzLWFkYzEtMDU4ZDFhNTE5MjRlL3Jlc291cmNlR3JvdXBzL29uZXNkazQ2MzAvcmVzb3VyY2VzPyZhcGktdmVyc2lvbj0yMDE0LTA0LTAxLXByZXZpZXc=",
201201
"RequestMethod": "GET",
202202
"RequestBody": "",

src/ResourceManager/Batch/Commands.Batch.Test/SessionRecords/Microsoft.Azure.Commands.Batch.Test.ScenarioTests.BatchAccountTests/TestGetBatchAccountsUnderResourceGroups.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"Entries": [
33
{
4-
"RequestUri": "/subscriptions/4a06fe24-c197-4353-adc1-058d1a51924e/providers?&api-version=2014-04-01-preview",
4+
"RequestUri": "/subscriptions/4a06fe24-c197-4353-adc1-058d1a51924e/providers?api-version=2014-04-01-preview",
55
"EncodedRequestUri": "L3N1YnNjcmlwdGlvbnMvNGEwNmZlMjQtYzE5Ny00MzUzLWFkYzEtMDU4ZDFhNTE5MjRlL3Byb3ZpZGVycz8mYXBpLXZlcnNpb249MjAxNC0wNC0wMS1wcmV2aWV3",
66
"RequestMethod": "GET",
77
"RequestBody": "",
@@ -196,7 +196,7 @@
196196
"StatusCode": 201
197197
},
198198
{
199-
"RequestUri": "/subscriptions/4a06fe24-c197-4353-adc1-058d1a51924e/resourceGroups/onesdk6761/resources?&api-version=2014-04-01-preview",
199+
"RequestUri": "/subscriptions/4a06fe24-c197-4353-adc1-058d1a51924e/resourceGroups/onesdk6761/resources?api-version=2014-04-01-preview",
200200
"EncodedRequestUri": "L3N1YnNjcmlwdGlvbnMvNGEwNmZlMjQtYzE5Ny00MzUzLWFkYzEtMDU4ZDFhNTE5MjRlL3Jlc291cmNlR3JvdXBzL29uZXNkazY3NjEvcmVzb3VyY2VzPyZhcGktdmVyc2lvbj0yMDE0LTA0LTAxLXByZXZpZXc=",
201201
"RequestMethod": "GET",
202202
"RequestBody": "",
@@ -442,7 +442,7 @@
442442
"StatusCode": 201
443443
},
444444
{
445-
"RequestUri": "/subscriptions/4a06fe24-c197-4353-adc1-058d1a51924e/resourceGroups/onesdk1390/resources?&api-version=2014-04-01-preview",
445+
"RequestUri": "/subscriptions/4a06fe24-c197-4353-adc1-058d1a51924e/resourceGroups/onesdk1390/resources?api-version=2014-04-01-preview",
446446
"EncodedRequestUri": "L3N1YnNjcmlwdGlvbnMvNGEwNmZlMjQtYzE5Ny00MzUzLWFkYzEtMDU4ZDFhNTE5MjRlL3Jlc291cmNlR3JvdXBzL29uZXNkazEzOTAvcmVzb3VyY2VzPyZhcGktdmVyc2lvbj0yMDE0LTA0LTAxLXByZXZpZXc=",
447447
"RequestMethod": "GET",
448448
"RequestBody": "",

src/ResourceManager/DataFactories/Commands.DataFactories.Test/ScenarioTests/DataFactoriesScenarioTestsBase.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
using Microsoft.Azure.Management.DataFactories;
1919
using Microsoft.Azure.Management.Resources;
2020
using Microsoft.Azure.Subscriptions;
21+
using Microsoft.Azure.Test.HttpRecorder;
2122
using Microsoft.WindowsAzure.Commands.ScenarioTest;
2223
using Microsoft.WindowsAzure.Commands.Utilities.Common;
2324
using Microsoft.WindowsAzure.Management.Storage;
@@ -51,6 +52,7 @@ protected void SetupManagementClients()
5152

5253
protected void RunPowerShellTest(params string[] scripts)
5354
{
55+
HttpMockServer.Matcher = new PermissiveRecordMatcher();
5456
using (UndoContext context = UndoContext.Current)
5557
{
5658
context.Start(TestUtilities.GetCallingClass(2), TestUtilities.GetCurrentMethodName(2));

src/ResourceManager/Sql/Commands.Sql.Test/ScenarioTests/SqlTestsBase.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
using Microsoft.Azure.Management.Sql;
1616
using Microsoft.Azure.Management.Resources;
17+
using Microsoft.Azure.Test.HttpRecorder;
1718
using Microsoft.WindowsAzure.Commands.ScenarioTest;
1819
using Microsoft.WindowsAzure.Commands.Utilities.Common;
1920
using Microsoft.WindowsAzure.Management.Storage;
@@ -41,6 +42,7 @@ protected void SetupManagementClients()
4142

4243
protected void RunPowerShellTest(params string[] scripts)
4344
{
45+
HttpMockServer.Matcher = new PermissiveRecordMatcher();
4446
// Enable undo functionality as well as mock recording
4547
using (UndoContext context = UndoContext.Current)
4648
{

src/ResourceManager/Websites/Commands.Websites.Test/ScenarioTests/WebsitesController.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ public void RunPsTestWorkflow(
8585
string callingClassType,
8686
string mockName)
8787
{
88+
HttpMockServer.Matcher = new PermissiveRecordMatcher();
8889
using (UndoContext context = UndoContext.Current)
8990
{
9091
context.Start(callingClassType, mockName);

src/ServiceManagement/Services/Commands.Test/Profile/ProfileTestController.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
using Microsoft.Azure.Common.Authentication;
1616
using Microsoft.Azure.Common.Authentication.Factories;
1717
using Microsoft.Azure.Common.Authentication.Models;
18+
using Microsoft.Azure.Test.HttpRecorder;
1819
using Microsoft.VisualStudio.TestTools.UnitTesting;
1920
using Microsoft.WindowsAzure.Commands.Common.Test.Mocks;
2021
using Microsoft.WindowsAzure.Commands.Profile;
@@ -156,6 +157,7 @@ public void RunPsTestWorkflow(
156157
string callingClassType,
157158
string mockName)
158159
{
160+
HttpMockServer.Matcher = new PermissiveRecordMatcher();
159161
using (UndoContext context = UndoContext.Current)
160162
{
161163
context.Start(callingClassType, mockName);

0 commit comments

Comments
 (0)