Beispiel #1
0
        public void Url_Should_Be_Created_Received_And_Deleted_Successfully()
        {
            var url = new UrlViewModel {
                OriginalUrl = "www.google.com", ShortUrl = "googl"
            };

            Assert.That(() => _urlService.CreateUrlAsync(url), Throws.Nothing);
            var result = _urlService.GetUrlByKeyAsync("googl");

            Assert.IsNotNull(result);

            Assert.That(() => _urlService.DeleteUrlAsync("googl"), Throws.Nothing);
        }
Beispiel #2
0
        public async Task <IActionResult> DeleteUrl(string key)
        {
            try
            {
                await _urlService.DeleteUrlAsync(key);

                return(Ok());
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            while (!stoppingToken.IsCancellationRequested)
            {
                _logger.LogInformation("Looking for URLs to cleanup...");

                foreach (var url in await _urlService.FindOlderThanAsync(
                             DateTimeOffset.UtcNow.AddDays(-_keepForDays)))
                {
                    await _urlService.DeleteUrlAsync(url);

                    _logger.LogInformation($"Found and removed url older than {_keepForDays} days " +
                                           $"with ID ({url.AdverbId}, {url.AdjectiveId}, {url.NounId})");
                }

                await Task.Delay(_delayMilliseconds, stoppingToken);
            }
        }