From be84966dea9f734935d87bddd041e9ab8726c158 Mon Sep 17 00:00:00 2001 From: Jimmy Campbell Date: Tue, 8 Aug 2017 10:02:51 -0700 Subject: [PATCH] Fixed issue causing a site's key property to take the next available value on creation. --- .../SiteHelper.cs | 6 ++-- .../Sites.cs | 30 +++++++++++++++++++ 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/src/Microsoft.IIS.Administration.WebServer.Sites/SiteHelper.cs b/src/Microsoft.IIS.Administration.WebServer.Sites/SiteHelper.cs index 6926a70..82c0c3b 100644 --- a/src/Microsoft.IIS.Administration.WebServer.Sites/SiteHelper.cs +++ b/src/Microsoft.IIS.Administration.WebServer.Sites/SiteHelper.cs @@ -55,12 +55,12 @@ namespace Microsoft.IIS.Administration.WebServer.Sites // Initialize new site settings SetToDefaults(site, sm.SiteDefaults); - // Set site settings to those provided - SetSite(site, model, fileProvider); - // Initialize site Id by obtaining the first available site.Id = FirstAvailableId(); + // Set site settings to those provided + SetSite(site, model, fileProvider); + return site; } diff --git a/test/Microsoft.IIS.Administration.Tests/Sites.cs b/test/Microsoft.IIS.Administration.Tests/Sites.cs index 5f9eb0c..80278a1 100644 --- a/test/Microsoft.IIS.Administration.Tests/Sites.cs +++ b/test/Microsoft.IIS.Administration.Tests/Sites.cs @@ -383,6 +383,36 @@ namespace Microsoft.IIS.Administration.Tests } } + [Theory] + [InlineData(99722)] + public void CreateWithKey(int key) + { + using (HttpClient client = ApiHttpClient.Create()) { + + EnsureNoSite(client, TEST_SITE_NAME); + + var siteData = new { + name = TEST_SITE_NAME, + physical_path = TEST_SITE_PATH, + key = key, + bindings = new object[] { + new { + ip_address = "*", + port = TEST_PORT, + protocol = "http" + } + } + }; + + JObject site = client.Post(SITE_URL, siteData); + Assert.NotNull(site); + + Assert.Equal(key, site.Value("key")); + + Assert.True(client.Delete(Utils.Self(site))); + } + } + private bool HasExactProperties(JObject obj, IEnumerable names) { if (obj.Properties().Count() != names.Count()) { return false;