Skip to content

Commit 570c4ca

Browse files
Ethan CrawfordEthan Crawford
authored andcommitted
Check fullSetParametersFile for null before attempting a Path.Combine
1 parent cfafbe8 commit 570c4ca

File tree

2 files changed

+63
-13
lines changed

2 files changed

+63
-13
lines changed

src/ServiceManagement/Services/Commands.Test/Websites/PublishAzureWebsiteProjectTests.cs

Lines changed: 55 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,71 @@
1-
using System.Collections;
2-
using System.IO;
1+
using System;
2+
using System.Collections;
33
using System.Management.Automation;
4+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
45
using Microsoft.WindowsAzure.Commands.Test.Utilities.Common;
56
using Microsoft.WindowsAzure.Commands.Test.Utilities.Websites;
7+
using Microsoft.WindowsAzure.Commands.Utilities.Common;
68
using Microsoft.WindowsAzure.Commands.Utilities.Websites;
79
using Microsoft.WindowsAzure.Commands.Websites;
810
using Microsoft.WindowsAzure.Management.WebSites.Models;
911
using Moq;
10-
using Microsoft.WindowsAzure.Commands.ScenarioTest;
1112
using Xunit;
12-
using System;
13-
using Microsoft.WindowsAzure.Commands.Utilities.Common;
1413

1514
namespace Microsoft.WindowsAzure.Commands.Test.Websites
1615
{
1716
public class PublishAzureWebsiteProjectTests : WebsitesTestBase
1817
{
18+
[Fact]
19+
[Trait(Category.AcceptanceType, Category.CheckIn)]
20+
public void PublishFromPackageWithoutSetParameters()
21+
{
22+
const string websiteName = "test-site";
23+
const string package = "test-package";
24+
string slot = null;
25+
var connectionStrings = new Hashtable { ["DefaultConnection"] = "test-connection-string" };
26+
27+
var publishProfile = new WebSiteGetPublishProfileResponse.PublishProfile
28+
{
29+
UserName = "test-user-name",
30+
UserPassword = "test-password",
31+
PublishUrl = "test-publish-url"
32+
};
33+
34+
var published = false;
35+
36+
var clientMock = new Mock<IWebsitesClient>();
37+
38+
clientMock.Setup(c => c.GetWebDeployPublishProfile(websiteName, slot)).Returns(publishProfile);
39+
clientMock.Setup(c => c.PublishWebProject(websiteName, slot, package, null, connectionStrings, false, false))
40+
.Callback((string n, string s, string p, string spf, Hashtable cs, bool skipAppData, bool doNotDelete) =>
41+
{
42+
Assert.Equal(websiteName, n);
43+
Assert.Equal(slot, s);
44+
Assert.Equal(package, p);
45+
Assert.Equal(connectionStrings, cs);
46+
Assert.False(skipAppData);
47+
Assert.False(doNotDelete);
48+
published = true;
49+
});
50+
51+
var powerShellMock = new Mock<ICommandRuntime>();
52+
53+
var command = new PublishAzureWebsiteProject
54+
{
55+
CommandRuntime = powerShellMock.Object,
56+
Name = websiteName,
57+
Package = package,
58+
ConnectionString = connectionStrings,
59+
WebsitesClient = clientMock.Object,
60+
SetParametersFile = null
61+
};
62+
63+
command.ExecuteCmdlet();
64+
65+
powerShellMock.Verify(f => f.WriteVerbose(string.Format("[Complete] Publishing package {0}", package)), Times.Once());
66+
Assert.True(published);
67+
}
68+
1969
[Fact]
2070
[Trait(Category.AcceptanceType, Category.CheckIn)]
2171
public void PublishFromPackage()

src/ServiceManagement/Services/Commands/Websites/PublishAzureWebsiteProject.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,12 @@ public override void ExecuteCmdlet()
8787
}
8888
}
8989

90-
if (!File.Exists(fullSetParametersFile))
90+
if (!string.IsNullOrEmpty(fullSetParametersFile) && !File.Exists(fullSetParametersFile))
9191
{
9292
if (File.Exists(Path.Combine(Path.GetDirectoryName(fullPackage), fullSetParametersFile)))
9393
{
9494
WriteVerbose("Setting path for Parameters file to local one to package: " + Path.Combine(Path.GetDirectoryName(fullPackage), fullSetParametersFile));
95-
fullSetParametersFile = Path.Combine(Path.GetDirectoryName(fullPackage),fullSetParametersFile);
95+
fullSetParametersFile = Path.Combine(Path.GetDirectoryName(fullPackage), fullSetParametersFile);
9696
}
9797
}
9898

@@ -155,12 +155,12 @@ public object GetDynamicParameters()
155155
parameter.Name = name;
156156
parameter.ParameterType = typeof(string);
157157
parameter.Attributes.Add(new ParameterAttribute()
158-
{
159-
ParameterSetName = "ProjectFile",
160-
Mandatory = false,
161-
ValueFromPipelineByPropertyName = true,
162-
HelpMessage = "Connection string from Web.config."
163-
}
158+
{
159+
ParameterSetName = "ProjectFile",
160+
Mandatory = false,
161+
ValueFromPipelineByPropertyName = true,
162+
HelpMessage = "Connection string from Web.config."
163+
}
164164
);
165165
dynamicParameters.Add(name, parameter);
166166
}

0 commit comments

Comments
 (0)