public void AccountsLinkWithNullAccountId_ReturnRouteLink() { var options = Substitute.For <IOptionsMonitor <MaPageConfiguration> >(); var config = new MaPageConfiguration { Routes = new MaRoutes { Accounts = new System.Collections.Generic.Dictionary <string, string> { { "Routename", "ProperLink/{0}" } } } }; options.CurrentValue.Returns(config); var linkGenerator = Substitute.For <ILinkGenerator>(); linkGenerator.AccountsLink(Arg.Any <string>()).Returns("ProperLink"); linkGenerator.AccountsLink("").Returns("RouteLink"); var urlBuilder = new UrlBuilder(Substitute.For <ILogger <UrlBuilder> >(), options, linkGenerator); Assert.Equal("RouteLink", urlBuilder.AccountsLink()); //Assert.Equal("RouteLink", urlBuilder.AccountsLink("Routename", "")); //Assert.Equal("RouteLink", urlBuilder.AccountsLink("Routename")); //Assert.Equal("RouteLink", urlBuilder.AccountsLink("Routename", null)); Assert.Equal("ProperLink", urlBuilder.AccountsLink("Routename", "ABC123")); }
public ConfirmationControllerTests() { _cachedSurveyModel = _fixture.Create <SurveyModel>(); var sessionServiceMock = new Mock <ISessionService>(); var loggerMock = new Mock <ILogger <ConfirmationController> >(); var optionsMock = new Mock <IOptionsMonitor <MaPageConfiguration> >(); var linkGeneratorMock = new Mock <ILinkGenerator>(); var maPageConfiguration = new MaPageConfiguration { Routes = new MaRoutes { Accounts = new Dictionary <string, string>() } }; maPageConfiguration.Routes.Accounts.Add("AccountsHome", "http://AnAccountsLink/{0}"); optionsMock.Setup(s => s.CurrentValue).Returns(maPageConfiguration); linkGeneratorMock.Setup(s => s.AccountsLink(It.IsAny <string>())).Returns <string>(x => x); var config = new ProvideFeedbackEmployerWebConfiguration() { ExternalLinks = _externalLinks }; var urlBuilder = new UrlBuilder(Mock.Of <ILogger <UrlBuilder> >(), optionsMock.Object, linkGeneratorMock.Object); sessionServiceMock .Setup(mock => mock.Get <SurveyModel>(It.IsAny <string>())) .Returns(Task.FromResult(_cachedSurveyModel)); _controller = new ConfirmationController( sessionServiceMock.Object, config, urlBuilder, loggerMock.Object); var context = new DefaultHttpContext() { User = new ClaimsPrincipal(new ClaimsIdentity(new Claim[] { new Claim(ClaimTypes.NameIdentifier, "TestUserIdValue"), })) }; _controller.ControllerContext = new ControllerContext { HttpContext = context }; }
static ProviderControllerTests() { _surveyModel = new SurveyModel() { UserRef = Guid.NewGuid(), ProviderName = "TestProviderName", }; _employerEmailDetailsRepoMock = new Mock <IEmployerFeedbackRepository>(); _sessionServiceMock = new Mock <ISessionService>(); _sessionServiceMock.Setup(mock => mock.Get <SurveyModel>(It.IsAny <string>())).Returns(Task.FromResult(_surveyModel)); _trainingProviderServiceMock = new Mock <ITrainingProviderService>(); _trainingProviderServiceMock.Setup(m => m.GetTrainingProviderSearchViewModel( It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>(), It.IsAny <string>())) .ReturnsAsync(new ProviderSearchViewModel() { TrainingProviders = new PaginatedList <ProviderSearchViewModel.EmployerTrainingProvider>( new List <ProviderSearchViewModel.EmployerTrainingProvider>() { }, 0, 0, 0, 6) }); _encodingServiceMock = new Mock <IEncodingService>(); _loggerMock = new Mock <ILogger <ProviderController> >(); _urlBuilderloggerMock = new Mock <ILogger <UrlBuilder> >(); _maPageConfigurationMock = new Mock <IOptionsMonitor <MaPageConfiguration> >(); _linkGeneratorMock = new Mock <ILinkGenerator>(); var maPageConfiguration = new MaPageConfiguration { Routes = new MaRoutes { Accounts = new Dictionary <string, string>() } }; maPageConfiguration.Routes.Accounts.Add("AccountsHome", "http://AnAccountsLink/{0}"); _maPageConfigurationMock.Setup(s => s.CurrentValue).Returns(maPageConfiguration); _linkGeneratorMock.Setup(s => s.AccountsLink(It.IsAny <string>())).Returns <string>(x => x); _urlBuilder = new UrlBuilder(_urlBuilderloggerMock.Object, _maPageConfigurationMock.Object, _linkGeneratorMock.Object); _controller = new ProviderController( _employerEmailDetailsRepoMock.Object, _sessionServiceMock.Object, _trainingProviderServiceMock.Object, _encodingServiceMock.Object, _loggerMock.Object, _urlBuilder); var context = new DefaultHttpContext() { User = new ClaimsPrincipal(new ClaimsIdentity(new Claim[] { new Claim(ClaimTypes.NameIdentifier, "TestUserIdValue"), })) }; _controller.ControllerContext = new ControllerContext { HttpContext = context }; }