예제 #1
0
        public async Task NextTenWordsTest()
        {
            string bookName = "DummyBookName";

            Mock <ISession> mockSession = new Mock <ISession>();

            mockSession.Setup(x => x.GetString("bookName")).Returns(bookName);

            Mock <HttpContext> mockHttpContxt = new Mock <HttpContext>();

            mockHttpContxt.Setup(x => x.Session).Returns(mockSession.Object);

            Mock <IHttpContextAccessor> mockAccessor = new Mock <IHttpContextAccessor>();

            mockAccessor.Setup(x => x.HttpContext).Returns(mockHttpContxt.Object);

            Mock <IServiceProvider> mockServices = new Mock <IServiceProvider>();

            mockServices.Setup(svc => svc.GetRequiredService <IHttpContextAccessor>()).Returns(mockAccessor.Object);

            IEnumerable <WordOccurance> wordOccurances = this.GetWordOccurances();

            Mock <IWebApiManager> mockManager = new Mock <IWebApiManager>();

            mockManager.Setup(x => x.GetIndivisualWordsCount(bookName)).Returns(Task.FromResult(wordOccurances));

            Mock <IDependencyResolver> mockDepResolver = new Mock <IDependencyResolver>();

            mockDepResolver.Setup(x => x.GetWebApiManagerByName(null)).Returns(mockManager.Object);

            LoyalBooksDataController controller = new LoyalBooksDataController(mockDepResolver.Object, mockServices.Object);

            IEnumerable <WordOccurance> result = await controller.NextTenWords();
        }
        public async Task NextTenWords_SHould_Return_Last_10_Words_When_WordsToSkip_Goes_Beyond_The_Total_Number_Of_Words_In_The_Collection()
        {
            string bookName = "DummyBookName";

            Mock <ISessionWrapper> mockSession = new Mock <ISessionWrapper>();

            mockSession.Setup(x => x.GetString("bookName")).Returns(bookName);


            Mock <IServiceProviderWrapper> mockServices = new Mock <IServiceProviderWrapper>();

            mockServices.Setup(svc => svc.GetRequiredService()).Returns(mockSession.Object);

            IEnumerable <WordOccurance> wordOccurances = this.GetWordOccurances();

            Mock <IWebApiManager> mockManager = new Mock <IWebApiManager>();

            mockManager.Setup(x => x.GetIndivisualWordsCount(bookName)).Returns(Task.FromResult(wordOccurances));

            Mock <IDependencyResolver> mockDepResolver = new Mock <IDependencyResolver>();

            mockDepResolver.Setup(x => x.GetWebApiManagerByName(null)).Returns(mockManager.Object);

            LoyalBooksDataController controller = new LoyalBooksDataController(mockDepResolver.Object, mockServices.Object);

            //
            // Act.
            //

            IEnumerable <WordOccurance> result = await controller.NextTenWords(4);

            //
            // Assert.
            //

            Assert.AreEqual(result.FirstOrDefault(item => item.Word == "WordNumber12").Count, 12);
            Assert.AreEqual(result.FirstOrDefault(item => item.Word == "WordNumber13").Count, 13);
            Assert.AreEqual(result.FirstOrDefault(item => item.Word == "WordNumber14").Count, 14);
            Assert.AreEqual(result.FirstOrDefault(item => item.Word == "WordNumber15").Count, 15);
            Assert.AreEqual(result.FirstOrDefault(item => item.Word == "WordNumber16").Count, 16);
            Assert.AreEqual(result.FirstOrDefault(item => item.Word == "WordNumber17").Count, 17);
            Assert.AreEqual(result.FirstOrDefault(item => item.Word == "WordNumber18").Count, 18);
            Assert.AreEqual(result.FirstOrDefault(item => item.Word == "WordNumber19").Count, 19);
            Assert.AreEqual(result.FirstOrDefault(item => item.Word == "WordNumber20").Count, 20);
            Assert.AreEqual(result.FirstOrDefault(item => item.Word == "WordNumber21").Count, 21);

            Assert.IsNull(result.FirstOrDefault(item => item.Word == "WordNumber1"));
        }
        public async Task NextTenWordsTest_SHould_Return_First_10_Words_When_No_Page_Number_Is_Given()
        {
            string bookName = "DummyBookName";

            Mock <ISessionWrapper> mockSession = new Mock <ISessionWrapper>();

            mockSession.Setup(x => x.GetString("bookName")).Returns(bookName);


            Mock <IServiceProviderWrapper> mockServices = new Mock <IServiceProviderWrapper>();

            mockServices.Setup(svc => svc.GetRequiredService()).Returns(mockSession.Object);

            IEnumerable <WordOccurance> wordOccurances = this.GetWordOccurances();

            Mock <IWebApiManager> mockManager = new Mock <IWebApiManager>();

            mockManager.Setup(x => x.GetIndivisualWordsCount(bookName)).Returns(Task.FromResult(wordOccurances));

            Mock <IDependencyResolver> mockDepResolver = new Mock <IDependencyResolver>();

            mockDepResolver.Setup(x => x.GetWebApiManagerByName(null)).Returns(mockManager.Object);

            LoyalBooksDataController controller = new LoyalBooksDataController(mockDepResolver.Object, mockServices.Object);

            //
            // Act.
            //

            IEnumerable <WordOccurance> result = await controller.NextTenWords();

            //
            // Assert.
            //

            Assert.AreEqual(result.FirstOrDefault(item => item.Word == "WordNumber1").Count, 1);
            Assert.AreEqual(result.FirstOrDefault(item => item.Word == "WordNumber2").Count, 2);
            Assert.AreEqual(result.FirstOrDefault(item => item.Word == "WordNumber3").Count, 3);
            Assert.AreEqual(result.FirstOrDefault(item => item.Word == "WordNumber4").Count, 4);
            Assert.AreEqual(result.FirstOrDefault(item => item.Word == "WordNumber5").Count, 5);
            Assert.AreEqual(result.FirstOrDefault(item => item.Word == "WordNumber6").Count, 6);
            Assert.AreEqual(result.FirstOrDefault(item => item.Word == "WordNumber7").Count, 7);
            Assert.AreEqual(result.FirstOrDefault(item => item.Word == "WordNumber8").Count, 8);
            Assert.AreEqual(result.FirstOrDefault(item => item.Word == "WordNumber9").Count, 9);
            Assert.AreEqual(result.FirstOrDefault(item => item.Word == "WordNumber10").Count, 10);

            Assert.IsNull(result.FirstOrDefault(item => item.Word == "WordNumber11"));
        }
        public async Task NextTenWords_Should_Return_Only_1_Word_When_Page_3_Is_Requested()
        {
            string bookName = "DummyBookName";

            Mock <ISessionWrapper> mockSession = new Mock <ISessionWrapper>();

            mockSession.Setup(x => x.GetString("bookName")).Returns(bookName);


            Mock <IServiceProviderWrapper> mockServices = new Mock <IServiceProviderWrapper>();

            mockServices.Setup(svc => svc.GetRequiredService()).Returns(mockSession.Object);

            IEnumerable <WordOccurance> wordOccurances = this.GetWordOccurances();

            Mock <IWebApiManager> mockManager = new Mock <IWebApiManager>();

            mockManager.Setup(x => x.GetIndivisualWordsCount(bookName)).Returns(Task.FromResult(wordOccurances));

            Mock <IDependencyResolver> mockDepResolver = new Mock <IDependencyResolver>();

            mockDepResolver.Setup(x => x.GetWebApiManagerByName(null)).Returns(mockManager.Object);

            LoyalBooksDataController controller = new LoyalBooksDataController(mockDepResolver.Object, mockServices.Object);

            //
            // Act.
            //

            IEnumerable <WordOccurance> result = await controller.NextTenWords(3);

            //
            // Assert.
            //

            Assert.AreEqual(result.FirstOrDefault(item => item.Word == "WordNumber21").Count, 21);

            Assert.IsNull(result.FirstOrDefault(item => item.Word == "WordNumber20"));
            Assert.IsNull(result.FirstOrDefault(item => item.Word == "WordNumber1"));
        }