Esempio n. 1
0
        public async Task FindHeaderIndex_GivenHeaderText_ShouldReturnCorrectIndex(string headerText, int expectedIndex)
        {
            // Arrange.
            string[] columnNames =
            {
                DateColumnText,
                "Title",
                "Leader Name"
            };

            string[] rowValues1 =
            {
                "2019-01-01",
                "Title 1",
                "Leader 1"
            };

            string[] rowValues2 =
            {
                "2019-01-02",
                "Title 2",
                "Leader 2"
            };

            var url          = new Uri("https://somegooglesheet");
            var requestMaker = Substitute.For <IRestRequestMaker>();
            var logger       = Substitute.For <ILogger>();

            requestMaker
            .Get <GoogleSheet>(url)
            .Returns(new GoogleSheet
            {
                values = new[]
                {
                    columnNames,
                    rowValues1,
                    rowValues2
                }
            });

            var testObject = new MeetsGoogleSheet(
                url,
                requestMaker,
                logger);

            await testObject.Retrieve();

            // Act.
            int result = testObject.FindHeaderIndex(headerText);

            // Assert.
            Assert.AreEqual(expectedIndex, result);
        }
Esempio n. 2
0
        public void FindHeaderIndex_GivenMissingValueAndNotRequiredToRaiseException_ShouldReturnNegativeOne()
        {
            // Arrange.
            string[] columnNames =
            {
                DateColumnText,
                "Title",
                "Leader Name"
            };

            string[] rowValues1 =
            {
                "2019-01-01",
                "Title 1",
                "Leader 1"
            };

            string[] rowValues2 =
            {
                "2019-01-02",
                "Title 2",
                "Leader 2"
            };

            var url          = new Uri("https://somegooglesheet");
            var requestMaker = Substitute.For <IRestRequestMaker>();
            var logger       = Substitute.For <ILogger>();

            requestMaker
            .Get <GoogleSheet>(url)
            .Returns(new GoogleSheet
            {
                values = new[]
                {
                    columnNames,
                    rowValues1,
                    rowValues2
                }
            });

            var testObject = new MeetsGoogleSheet(
                url,
                requestMaker,
                logger);

            // Act.
            int result = testObject.FindHeaderIndex("missing header");

            // Assert.
            Assert.AreEqual(-1, result);
        }