Index: Migration/Scripts/test/Migration.Scripts.Data.Test/UpgradeScriptTest.cs =================================================================== diff -u -r7b09e29a12bb9207e3ed23dba4771007f7d948d5 -rdcce1c8c694a59962a2c0cdf4c4f71cacbff0e74 --- Migration/Scripts/test/Migration.Scripts.Data.Test/UpgradeScriptTest.cs (.../UpgradeScriptTest.cs) (revision 7b09e29a12bb9207e3ed23dba4771007f7d948d5) +++ Migration/Scripts/test/Migration.Scripts.Data.Test/UpgradeScriptTest.cs (.../UpgradeScriptTest.cs) (revision dcce1c8c694a59962a2c0cdf4c4f71cacbff0e74) @@ -24,6 +24,7 @@ using System.IO; using Core.Common.TestUtil; using NUnit.Framework; +using Rhino.Mocks; namespace Migration.Scripts.Data.Test { @@ -102,57 +103,62 @@ public void Upgrade_SourceNull_ThrowsArgumentNullException() { // Setup + var mockRepository = new MockRepository(); + var targetVersionedFile = mockRepository.Stub(); + mockRepository.ReplayAll(); + const string fromVersion = "fromVersion"; const string toVersion = "toVersion"; const string query = ";"; var upgradeScript = new UpgradeScript(fromVersion, toVersion, query); - string filename = Path.GetRandomFileName(); - string filePath = TestHelper.GetTestDataPath(TestDataPath.Migration.Core.Storage, filename); - - var targetVersionedFile = new VersionedFile(filePath); - // Call TestDelegate call = () => upgradeScript.Upgrade(null, targetVersionedFile); // Assert string paramName = Assert.Throws(call).ParamName; Assert.AreEqual("source", paramName); + mockRepository.VerifyAll(); } [Test] public void Upgrade_TargetNull_ThrowsArgumentNullException() { // Setup + var mockRepository = new MockRepository(); + var sourceVersionedFile = mockRepository.Stub(); + mockRepository.ReplayAll(); + const string fromVersion = "fromVersion"; const string toVersion = "toVersion"; const string query = ";"; var upgradeScript = new UpgradeScript(fromVersion, toVersion, query); - string filename = Path.GetRandomFileName(); - string filePath = TestHelper.GetTestDataPath(TestDataPath.Migration.Core.Storage, filename); - - var sourceVersionedFile = new VersionedFile(filePath); - // Call TestDelegate call = () => upgradeScript.Upgrade(sourceVersionedFile, null); // Assert string paramName = Assert.Throws(call).ParamName; Assert.AreEqual("target", paramName); + mockRepository.VerifyAll(); } [Test] public void Upgrade_UpgradeFails_ThrowsSQLiteException() { // Setup - var upgradeScript = new UpgradeScript("1", "2", "THIS WILL FAIL"); - var sourceVersionedFile = new VersionedFile("c:\\file.ext"); - string filename = Path.GetRandomFileName(); string filePath = TestHelper.GetTestDataPath(TestDataPath.Migration.Core.Storage, filename); - var targetVersionedFile = new VersionedFile(filePath); + var mockRepository = new MockRepository(); + var sourceVersionedFile = mockRepository.Stub(); + sourceVersionedFile.Expect(tvf => tvf.Location).Return("c:\\file.ext"); + var targetVersionedFile = mockRepository.Stub(); + targetVersionedFile.Expect(tvf => tvf.Location).Return(filePath); + mockRepository.ReplayAll(); + + var upgradeScript = new UpgradeScript("1", "2", "THIS WILL FAIL"); + // Call TestDelegate call = () => upgradeScript.Upgrade(sourceVersionedFile, targetVersionedFile); @@ -161,28 +167,35 @@ { Assert.Throws(call); } + mockRepository.VerifyAll(); } [Test] public void Upgrade_ValidParameters_ExpectedProperties() { // Setup - var upgradeScript = new UpgradeScript("1", "2", ";"); - var sourceVersionedFile = new VersionedFile("c:\\file.ext"); - string filename = Path.GetRandomFileName(); string filePath = TestHelper.GetTestDataPath(TestDataPath.Migration.Core.Storage, filename); - var targetVersionedFile = new VersionedFile(filePath); + var mockRepository = new MockRepository(); + var sourceVersionedFile = mockRepository.Stub(); + sourceVersionedFile.Expect(tvf => tvf.Location).Return("c:\\file.ext"); + var targetVersionedFile = mockRepository.Stub(); + targetVersionedFile.Expect(tvf => tvf.Location).Return(filePath); + mockRepository.ReplayAll(); + + var upgradeScript = new UpgradeScript("1", "2", ";"); + // Call upgradeScript.Upgrade(sourceVersionedFile, targetVersionedFile); // Assert Assert.IsNotNull(targetVersionedFile); - using (new FileDisposeHelper(targetVersionedFile.Location)) + using (new FileDisposeHelper(filePath)) { - Assert.IsTrue(File.Exists(targetVersionedFile.Location)); + Assert.IsTrue(File.Exists(filePath)); } + mockRepository.VerifyAll(); } } } \ No newline at end of file