Пример #1
0
        public void FindPageByBlobName_Ctor_Argument_Pages_Null()
        {
            try
            {
                var fnd = new FindPageByBlobName(null, new BlobNameToURLPart());

                Assert.Fail("Очікувалося ArgumentNullException");
            }
            catch (ArgumentNullException ex)
            {
                Assert.IsTrue(ex.ParamName == "pages");
            }
        }
Пример #2
0
        public void FindPageByBlobName_Ctor_Argument_BlobNameToURLPart_Null()
        {
            try
            {
                QueryableStub <SitePage> queryableStub = new QueryableStub <SitePage>();

                var fnd = new FindPageByBlobName(queryableStub, null);

                Assert.Fail("Очікувалося ArgumentNullException");
            }
            catch (ArgumentNullException ex)
            {
                Assert.IsTrue(ex.ParamName == "blobNameToURLPart");
            }
        }
Пример #3
0
        public void FindPageByBlobName_Normal_Find()
        {
            string connString = "mongodb://localhost:27017/?readPreference=primary&appname=kawaiitwitter&ssl=false";
            string dbName     = "unit-test-kawaii";
            string collName   = "sitepages-find-page-by-blobname";

            var db = new Database(connString, false, dbName);

            SitePageCollection sitePageCollection = new SitePageCollection(db, collName, true);
            var sitePages = sitePageCollection.SitePages;

            //коллекцию очистить от данных
            var delFilter = Builders <SitePage> .Filter.Exists(x => x.URL);

            sitePages.DeleteMany(delFilter);

            //заполняем тест-данные
            var page2 = new SitePage()
            {
                Blocked      = false,
                SpecialDay   = null,
                Title        = "Shuumatsu no Izetta",
                LastModified = new DateTime(2020, 04, 25),
                TweetDate    = null,
                URL          = "https://kawaii-mobile.com/2017/01/shuumatsu-no-izetta/"
            };

            List <SitePage> pagesForTest = new List <SitePage>()
            {
                new SitePage()
                {
                    Blocked = false, SpecialDay = null, Title = "Princess connect! Re:Dive", LastModified = new DateTime(2020, 04, 26), TweetDate = null, URL = "https://kawaii-mobile.com/2020/08/princess-connect-redive/"
                },
                page2,
                new SitePage()
                {
                    Blocked = false, SpecialDay = null, Title = "Gleipnir", LastModified = new DateTime(2020, 04, 23), TweetDate = null, URL = "https://kawaii-mobile.com/2020/07/gleipnir/"
                },
            };

            sitePages.InsertMany(pagesForTest);

            string blobName = "shuumatsu-no-izetta:image1.gif";

            var queryAble = sitePages.AsQueryable();

            var fnd    = new FindPageByBlobName(queryAble, new BlobNameToURLPart());
            var result = fnd.Find(blobName).Result;

            //сверим что мы нашли -
            Assert.IsNotNull(result);
            Assert.IsTrue(result.URL == page2.URL, "URL");
            Assert.IsTrue(result.Blocked == page2.Blocked, "Blocked");
            Assert.IsTrue(result.Title == page2.Title, "Title");
            Assert.IsTrue(result.LastModified == page2.LastModified, "LastModified");
            Assert.IsTrue(result.TweetDate == page2.TweetDate, "TweetDate");

            //и еще тест на "не нашли"
            string blobNot   = "rezero:image1.gif";
            var    resultNot = fnd.Find(blobNot).Result;

            Assert.IsTrue(resultNot == null, "Ожидался возврат resultNot == null");
        }