Example #1
0
        public void SearchThrowsExceptionIfSearchPredicateIsNull()
        {
            // Arrange
            var sessionMock = new Mock<ISession>();
            var crawler = new HallOfFameCrawler(sessionMock.Object);
            Func<Task> sut = async () => await crawler.SearchAsync(null);

            // Act / Assert
            sut.ShouldThrow<ArgumentNullException>()
               .Where(e => e.ParamName == "searchPredicate");
        }
Example #2
0
        public void SearchThrowsExceptionIfSearchPredicateMinLevelIsLessThanOne()
        {
            // Arrange
            var sessionMock = new Mock<ISession>();
            var crawler = new HallOfFameCrawler(sessionMock.Object);
            Func<Task> sut = async () => await crawler.SearchAsync(new HallOfFameSearchPredicate { MinLevel = 0 });

            // Act / Assert
            sut.ShouldThrow<ArgumentException>()
               .Where(
                   e => e.ParamName == "searchPredicate" && e.Message.StartsWith("MinLevel must be greater than zero."));
        }
Example #3
0
        public async Task SearchShouldReturnListOfCharactersWithValidArguments()
        {
            // Arrange
            var characters = new List<ICharacter>();
            for (int i = 1; i < 5; i++)
            {
                var characterMock = new Mock<ICharacter>();
                characterMock.Setup(c => c.Rank).Returns(i);
                characterMock.Setup(c => c.Honor).Returns(i);
                characterMock.Setup(c => c.Level).Returns(i);
                characterMock.Setup(c => c.Username).Returns("User No. " + i);
                characters.Add(characterMock.Object);
            }
            var sessionMock = new Mock<ISession>();
            sessionMock.Setup(s => s.HallOfFameAsync(It.IsAny<string>(), It.IsAny<bool>()))
                       .ReturnsAsync(characters);
            var crawler = new HallOfFameCrawler(sessionMock.Object);
            
            // Act
            var results = await crawler.SearchAsync(new HallOfFameSearchPredicate());

            // Assert
            results.Should().HaveCount(c => c > 0);
        }