Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add output validation in unit tests

  • Loading branch information...
commit 1f27cc382e6540526a0caaca963d032aa0d7d352 1 parent 156ba7b
@ogail ogail authored
View
47 WindowsAzurePowershell/src/Management.CloudService.Test/Tests/Cmdlet/SetAzureServiceProjectTests.cs
@@ -19,12 +19,24 @@ namespace Microsoft.WindowsAzure.Management.CloudService.Test.Tests.Cmdlet
using CloudService.Cmdlet;
using CloudService.Model;
using CloudService.Properties;
+ using Microsoft.WindowsAzure.Management.CloudService.Test.Utilities;
using TestData;
using VisualStudio.TestTools.UnitTesting;
[TestClass]
public class SetAzureServiceProjectTests : TestBase
{
+ FakeWriter writer;
+ SetAzureServiceProjectCommand cmdlet;
+
+ [TestInitialize]
+ public void SetupTest()
+ {
+ writer = new FakeWriter();
+ cmdlet = new SetAzureServiceProjectCommand();
+ cmdlet.Writer = writer;
+ }
+
[TestMethod]
public void SetAzureServiceProjectTestsSubscriptionValid()
{
@@ -36,14 +48,17 @@ public void SetAzureServiceProjectTestsSubscriptionValid()
//
ServicePathInfo paths = new ServicePathInfo(files.RootPath);
ServiceSettings settings = new ServiceSettings();
+ writer = new FakeWriter();
+ cmdlet.Writer = writer;
settings.Save(paths.Settings);
- new SetAzureServiceProjectCommand().SetAzureServiceProjectProcess(null, null, null, item, paths.Settings);
+ settings = cmdlet.SetAzureServiceProjectProcess(null, null, null, item, paths.Settings);
// Assert subscription is changed
//
- settings = ServiceSettings.Load(paths.Settings);
Assert.AreEqual<string>(item, settings.Subscription);
+ ServiceSettings actualOutput = writer.OutputChannel[0] as ServiceSettings;
+ Assert.AreEqual<string>(item, actualOutput.Subscription);
}
}
}
@@ -59,7 +74,7 @@ public void SetAzureServiceProjectTestsSubscriptionEmptyFail()
ServiceSettings settings = new ServiceSettings();
settings.Save(paths.Settings);
- Testing.AssertThrows<ArgumentException>(() => new SetAzureServiceProjectCommand().SetAzureServiceProjectProcess(null, null, null, string.Empty, paths.Settings), string.Format(Resources.InvalidOrEmptyArgumentMessage, "Subscription"));
+ Testing.AssertThrows<ArgumentException>(() => cmdlet.SetAzureServiceProjectProcess(null, null, null, string.Empty, paths.Settings), string.Format(Resources.InvalidOrEmptyArgumentMessage, "Subscription"));
}
}
@@ -74,13 +89,16 @@ public void SetAzureServiceProjectTestsLocationValid()
//
ServicePathInfo paths = new ServicePathInfo(files.RootPath);
ServiceSettings settings = new ServiceSettings();
+ writer = new FakeWriter();
+ cmdlet.Writer = writer;
settings.Save(paths.Settings);
- new SetAzureServiceProjectCommand().SetAzureServiceProjectProcess(item.Value, null, null, null, paths.Settings);
+ settings = cmdlet.SetAzureServiceProjectProcess(item.Value, null, null, null, paths.Settings);
// Assert location is changed
//
- settings = ServiceSettings.Load(paths.Settings);
+ Assert.AreEqual<string>(item.Value, settings.Location);
+ ServiceSettings actualOutput = writer.OutputChannel[0] as ServiceSettings;
Assert.AreEqual<string>(item.Value, settings.Location);
}
}
@@ -97,7 +115,7 @@ public void SetAzureServiceProjectTestsLocationEmptyFail()
ServiceSettings settings = new ServiceSettings();
settings.Save(paths.Settings);
- Testing.AssertThrows<ArgumentException>(() => new SetAzureServiceProjectCommand().SetAzureServiceProjectProcess(string.Empty, null, null, null, paths.Settings), string.Format(Resources.InvalidOrEmptyArgumentMessage, "Location"));
+ Testing.AssertThrows<ArgumentException>(() => cmdlet.SetAzureServiceProjectProcess(string.Empty, null, null, null, paths.Settings), string.Format(Resources.InvalidOrEmptyArgumentMessage, "Location"));
}
}
@@ -112,7 +130,7 @@ public void SetAzureServiceProjectTestsLocationInvalidFail()
ServiceSettings settings = new ServiceSettings();
settings.Save(paths.Settings);
- Testing.AssertThrows<ArgumentException>(() => new SetAzureServiceProjectCommand().SetAzureServiceProjectProcess("MyHome", null, null, null, paths.Settings), string.Format(Resources.InvalidServiceSettingElement, "Location"));
+ Testing.AssertThrows<ArgumentException>(() => cmdlet.SetAzureServiceProjectProcess("MyHome", null, null, null, paths.Settings), string.Format(Resources.InvalidServiceSettingElement, "Location"));
}
}
@@ -125,13 +143,16 @@ public void SetAzureServiceProjectTestsStorageTests()
//
ServicePathInfo paths = new ServicePathInfo(files.RootPath);
ServiceSettings settings = new ServiceSettings();
+ writer = new FakeWriter();
+ cmdlet.Writer = writer;
settings.Save(paths.Settings);
- new SetAzureServiceProjectCommand().SetAzureServiceProjectProcess(null, null, "companystore", null, paths.Settings);
+ settings = cmdlet.SetAzureServiceProjectProcess(null, null, "companystore", null, paths.Settings);
// Assert storageAccountName is changed
//
- settings = ServiceSettings.Load(paths.Settings);
+ Assert.AreEqual<string>("companystore", settings.StorageAccountName);
+ ServiceSettings actualOutput = writer.OutputChannel[0] as ServiceSettings;
Assert.AreEqual<string>("companystore", settings.StorageAccountName);
}
}
@@ -147,7 +168,7 @@ public void SetAzureServiceProjectTestsStorageTestsEmptyFail()
ServiceSettings settings = new ServiceSettings();
settings.Save(paths.Settings);
- Testing.AssertThrows<ArgumentException>(() => new SetAzureServiceProjectCommand().SetAzureServiceProjectProcess(null, null, string.Empty, null, paths.Settings), string.Format(Resources.InvalidOrEmptyArgumentMessage, "StorageAccountName"));
+ Testing.AssertThrows<ArgumentException>(() => cmdlet.SetAzureServiceProjectProcess(null, null, string.Empty, null, paths.Settings), string.Format(Resources.InvalidOrEmptyArgumentMessage, "StorageAccountName"));
}
}
@@ -164,7 +185,7 @@ public void SetAzureServiceProjectTestsSlotTests()
ServiceSettings settings = new ServiceSettings();
settings.Save(paths.Settings);
- new SetAzureServiceProjectCommand().SetAzureServiceProjectProcess(null, item.Value, null, null, paths.Settings);
+ cmdlet.SetAzureServiceProjectProcess(null, item.Value, null, null, paths.Settings);
// Assert slot is changed
//
@@ -185,7 +206,7 @@ public void SetAzureServiceProjectTestsSlotTestsEmptyFail()
ServiceSettings settings = new ServiceSettings();
settings.Save(paths.Settings);
- Testing.AssertThrows<ArgumentException>(() => new SetAzureServiceProjectCommand().SetAzureServiceProjectProcess(null, string.Empty, null, null, paths.Settings), string.Format(Resources.InvalidOrEmptyArgumentMessage, "Slot"));
+ Testing.AssertThrows<ArgumentException>(() => cmdlet.SetAzureServiceProjectProcess(null, string.Empty, null, null, paths.Settings), string.Format(Resources.InvalidOrEmptyArgumentMessage, "Slot"));
}
}
@@ -200,7 +221,7 @@ public void SetAzureServiceProjectTestsSlotTestsInvalidFail()
ServiceSettings settings = new ServiceSettings();
settings.Save(paths.Settings);
- Testing.AssertThrows<ArgumentException>(() => new SetAzureServiceProjectCommand().SetAzureServiceProjectProcess(null, "MyHome", null, null, paths.Settings), string.Format(Resources.InvalidServiceSettingElement, "Slot"));
+ Testing.AssertThrows<ArgumentException>(() => cmdlet.SetAzureServiceProjectProcess(null, "MyHome", null, null, paths.Settings), string.Format(Resources.InvalidServiceSettingElement, "Slot"));
}
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.