示例#1
0
        public async Task TestExtract()
        {
            // arrange
            var services = new ServiceCollection();

            services.AddMemoryCache();
            services.AddLogging();
            var serviceProvider = services.BuildServiceProvider();

            var memoryCache = serviceProvider.GetService <IMemoryCache>();
            var logger      = serviceProvider.GetService <ILogger <SEOSearchController> >();

            var xdoc = new XmlDocument();

            xdoc.Load("TestAssets\\BingSearchResult.xml");

            var bingServiceMock = new Mock <BingService>(It.IsAny <ILogger <BingService> >(), It.IsAny <ISEOClientService>(), memoryCache);

            bingServiceMock
            .Setup(bs => bs.FetchResults("e-settlements"))
            .ReturnsAsync(xdoc.OuterXml);

            var expected = new List <SEOResult>
            {
                {
                    new SEOResult
                    {
                        Position    = 11,
                        Title       = "Making e-Settlements Simple | Sympli",
                        Url         = "https://www.sympli.com.au/",
                        Description = "An e-settlements service built by users, for users. We’ve spoken with thousands of lawyers and conveyancers from across the industry to identify what you want to see in an e-settlements service. The result is an efficient and user-friendly platform shaped by your feedback."
                    }
                },
                {
                    new SEOResult
                    {
                        Position    = 12,
                        Title       = "e-Settlement Services | Sympli - Making e-Settlements Simple",
                        Url         = "https://www.sympli.com.au/e-settlement-services/",
                        Description = "e-Settlement Services Designed by users, for users. You’ve told us what you need to conduct e-Settlements with confidence and our highly experienced team have taken your feedback to develop a service that’s efficient, easy to use, reliable and secure."
                    }
                }
            };

            // act
            var controller   = new SEOSearchController(logger, null, bingServiceMock.Object);
            var actionResult = await controller.Get("Bing", "e-settlements", "sympli.com.au");

            // assert
            Assert.IsNotNull(actionResult);
            var result = actionResult.Value;

            expected.Should().BeEquivalentTo(result);
        }
示例#2
0
        //Tests two separate google results, ensuring that incorrect data isn't pulled from the cache
        public void TestSeparateGoogleResults()
        {
            var mockContext = new Microsoft.AspNetCore.Http.DefaultHttpContext();

            mockContext.Request.Headers.Add("searchString", "e-Settlements");
            mockContext.Request.Headers.Add("targetUrl", "www.sympli.com.au");
            mockContext.Request.Headers.Add("resultsCount", "100");
            mockContext.Request.Headers.Add("engineTypeId", $"{(int)SearchEngineType.Google}");

            var ctl = new SEOSearchController()
            {
                ControllerContext = new Microsoft.AspNetCore.Mvc.ControllerContext()
                {
                    HttpContext = mockContext
                }
            };

            var response = ctl.Get();

            System.Threading.Thread.Sleep(1000);

            var mockContext2 = new Microsoft.AspNetCore.Http.DefaultHttpContext();

            mockContext2.Request.Headers.Add("searchString", "Digital Settlements");
            mockContext2.Request.Headers.Add("targetUrl", "www.sympli.com.au");
            mockContext2.Request.Headers.Add("resultsCount", "50");
            mockContext2.Request.Headers.Add("engineTypeId", $"{(int)SearchEngineType.Google}");

            ctl.ControllerContext = new Microsoft.AspNetCore.Mvc.ControllerContext()
            {
                HttpContext = mockContext2
            };

            var secondResponse = ctl.Get();

            Assert.IsTrue(response.Success && secondResponse.Success && secondResponse.SearchDate != response.SearchDate);
        }
示例#3
0
        public async Task TestExtract()
        {
            // arrange
            var services = new ServiceCollection();

            services.AddMemoryCache();
            services.AddLogging();
            var serviceProvider = services.BuildServiceProvider();

            var memoryCache = serviceProvider.GetService <IMemoryCache>();
            var logger      = serviceProvider.GetService <ILogger <SEOSearchController> >();

            var hdoc = new HtmlAgilityPack.HtmlDocument();

            hdoc.Load("TestAssets\\GoogleSearchResult.html");

            var googleServiceMock = new Mock <GoogleService>(It.IsAny <ILogger <GoogleService> >(), It.IsAny <ISEOClientService>(), memoryCache);

            googleServiceMock
            .Setup(bs => bs.FetchResults("e-settlements"))
            .ReturnsAsync(hdoc.Text);

            var expected = new List <SEOResult>
            {
                {
                    new SEOResult
                    {
                        Position    = 2,
                        Title       = "Sympli: Making e-Settlements Simple",
                        Url         = "/url?q=https://www.sympli.com.au/&amp;sa=U&amp;ved=2ahUKEwjVue_Xl67tAhVHfMAKHRAPA9UQFjAMegQILhAB&amp;usg=AOvVaw2IhKVbTuIalIywK7K-FXvL",
                        Description = "\r\n                    \r\n                        \r\n                            \r\n                                \r\n                                    \r\n                                        Meet Sympli - the new Electronic Settlements provider built by users for users. We're here to make e-Settlements simple. Find out more.\r\n                                        e-Settlement Services · About Us · Our Team · Contact Us\r\n                                    \r\n                                \r\n                            \r\n                        \r\n                    \r\n                "
                    }
                }
            };

            // act
            var controller   = new SEOSearchController(logger, googleServiceMock.Object, null);
            var actionResult = await controller.Get("Google", "e-settlements", "sympli.com.au");

            // assert
            Assert.IsNotNull(actionResult);
            var result = actionResult.Value;

            expected.Should().BeEquivalentTo(result);
        }
示例#4
0
        //Search google for "e-Settlements" and return the number of matches pointing to sympli.com.au in the first 100 results.
        public void TestGoogleSearchSuccess()
        {
            var mockContext = new Microsoft.AspNetCore.Http.DefaultHttpContext();

            mockContext.Request.Headers.Add("searchString", "e-Settlements");
            mockContext.Request.Headers.Add("targetUrl", "www.sympli.com.au");
            mockContext.Request.Headers.Add("resultsCount", "100");
            mockContext.Request.Headers.Add("engineTypeId", $"{(int)SearchEngineType.Google}");

            var ctl = new SEOSearchController()
            {
                ControllerContext = new Microsoft.AspNetCore.Mvc.ControllerContext()
                {
                    HttpContext = mockContext
                }
            };

            var response = ctl.Get();

            Assert.IsTrue(response.Success);
        }