Skip to content

Commit

Permalink
Apply changes of PR-43943 [main]
Browse files Browse the repository at this point in the history
  • Loading branch information
anvillan committed Oct 9, 2024
1 parent 02e2ea9 commit c6b02fe
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace Microsoft.NET.Sdk.Publish.Tasks.OneDeploy.Tests;
public class OneDeployStatusServiceTests
{
private const string Username = "someUser";
private const string Password = "123secret";
private const string NotShareableValue = "PLACEHOLDER";
private const string UserAgent = "websdk/8.0"; // as OneDeploy.UserAgentName
private const string PublishUrl = "https://mysite.scm.azurewebsites.net";
private const string DeploymentId = "056f49ce-fcd7-497c-929b-d74bc6f8905e";
Expand Down Expand Up @@ -57,7 +57,7 @@ public async Task PollDeployment_Completes(HttpStatusCode statusCode, Deployment
var oneDeployStatusService = new OneDeployStatusService(taskLoggerMock.Object);

// Act
var result = await oneDeployStatusService.PollDeploymentAsync(httpClientMock.Object, DeploymentUri.AbsoluteUri, Username, Password, UserAgent, cancellationToken);
var result = await oneDeployStatusService.PollDeploymentAsync(httpClientMock.Object, DeploymentUri.AbsoluteUri, Username, NotShareableValue, UserAgent, cancellationToken);

// Assert: poll deployment status runs to completion, resulting in the given expectedDeploymentStatus
Assert.Equal(expectedDeploymentStatus, deploymentResponse.Status);
Expand Down Expand Up @@ -85,7 +85,7 @@ public async Task PollDeployment_HttpResponse_Fail(HttpStatusCode statusCode)
var oneDeployStatusService = new OneDeployStatusService(taskLoggerMock.Object);

// Act
var result = await oneDeployStatusService.PollDeploymentAsync(httpClientMock.Object, DeploymentUri.AbsoluteUri, Username, Password, UserAgent, cancellationToken);
var result = await oneDeployStatusService.PollDeploymentAsync(httpClientMock.Object, DeploymentUri.AbsoluteUri, Username, NotShareableValue, UserAgent, cancellationToken);

// Assert: poll deployment status runs to completion, resulting in 'Unknown' status because failed HTTP Response Status code
Assert.Equal(DeploymentStatus.Unknown, result.Status);
Expand All @@ -112,7 +112,7 @@ public async Task PollDeployment_Completes_No_Logger()
var oneDeployStatusService = new OneDeployStatusService();

// Act
var result = await oneDeployStatusService.PollDeploymentAsync(httpClientMock.Object, DeploymentUri.AbsoluteUri, Username, Password, UserAgent, cancellationToken);
var result = await oneDeployStatusService.PollDeploymentAsync(httpClientMock.Object, DeploymentUri.AbsoluteUri, Username, NotShareableValue, UserAgent, cancellationToken);

// Assert: poll deployment status runs to completion with NULL ITaskLogger
Assert.Equal(DeploymentStatus.Success, deploymentResponse.Status);
Expand All @@ -136,7 +136,7 @@ public async Task PollDeployment_Halted()

// Act
cancellationTokenSource.Cancel();
var result = await oneDeployStatusService.PollDeploymentAsync(httpClientMock.Object, DeploymentUri.AbsoluteUri, Username, Password, UserAgent, cancellationToken);
var result = await oneDeployStatusService.PollDeploymentAsync(httpClientMock.Object, DeploymentUri.AbsoluteUri, Username, NotShareableValue, UserAgent, cancellationToken);

// Assert: deployment status won't poll for deployment as 'CancellationToken' is already cancelled
Assert.Equal(DeploymentStatus.Unknown, result.Status);
Expand Down Expand Up @@ -164,7 +164,7 @@ public async Task PollDeployment_InvalidURL(string invalidUrl)
var oneDeployStatusService = new OneDeployStatusService(taskLoggerMock.Object);

// Act
var result = await oneDeployStatusService.PollDeploymentAsync(httpClientMock.Object, invalidUrl, Username, Password, UserAgent, cancellationToken);
var result = await oneDeployStatusService.PollDeploymentAsync(httpClientMock.Object, invalidUrl, Username, NotShareableValue, UserAgent, cancellationToken);

// Assert: deployment status won't poll for deployment because given polling URL is invalid
Assert.Equal(DeploymentStatus.Unknown, result.Status);
Expand All @@ -186,7 +186,7 @@ public async Task PollDeployment_Missing_HttpClient()
var oneDeployStatusService = new OneDeployStatusService(taskLoggerMock.Object);

// Act
var result = await oneDeployStatusService.PollDeploymentAsync(null, DeploymentUri.AbsoluteUri, Username, Password, UserAgent, cancellationToken);
var result = await oneDeployStatusService.PollDeploymentAsync(null, DeploymentUri.AbsoluteUri, Username, NotShareableValue, UserAgent, cancellationToken);

// Assert: deployment status won't poll for deployment because IHttpClient is NULL
Assert.Equal(DeploymentStatus.Unknown, result.Status);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public async Task OneDeploy_WebJob_Execute_Completes(

// Act
var result = await oneDeployTask.OneDeployAsync(
FileToPublish, Username, Password, PublishUrl, $"{UserAgentName}/8.0", WebJobName, webJobType, httpClientMock.Object, deploymentStatusServiceMock.Object, CancellationToken.None);
FileToPublish, Username, NotShareableValue, PublishUrl, $"{UserAgentName}/8.0", WebJobName, webJobType, httpClientMock.Object, deploymentStatusServiceMock.Object, CancellationToken.None);

// Assert: WebJob deployment operation runs to completion with expected result
Assert.Equal(expectedResult, result);
Expand Down Expand Up @@ -93,7 +93,7 @@ public async Task OneDeploy_WebJob_PublishUrl_Invalid(string invalidUrl, string

// Act
var result = await oneDeployTask.OneDeployAsync(
FileToPublish, Username, Password, invalidUrl, $"{UserAgentName}/8.0", WebJobName, webjobType, httpClientMock.Object, deploymentStatusServiceMock.Object, CancellationToken.None);
FileToPublish, Username, NotShareableValue, invalidUrl, $"{UserAgentName}/8.0", WebJobName, webjobType, httpClientMock.Object, deploymentStatusServiceMock.Object, CancellationToken.None);

// Assert: deployment operation fails because 'PublishUrl' is not valid
Assert.False(result);
Expand Down Expand Up @@ -126,9 +126,9 @@ public async Task OneDeploy_WebJob_Missing_NameOrType(string webjobName, string
httpClientMock
.Setup(hc => hc.PostAsync(OneDeployUri, It.IsAny<StreamContent>()))
.ReturnsAsync(new HttpResponseMessage(HttpStatusCode.BadGateway)
{
Content = new StringContent(PutErrorResponseMessage)
}
{
Content = new StringContent(PutErrorResponseMessage)
}
);

var deploymentStatusServiceMock = new Mock<IDeploymentStatusService<DeploymentResponse>>();
Expand All @@ -142,7 +142,7 @@ public async Task OneDeploy_WebJob_Missing_NameOrType(string webjobName, string

// Act
var result = await oneDeployTask.OneDeployAsync(
FileToPublish, Username, Password, PublishUrl, $"{UserAgentName}/8.0", webjobName, webjobType, httpClientMock.Object, deploymentStatusServiceMock.Object, CancellationToken.None);
FileToPublish, Username, NotShareableValue, PublishUrl, $"{UserAgentName}/8.0", webjobName, webjobType, httpClientMock.Object, deploymentStatusServiceMock.Object, CancellationToken.None);

// Assert: deployment operation fails because since 'WebJobName' and/or 'WebJobType' is invalid, so we calculate the
// default OneDeploy URI ('<site_scm_ulr>/api/publish'), which target instance does not recognized as valid
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace Microsoft.NET.Sdk.Publish.Tasks.OneDeploy.Tests;
public partial class OneDeployTests
{
private const string Username = "someUser";
private const string Password = "123secret";
private const string NotShareableValue = "PLACEHOLDER";
private const string PublishUrl = "https://mysite.scm.azurewebsites.net";
private const string UserAgentName = "websdk"; // as OneDeploy.UserAgentName
private const string DeploymentUrl = $@"{PublishUrl}/api/deployments/056f49ce-fcd7-497c-929b-d74bc6f8905e";
Expand Down Expand Up @@ -87,7 +87,7 @@ public async Task OneDeploy_Execute_Completes(DeploymentStatus deployStatus, Htt

// Act
var result = await oneDeployTask.OneDeployAsync(
FileToPublish, Username, Password, PublishUrl, $"{UserAgentName}/8.0", webjobName: null, webjobType: null, httpClientMock.Object, deploymentStatusServiceMock.Object, CancellationToken.None);
FileToPublish, Username, NotShareableValue, PublishUrl, $"{UserAgentName}/8.0", webjobName: null, webjobType: null, httpClientMock.Object, deploymentStatusServiceMock.Object, CancellationToken.None);

// Assert: deployment operation runs to completion with expected result
Assert.Equal(expectedResult, result);
Expand Down Expand Up @@ -130,7 +130,7 @@ public async Task OneDeploy_Execute_Deploy_Location_Missing(string invalidLocati

// Act
var result = await oneDeployTask.OneDeployAsync(
FileToPublish, Username, Password, PublishUrl, $"{UserAgentName}/8.0", webjobName: null, webjobType: null, httpClientMock.Object, deploymentStatusServiceMock.Object, CancellationToken.None);
FileToPublish, Username, NotShareableValue, PublishUrl, $"{UserAgentName}/8.0", webjobName: null, webjobType: null, httpClientMock.Object, deploymentStatusServiceMock.Object, CancellationToken.None);

// Assert: deployment operation runs to completion, without polling the deployment because 'Location' header was not found in response
Assert.True(result);
Expand Down Expand Up @@ -161,7 +161,7 @@ public async Task OneDeploy_Execute_HttpResponse_Fail(HttpStatusCode statusCode)

// Act
var result = await oneDeployTask.OneDeployAsync(
FileToPublish, Username, Password, PublishUrl, $"{UserAgentName}/8.0", webjobName: null, webjobType: null, httpClientMock.Object, deploymentStatusServiceMock.Object, CancellationToken.None);
FileToPublish, Username, NotShareableValue, PublishUrl, $"{UserAgentName}/8.0", webjobName: null, webjobType: null, httpClientMock.Object, deploymentStatusServiceMock.Object, CancellationToken.None);

// Assert: deployment operation fails because HTTP POST request to upload the package returns a failed HTTP Response
Assert.False(result);
Expand Down Expand Up @@ -190,7 +190,7 @@ public async Task OneDeploy_Execute_PublishUrl_Invalid(string invalidUrl)

// Act
var result = await oneDeployTask.OneDeployAsync(
FileToPublish, Username, Password, invalidUrl, $"{UserAgentName}/8.0", webjobName: null, webjobType: null, httpClientMock.Object, deploymentStatusServiceMock.Object, CancellationToken.None);
FileToPublish, Username, NotShareableValue, invalidUrl, $"{UserAgentName}/8.0", webjobName: null, webjobType: null, httpClientMock.Object, deploymentStatusServiceMock.Object, CancellationToken.None);

// Assert: deployment operation fails because 'PublishUrl' is not valid
Assert.False(result);
Expand Down Expand Up @@ -219,7 +219,7 @@ public async Task OneDeploy_Execute_FileToPublish_Missing(string invalidFileToPu

// Act
var result = await oneDeployTask.OneDeployAsync(
invalidFileToPublish, Username, Password, PublishUrl, $"{UserAgentName}/8.0", webjobName: null, webjobType: null, httpClientMock.Object, deploymentStatusServiceMock.Object, CancellationToken.None);
invalidFileToPublish, Username, NotShareableValue, PublishUrl, $"{UserAgentName}/8.0", webjobName: null, webjobType: null, httpClientMock.Object, deploymentStatusServiceMock.Object, CancellationToken.None);

// Assert: deployment operation fails because 'FileToPublishPath' is not valid
Assert.False(result);
Expand Down Expand Up @@ -277,12 +277,12 @@ public async Task OneDeploy_Execute_Credentials_From_TaskHostObject()
var oneDeployTask = new OneDeploy(taskLoggerMock.Object);

var msbuildHostObject = new VSMsDeployTaskHostObject();
msbuildHostObject.AddCredentialTaskItemIfExists(Username, Password);
msbuildHostObject.AddCredentialTaskItemIfExists(Username, NotShareableValue);
oneDeployTask.HostObject = msbuildHostObject;

// Act
var result = await oneDeployTask.OneDeployAsync(
FileToPublish, Username, Password, PublishUrl, $"{UserAgentName}/8.0", webjobName: null, webjobType: null, httpClientMock.Object, deploymentStatusServiceMock.Object, CancellationToken.None);
FileToPublish, Username, NotShareableValue, PublishUrl, $"{UserAgentName}/8.0", webjobName: null, webjobType: null, httpClientMock.Object, deploymentStatusServiceMock.Object, CancellationToken.None);

// Assert: deployment operation runs to completion
// obtaining the credentials from the Task HostObject
Expand Down Expand Up @@ -344,7 +344,7 @@ private Mock<IDeploymentStatusService<DeploymentResponse>> GetDeploymentStatusSe
var statusServiceMock = new Mock<IDeploymentStatusService<DeploymentResponse>>();

statusServiceMock
.Setup(s => s.PollDeploymentAsync(httpClient, DeploymentUrl, Username, Password, $"{UserAgentName}/8.0", It.IsAny<CancellationToken>()))
.Setup(s => s.PollDeploymentAsync(httpClient, DeploymentUrl, Username, NotShareableValue, $"{UserAgentName}/8.0", It.IsAny<CancellationToken>()))
.ReturnsAsync(deploymentResponse);

return statusServiceMock;
Expand Down

0 comments on commit c6b02fe

Please sign in to comment.