Example #1
0
 //        [Test]
 public void testFakeParams()
 {
     const string theId = "555b77b99b111d2aa4b33333";
     var rect = new Rectangle(10, 10, 10, 10);
     var faked = new FakeScrapeParams(theId, bounding: rect);
     Assert.IsTrue(theId == faked.Id && rect == faked.Bounding);
 }
Example #2
0
        public Scrape FakeScrape(FakeScrapeParams fakeScrapeParams)
        {
            fakeScrapeParams.Cookies = new List<string>();

            #region Header/Cookie Content

            if (!fakeScrapeParams.Cookies.Any())
            {
                fakeScrapeParams.Cookies.AddRange(FakeCookies());
            }
            var headerOne = new List<string>()
            {
                "Content-Length:194",
                "Cache-Control:public, must-revalidate",
                "Content-Type:application/x-javascript",
                "Date:Thu, 20 Sep 2012 17:15:03 GMT",
                "ETag:JsJt380DknGc4kAEEn76og=="
            };
            var headerTwo = new List<string>()
            {
                "Content-Length:17423",
                "Cache-Control:public, must-revalidate",
                "Content-Type:application/x-javascript",
                "Date:Thu, 20 Sep 2012 17:15:03 GMT",
                "ETag:qloGz7WY45YMKQ1Fmuuw8A=="
            };
            var headerThree = new List<string>()
            {
                "Content-Length:2552",
                "Cache-Control:public, must-revalidate",
                "Content-Type:image/gif",
                "Date:Thu, 20 Sep 2012 17:15:03 GMT",
                "ETag:UAFdRlkmdsJ1EGIoGalWng=="
            };

            #endregion

            if (fakeScrapeParams.Resources == null)
            {
                //Uri, statusCode, StatusDesc, Headers
                var first = GetSession().List<Resource>(3).First(1)
                    .Impose(x => x.Uri, "http://c.mfcreativedev.com/webparts/banner/Banner.js?v=c5589edb")
                    .Impose(x => x.StatusCode, HttpStatusCode.OK)
                    .Impose(x => x.StatusDescription, "OK")
                    .Impose(x => x.Headers, headerOne)
                    .Next(1)
                    .Impose(x => x.Uri, "http://c.mfcreativedev.com/webparts/header/HeaderV1_2.js?v=730f5c7b1")
                    .Impose(x => x.StatusCode, HttpStatusCode.OK)
                    .Impose(x => x.StatusDescription, "OK")
                    .Impose(x => x.Headers, headerTwo)
                    .Next(1)
                    .Impose(x => x.Uri, "http://c.mfcreativedev.com/s/0/p/0/i/ances_logo.gif")
                    .Impose(x => x.StatusCode, HttpStatusCode.OK)
                    .Impose(x => x.StatusDescription, "OK")
                    .Impose(x => x.Headers, headerThree)
                    .All().Get().ToArray();
                fakeScrapeParams.Resources = first;
            }

            if (fakeScrapeParams.Elements == null)
            {
                var elements = new List<ScrapedElement>();
                var ele1 = new ScrapedElement()
                {
                    Attributes                  = new Dictionary<string, string>() {{"id", "mngb"}},
                    CorrespondingScrapedElement = null,
                    Css                         = new Dictionary<string, string>(),
                    Html                        = "<div id=\"mngb\"></div>",
                    Location                    = new Rectangle(0, 0, 800, 30),
                    LocationOnScreenshot        = new Rectangle(0, 0, 800, 30),
                    Tag                         = "div",
                    Text                        = ""
                };
                elements.Add(ele1);
                fakeScrapeParams.Elements = new List<ScrapedElement>(elements);
            }
            var scr = new Scrape
            {
                Id                    = new ObjectId(fakeScrapeParams.Id),
                ExcludeJquerySelector = fakeScrapeParams.Exclude,
                IncludeJquerySelector = fakeScrapeParams.Include,
                Script                = fakeScrapeParams.Script,
                BoundingRectangle     = fakeScrapeParams.Bounding,
                Path                  = new StringAsReference {Value = fakeScrapeParams.Path},
                Elements              = fakeScrapeParams.Elements,
                Resources             = fakeScrapeParams.Resources,
                Html                  = fakeScrapeParams.Html,
                HtmlRef               = new StringAsReference {Value = fakeScrapeParams.HtmlRef},
                Url                   = fakeScrapeParams.Url,
                Screenshot            = fakeScrapeParams.ScreenShot,
                ScreenshotRef         = new StringAsReference {Value = fakeScrapeParams.ScreenShotRef},
                ViewportSize          = fakeScrapeParams.ViewportSize == null ? new Size(800 , 600) : fakeScrapeParams.ViewportSize.Value,
                Browser               = fakeScrapeParams.Browser,
                BrowserVersion        = fakeScrapeParams.BrowserVersion,
                TimeStamp             = fakeScrapeParams.TimeStamp == null ? DateTime.Now : fakeScrapeParams.TimeStamp.Value,
                Platform              = fakeScrapeParams.Platform,
                Cookies               = fakeScrapeParams.Cookies
            };
            return scr;
        }