Пример #1
0
        public override void CreateTestData()
        {
            base.CreateTestData();

            var provider = TestObjects.GetScopeProvider(Logger);

            using (var scope = provider.CreateScope())
            {
                var repository  = new RedirectUrlRepository((IScopeAccessor)provider, AppCaches.Disabled, Mock.Of <ILogger>());
                var rootContent = ServiceContext.ContentService.GetRootContent().FirstOrDefault();
                var subPages    = ServiceContext.ContentService.GetPagedChildren(rootContent.Id, 0, 2, out _).ToList();
                _testPage    = subPages[0];
                _altTestPage = subPages[1];

                repository.Save(new RedirectUrl
                {
                    ContentKey = _testPage.Key,
                    Url        = _url,
                    Culture    = _cultureA
                });
                repository.Save(new RedirectUrl
                {
                    ContentKey = _altTestPage.Key,
                    Url        = _url,
                    Culture    = _cultureB
                });
                scope.Complete();
            }
        }
Пример #2
0
    public override void CreateTestData()
    {
        base.CreateTestData();

        using (var scope = ScopeProvider.CreateScope())
        {
            var repository = new RedirectUrlRepository((IScopeAccessor)ScopeProvider, AppCaches.Disabled,
                                                       Mock.Of <ILogger <RedirectUrlRepository> >());
            var rootContent = ContentService.GetRootContent().First();
            var subPages    = ContentService.GetPagedChildren(rootContent.Id, 0, 3, out _).ToList();
            _firstSubPage  = subPages[0];
            _secondSubPage = subPages[1];
            _thirdSubPage  = subPages[2];


            repository.Save(new RedirectUrl {
                ContentKey = _firstSubPage.Key, Url = Url, Culture = CultureEnglish
            });
            Thread.Sleep(
                1000); //Added delay to ensure timestamp difference as sometimes they seem to have the same timestamp
            repository.Save(new RedirectUrl {
                ContentKey = _secondSubPage.Key, Url = Url, Culture = CultureGerman
            });
            Thread.Sleep(1000);
            repository.Save(new RedirectUrl {
                ContentKey = _thirdSubPage.Key, Url = UrlAlt, Culture = string.Empty
            });

            scope.Complete();
        }
    }
Пример #3
0
        public async Task GetByShortenedUrlAsync_WhenMatchFound_ReturnsTargetUrl()
        {
            const string expectedTargetUrl = "https://localhost/target";

            _urlServiceMock.Setup(m => m.GetByShortenedUrlAsync(It.IsAny <string>(), It.IsAny <string>()))
            .ReturnsAsync(new Url {
                TargetUrl = expectedTargetUrl
            });

            var repository = new RedirectUrlRepository(_urlServiceMock.Object);
            var actual     = await repository.GetByShortenedUrlAsync("https://localhost", "en");

            Assert.Equal(expectedTargetUrl, actual.Url);
        }
Пример #4
0
 public async Task GetByShortenedUrlAsync_WhenMatchNotFound_Throws()
 {
     var repository = new RedirectUrlRepository(_urlServiceMock.Object);
     await Assert.ThrowsAsync <InvalidOperationException>(() =>
                                                          repository.GetByShortenedUrlAsync("https://localhost", "en"));
 }