/src/DataFactory/DataFactories.Test/UnitTests/GetActivityWindowTests.cs

https://github.com/Azure/azure-powershell · C# · 259 lines · 200 code · 35 blank · 24 comment · 16 complexity · 1c13a962d9c6923d013fa0d4b3037dd1 MD5 · raw file

  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. using Microsoft.Azure.Commands.DataFactories.Models;
  15. using Microsoft.Azure.Management.DataFactories.Models;
  16. using Microsoft.WindowsAzure.Commands.ScenarioTest;
  17. using Moq;
  18. using System;
  19. using System.Collections.Generic;
  20. using System.Linq;
  21. using Xunit;
  22. namespace Microsoft.Azure.Commands.DataFactories.Test.UnitTests
  23. {
  24. public class GetActivityWindowTests : DataFactoryUnitTestBase
  25. {
  26. private const string pipelineName = "pipeline";
  27. private const string datasetName = "dataset";
  28. private const string activityName = "activity";
  29. private GetAzureDataFactoryActivityWindowsCommand cmdlet;
  30. private List<PSActivityWindow> expectedDf;
  31. private ActivityWindowListResponse response;
  32. // Arrange
  33. List<ActivityWindow> activityWindowsForResponseWindows = new List<ActivityWindow>()
  34. {
  35. new ActivityWindow()
  36. {
  37. PipelineName = pipelineName,
  38. DataFactoryName = DataFactoryName,
  39. ResourceGroupName = ResourceGroupName,
  40. LinkedServiceName = "ls",
  41. RunStart = new DateTime(2016, 10, 02),
  42. RunEnd = new DateTime(2016, 10, 03),
  43. PercentComplete = 90
  44. },
  45. new ActivityWindow()
  46. {
  47. PipelineName = pipelineName,
  48. DataFactoryName = DataFactoryName,
  49. ResourceGroupName = ResourceGroupName,
  50. LinkedServiceName = "ls2",
  51. RunStart = new DateTime(2016, 10, 02),
  52. RunEnd = new DateTime(2016, 10, 03),
  53. PercentComplete = 70
  54. }
  55. };
  56. public GetActivityWindowTests(Xunit.Abstractions.ITestOutputHelper output)
  57. {
  58. Azure.ServiceManagement.Common.Models.XunitTracingInterceptor.AddToContext(new Azure.ServiceManagement.Common.Models.XunitTracingInterceptor(output));
  59. base.SetupTest();
  60. this.expectedDf = new List<PSActivityWindow>();
  61. this.expectedDf.AddRange(activityWindowsForResponseWindows.Select(activityWindow => new PSActivityWindow(activityWindow)));
  62. this.response = new ActivityWindowListResponse()
  63. {
  64. ActivityWindowListResponseValue = new ActivityWindowListResponseValue()
  65. {
  66. ActivityWindows = activityWindowsForResponseWindows,
  67. LastUpdate = DateTime.UtcNow.ToString()
  68. },
  69. NextLink = null
  70. };
  71. }
  72. [Fact]
  73. [Trait(Category.AcceptanceType, Category.CheckIn)]
  74. public void CanListDataFactoryActivityWindows()
  75. {
  76. cmdlet = new GetAzureDataFactoryActivityWindowsCommand()
  77. {
  78. CommandRuntime = commandRuntimeMock.Object,
  79. DataFactoryClient = dataFactoriesClientMock.Object,
  80. ResourceGroupName = ResourceGroupName,
  81. DataFactoryName = DataFactoryName
  82. };
  83. dataFactoriesClientMock
  84. .Setup(
  85. c =>
  86. c.ListByDataFactoryActivityWindows(It.IsAny<string>(),
  87. It.Is<ActivityWindowsByDataFactoryListParameters>(
  88. options =>
  89. options.ResourceGroupName == ResourceGroupName &&
  90. options.DataFactoryName == DataFactoryName)))
  91. .Returns(this.response)
  92. .Verifiable();
  93. // Action
  94. cmdlet.ExecuteCmdlet();
  95. // Assert
  96. dataFactoriesClientMock.VerifyAll();
  97. commandRuntimeMock.Verify(f => f.WriteObject(It.Is<List<PSActivityWindow>>(x => this.ValidateResult(x)), true), Times.Once());
  98. }
  99. [Fact]
  100. [Trait(Category.AcceptanceType, Category.CheckIn)]
  101. public void CanListPipelineActivityWindows()
  102. {
  103. cmdlet = new GetAzureDataFactoryActivityWindowsCommand()
  104. {
  105. CommandRuntime = commandRuntimeMock.Object,
  106. DataFactoryClient = dataFactoriesClientMock.Object,
  107. ResourceGroupName = ResourceGroupName,
  108. DataFactoryName = DataFactoryName,
  109. PipelineName = pipelineName
  110. };
  111. dataFactoriesClientMock
  112. .Setup(
  113. c =>
  114. c.ListByPipelineActivityWindows(It.IsAny<string>(),
  115. It.Is<ActivityWindowsByPipelineListParameters>(
  116. options =>
  117. options.ResourceGroupName == ResourceGroupName &&
  118. options.DataFactoryName == DataFactoryName &&
  119. options.PipelineName == pipelineName)))
  120. .Returns(this.response)
  121. .Verifiable();
  122. // Action
  123. cmdlet.ExecuteCmdlet();
  124. // Assert
  125. dataFactoriesClientMock.VerifyAll();
  126. commandRuntimeMock.Verify(f => f.WriteObject(It.Is<List<PSActivityWindow>>(x => this.ValidateResult(x)), true), Times.Once());
  127. }
  128. [Fact]
  129. [Trait(Category.AcceptanceType, Category.CheckIn)]
  130. public void CanListDatasetActivityWindows()
  131. {
  132. cmdlet = new GetAzureDataFactoryActivityWindowsCommand()
  133. {
  134. CommandRuntime = commandRuntimeMock.Object,
  135. DataFactoryClient = dataFactoriesClientMock.Object,
  136. ResourceGroupName = ResourceGroupName,
  137. DataFactoryName = DataFactoryName,
  138. DatasetName = datasetName
  139. };
  140. dataFactoriesClientMock
  141. .Setup(
  142. c =>
  143. c.ListByDatasetActivityWindows(It.IsAny<string>(),
  144. It.Is<ActivityWindowsByDatasetListParameters>(
  145. options =>
  146. options.ResourceGroupName == ResourceGroupName &&
  147. options.DataFactoryName == DataFactoryName &&
  148. options.DatasetName == datasetName)))
  149. .Returns(this.response)
  150. .Verifiable();
  151. // Action
  152. cmdlet.ExecuteCmdlet();
  153. // Assert
  154. dataFactoriesClientMock.VerifyAll();
  155. commandRuntimeMock.Verify(f => f.WriteObject(It.Is<List<PSActivityWindow>>(x => this.ValidateResult(x)), true), Times.Once());
  156. }
  157. [Fact]
  158. [Trait(Category.AcceptanceType, Category.CheckIn)]
  159. public void CanListActivityActivityWindows()
  160. {
  161. cmdlet = new GetAzureDataFactoryActivityWindowsCommand()
  162. {
  163. CommandRuntime = commandRuntimeMock.Object,
  164. DataFactoryClient = dataFactoriesClientMock.Object,
  165. ResourceGroupName = ResourceGroupName,
  166. DataFactoryName = DataFactoryName,
  167. PipelineName = pipelineName,
  168. ActivityName = activityName
  169. };
  170. dataFactoriesClientMock
  171. .Setup(
  172. c =>
  173. c.ListByActivityActivityWindows(It.IsAny<string>(),
  174. It.Is<ActivityWindowsByActivityListParameters>(
  175. options =>
  176. options.ResourceGroupName == ResourceGroupName &&
  177. options.DataFactoryName == DataFactoryName &&
  178. options.PipelineName == pipelineName &&
  179. options.ActivityName == activityName)))
  180. .Returns(this.response)
  181. .Verifiable();
  182. // Action
  183. cmdlet.ExecuteCmdlet();
  184. // Assert
  185. dataFactoriesClientMock.VerifyAll();
  186. commandRuntimeMock.Verify(f => f.WriteObject(It.Is<List<PSActivityWindow>>(x => this.ValidateResult(x)), true), Times.Once());
  187. }
  188. [Fact]
  189. [Trait(Category.AcceptanceType, Category.CheckIn)]
  190. public void CanThrowWarningWhenBadArgumentPassed()
  191. {
  192. cmdlet = new GetAzureDataFactoryActivityWindowsCommand()
  193. {
  194. CommandRuntime = commandRuntimeMock.Object,
  195. DataFactoryClient = dataFactoriesClientMock.Object,
  196. ResourceGroupName = ResourceGroupName,
  197. DataFactoryName = DataFactoryName,
  198. DatasetName = datasetName,
  199. PipelineName = pipelineName,
  200. ActivityName = activityName
  201. };
  202. // Action
  203. cmdlet.ExecuteCmdlet();
  204. // Assert
  205. dataFactoriesClientMock.VerifyAll();
  206. commandRuntimeMock.Verify(f => f.WriteWarning(It.Is<string>(x => x.Contains("An incorrect combination of arguments was passed"))), Times.Once());
  207. }
  208. private bool ValidateResult(List<PSActivityWindow> result)
  209. {
  210. if (result.Count != expectedDf.Count)
  211. {
  212. return false;
  213. }
  214. for (int i = 0; i < result.Count; i++)
  215. {
  216. if (!result[i].IsEqualTo(expectedDf[i]))
  217. {
  218. return false;
  219. }
  220. }
  221. return true;
  222. }
  223. }
  224. }