public void UrlFound_LogsShortCodeAndURLAndTrackingId() { var testShortCode = "sk"; var testUrl = "http://SeanKilleen.com"; var testGaCode = "12345"; _mockRepo.Setup(x => x.GetByShortCode(It.IsAny <string>())) .Returns(new ShortLinkItem(testShortCode, testUrl)); _mockGaOptions.Setup(x => x.Value) .Returns(new GoogleAnalyticsOptions { TrackingPropertyId = testGaCode }); // need to recreate SUT instead of setup because .Value is used in the Ctor, // meaning we can't just overwrite it with a Mock. var sut = new RedirectController( _mockRepo.Object, _mockLogger.Object, _mockRedirectOptions.Object, _mockGaOptions.Object); sut.Index("thisCodeDoesntMatter"); _mockLogger.Verify(x => x.Information("Redirecting {shortCode} to {redirectUrl} using tracking Id {gaTrackingId}", testShortCode, testUrl, testGaCode)); }
public void UrlFound_PopulatesViewModelCorrectly() { var testShortCode = "sk"; var testUrl = "http://SeanKilleen.com"; var testGaCode = "12345"; var testSecondsToWait = 3; _mockRepo.Setup(x => x.GetByShortCode(It.IsAny <string>())) .Returns(new ShortLinkItem(testShortCode, testUrl)); _mockGaOptions.Setup(x => x.Value) .Returns(new GoogleAnalyticsOptions { TrackingPropertyId = testGaCode }); _mockRedirectOptions.Setup(x => x.Value) .Returns(new RedirectOptions { SecondsToWaitForAnalytics = testSecondsToWait }); // need to recreate SUT instead of setup because .Value is used in the Ctor, // meaning we can't just overwrite it with a Mock. var sut = new RedirectController( _mockRepo.Object, _mockLogger.Object, _mockRedirectOptions.Object, _mockGaOptions.Object); var result = sut.Index(testShortCode); var viewResult = Assert.IsType <ViewResult>(result); var model = Assert.IsAssignableFrom <RedirectViewModel>( viewResult.ViewData.Model); model.ShortLinkCode.Should().Be(testShortCode); model.NumberOfSecondsToWait.Should().Be(testSecondsToWait); model.TrackingCode.Should().Be(testGaCode); model.Url.Should().Be(testUrl); }
public async Task UrlFound_PopulatesViewModelCorrectly(string testShortCode, string testUrl, string testGaCode, int testSecondsToWait, string testImageUrl, string testTitle, string testDescription) { _mockRepo.Setup(x => x.GetByShortCode(It.IsAny <string>())) .Returns(Task.FromResult(new ShortLinkItem(testShortCode, testUrl, testImageUrl, testTitle, testDescription))); _mockGaOptions.Setup(x => x.Value) .Returns(new GoogleAnalyticsOptions { TrackingPropertyId = testGaCode }); _mockRedirectOptions.Setup(x => x.Value) .Returns(new RedirectOptions { SecondsToWaitForAnalytics = testSecondsToWait }); // need to recreate SUT instead of setup because .Value is used in the Ctor, // meaning we can't just overwrite it with a Mock. var sut = new RedirectController( _mockRepo.Object, _mockLogger.Object, _mockRedirectOptions.Object, _mockGaOptions.Object); var result = await sut.Index(testShortCode); var viewResult = Assert.IsType <ViewResult>(result); var model = Assert.IsAssignableFrom <RedirectViewModel>( viewResult.ViewData.Model); model.ShortLinkCode.Should().Be(testShortCode); model.NumberOfSecondsToWait.Should().Be(testSecondsToWait); model.TrackingCode.Should().Be(testGaCode); model.ImageUrl.Should().Be(testImageUrl); model.Title.Should().Be(testTitle); model.Description.Should().Be(testDescription); model.Url.Should().Be(testUrl); }
public void LogsTheRedirectShortCode() { _sut.Index("abc"); _mockLogger.Verify(x => x.Debug("Entered the redirect for short code {shortCode}", "abc")); }