public void CheckPrerequisitiesTest_ShouldFail() { //arrange MigrationFlowData flowData = new MigrationFlowData(); flowData.VhdFileDestinationFolder = "destination\\folder"; this.fileSystemMock.Setup(x => x.File.Exists(It.IsAny <string>())) .Returns <string>((path) => { return(path == flowData.VhdFileDestinationFolder + "\\" ? true : false); }); CreateFinalVhdMigrationStep step = new CreateFinalVhdMigrationStep(loggerMock.Object, fileSystemHelperMock.Object, fileSystemMock.Object, flowData); //act string[] messages = new string[0]; bool result = step.CheckPrerequisities(ref messages); //assert Assert.IsFalse(result); Assert.AreEqual(1, messages.Where(x => x.Contains("already exists")).Count()); Assert.AreEqual(1, messages.Where(x => x.Contains("DISKPART was not found")).Count()); }
public void CheckPrerequisitiesTest_ShouldBeOk() { //arrange MigrationFlowData flowData = new MigrationFlowData(); flowData.VhdFileDestinationFolder = "destination\\folder"; this.fileSystemMock.Setup(x => x.File.Exists(It.IsAny <string>())) .Returns <string>((path) => { return(path == flowData.VhdFileDestinationFolder + "\\" ? false : true); }); CreateFinalVhdMigrationStep step = new CreateFinalVhdMigrationStep(loggerMock.Object, fileSystemHelperMock.Object, fileSystemMock.Object, flowData); //act string[] messages = new string[0]; bool result = step.CheckPrerequisities(ref messages); //assert Assert.IsTrue(result); }
public void PerformStepTest_ShouldFinishOk() { //arrange MigrationFlowData flowData = new MigrationFlowData(); flowData.VhdFileTemporaryFolder = "temporary\\folder"; flowData.VhdFileDestinationFolder = "destination\\folder"; flowData.VhdFileName = "test.vhdx"; flowData.VhdFileType = Logic.Models.Enums.VhdType.VhdxDynamic; flowData.DestinationVhdMaxFileSize = 200000000; flowData.DesiredTempVhdShrinkSize = 100000000; string vhdFullName = $"{flowData.VhdFileDestinationFolder}\\{flowData.VhdFileName}"; long maximumVhdSizeInMb = flowData.DestinationVhdMaxFileSize >> 20;// / (1024 * 1024); string vhdTypeString = flowData.VhdFileType == VhdType.VhdDynamic || flowData.VhdFileType == VhdType.VhdxDynamic ? "expandable" : "fixed"; Mock <StreamWriter> streamWriterMock = new Mock <StreamWriter>(new MemoryStream()); streamWriterMock.Setup(x => x.WriteLine(It.IsAny <string>())) .Verifiable(); StreamWriter swMock = streamWriterMock.Object; this.fileSystemMock.Setup(x => x.File.CreateText(It.IsAny <string>())) .Returns <string>((path) => { return(swMock); }) .Verifiable(); this.fileSystemMock.Setup(x => x.Directory.CreateDirectory(It.IsAny <string>())) .Verifiable(); this.fileSystemMock.Setup(x => x.File.Delete(It.IsAny <string>())) .Verifiable(); CreateFinalVhdMigrationStep step = new CreateFinalVhdMigrationStep(loggerMock.Object, fileSystemHelperMock.Object, fileSystemMock.Object, flowData); //act step.PerformStep(); //assert streamWriterMock.Verify(x => x.WriteLine(It.Is <string>(str => str.Contains($"create vdisk file={vhdFullName} maximum={maximumVhdSizeInMb} type={vhdTypeString}"))), Times.Once); streamWriterMock.Verify(x => x.WriteLine(It.Is <string>(str => str.Contains($"select vdisk file={vhdFullName}"))), Times.Once); this.fileSystemHelperMock.Verify(x => x.ExecuteDiskpart(It.IsAny <string>(), It.IsAny <ILogger>()), Times.Once); this.fileSystemMock.Verify(x => x.File.CreateText(It.IsAny <string>()), Times.Once); this.fileSystemMock.Verify(x => x.File.Delete(It.IsAny <string>()), Times.Once); }
public void PerformStepTest_ShouldFinishOkButDoNothing() { //arrange MigrationFlowData flowData = new MigrationFlowData(); flowData.VhdFileTemporaryFolder = "temporary\\folder"; flowData.VhdFileDestinationFolder = null; flowData.VhdFileName = "test.vhdx"; flowData.DestinationVhdMaxFileSize = 101; Mock <StreamWriter> streamWriterMock = new Mock <StreamWriter>(new MemoryStream()); streamWriterMock.Setup(x => x.WriteLine(It.IsAny <string>())) .Verifiable(); StreamWriter swMock = streamWriterMock.Object; this.fileSystemMock.Setup(x => x.File.CreateText(It.IsAny <string>())) .Returns <string>((path) => { return(swMock); }) .Verifiable(); this.fileSystemMock.Setup(x => x.Directory.CreateDirectory(It.IsAny <string>())) .Verifiable(); this.fileSystemMock.Setup(x => x.File.Delete(It.IsAny <string>())) .Verifiable(); CreateFinalVhdMigrationStep step = new CreateFinalVhdMigrationStep(loggerMock.Object, fileSystemHelperMock.Object, fileSystemMock.Object, flowData); //act step.PerformStep(); //assert streamWriterMock.Verify(x => x.WriteLine(It.Is <string>(str => str.Contains("shrink desired"))), Times.Never); this.fileSystemMock.Verify(x => x.File.CreateText(It.IsAny <string>()), Times.Never); this.fileSystemMock.Verify(x => x.File.Delete(It.IsAny <string>()), Times.Never); }