public async Task ScaffoldAsync_InvalidOperationException_CallCreateWhileRunning_Async()
        {
            // Arrange
            var wufMock    = Mock.Of <IWorkUnitFactory>();
            var vsaMock    = Mock.Of <IVisualStudioAccess>();
            var loggerMock = Mock.Of <ILogger>();
            IScaffoldingService service = new ScaffoldingService(wufMock, vsaMock, loggerMock);
            var       project           = new SqlProject("a", "b", "c");
            var       configuration     = ConfigurationModel.GetDefault();
            var       targetVersion     = new Version(1, 0);
            var       invokedSecondTime = false;
            Exception thrownException   = null;

            service.IsScaffoldingChanged += (sender,
                                             args) =>
            {
                if (!service.IsScaffolding)
                {
                    return;
                }
                invokedSecondTime = true;
                thrownException   = Assert.Throws <InvalidOperationException>(() => service.ScaffoldAsync(project, configuration, targetVersion, CancellationToken.None));
            };

            // Act
            await service.ScaffoldAsync(project, configuration, targetVersion, CancellationToken.None);

            // Assert
            Assert.IsTrue(invokedSecondTime);
            Assert.IsNotNull(thrownException);
            Assert.IsInstanceOf <InvalidOperationException>(thrownException);
        }
        public async Task ScaffoldAsync_CompleteRun_ExceptionInStopLongRunningTask_Async()
        {
            // Arrange
            var wufMock = Mock.Of <IWorkUnitFactory>();
            var vsaMock = new Mock <IVisualStudioAccess>();

            vsaMock.Setup(m => m.StopLongRunningTaskIndicatorAsync())
            .ThrowsAsync(new Exception("test exception"));
            var loggerMock = Mock.Of <ILogger>();
            IScaffoldingService service = new ScaffoldingService(wufMock, vsaMock.Object, loggerMock);
            var project        = new SqlProject("a", "b", "c");
            var configuration  = ConfigurationModel.GetDefault();
            var targetVersion  = new Version(1, 0);
            var isCreatingList = new List <bool>();

            service.IsScaffoldingChanged += (sender,
                                             args) =>
            {
                isCreatingList.Add(service.IsScaffolding);
            };

            // Act
            var result = await service.ScaffoldAsync(project, configuration, targetVersion, CancellationToken.None);

            // Assert
            Assert.IsTrue(result);
            Assert.AreEqual(2, isCreatingList.Count);
            Assert.IsTrue(isCreatingList[0]);
            Assert.IsFalse(isCreatingList[1]);
            vsaMock.Verify(m => m.StartLongRunningTaskIndicatorAsync(), Times.Once);
            vsaMock.Verify(m => m.ClearSSDTLifecycleOutputAsync(), Times.Once);
            vsaMock.Verify(m => m.StopLongRunningTaskIndicatorAsync(), Times.Once);
        }
        public void ScaffoldAsync_ArgumentNullException_Project()
        {
            // Arrange
            var wufMock    = Mock.Of <IWorkUnitFactory>();
            var vsaMock    = Mock.Of <IVisualStudioAccess>();
            var loggerMock = Mock.Of <ILogger>();
            IScaffoldingService service = new ScaffoldingService(wufMock, vsaMock, loggerMock);

            // Act & Assert
            // ReSharper disable AssignNullToNotNullAttribute
            Assert.Throws <ArgumentNullException>(() => service.ScaffoldAsync(null, null, null, CancellationToken.None));
            // ReSharper restore AssignNullToNotNullAttribute
        }
        public void ScaffoldAsync_ArgumentNullException_PreviousVersion()
        {
            // Arrange
            var wufMock    = Mock.Of <IWorkUnitFactory>();
            var vsaMock    = Mock.Of <IVisualStudioAccess>();
            var loggerMock = Mock.Of <ILogger>();
            IScaffoldingService service = new ScaffoldingService(wufMock, vsaMock, loggerMock);
            var project       = new SqlProject("a", "b", "c");
            var configuration = ConfigurationModel.GetDefault();

            // Act & Assert
            // ReSharper disable AssignNullToNotNullAttribute
            Assert.Throws <ArgumentNullException>(() => service.ScaffoldAsync(project, configuration, null, CancellationToken.None));
            // ReSharper restore AssignNullToNotNullAttribute
        }
        public async Task ScaffoldAsync_CompleteRun_WithFailedWorkUnit_Async()
        {
            // Arrange
            var workUnitProvided = false;
            var wuMock           = new Mock <IWorkUnit <ScaffoldingStateModel> >();
            var wufMock          = new Mock <IWorkUnitFactory>();

            wufMock.Setup(m => m.GetNextWorkUnit(It.IsNotNull <ScaffoldingStateModel>()))
            .Returns <ScaffoldingStateModel>(sm =>
            {
                if (workUnitProvided)
                {
                    return(null);
                }
                workUnitProvided = true;
                sm.Result        = false;
                return(wuMock.Object);
            });
            var vsaMock    = new Mock <IVisualStudioAccess>();
            var loggerMock = Mock.Of <ILogger>();
            IScaffoldingService service = new ScaffoldingService(wufMock.Object, vsaMock.Object, loggerMock);
            var project        = new SqlProject("a", "b", "c");
            var configuration  = ConfigurationModel.GetDefault();
            var targetVersion  = new Version(1, 0);
            var isCreatingList = new List <bool>();

            service.IsScaffoldingChanged += (sender,
                                             args) =>
            {
                isCreatingList.Add(service.IsScaffolding);
            };

            // Act
            var result = await service.ScaffoldAsync(project, configuration, targetVersion, CancellationToken.None);

            // Assert
            Assert.IsFalse(result);
            Assert.AreEqual(2, isCreatingList.Count);
            Assert.IsTrue(isCreatingList[0]);
            Assert.IsFalse(isCreatingList[1]);
            vsaMock.Verify(m => m.StartLongRunningTaskIndicatorAsync(), Times.Once);
            vsaMock.Verify(m => m.ClearSSDTLifecycleOutputAsync(), Times.Once);
            vsaMock.Verify(m => m.StopLongRunningTaskIndicatorAsync(), Times.Once);
        }