public void GetEvents_Caches_Results()
        {
            //Arrange
            var eventsRepo = new StubIRepository<Event>()
            {
                All = () => EventTestData.SingleEvent.AsQueryable()
            };
            var cacheService = new DefaultMemoryCache();
            var eventService = new EventsService(eventsRepo, cacheService);

            //Act
            eventService.GetEvents();
            //Assert
            Assert.IsTrue(cacheService.Exists("events:all"));
        }
        public void GetEvents_Returns_Results_From_Cache()
        {
            //arrange
            var cacheService = new StubICacheService()
            {
                ExistsString = (key) => true
            };

            cacheService.RetrieveOf1String<IEnumerable<Event>>(
                (key) => EventTestData.SingleEvent.AsEnumerable()
            );
            var eventsRepo = new StubIRepository<Event>();
            var eventService = new EventsService(eventsRepo, cacheService);

            //Act
            var results = eventService.GetEvents();
            Assert.AreEqual(results.Count(), EventTestData.SingleEvent.Count);
        }
        public void GetEvents_Does_Not_Call_Repository_All_When_Cache_Available()
        {
            //arrange
            var cacheService = new DefaultMemoryCache();
            cacheService.Store("events:all", EventTestData.SingleEvent.AsQueryable());
            bool allWasCalled = false;
            var eventsRepo = new StubIRepository<Event>()
            {
                All = () =>
                {
                    allWasCalled = true;
                    return Enumerable.Empty<Event>().AsQueryable();
                }
            };
            var eventService = new EventsService(eventsRepo, cacheService);

            //Act
            var results = eventService.GetEvents();

            //Assert
            Assert.IsFalse(allWasCalled);
        }
        public void NormalGroupAddTest()
        {
            XmlDocumentGroup xmlDocumentGroup = XmlHelper.GetXmlDocumentGroup(@".\DataContent\NormalContent\cc54a49bf188f994899cb1c954bb795f.xml");
            UploadDocumentGroup uploadDocumentGroup = XmlHelper.GetUploadDocumentGroup(xmlDocumentGroup, @".\DataContent\NormalContent\cc54a49bf188f994899cb1c954bb795f.zip");

            using (ShimsContext.Create())
            {
                ShimDateTime.NowGet = () => new DateTime(2000, 1, 1);

                CrawlerLog log = new CrawlerLog();
                DocumentGroup documentGroup = new DocumentGroup();
                IRepository fakeRepository = new StubIRepository
                {
                    GetIdentifierString = (identifier) => { return string.Empty; },
                    GetOrCreateCrawlerIdString = (crawlerName) => { return 1; },
                    AddDocumentGroupDocumentGroup = (newDocumentGroup) => { documentGroup = newDocumentGroup; },
                    AddNewLogCrawlerLog = (crawlerLog) => { log = crawlerLog; }
                };

                WcfHost eu = new WcfHost(fakeRepository);
                var msgActual = eu.UploadFile(uploadDocumentGroup);

                // ReturnMessage
                Assert.AreEqual("Ok", msgActual, "Service return message.");

                // AddDocumentGroup
                Assert.AreEqual(xmlDocumentGroup.Identifier, documentGroup.Identifier, "Identifier");
                Assert.AreEqual(1, documentGroup.CrawlerId, "CrawlerId");
                Assert.AreEqual(0, documentGroup.Operation, "Operation");
                Assert.AreEqual(xmlDocumentGroup.Document.Count, documentGroup.Documents.Count, "DocumentsCount");

                // LogAsserts
                Assert.AreEqual(xmlDocumentGroup.Identifier, log.Identifier, "IdentifierLog");
                Assert.AreEqual(true, log.IsSuccess, "IsSuccess");
                Assert.AreEqual(new DateTime(2000, 1, 1), log.LogDate, "LogDate");
                Assert.AreEqual(xmlDocumentGroup.Crawler, log.CrawlerName, "CrawlerNameLog");
                Assert.AreEqual(0, log.Operation, "OperationLog");
            }
        }
Exemplo n.º 5
0
        public void RepositoryBase_WhenExportingWithItemCountLessThanZero_ExpectException()
        {
            var dataSource = new StubIDataSource <StubIConnection>
            {
                LoadT0 = connection => { },
                SaveT0 = connection => { }
            };

            var repository =
                new StubIRepository <StubIDataSource <StubIConnection>, StubIConnection>
            {
                ExportT0 = source => { },
                ImportT0 = source => { }
            };

            repository.ExportT0(dataSource);

            //var sut = new MockRepository
            //{
            //    ItemCount = -1
            //};

            //sut.Export(new MockDataSource());
        }
        public void GetPastEvents_Only_Returns_Previous_Events()
        {
            //Arrange
            var cacheService = new StubICacheService();
            var eventsRepo = new StubIRepository<Event>()
            {
                FindExpressionOfFuncOfT0Boolean = (func) => EventTestData.MultipleEvents.AsQueryable().Where(func)
            };
            var eventService = new EventsService(eventsRepo, cacheService);

            //act
            using (ShimsContext.Create())
            {
                //Set current DateTime.Now to 12/12/12
                ShimDateTime.NowGet = () => new DateTime(2012, 12, 12);
                var results = eventService.GetPastEvents();

                //assert
                Assert.AreEqual(2, results.Count());

            }
        }
        public void IdentifierGroupDeleteTestNull()
        {
            XmlDocumentGroup xmlDocumentGroup = XmlHelper.GetXmlDocumentGroup(@".\DataContent\NormalContent\cc54a49bf188f994899cb1c954bb795f.xml");
            xmlDocumentGroup.Operation = Operation.Del;
            UploadDocumentGroup uploadDocumentGroup = XmlHelper.GetUploadDocumentGroup(xmlDocumentGroup, @".\DataContent\NormalContent\cc54a49bf188f994899cb1c954bb795f.zip");
            uploadDocumentGroup.Data = null;

            using (ShimsContext.Create())
            {
                ShimDateTime.NowGet = () => new DateTime(2000, 1, 1);

                string ident = string.Empty;
                CrawlerLog log = new CrawlerLog();
                DocumentGroup documentGroup = new DocumentGroup();
                IRepository fakeRepository = new StubIRepository
                {
                    GetIdentifierString = (identifier) => { return string.Empty; },
                    GetOrCreateCrawlerIdString = (crawlerName) => { return 1; },
                    AddDocumentGroupDocumentGroup = (newDocumentGroup) => { documentGroup = newDocumentGroup; },
                    DeleteDocumentGroupString = (identifier) => { ident = identifier; return 1; },
                    AddNewLogCrawlerLog = (crawlerLog) => { log = crawlerLog; }
                };

                WcfHost eu = new WcfHost(fakeRepository);
                var msgActual = eu.UploadFile(uploadDocumentGroup);
                string msgExpected = "Error: Validation Exception - No document idenfier: " + xmlDocumentGroup.Identifier + " .You can't use Operation: Del";

                // ReturnMessage
                Assert.AreEqual(msgExpected, msgActual, "Service return message.");

                // LogAsserts
                Assert.AreEqual(xmlDocumentGroup.Identifier, log.Identifier, "IdentifierLog");
                Assert.AreEqual(false, log.IsSuccess, "IsSuccess");
                Assert.AreEqual(new DateTime(2000, 1, 1), log.LogDate, "LogDate");
                Assert.AreEqual(xmlDocumentGroup.Crawler, log.CrawlerName, "CrawlerNameLog");
                Assert.AreEqual(2, log.Operation, "OperationLog");
            }
        }
        public void ZipXmlValidationTestNull()
        {
            XmlDocumentGroup xmlDocumentGroup = XmlHelper.GetXmlDocumentGroup(@".\DataContent\NormalContent\cc54a49bf188f994899cb1c954bb795f.xml");
            UploadDocumentGroup uploadDocumentGroup = XmlHelper.GetUploadDocumentGroup(xmlDocumentGroup, @".\DataContent\NormalContent\cc54a49bf188f994899cb1c954bb795f.zip");
            uploadDocumentGroup.Data = null;

            using (ShimsContext.Create())
            {
                ShimDateTime.NowGet = () => new DateTime(2000, 1, 1);

                CrawlerLog log = new CrawlerLog();
                IRepository fakeRepository = new StubIRepository
                {
                    GetIdentifierString = (identifier) => { return string.Empty; },
                    AddNewLogCrawlerLog = (crawlerLog) => { log = crawlerLog; }
                };

                WcfHost eu = new WcfHost(fakeRepository);
                var msgActual = eu.UploadFile(uploadDocumentGroup);
                string msgExpected = "Error: Validation Exception - ZipData length is zero or ZipData is NULL, document idenfier: " + xmlDocumentGroup.Identifier + " and Operation: Add";

                Assert.AreEqual(msgExpected, msgActual, "Service return message.");
                Assert.AreEqual(false, log.IsSuccess, "IsSuccess");
                Assert.AreEqual(new DateTime(2000, 1, 1), log.LogDate, "LogDate");
            }
        }
        public void FormatXmlValidationTestInvalid()
        {
            XmlDocumentGroup xmlDocumentGroup = XmlHelper.GetXmlDocumentGroup(@".\DataContent\NormalContent\cc54a49bf188f994899cb1c954bb795f.xml");
            xmlDocumentGroup.Format = "application/badapplication";
            UploadDocumentGroup uploadDocumentGroup = XmlHelper.GetUploadDocumentGroup(xmlDocumentGroup, @".\DataContent\NormalContent\cc54a49bf188f994899cb1c954bb795f.zip");

            using (ShimsContext.Create())
            {
                ShimDateTime.NowGet = () => new DateTime(2000, 1, 1);

                CrawlerLog log = new CrawlerLog();
                IRepository fakeRepository = new StubIRepository
                {
                    GetIdentifierString = (identifier) => { return string.Empty; },
                    AddNewLogCrawlerLog = (crawlerLog) => { log = crawlerLog; }
                };

                WcfHost eu = new WcfHost(fakeRepository);
                var msgActual = eu.UploadFile(uploadDocumentGroup);
                string msgExpected = "Error: Validation Exception - The 'format' attribute has an invalid value according to its data type.\r\n";

                Assert.AreEqual(msgExpected, msgActual, "Service return message.");
                Assert.AreEqual(false, log.IsSuccess, "IsSuccess");
                Assert.AreEqual(new DateTime(2000, 1, 1), log.LogDate, "LogDate");
            }
        }