コード例 #1
0
        public async Task GetCardsAsync_UriTextContainsUris_ReturnsCardsForUrisAndIgnoresRest(string firstUriText,
            string secondUriText,
            string thirdUriText,
            string firstCardName,
            string secondCardName,
            string thirdCardName,
            string firstFileName,
            string secondFileName,
            string thirdFileName)
        {
            // Arrange
            var uriText = $"{firstUriText}{Environment.NewLine}{secondUriText}{Environment.NewLine}{thirdUriText}";
            var testMessageHandler = new TestMessageHandler();

            int numUris = 0;
            if (Uri.TryCreate(firstUriText, UriKind.Absolute, out Uri firstUri))
            {
                testMessageHandler.AddResponseMessageToReturnForUri(firstUri, new HttpResponseMessage(HttpStatusCode.OK)
                {
                    Content = new StringContent(File.ReadAllText(firstFileName))
                });
                numUris++;
            }

            if (Uri.TryCreate(secondUriText, UriKind.Absolute, out Uri secondUri))
            {
                testMessageHandler.AddResponseMessageToReturnForUri(secondUri, new HttpResponseMessage(HttpStatusCode.OK)
                {
                    Content = new StringContent(File.ReadAllText(secondFileName))
                });
                numUris++;                
            }

            if (Uri.TryCreate(thirdUriText, UriKind.Absolute, out Uri thirdUri))
            {
                testMessageHandler.AddResponseMessageToReturnForUri(thirdUri, new HttpResponseMessage(HttpStatusCode.OK)
                {
                    Content = new StringContent(File.ReadAllText(thirdFileName))
                });
                numUris++;
            }

            var testCardsService = new CardsService(this.parsers, testMessageHandler, false);

            // Act
            var cards = await testCardsService.GetCardsAsync(uriText);

            // Assert
            var cardNames = cards.Select(c => c.Name);
            Assert.AreEqual(numUris, cards.Count);

            if (!string.IsNullOrWhiteSpace(firstCardName))
            {
                Assert.IsTrue(cardNames.Contains(firstCardName));
            }
            else
            {
                Assert.IsFalse(cardNames.Contains(firstCardName));
            }

            if (!string.IsNullOrWhiteSpace(secondCardName))
            {
                Assert.IsTrue(cardNames.Contains(secondCardName));
            }
            else
            {
                Assert.IsFalse(cardNames.Contains(secondCardName));
            }

            if (!string.IsNullOrWhiteSpace(thirdCardName))
            {
                Assert.IsTrue(cardNames.Contains(thirdCardName));
            }
            else
            {
                Assert.IsFalse(cardNames.Contains(thirdCardName));
            }
        }