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 Commands . StorageSync . Interop . Clients ;
16
+ using Commands . StorageSync . Interop . DataObjects ;
17
+ using Commands . StorageSync . Interop . Interfaces ;
18
+ using Microsoft . Azure . Commands . StorageSync . Common ;
19
+ using Microsoft . Azure . Commands . StorageSync . Interfaces ;
20
+ using System ;
21
+ using System . Text . RegularExpressions ;
22
+
23
+ namespace StorageSync . Test . Common
24
+ {
25
+ /// <summary>
26
+ /// Class StorageSyncResourceManager.
27
+ /// Implements the <see cref="Microsoft.Azure.Commands.StorageSync.Common.IStorageSyncResourceManager" />
28
+ /// Implements the <see cref="Microsoft.Azure.Commands.StorageSync.Interfaces.IStorageSyncResourceManager" />
29
+ /// </summary>
30
+ /// <seealso cref="Microsoft.Azure.Commands.StorageSync.Interfaces.IStorageSyncResourceManager" />
31
+ /// <seealso cref="Microsoft.Azure.Commands.StorageSync.Common.IStorageSyncResourceManager" />
32
+ public class MockStorageSyncResourceManager : IStorageSyncResourceManager
33
+ {
34
+
35
+ /// <summary>
36
+ /// Initializes a new instance of the <see cref="MockStorageSyncResourceManager"/> class.
37
+ /// </summary>
38
+ /// <param name="testName">Name of the test.</param>
39
+ public MockStorageSyncResourceManager ( string testName )
40
+ {
41
+ TestName = testName ;
42
+ }
43
+
44
+ /// <summary>
45
+ /// The is playback mode
46
+ /// </summary>
47
+ private bool ? isPlaybackMode ;
48
+
49
+ /// <summary>
50
+ /// Gets a value indicating whether this instance is playback mode.
51
+ /// </summary>
52
+ /// <value><c>true</c> if this instance is playback mode; otherwise, <c>false</c>.</value>
53
+ /// <exception cref="NotSupportedException"></exception>
54
+ protected bool IsPlaybackMode
55
+ {
56
+ get
57
+ {
58
+ if ( ! isPlaybackMode . HasValue )
59
+ {
60
+ if ( Microsoft . Azure . Test . HttpRecorder . HttpMockServer . Mode == Microsoft . Azure . Test . HttpRecorder . HttpRecorderMode . Playback )
61
+ {
62
+ isPlaybackMode = true ;
63
+ }
64
+ else if ( Microsoft . Azure . Test . HttpRecorder . HttpMockServer . Mode == Microsoft . Azure . Test . HttpRecorder . HttpRecorderMode . Record )
65
+ {
66
+ isPlaybackMode = false ;
67
+
68
+ } else
69
+ {
70
+ throw new NotSupportedException ( $ "{ Microsoft . Azure . Test . HttpRecorder . HttpMockServer . Mode } Mode is not supported") ;
71
+ }
72
+ }
73
+ return isPlaybackMode . Value ;
74
+ }
75
+ }
76
+
77
+ /// <summary>
78
+ /// Gets the name of the test.
79
+ /// </summary>
80
+ /// <value>The name of the test.</value>
81
+ public string TestName
82
+ {
83
+ get ;
84
+ }
85
+
86
+ /// <summary>
87
+ /// Creates the ecs management.
88
+ /// </summary>
89
+ /// <returns>IEcsManagement.</returns>
90
+ public IEcsManagement CreateEcsManagement ( ) => IsPlaybackMode ? new MockEcsManagementInteropClient ( ) as IEcsManagement : new EcsManagementInteropClient ( ) ;
91
+
92
+ /// <summary>
93
+ /// Gets the unique identifier.
94
+ /// </summary>
95
+ /// <param name="testName">Name of the test.</param>
96
+ /// <returns>Guid.</returns>
97
+ public Guid GetGuid ( string testName ) => Microsoft . Azure . Test . HttpRecorder . HttpMockServer . GetAssetGuid ( testName ) ;
98
+
99
+ /// <summary>
100
+ /// Gets the afs agent installer path.
101
+ /// </summary>
102
+ /// <param name="afsAgentInstallerPath">The afs agent installer path.</param>
103
+ /// <returns>System.String.</returns>
104
+ public bool TryGetAfsAgentInstallerPath ( out string afsAgentInstallerPath )
105
+ {
106
+ afsAgentInstallerPath = @"C:\Program Files\Azure\StorageSyncAgent\" ;
107
+ return true ;
108
+ }
109
+
110
+ /// <summary>
111
+ /// Gets the afs agent version.
112
+ /// </summary>
113
+ /// <param name="afsAgentVersion">The afs agent version.</param>
114
+ /// <returns>System.String.</returns>
115
+ public bool TryGetAfsAgentVersion ( out string afsAgentVersion )
116
+ {
117
+ afsAgentVersion = @"5.0.2.0" ;
118
+ return true ;
119
+ }
120
+
121
+ /// <summary>
122
+ /// Updates the server registration data.
123
+ /// </summary>
124
+ /// <param name="pServerRegistrationData">The p server registration data.</param>
125
+ /// <returns>ServerRegistrationData.</returns>
126
+ public ServerRegistrationData UpdateServerRegistrationData ( ServerRegistrationData pServerRegistrationData )
127
+ {
128
+ pServerRegistrationData . Id = Microsoft . Azure . Test . HttpRecorder . HttpMockServer . GetVariable ( StorageSyncConstants . SyncServerId , pServerRegistrationData . Id ) ;
129
+ pServerRegistrationData . ServerId = Guid . Parse ( Regex . Match ( pServerRegistrationData . Id , @"([^/]+)$" ) . Value ) ;
130
+ return pServerRegistrationData ;
131
+ }
132
+
133
+ /// <summary>
134
+ /// Waits for access propogation.
135
+ /// </summary>
136
+ public void WaitForAccessPropogation ( )
137
+ {
138
+ if ( ! IsPlaybackMode )
139
+ {
140
+ System . Threading . Thread . Sleep ( 40 * 1000 ) ;
141
+ }
142
+ }
143
+ }
144
+ }
0 commit comments