From 056de19002d77dd18782e7c7c973c88a6ff83cba Mon Sep 17 00:00:00 2001 From: Sivaguru Sankaridurg Date: Mon, 7 Nov 2016 13:59:28 +0530 Subject: [PATCH] Removed Moq dependency in unit tests --- .../HDInsight.Tests/HDInsight.Tests.csproj | 3 - .../UnitTests/ClusterCreateTests.cs | 68 ++----------------- .../HDInsight/HDInsight.Tests/packages.config | 1 - ...ClusterOperations.Create.Customizations.cs | 2 +- .../HDInsight/Properties/AssemblyInfo.cs | 5 +- 5 files changed, 9 insertions(+), 70 deletions(-) diff --git a/src/ResourceManagement/HDInsight/HDInsight.Tests/HDInsight.Tests.csproj b/src/ResourceManagement/HDInsight/HDInsight.Tests/HDInsight.Tests.csproj index 6e438175ece07..6e18e76ae1346 100644 --- a/src/ResourceManagement/HDInsight/HDInsight.Tests/HDInsight.Tests.csproj +++ b/src/ResourceManagement/HDInsight/HDInsight.Tests/HDInsight.Tests.csproj @@ -132,9 +132,6 @@ False $(LibraryNugetPackageFolder)\Microsoft.Azure.Common.2.1.0\lib\net45\Microsoft.Azure.Common.dll - - $(LibraryNugetPackageFolder)\Moq.4.2.1510.2205\lib\net40\Moq.dll - diff --git a/src/ResourceManagement/HDInsight/HDInsight.Tests/UnitTests/ClusterCreateTests.cs b/src/ResourceManagement/HDInsight/HDInsight.Tests/UnitTests/ClusterCreateTests.cs index 6725680862c6a..995ea93a4abe1 100644 --- a/src/ResourceManagement/HDInsight/HDInsight.Tests/UnitTests/ClusterCreateTests.cs +++ b/src/ResourceManagement/HDInsight/HDInsight.Tests/UnitTests/ClusterCreateTests.cs @@ -1,57 +1,20 @@ -using HDInsight.Tests.Helpers; -using Microsoft.Azure.Management.HDInsight; -using Microsoft.Azure.Test; -using Moq; -using System; +using Microsoft.Azure.Management.HDInsight; using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using Xunit; using Microsoft.Azure.Management.HDInsight.Models; -using Microsoft.Azure.Management.Resources; -using System.Threading; using Newtonsoft.Json; -using System.Collections; namespace HDInsight.Tests.UnitTests { public class ClusterCreateTests { - private Mock clientMock; - private Mock clusterOperationsMock; - public ClusterCreateTests() { - clientMock = new Mock(); - clusterOperationsMock = new Mock(clientMock.Object); - - clientMock.SetupGet(c => c.Clusters).Returns(clusterOperationsMock.Object); - - clusterOperationsMock.As() - .Setup(op => op.CreateAsync(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())) - .CallBase(); - - clusterOperationsMock.As() - .Setup(op => op.BeginCreatingAsync(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())) - .Returns(() => Task.FromResult(new ClusterCreateResponse())); - - clusterOperationsMock.As() - .Setup(op => op.GetCreateStatusAsync(It.IsAny(), It.IsAny())) - .Returns(() => Task.FromResult(new ClusterGetResponse { - Cluster = new Cluster { - Properties = new ClusterGetProperties { - ProvisioningState = HDInsightClusterProvisioningState.Succeeded - } - } - } - )); } [Fact] public void TestCreateDefaultFsAzureBlobClusterUsingClusterParameters() { - string resourceGroupName = "resourcegroup"; string clusterName = "cluster"; string storageContainerName = "storageContainer"; @@ -69,23 +32,14 @@ public void TestCreateDefaultFsAzureBlobClusterUsingClusterParameters() Version = "3.2" }; - var createresponse = clientMock.Object.Clusters.Create(resourceGroupName, clusterName, clusterCreateParams); - - clusterOperationsMock.As().Verify(c => - c.BeginCreatingAsync( - It.Is(x => x == resourceGroupName), - It.Is(x => x == clusterName), - It.Is(x => ContainerMatchesNameProvided(x, storageContainerName) == true), - It.IsAny() - ), - Times.Once - ); + ClusterOperations op = new ClusterOperations(new HDInsightManagementClient()); + var extendedParams = op.GetExtendedClusterCreateParameters(clusterName, clusterCreateParams); + Assert.True(ContainerMatchesNameProvided(extendedParams, storageContainerName), "Container name does not match the one specified"); } [Fact] public void TestCreateDefaultFsAzureBlobClusterContainerNotSpecified() { - string resourceGroupName = "resourcegroup"; string clusterName = "cluster"; var clusterCreateParams = new ClusterCreateParameters @@ -103,17 +57,9 @@ public void TestCreateDefaultFsAzureBlobClusterContainerNotSpecified() Version = "3.2" }; - clientMock.Object.Clusters.Create(resourceGroupName, clusterName, clusterCreateParams); - - clusterOperationsMock.As().Verify(c => - c.BeginCreatingAsync( - It.Is(x => x == resourceGroupName), - It.Is(x => x == clusterName), - It.Is(x => ContainerMatchesNameProvided(x, clusterName) == true), - It.IsAny() - ), - Times.Once - ); + ClusterOperations op = new ClusterOperations(new HDInsightManagementClient()); + var extendedParams = op.GetExtendedClusterCreateParameters(clusterName, clusterCreateParams); + Assert.True(ContainerMatchesNameProvided(extendedParams, clusterName), "Container name does not match the cluster name"); } private bool ContainerMatchesNameProvided(ClusterCreateParametersExtended x, string name) diff --git a/src/ResourceManagement/HDInsight/HDInsight.Tests/packages.config b/src/ResourceManagement/HDInsight/HDInsight.Tests/packages.config index 201e288e32262..3fcbf066b30cd 100644 --- a/src/ResourceManagement/HDInsight/HDInsight.Tests/packages.config +++ b/src/ResourceManagement/HDInsight/HDInsight.Tests/packages.config @@ -5,5 +5,4 @@ - \ No newline at end of file diff --git a/src/ResourceManagement/HDInsight/HDInsight/Customizations/ClusterOperations.Create.Customizations.cs b/src/ResourceManagement/HDInsight/HDInsight/Customizations/ClusterOperations.Create.Customizations.cs index 01a7618318b54..72493a2384230 100644 --- a/src/ResourceManagement/HDInsight/HDInsight/Customizations/ClusterOperations.Create.Customizations.cs +++ b/src/ResourceManagement/HDInsight/HDInsight/Customizations/ClusterOperations.Create.Customizations.cs @@ -91,7 +91,7 @@ public async Task BeginCreatingAsync(string resourceGroup } } - private ClusterCreateParametersExtended GetExtendedClusterCreateParameters( + internal ClusterCreateParametersExtended GetExtendedClusterCreateParameters( string clusterName, ClusterCreateParameters clusterCreateParameters) { var createParamsExtended = new ClusterCreateParametersExtended diff --git a/src/ResourceManagement/HDInsight/HDInsight/Properties/AssemblyInfo.cs b/src/ResourceManagement/HDInsight/HDInsight/Properties/AssemblyInfo.cs index 2536778f044a5..37c346bbcb1b3 100644 --- a/src/ResourceManagement/HDInsight/HDInsight/Properties/AssemblyInfo.cs +++ b/src/ResourceManagement/HDInsight/HDInsight/Properties/AssemblyInfo.cs @@ -39,7 +39,4 @@ [assembly:InternalsVisibleTo("HDInsight.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100b5fc90e7027f67871e773a8fde8938c81dd402ba65b9201d60593e96c492651e889cc13f1415ebb53fac1131ae0bd333c5ee6021672d9718ea31a8aebd0da0072f25d87dba6fc90ffd598ed4da35e44c398c454307e8e33b8426143daec9f596836f97c8f74750e5975c64e2189f45def46b2a2b1247adc3652bf5c308055da9")] #else [assembly:InternalsVisibleTo("HDInsight.Tests")] -#endif - -// Extra setup for unit testing -[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")] \ No newline at end of file +#endif \ No newline at end of file