public void CheckPrerequisitiesTest_ShouldBeOk() { //arrange MigrationFlowData flowData = new MigrationFlowData(); flowData.VhdFileTemporaryFolder = "temporary\\folder"; this.vssBackupComponentsMock.Setup(x => x.IsVolumeSupported(It.IsAny <string>())) .Returns(true); CloneOSMigrationStep step = new CloneOSMigrationStep(loggerMock.Object, osHelperMock.Object, fileSystemHelperMock.Object, flowData, vssImplementationMock.Object); //act string[] messages = new string[0]; bool result = step.CheckPrerequisities(ref messages); //assert Assert.IsTrue(result); }
public void CheckPrerequisitiesTest_ShouldFail() { //arrange MigrationFlowData flowData = new MigrationFlowData(); flowData.VhdFileTemporaryFolder = "temporary\\folder"; this.vssBackupComponentsMock.Setup(x => x.IsVolumeSupported(It.IsAny <string>())) .Returns(false); CloneOSMigrationStep step = new CloneOSMigrationStep(loggerMock.Object, osHelperMock.Object, fileSystemHelperMock.Object, flowData, vssImplementationMock.Object); //act string[] messages = new string[0]; bool result = step.CheckPrerequisities(ref messages); //assert Assert.IsFalse(result); Assert.AreEqual(1, messages.Where(x => x.Contains("System volume does not support VSS")).Count()); }
public void PerformStepTest_ShouldDeleteSnapshotOnError() { //arrange MigrationFlowData flowData = new MigrationFlowData(); flowData.VhdFileTemporaryFolder = "temporary\\folder"; flowData.OperatingSystemDriveLetter = 'C'; flowData.VhdFileName = "test.vhdx"; Mock <VirtualDiskDecorator> diskMock = new Mock <VirtualDiskDecorator>(); Mock <BiosPartitionTableDecorator> partitionTableMock = new Mock <BiosPartitionTableDecorator>(); diskMock.Setup(x => x.Partitions) .Returns(partitionTableMock.Object); MemoryStream streamMock = new MemoryStream(); StreamWriter swMock = new StreamWriter(streamMock); VssSnapshotProperties fakeSnapshotDetails = new VssSnapshotProperties(Guid.NewGuid(), Guid.NewGuid(), 1, "snapshotDeviceObject", "C:", "unit-testing", "unit-testing", null, null, Guid.NewGuid(), VssVolumeSnapshotAttributes.Differential, DateTime.Now, VssSnapshotState.Created); this.vssBackupComponentsMock.Setup(x => x.InitializeForBackup(It.IsAny <string>())).Verifiable(); this.vssBackupComponentsMock.Setup(x => x.GatherWriterMetadata()).Verifiable(); this.vssBackupComponentsMock.Setup(x => x.SetContext(It.IsAny <VssVolumeSnapshotAttributes>())).Verifiable(); this.vssBackupComponentsMock.Setup(x => x.StartSnapshotSet()) .Returns(fakeSnapshotDetails.SnapshotSetId) .Verifiable(); this.vssBackupComponentsMock.Setup(x => x.AddToSnapshotSet(It.Is <string>((param) => param == $"{flowData.OperatingSystemDriveLetter}:\\"))) .Returns(fakeSnapshotDetails.SnapshotId) .Verifiable(); this.vssBackupComponentsMock.Setup(x => x.PrepareForBackup()).Verifiable(); this.vssBackupComponentsMock.Setup(x => x.DoSnapshotSet()) .Throws <Exception>() .Verifiable(); this.vssBackupComponentsMock.Setup(x => x.DeleteSnapshot(It.Is <Guid>((snapshotId) => snapshotId == fakeSnapshotDetails.SnapshotId), It.IsAny <bool>())).Verifiable(); this.vssBackupComponentsMock.Setup(x => x.GetSnapshotProperties(It.Is <Guid>((snapshotId) => snapshotId == fakeSnapshotDetails.SnapshotId))) .Returns(fakeSnapshotDetails) .Verifiable(); this.fileSystemHelperMock.Setup(x => x.OpenRawDiskStream(It.Is <string>(snapshotPath => snapshotPath == fakeSnapshotDetails.SnapshotDeviceObject))) .Returns(streamMock) .Verifiable(); this.fileSystemHelperMock.Setup(x => x.OpenVhdx(It.Is <string>(snapshotPath => snapshotPath == $"{flowData.VhdFileTemporaryFolder}\\{flowData.VhdFileName}"))) .Returns(diskMock.Object) .Verifiable(); this.fileSystemHelperMock.Setup(x => x.CloneNtfsFileSystem(It.IsAny <Stream>(), It.IsAny <Stream>(), It.IsAny <ILogger>())) .Verifiable(); CloneOSMigrationStep step = new CloneOSMigrationStep(loggerMock.Object, osHelperMock.Object, fileSystemHelperMock.Object, flowData, vssImplementationMock.Object); //act Assert.Throws <Exception>(() => { step.PerformStep(); }); swMock.Dispose(); //assert this.vssBackupComponentsMock.Verify(x => x.InitializeForBackup(It.IsAny <string>()), Times.Once); this.vssBackupComponentsMock.Verify(x => x.GatherWriterMetadata(), Times.Once); this.vssBackupComponentsMock.Verify(x => x.SetContext(It.IsAny <VssVolumeSnapshotAttributes>()), Times.Once); this.vssBackupComponentsMock.Verify(x => x.StartSnapshotSet(), Times.Once); this.vssBackupComponentsMock.Verify(x => x.AddToSnapshotSet(It.Is <string>((param) => param == $"{flowData.OperatingSystemDriveLetter}:\\")), Times.Once); this.vssBackupComponentsMock.Verify(x => x.PrepareForBackup(), Times.Once); this.vssBackupComponentsMock.Verify(x => x.DoSnapshotSet(), Times.Once); this.vssBackupComponentsMock.Verify(x => x.DeleteSnapshot(It.Is <Guid>((snapshotId) => snapshotId == fakeSnapshotDetails.SnapshotId), It.IsAny <bool>()), Times.Once); this.fileSystemHelperMock.Verify(x => x.OpenVhdx(It.Is <string>(snapshotPath => snapshotPath == $"{flowData.VhdFileTemporaryFolder}\\{flowData.VhdFileName}")), Times.Never); this.fileSystemHelperMock.Verify(x => x.CloneNtfsFileSystem(It.IsAny <Stream>(), It.IsAny <Stream>(), It.IsAny <ILogger>()), Times.Never); }