public void CheckPrerequisitiesTest_ShouldFail()
        {
            //arrange
            MigrationFlowData flowData = new MigrationFlowData();

            flowData.VhdFileTemporaryFolder = "temporary\\folder";
            flowData.AddVhdToBootManager    = true;

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

            AddFinalVhdToBootManagerMigrationStep step = new AddFinalVhdToBootManagerMigrationStep(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("BCDEDIT was not found on your system")).Count());
        }
        public void CheckPrerequisitiesTest_ShouldBeOk()
        {
            //arrange
            MigrationFlowData flowData = new MigrationFlowData();

            flowData.VhdFileTemporaryFolder = "temporary\\folder";
            flowData.AddVhdToBootManager    = true;

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

            AddFinalVhdToBootManagerMigrationStep step = new AddFinalVhdToBootManagerMigrationStep(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_ShouldFinishOkButDoNothing()
        {
            //arrange
            MigrationFlowData flowData = new MigrationFlowData();

            flowData.VhdFileTemporaryFolder = "temporary\\folder";
            flowData.AddVhdToBootManager    = false;


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

            //act
            step.PerformStep();

            //assert
            this.fileSystemHelperMock.Verify(x => x.ExecuteBcdeditCommand(
                                                 It.Is <string>(script => script.Contains("/copy")),
                                                 It.IsAny <ILogger>()), Times.Never);

            this.fileSystemHelperMock.Verify(x => x.ExecuteBcdeditCommand(
                                                 It.Is <string>(script => script.Contains("/set")),
                                                 It.IsAny <ILogger>()), Times.Never);
        }
        public void PerformStepTest_ShouldNotBeAbleToCreateNewBootManagerEntry()
        {
            //arrange
            MigrationFlowData flowData = new MigrationFlowData();

            flowData.VhdFileTemporaryFolder = "temporary\\folder";
            flowData.AddVhdToBootManager    = true;

            Guid newEntryId = Guid.NewGuid();

            this.fileSystemHelperMock.Setup(x => x.ExecuteBcdeditCommand(
                                                It.Is <string>(script => script.Contains("/copy")),
                                                It.IsAny <ILogger>()))
            .Returns($"Operation failed");

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

            //act
            ArgumentException aex = Assert.Throws <ArgumentException>(() =>
            {
                step.PerformStep();
            });

            //assert
            this.fileSystemHelperMock.Verify(x => x.ExecuteBcdeditCommand(
                                                 It.Is <string>(script => script.Contains("/copy")),
                                                 It.IsAny <ILogger>()), Times.Once);

            this.fileSystemHelperMock.Verify(x => x.ExecuteBcdeditCommand(
                                                 It.Is <string>(script => script.Contains("/set") && script.Contains(newEntryId.ToString())),
                                                 It.IsAny <ILogger>()), Times.Never);
        }
        public void PerformStepTest_ShouldFinishOk()
        {
            //arrange
            MigrationFlowData flowData = new MigrationFlowData();

            flowData.VhdFileTemporaryFolder     = "F:\\temporary\\folder";
            flowData.AddVhdToBootManager        = true;
            flowData.OperatingSystemDriveLetter = 'C';

            Guid newEntryId = Guid.NewGuid();

            this.fileSystemHelperMock.Setup(x => x.ExecuteBcdeditCommand(
                                                It.Is <string>(script => script.Contains("/copy")),
                                                It.IsAny <ILogger>()))
            .Returns($"Cloned successfully {{{newEntryId}}}");

            this.fileSystemHelperMock.Setup(x => x.ExecuteBcdeditCommand(
                                                It.Is <string>(script => script.Contains("/set") && script.Contains(newEntryId.ToString())),
                                                It.IsAny <ILogger>()))
            .Returns($"Operation completed successfully.");

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

            //act
            step.PerformStep();

            //assert
            this.fileSystemHelperMock.Verify(x => x.ExecuteBcdeditCommand(
                                                 It.Is <string>(script => script.Contains("/copy")),
                                                 It.IsAny <ILogger>()), Times.Once);

            this.fileSystemHelperMock.Verify(x => x.ExecuteBcdeditCommand(
                                                 It.Is <string>(script => script.Contains("/set") && script.Contains(newEntryId.ToString())),
                                                 It.IsAny <ILogger>()), Times.Exactly(2));

            this.fileSystemHelperMock.Verify(x => x.ExecuteBcdeditCommand(
                                                 It.Is <string>(script => script.Contains("/set") && script.Contains("vhd=[" + flowData.VhdFileTemporaryFolder[0])),
                                                 It.IsAny <ILogger>()), Times.Exactly(2));
        }