Exemplo n.º 1
0
        public async Task TestFirstTimeRequestLinkNotExistsWithInvalidDefRedir(LinkVerifyResult linkVerifyResult)
        {
            string inputToken = "996";
            string t;

            _tokenGeneratorMock
            .Setup(p => p.TryParseToken(inputToken, out t))
            .Returns(true);

            var link        = new Link();
            var memoryCache = MockMemoryCacheService.GetMemoryCache(link, false);

            _linkForwarderServiceMock
            .Setup(p => p.GetLinkAsync(null))
            .ReturnsAsync(new SuccessResponse <Link>(null));

            _linkVerifierMock
            .Setup(p => p.Verify(It.IsAny <string>(), It.IsAny <IUrlHelper>(), It.IsAny <HttpRequest>()))
            .Returns(linkVerifyResult);

            _appSettingsMock.Setup(p => p.Value).Returns(new AppSettings
            {
                DefaultRedirectionUrl = "INVALID_VALUE"
            });

            var ctl = new ForwardController(
                _appSettingsMock.Object,
                _loggerMock.Object,
                _linkForwarderServiceMock.Object,
                _tokenGeneratorMock.Object,
                memoryCache,
                _linkVerifierMock.Object)
            {
                ControllerContext = GetHappyPathHttpContext()
            };

            var result = await ctl.Forward(inputToken);

            Assert.IsInstanceOf(typeof(StatusCodeResult), result);

            var statusCode = ((StatusCodeResult)result).StatusCode;

            Assert.IsTrue(statusCode == 500);
        }
Exemplo n.º 2
0
        public void FirstTimeRequest_LinkNotExists_InvalidDefRedir(LinkVerifyResult linkVerifyResult)
        {
            string inputToken = "996";
            string t;

            _tokenGeneratorMock
            .Setup(p => p.TryParseToken(inputToken, out t))
            .Returns(true);

            var link        = new Link();
            var memoryCache = MockMemoryCacheService.GetMemoryCache(link, false);

            _linkForwarderServiceMock
            .Setup(p => p.GetLinkAsync(null))
            .ReturnsAsync(() => null);

            _linkVerifierMock
            .Setup(p => p.Verify(It.IsAny <string>(), It.IsAny <IUrlHelper>(), It.IsAny <HttpRequest>(), false))
            .Returns(linkVerifyResult);

            _appSettingsMock.Setup(p => p.Value).Returns(new AppSettings
            {
                DefaultRedirectionUrl = "INVALID_VALUE"
            });

            var ctl = new ForwardController(
                _appSettingsMock.Object,
                _loggerMock.Object,
                _linkForwarderServiceMock.Object,
                _tokenGeneratorMock.Object,
                memoryCache,
                _linkVerifierMock.Object,
                _mockFeatureManager.Object)
            {
                ControllerContext = GetHappyPathHttpContext()
            };

            Assert.ThrowsAsync(typeof(UriFormatException), async() =>
            {
                await ctl.Forward(inputToken);
            });
        }