Permalink
Browse files

Adding remove operations to cache.

  • Loading branch information...
1 parent 8592f3f commit 45b2e3c76013d714d9fcbe4c338499d2be3513cb Andre Rodrigues committed Sep 11, 2012
@@ -121,7 +121,7 @@
<Compile Include="UnitTests\Cmdlets\RemoveAzureWebSiteTests.cs" />
<Compile Include="UnitTests\Cmdlets\GetAzureWebsiteLocationTests.cs" />
<Compile Include="UnitTests\Cmdlets\ShowAzureWebsiteTests.cs" />
- <Compile Include="UnitTests\Cmdlets\CacheTests.cs" />
+ <Compile Include="UnitTests\Services\CacheTests.cs" />
<Compile Include="UnitTests\Services\GitTests.cs" />
<Compile Include="UnitTests\Utilities\SimpleWebsitesManagement.cs" />
</ItemGroup>
@@ -12,7 +12,7 @@
// limitations under the License.
// ----------------------------------------------------------------------------------
-namespace Microsoft.WindowsAzure.Management.Websites.Test.UnitTests.Cmdlets
+namespace Microsoft.WindowsAzure.Management.Websites.Test.UnitTests.Services
{
using System.Collections.Generic;
using System.IO;
@@ -53,6 +53,33 @@ public void SetupTest()
}
[TestMethod]
+ public void AddWebSpaceTest()
+ {
+ WebSpace webSpace = new WebSpace {Name = "newwebspace"};
+ // Add without any cache from before
+ Cache.AddWebSpace(SubscriptionName, webSpace);
+
+ WebSpaces getWebSpaces = Cache.GetWebSpaces(SubscriptionName);
+ Assert.IsNotNull(getWebSpaces.Find(ws => ws.Name.Equals("newwebspace")));
+ }
+
+ [TestMethod]
+ public void RemoveWebSpaceTest()
+ {
+ WebSpace webSpace = new WebSpace { Name = "newwebspace" };
+ // Add without any cache from before
+ Cache.AddWebSpace(SubscriptionName, webSpace);
+
+ WebSpaces getWebSpaces = Cache.GetWebSpaces(SubscriptionName);
+ Assert.IsNotNull(getWebSpaces.Find(ws => ws.Name.Equals("newwebspace")));
+
+ // Now remove it
+ Cache.RemoveWebSpace(SubscriptionName, webSpace);
+ getWebSpaces = Cache.GetWebSpaces(SubscriptionName);
+ Assert.IsNull(getWebSpaces.Find(ws => ws.Name.Equals("newwebspace")));
+ }
+
+ [TestMethod]
public void GetSetWebSpacesTest()
{
// Test no webspaces
@@ -68,6 +95,33 @@ public void GetSetWebSpacesTest()
}
[TestMethod]
+ public void AddSiteTest()
+ {
+ Site site = new Site { Name = "newsite" };
+ // Add without any cache from before
+ Cache.AddSite(SubscriptionName, site);
+
+ Sites getSites = Cache.GetSites(SubscriptionName);
+ Assert.IsNotNull(getSites.Find(ws => ws.Name.Equals("newsite")));
+ }
+
+ [TestMethod]
+ public void RemoveSiteTest()
+ {
+ Site site = new Site { Name = "newsite" };
+ // Add without any cache from before
+ Cache.AddSite(SubscriptionName, site);
+
+ Sites getSites = Cache.GetSites(SubscriptionName);
+ Assert.IsNotNull(getSites.Find(ws => ws.Name.Equals("newsite")));
+
+ // Now remove it
+ Cache.RemoveSite(SubscriptionName, site);
+ getSites = Cache.GetSites(SubscriptionName);
+ Assert.IsNull(getSites.Find(ws => ws.Name.Equals("newsite")));
+ }
+
+ [TestMethod]
public void GetSetSitesTest()
{
Assert.IsNull(Cache.GetSites(SubscriptionName));
@@ -250,6 +250,8 @@ internal override void ExecuteCommand()
{
Cache.AddWebSpace(CurrentSubscription.SubscriptionId, webspace);
}
+
+ Cache.AddSite(CurrentSubscription.SubscriptionId, website);
}
catch (ProtocolException ex)
{
@@ -34,6 +34,18 @@ public static void AddWebSpace(string subscriptionId, WebSpace webSpace)
SaveSpaces(subscriptionId, webSpaces);
}
+ public static void RemoveWebSpace(string subscriptionId, WebSpace webSpace)
+ {
+ WebSpaces webSpaces = GetWebSpaces(subscriptionId);
+ if (webSpaces == null)
+ {
+ return;
+ }
+
+ webSpaces.RemoveAll(ws => ws.Name.Equals(webSpace.Name));
+ SaveSpaces(subscriptionId, webSpaces);
+ }
+
public static WebSpaces GetWebSpaces(string subscriptionId)
{
string webspacesFile = Path.Combine(GlobalPathInfo.AzureAppDir, string.Format("spaces.{0}.json", subscriptionId));
@@ -59,6 +71,18 @@ public static void AddSite(string subscriptionId, Site site)
SaveSites(subscriptionId, sites);
}
+ public static void RemoveSite(string subscriptionId, Site site)
+ {
+ Sites sites = GetSites(subscriptionId);
+ if (sites == null)
+ {
+ return;
+ }
+
+ sites.RemoveAll(s => s.Name.Equals(site.Name));
+ SaveSites(subscriptionId, sites);
+ }
+
public static Sites GetSites(string subscriptionId)
{
string sitesFile = Path.Combine(GlobalPathInfo.AzureAppDir, string.Format("sites.{0}.json", subscriptionId));

0 comments on commit 45b2e3c

Please sign in to comment.