public void GetAllegroCategoryFetchFromFactory()
        {
            CategoryFetcherFactory fetcher  = new AllegroCategoryFetcherFactory();
            ICategoryFetcher       instance = fetcher.GetFetcher();

            Assert.IsInstanceOf <AllegroCategoryFetcher>(instance);
        }
        public void NegativeTaskCountThrow(int taskCount)
        {
            CategoryFetcherFactory fetcher  = new AllegroCategoryFetcherFactory();
            ICategoryFetcher       instance = fetcher.GetFetcher();
            RequestException       ex       = Assert.Throws <RequestException>(() => instance.SetIndexCategoryFetchLimit(taskCount));

            Assert.That(ex.Message, Contains.Substring("Cannot set task count <= 0"));
        }
        public void CreateRequestNotFoundDoNotThrowButReturnResponse()
        {
            CategoryFetcherFactory fetcher  = new AllegroCategoryFetcherFactory();
            ICategoryFetcher       instance = fetcher.GetFetcher();

            OfferCategory category = instance.GetCategoryById(0);

            Assert.IsNull(category);
        }
        public void RunDoNotThrow()
        {
            Mock <IDal>            db       = new Mock <IDal>();
            CategoryFetcherFactory fetcher  = new AllegroCategoryFetcherFactory();
            ICategoryFetcher       instance = fetcher.GetFetcher();

            instance.SetIndexCategoryFetchLimit(1);
            instance.Run(db.Object);
        }
 public void TakeFirstTenCategoriesWithoutException()
 {
     using (Dal db = new Dal())
     {
         CategoryFetcherFactory fetcher  = new AllegroCategoryFetcherFactory();
         ICategoryFetcher       instance = fetcher.GetFetcher();
         instance.SetIndexCategoryFetchLimit(10);
         Assert.DoesNotThrow(() => instance.Run(db));
     }
 }
        public void DatabaseExceptionDuringRunDoNotThrowUp()
        {
            Mock <IDal> dbMock = new Mock <IDal>();

            dbMock.Setup(x => x.ExecuteNonQuery(It.IsAny <string>())).Throws <Exception>();

            CategoryFetcherFactory fetcher  = new AllegroCategoryFetcherFactory();
            ICategoryFetcher       instance = fetcher.GetFetcher();

            instance.SetIndexCategoryFetchLimit(10);
            Assert.DoesNotThrow(() => instance.Run(dbMock.Object));
        }
        public void IfCategoryDoNotExistInDbUpdateIsInvokedOnce()
        {
            Mock <IDal> dbMock = new Mock <IDal>();

            dbMock.Setup(x => x.ExecuteScalar(It.IsAny <string>())).Returns(0);
            dbMock.Setup(x => x.ExecuteNonQuery(It.IsAny <string>())).Verifiable();

            CategoryFetcherFactory fetcher  = new AllegroCategoryFetcherFactory();
            ICategoryFetcher       instance = fetcher.GetFetcher();

            instance.SetIndexCategoryFetchLimit(10);
            instance.Run(dbMock.Object);
            dbMock.Verify(x => x.ExecuteNonQuery(It.IsAny <string>()), Times.AtLeastOnce);
        }
Ejemplo n.º 8
0
        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            while (!stoppingToken.IsCancellationRequested)
            {
                _logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now);
                using (IDal dal = new Dal())
                {
                    CategoryFetcherFactory factory = new AllegroCategoryFetcherFactory();
                    factory.GetFetcher().Run(dal);
                }

                await Task.Delay(60000 *(60 * 24), stoppingToken);
            }
        }
        public void RequestNotFoundExceptionDoNotThrowUp()
        {
            Mock <IRest> restMock = new Mock <IRest>();

            restMock.Setup(x => x.Get(It.IsAny <IRestRequest>())).Returns(new RestResponse()
            {
                StatusCode = HttpStatusCode.NotFound
            });

            CategoryFetcherFactory fetcher  = new AllegroCategoryFetcherFactory();
            ICategoryFetcher       instance = fetcher.GetFetcher(restMock.Object);

            instance.SetIndexCategoryFetchLimit(10);
            instance.GetCategoryById(0);
        }
        public void RequestUnauthorizedDoNotThrowUp()
        {
            Mock <IRest> restMock = new Mock <IRest>();

            restMock.Setup(x => x.Get(It.IsAny <IRestRequest>())).Returns(new RestResponse()
            {
                StatusCode = HttpStatusCode.Unauthorized
            });

            CategoryFetcherFactory fetcher  = new AllegroCategoryFetcherFactory();
            ICategoryFetcher       instance = fetcher.GetFetcher(restMock.Object);

            instance.SetIndexCategoryFetchLimit(1);
            NullReferenceException ex = Assert.Throws <NullReferenceException> (() => instance.GetCategoryById(0));

            Assert.That(ex.Message, Contains.Substring("Object reference"));
        }