public void SampleCommand_Run_Succeeds_If_All_Steps_Complete()
        {
            JustMock.Arrange(() => _externalCommandData.Application).Returns(_uiApplication);

            JustMock.Arrange(() => _uiApplication.ActiveUIDocument).Returns(_uiDocument);

            JustMock.Arrange(() => _uiDocument.Document).Returns(_document);

            // Need to return at least one sheet to get as far as picking the file
            _mockedSheetRetriever.Setup(retriever => retriever.GetSheets(It.IsAny <Document>())).Returns(
                new List <Sheet>
            {
                new Sheet()
            });

            _mockedFilePathSelector.Setup(selector => selector.SelectFilePath()).Returns("filepath.csv");

            _mockedDataWriter.Setup(writer => writer.WriteDataToFile(It.IsAny <DataTable>(), It.IsAny <string>())).Returns(true);

            var sampleCommand = GetTestSampleCommand();

            var result = sampleCommand.Run(_externalCommandData);

            Assert.Equal(ResultEnum.Succeeded, result.RvtResult);
            Assert.Equal("Successfully wrote data to filepath.csv", result.Message);
        }
        public void SampleCommand_Displays_DialogBox_On_Success()
        {
            JustMock.Arrange(() => _externalCommandData.Application).Returns(_uiApplication);

            JustMock.Arrange(() => _uiApplication.ActiveUIDocument).Returns(_uiDocument);

            JustMock.Arrange(() => _uiDocument.Document).Returns(_document);

            // Need to return at least one sheet to get as far as picking the file
            _mockedSheetRetriever.Setup(retriever => retriever.GetSheets(It.IsAny <Document>())).Returns(
                new List <Sheet>
            {
                new Sheet()
            });

            _mockedFilePathSelector.Setup(selector => selector.SelectFilePath()).Returns("filepath.csv");

            _mockedDataWriter.Setup(writer => writer.WriteDataToFile(It.IsAny <DataTable>(), It.IsAny <string>())).Returns(true);

            var sampleCommand = GetTestSampleCommand();

            sampleCommand.Run(_externalCommandData);

            _mockedDialogService.Verify(dialogService => dialogService.ShowDialog("Success", "Successfully wrote data to filepath.csv"), Times.Once);
        }
        public void SampleCommand_Run_Fails_If_No_Document_Open()
        {
            JustMock.Arrange(() => _externalCommandData.Application).Returns(_uiApplication);

            JustMock.Arrange(() => _uiApplication.ActiveUIDocument).Returns((UIDocument)null);

            var result = _emptySampleCommand.Run(_externalCommandData);

            Assert.NotNull(result);

            Assert.Equal(ResultEnum.Failed, result.RvtResult);

            Assert.Equal("No active document is open", result.Message);
        }
        public void SampleCommand_Run_Succeeds_When_No_Sheets_In_Document()
        {
            JustMock.Arrange(() => _externalCommandData.Application).Returns(_uiApplication);

            JustMock.Arrange(() => _uiApplication.ActiveUIDocument).Returns(_uiDocument);

            JustMock.Arrange(() => _uiDocument.Document).Returns(_document);

            _mockedSheetRetriever.Setup(retriever => retriever.GetSheets(It.IsAny <Document>())).Returns(new List <Sheet>());

            var sampleCommand = GetTestSampleCommand();

            var result = sampleCommand.Run(_externalCommandData);

            Assert.Equal(ResultEnum.Succeeded, result.RvtResult);
            Assert.Equal("The document does not contain any sheets", result.Message);
        }
        public void SampleCommand_Run_Cancels_If_PickFile_Cancelled()
        {
            JustMock.Arrange(() => _externalCommandData.Application).Returns(_uiApplication);

            JustMock.Arrange(() => _uiApplication.ActiveUIDocument).Returns(_uiDocument);

            JustMock.Arrange(() => _uiDocument.Document).Returns(_document);

            // Need to return at least one sheet to get as far as picking the file
            _mockedSheetRetriever.Setup(retriever => retriever.GetSheets(It.IsAny <Document>())).Returns(
                new List <Sheet>
            {
                new Sheet()
            });

            var sampleCommand = GetTestSampleCommand();

            var result = sampleCommand.Run(_externalCommandData);

            Assert.Equal(ResultEnum.Cancelled, result.RvtResult);
            Assert.Equal("File path selection was cancelled", result.Message);
        }