/// <summary>
        ///     Initializes a new instance of the <see cref="SampleCommandTests" /> class.
        /// </summary>
        public SampleCommandTests()
        {
            _mockedSheetRetriever = new Mock <IElementRetriever>();

            _mockedDataTableCreator = new Mock <IDataTableCreator>();

            _mockedFilePathSelector = new Mock <IFilePathSelector>();

            _mockedDataWriter = new Mock <IDataWriter>();

            _mockedSampleProperties = new Mock <IRvtCommandProperties <SampleCommand> >();
            _mockedSampleProperties.SetupGet(p => p.Name).Returns("Sample");

            _mockedSampleProperties.SetupGet(p => p.DisplayName).Returns("Sample Command");

            _mockedDialogService = new Mock <IDialogService>();
            _mockedDialogService.Setup(dialogService => dialogService.ShowDialog(It.IsAny <string>(), It.IsAny <string>())).Verifiable();

            _emptySampleCommand = GetTestSampleCommand();

            _externalCommandData = JustMock.Create <ExternalCommandData>();

            _uiApplication = JustMock.Create <UIApplication>();

            _uiDocument = JustMock.Create <UIDocument>();

            _document = JustMock.Create <Document>();
        }
        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);
        }
Beispiel #6
0
        public void GetViews_All_Retrieved_Views_Are_Returned()
        {
            var viewList = new List <RvtView>
            {
                JustMock.Create <RvtView>(),
                JustMock.Create <RvtView>(),
                JustMock.Create <RvtView>()
            };

            _mockElementCollector.Setup(coll => coll.GetViews(It.IsAny <Document>())).Returns(viewList);

            _mockClassMapper.Setup(map => map.Map <View>(It.IsAny <RvtView>())).Returns(Mock.Of <View>());

            var elementRetriever = new ElementRetriever(_mockElementCollector.Object, _mockClassMapper.Object);

            ICollection <View> views = elementRetriever.GetViews(JustMock.Create <Document>());

            Assert.NotNull(views);
            Assert.Equal(viewList.Count, views.Count);
        }
Beispiel #7
0
        public void GetSheets_All_Retrieved_Sheets_Are_Returned()
        {
            var sheetList = new List <ViewSheet>
            {
                JustMock.Create <ViewSheet>(),
                JustMock.Create <ViewSheet>(),
                JustMock.Create <ViewSheet>()
            };

            _mockElementCollector.Setup(coll => coll.GetSheets(It.IsAny <Document>())).Returns(sheetList);

            _mockClassMapper.Setup(map => map.Map <Sheet>(It.IsAny <ViewSheet>())).Returns(Mock.Of <Sheet>());

            var elementRetriever = new ElementRetriever(_mockElementCollector.Object, _mockClassMapper.Object);

            ICollection <Sheet> sheets = elementRetriever.GetSheets(JustMock.Create <Document>());

            Assert.NotNull(sheets);
            Assert.Equal(sheetList.Count, sheets.Count);
        }
        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);
        }