Skip to content

Commit

Permalink
Removed Moq dependency in unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
srsiva committed Nov 7, 2016
1 parent d13fedd commit 056de19
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,6 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>$(LibraryNugetPackageFolder)\Microsoft.Azure.Common.2.1.0\lib\net45\Microsoft.Azure.Common.dll</HintPath>
</Reference>
<Reference Include="Moq">
<HintPath>$(LibraryNugetPackageFolder)\Moq.4.2.1510.2205\lib\net40\Moq.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Reference Include="Microsoft.Azure.ResourceManager">
Expand Down
Original file line number Diff line number Diff line change
@@ -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<HDInsightManagementClient> clientMock;
private Mock<ClusterOperations> clusterOperationsMock;

public ClusterCreateTests()
{
clientMock = new Mock<HDInsightManagementClient>();
clusterOperationsMock = new Mock<ClusterOperations>(clientMock.Object);

clientMock.SetupGet(c => c.Clusters).Returns(clusterOperationsMock.Object);

clusterOperationsMock.As<IClusterOperations>()
.Setup(op => op.CreateAsync(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<ClusterCreateParameters>(), It.IsAny<CancellationToken>()))
.CallBase();

clusterOperationsMock.As<IClusterOperations>()
.Setup(op => op.BeginCreatingAsync(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<ClusterCreateParametersExtended>(), It.IsAny<CancellationToken>()))
.Returns(() => Task.FromResult(new ClusterCreateResponse()));

clusterOperationsMock.As<IClusterOperations>()
.Setup(op => op.GetCreateStatusAsync(It.IsAny<string>(), It.IsAny<CancellationToken>()))
.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";

Expand All @@ -69,23 +32,14 @@ public void TestCreateDefaultFsAzureBlobClusterUsingClusterParameters()
Version = "3.2"
};

var createresponse = clientMock.Object.Clusters.Create(resourceGroupName, clusterName, clusterCreateParams);

clusterOperationsMock.As<IClusterOperations>().Verify(c =>
c.BeginCreatingAsync(
It.Is<string>(x => x == resourceGroupName),
It.Is<string>(x => x == clusterName),
It.Is<ClusterCreateParametersExtended>(x => ContainerMatchesNameProvided(x, storageContainerName) == true),
It.IsAny<CancellationToken>()
),
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
Expand All @@ -103,17 +57,9 @@ public void TestCreateDefaultFsAzureBlobClusterContainerNotSpecified()
Version = "3.2"
};

clientMock.Object.Clusters.Create(resourceGroupName, clusterName, clusterCreateParams);

clusterOperationsMock.As<IClusterOperations>().Verify(c =>
c.BeginCreatingAsync(
It.Is<string>(x => x == resourceGroupName),
It.Is<string>(x => x == clusterName),
It.Is<ClusterCreateParametersExtended>(x => ContainerMatchesNameProvided(x, clusterName) == true),
It.IsAny<CancellationToken>()
),
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@
<package id="Microsoft.Bcl.Async" version="1.0.168" targetFramework="net451" />
<package id="Microsoft.Bcl.Build" version="1.0.14" targetFramework="net451" />
<package id="Microsoft.Net.Http" version="2.2.22" targetFramework="net451" />
<package id="Moq" version="4.2.1510.2205" targetFramework="net45" />
</packages>
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public async Task<ClusterCreateResponse> BeginCreatingAsync(string resourceGroup
}
}

private ClusterCreateParametersExtended GetExtendedClusterCreateParameters(
internal ClusterCreateParametersExtended GetExtendedClusterCreateParameters(
string clusterName, ClusterCreateParameters clusterCreateParameters)
{
var createParamsExtended = new ClusterCreateParametersExtended
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,4 @@
[assembly:InternalsVisibleTo("HDInsight.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100b5fc90e7027f67871e773a8fde8938c81dd402ba65b9201d60593e96c492651e889cc13f1415ebb53fac1131ae0bd333c5ee6021672d9718ea31a8aebd0da0072f25d87dba6fc90ffd598ed4da35e44c398c454307e8e33b8426143daec9f596836f97c8f74750e5975c64e2189f45def46b2a2b1247adc3652bf5c308055da9")]
#else
[assembly:InternalsVisibleTo("HDInsight.Tests")]
#endif

// Extra setup for unit testing
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")]
#endif

0 comments on commit 056de19

Please sign in to comment.