Skip to content

. #205

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Nov 23, 2015
Merged

. #205

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,14 @@
<Compile Include="Certificates\NewBatchCertificateCommandTests.cs" />
<Compile Include="Certificates\RemoveBatchCertificateCommandTests.cs" />
<Compile Include="Certificates\StopBatchCertificateDeletionCommandTests.cs" />
<Compile Include="ComputeNodes\RemoveBatchComputeNodeCommandTests.cs" />
<Compile Include="ComputeNodes\ResetBatchComputeNodeCommandTests.cs" />
<Compile Include="ComputeNodes\RestartBatchComputeNodeCommandTests.cs" />
<Compile Include="ComputeNodeUsers\SetBatchComputeNoderUserCommandTests.cs" />
<Compile Include="Files\GetBatchRemoteDesktopProtocolFileCommandTests.cs" />
<Compile Include="Files\GetBatchNodeFileCommandTests.cs" />
<Compile Include="Files\GetBatchNodeFileContentCommandTests.cs" />
<Compile Include="Files\RemoveBatchNodeFileCommandTests.cs" />
<Compile Include="JobSchedules\DisableBatchJobScheduleCommandTests.cs" />
<Compile Include="JobSchedules\EnableBatchJobScheduleCommandTests.cs" />
<Compile Include="JobSchedules\SetBatchJobScheduleCommandTests.cs" />
Expand Down Expand Up @@ -363,6 +365,15 @@
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.ComputeNodeTests\TestReimageComputeNodePipeline.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.ComputeNodeTests\TestRemoveComputeNodeById.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.ComputeNodeTests\TestRemoveComputeNodePipeline.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.ComputeNodeTests\TestRemoveMultipleComputeNodes.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.ComputeNodeUserTests\TestCreateComputeNodeUser.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
Expand All @@ -375,6 +386,18 @@
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.ComputeNodeUserTests\TestUpdateComputeNodeUser.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.FileTests\TestDeleteNodeFileByComputeNodeByName.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.FileTests\TestDeleteNodeFileByComputeNodeByPipeline.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.FileTests\TestDeleteNodeFileByTaskByName.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.FileTests\TestDeleteNodeFileByTaskByPipeline.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.FileTests\TestGetNodeFileByComputeNodeByName.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------

using System;
using Microsoft.Azure.Batch;
using Microsoft.Azure.Batch.Common;
using Microsoft.Azure.Batch.Protocol;
using Microsoft.Azure.Batch.Protocol.Models;
using Microsoft.WindowsAzure.Commands.ScenarioTest;
using Moq;
using System.Collections.Generic;
using System.Management.Automation;
using System.Threading.Tasks;
using Xunit;
using BatchClient = Microsoft.Azure.Commands.Batch.Models.BatchClient;

namespace Microsoft.Azure.Commands.Batch.Test.Pools
{
public class RemoveBatchComputeNodeCommandTests : WindowsAzure.Commands.Test.Utilities.Common.RMTestBase
{
private RemoveBatchComputeNodeCommand cmdlet;
private Mock<BatchClient> batchClientMock;
private Mock<ICommandRuntime> commandRuntimeMock;

public RemoveBatchComputeNodeCommandTests()
{
batchClientMock = new Mock<BatchClient>();
commandRuntimeMock = new Mock<ICommandRuntime>();
cmdlet = new RemoveBatchComputeNodeCommand()
{
CommandRuntime = commandRuntimeMock.Object,
BatchClient = batchClientMock.Object,
};
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void RemoveBatchComputeNodeParametersTest()
{
// Setup cmdlet to skip confirmation popup
cmdlet.Force = true;
commandRuntimeMock.Setup(f => f.ShouldProcess(It.IsAny<string>(), It.IsAny<string>())).Returns(true);

BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();
cmdlet.BatchContext = context;
cmdlet.Ids = null;

Assert.Throws<ArgumentNullException>(() => cmdlet.ExecuteCmdlet());

cmdlet.PoolId = "testPool";

Assert.Throws<ArgumentNullException>(() => cmdlet.ExecuteCmdlet());

cmdlet.Ids = new string[] { "computeNode1" };

// Don't go to the service on a Remove ComputeNode call
RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor<ComputeNodeRemoveParameters, ComputeNodeRemoveResponse>();
cmdlet.AdditionalBehaviors = new List<BatchClientBehavior>() { interceptor };

// Verify no exceptions when required parameter is set
cmdlet.ExecuteCmdlet();
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void RemoveComputeNodeRequestTest()
{
// Setup cmdlet to skip confirmation popup
cmdlet.Force = true;
commandRuntimeMock.Setup(f => f.ShouldProcess(It.IsAny<string>(), It.IsAny<string>())).Returns(true);

BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();
cmdlet.BatchContext = context;

cmdlet.PoolId = "testPool";
cmdlet.Ids = new string[] { "computeNode1", "computeNode2" };
cmdlet.DeallocationOption = ComputeNodeDeallocationOption.Terminate;
cmdlet.ResizeTimeout = TimeSpan.FromMinutes(8);

ComputeNodeDeallocationOption? requestDeallocationOption = null;
TimeSpan? requestResizeTimeout = null;
IList<string> requestComputeNodeIds = null;

// Don't go to the service on a Remove ComputeNode call
RequestInterceptor interceptor = new RequestInterceptor((baseRequest) =>
{
BatchRequest<ComputeNodeRemoveParameters, ComputeNodeRemoveResponse> request =
(BatchRequest<ComputeNodeRemoveParameters, ComputeNodeRemoveResponse>)baseRequest;

request.ServiceRequestFunc = (cancellationToken) =>
{
// Grab the parameters from the outgoing request.
requestDeallocationOption = request.TypedParameters.ComputeNodeDeallocationOption;
requestResizeTimeout = request.TypedParameters.ResizeTimeout;
requestComputeNodeIds = request.TypedParameters.ComputeNodeIds;

ComputeNodeRemoveResponse response = new ComputeNodeRemoveResponse();
Task<ComputeNodeRemoveResponse> task = Task.FromResult(response);
return task;
};
});
cmdlet.AdditionalBehaviors = new List<BatchClientBehavior>() { interceptor };

cmdlet.ExecuteCmdlet();

// Verify that the parameters were properly set on the outgoing request
Assert.Equal(cmdlet.DeallocationOption, requestDeallocationOption);
Assert.Equal(cmdlet.ResizeTimeout, requestResizeTimeout);
Assert.Equal(cmdlet.Ids.Length, requestComputeNodeIds.Count);
foreach (string id in cmdlet.Ids)
{
Assert.True(requestComputeNodeIds.Contains(id));
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------

using System;
using System.IO;
using Microsoft.Azure.Batch;
using Microsoft.Azure.Batch.Protocol;
using Microsoft.WindowsAzure.Commands.ScenarioTest;
using Moq;
using System.Collections.Generic;
using System.Management.Automation;
using Xunit;
using BatchClient = Microsoft.Azure.Commands.Batch.Models.BatchClient;
using Microsoft.Azure.Batch.Protocol.Models;

namespace Microsoft.Azure.Commands.Batch.Test.Files
{
public class RemoveBatchNodeFileCommandTests : WindowsAzure.Commands.Test.Utilities.Common.RMTestBase
{
private RemoveBatchNodeFileCommand cmdlet;
private Mock<BatchClient> batchClientMock;
private Mock<ICommandRuntime> commandRuntimeMock;

public RemoveBatchNodeFileCommandTests()
{
batchClientMock = new Mock<BatchClient>();
commandRuntimeMock = new Mock<ICommandRuntime>();
cmdlet = new RemoveBatchNodeFileCommand()
{
CommandRuntime = commandRuntimeMock.Object,
BatchClient = batchClientMock.Object,
};
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void RemoveBatchNodeFileParametersTest()
{
// Setup cmdlet to skip confirmation popup
cmdlet.Force = true;
commandRuntimeMock.Setup(f => f.ShouldProcess(It.IsAny<string>(), It.IsAny<string>())).Returns(true);

// Setup cmdlet without required parameters
BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();
cmdlet.BatchContext = context;
cmdlet.JobId = null;
cmdlet.TaskId = null;
cmdlet.Name = null;
cmdlet.InputObject = null;

// Don't go to the service on a Delete NodeFile call
RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor<NodeFileDeleteParameters, NodeFileDeleteResponse>();
cmdlet.AdditionalBehaviors = new List<BatchClientBehavior>() { interceptor };

Assert.Throws<ArgumentException>(() => cmdlet.ExecuteCmdlet());

// Fill required task details
cmdlet.JobId = "job-1";
cmdlet.TaskId = "task";
cmdlet.Name = "stdout.txt";

// Verify no exceptions occur
cmdlet.ExecuteCmdlet();

// Setup compute node parameters
cmdlet.JobId = null;
cmdlet.TaskId = null;
cmdlet.PoolId = "testPool";
cmdlet.ComputeNodeId = "computeNode-1";

// Verify no exceptions occur
cmdlet.ExecuteCmdlet();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@
# limitations under the License.
# ----------------------------------------------------------------------------------

<#
.SYNOPSIS
Sleeps but only during recording.
#>
function Start-TestSleep($milliseconds)
{
if ([Microsoft.Azure.Test.HttpRecorder.HttpMockServer]::Mode -ne [Microsoft.Azure.Test.HttpRecorder.HttpRecorderMode]::Playback)
{
Start-Sleep -Milliseconds $milliseconds
}
}

<#
.SYNOPSIS
Gets a ScenarioTestContext for the specified account
Expand Down
Loading