示例#1
0
        public void CheckPrerequisitiesTest_ShouldBeOk()
        {
            //arrange
            MigrationFlowData flowData = new MigrationFlowData();

            FixClonedOsRegistryMigrationStep step = new FixClonedOsRegistryMigrationStep(loggerMock.Object,
                                                                                         fileSystemHelperMock.Object,
                                                                                         fileSystemMock.Object,
                                                                                         flowData);

            //act
            string[] messages = new string[0];
            bool     result   = step.CheckPrerequisities(ref messages);

            //assert
            Assert.IsTrue(result);
        }
示例#2
0
        public void PerformStepTest_ShouldFinishOk()
        {
            //arrange
            MigrationFlowData flowData = new MigrationFlowData();

            flowData.VhdFileTemporaryFolder = "temporary\\folder";
            flowData.VhdFileName            = "test.vhdx";

            MemoryStream      streamMock    = new MemoryStream();
            StreamWriter      swMock        = new StreamWriter(streamMock);
            Mock <IDriveInfo> driveInfoMock = new Mock <IDriveInfo>();

            driveInfoMock.Setup(x => x.AvailableFreeSpace)
            .Returns(600);

            fileSystemMock.Setup(x => x.DriveInfo.FromDriveName(It.IsAny <string>()))
            .Returns(driveInfoMock.Object);

            Mock <VirtualDiskDecorator>        diskMock           = new Mock <VirtualDiskDecorator>();
            Mock <BiosPartitionTableDecorator> partitionTableMock = new Mock <BiosPartitionTableDecorator>();
            Mock <PartitionInfoDecorator>      partitionInfoMock  = new Mock <PartitionInfoDecorator>();
            Mock <SparseStream>   sparseStreamMock   = new Mock <SparseStream>();
            Mock <DiscFileSystem> discFileSystemMock = new Mock <DiscFileSystem>();

            SparseStream sparseStream = sparseStreamMock.Object;

            partitionInfoMock.Setup(x => x.Open())
            .Returns(sparseStream)
            .Verifiable();

            var partInfo = partitionInfoMock.Object;

            partitionTableMock.Setup(x => x.Partitions)
            .Returns(new List <PartitionInfoDecorator>()
            {
                partInfo
            })
            .Verifiable();

            diskMock.Setup(x => x.Partitions)
            .Returns(partitionTableMock.Object);

            diskMock.Setup(x => x.Geometry)
            .Returns(new Geometry((long)500, 1, 10, 512));

            this.fileSystemHelperMock.Setup(x => x.OpenVhdx(It.Is <string>(snapshotPath => snapshotPath == $"{flowData.VhdFileTemporaryFolder}\\{flowData.VhdFileName}")))
            .Returns(diskMock.Object)
            .Verifiable();

            this.fileSystemHelperMock.Setup(x => x.OpenNtfsFileSystem(It.Is <SparseStream>(stream => stream == sparseStream)))
            .Returns(discFileSystemMock.Object)
            .Verifiable();

            this.fileSystemHelperMock.Setup(x => x.ChangeSystemDriveMappingFromRegistry(It.Is <Stream>(stream => stream == sparseStream)))
            .Verifiable();

            FixClonedOsRegistryMigrationStep step = new FixClonedOsRegistryMigrationStep(loggerMock.Object,
                                                                                         fileSystemHelperMock.Object,
                                                                                         fileSystemMock.Object,
                                                                                         flowData);

            //act
            step.PerformStep();
            swMock.Dispose();

            //assert
            this.fileSystemHelperMock.Verify(x => x.ChangeSystemDriveMappingFromRegistry(It.IsAny <Stream>()), Times.Once);
        }