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

            flowData.VhdFileTemporaryFolder = "temporary\\folder";

            this.fileSystemMock.Setup(x => x.File.Exists(It.IsAny <string>()))
            .Returns <string>((path) =>
            {
                return(path == flowData.VhdFileTemporaryFolder + "\\" ? false : true);
            });

            CreateTemporaryVhdMigrationStep step = new CreateTemporaryVhdMigrationStep(loggerMock.Object,
                                                                                       osHelperMock.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 CheckPrerequisitiesTest_ShouldFail()
        {
            //arrange
            MigrationFlowData flowData = new MigrationFlowData();

            flowData.VhdFileTemporaryFolder = "temporary\\folder";

            this.fileSystemMock.Setup(x => x.File.Exists(It.IsAny <string>()))
            .Returns <string>((path) =>
            {
                return(path == flowData.VhdFileTemporaryFolder + "\\" ? true : false);
            });

            CreateTemporaryVhdMigrationStep step = new CreateTemporaryVhdMigrationStep(loggerMock.Object,
                                                                                       osHelperMock.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());
        }
示例#3
0
        public void PerformStepTest_ShouldNotCreateTempDir()
        {
            //arrange
            MigrationFlowData flowData = new MigrationFlowData();

            flowData.VhdFileTemporaryFolder = "temporary\\folder";

            StreamWriter swMock = new StreamWriter(new MemoryStream());

            this.fileSystemMock.Setup(x => x.File.CreateText(It.IsAny <string>()))
            .Returns <string>((path) =>
            {
                return(swMock);
            })
            .Verifiable();

            this.fileSystemMock.Setup(x => x.Directory.Exists(It.IsAny <string>()))
            .Returns <string>((path) =>
            {
                return(path == flowData.VhdFileTemporaryFolder ? true : false);
            });

            this.fileSystemMock.Setup(x => x.Directory.CreateDirectory(It.IsAny <string>()))
            .Verifiable();

            this.fileSystemMock.Setup(x => x.File.Delete(It.IsAny <string>()))
            .Verifiable();

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

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

            //assert
            this.fileSystemMock.Verify(x => x.Directory.CreateDirectory(It.IsAny <string>()), Times.Never);
            this.fileSystemMock.Verify(x => x.File.CreateText(It.IsAny <string>()), Times.Once);
            this.fileSystemMock.Verify(x => x.File.Delete(It.IsAny <string>()), Times.Once);
        }