public ReviewAnswersController(
     ISessionService sessionService
     , ReviewAnswersOrchestrator orchestrator
     , ProvideFeedbackEmployerWebConfiguration config
     )
 {
     _sessionService = sessionService;
     _orchestrator   = orchestrator;
     _config         = config;
 }
 public ConfirmationController(
     ISessionService sessionService,
     ProvideFeedbackEmployerWebConfiguration config,
     UrlBuilder urlBuilder,
     ILogger <ConfirmationController> logger)
 {
     _sessionService = sessionService;
     _logger         = logger;
     _config         = config;
     _urlBuilder     = urlBuilder;
 }
 public TrainingProviderService(
     ICommitmentService commitmentService
     , IEncodingService encodingService
     , IEmployerFeedbackRepository employerFeedbackRepository
     , ProvideFeedbackEmployerWebConfiguration config)
 {
     _commitmentService          = commitmentService;
     _encodingService            = encodingService;
     _employerFeedbackRepository = employerFeedbackRepository;
     _config = config;
 }
Exemple #4
0
        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
            };
        }
        public void When_Feedback_Submitted_Recently_Then_Redirect_To_FeedbackAlreadySubmitted()
        {
            // Arrange

            var config = new ProvideFeedbackEmployerWebConfiguration()
            {
                // Configure "recently" to be 10 days ago
                FeedbackWaitPeriodDays = 10
            };

            var sessionServiceMock = new Mock <IEmployerFeedbackRepository>();

            sessionServiceMock.Setup(mock => mock.IsCodeBurnt(It.IsAny <Guid>())).ReturnsAsync(true);
            // Set feedback given 5 days ago
            sessionServiceMock.Setup(mock => mock.GetCodeBurntDate(It.IsAny <Guid>())).ReturnsAsync(DateTime.Now.AddDays(-5));

            var httpContext = new DefaultHttpContext();
            var context     = new ActionExecutingContext(
                new ActionContext
            {
                HttpContext      = httpContext,
                RouteData        = new RouteData(),
                ActionDescriptor = new ActionDescriptor()
            },
                new List <IFilterMetadata>(),
                new Dictionary <string, object>(),
                _controller);

            context.ActionArguments.Add("uniqueCode", Guid.NewGuid());

            var ensureSession = new EnsureFeedbackNotSubmittedRecentlyAttribute(sessionServiceMock.Object, config);

            // Act
            ensureSession.OnActionExecuting(context);

            // Assert
            context
            .Result
            .Should()
            .NotBeNull()
            .And
            .BeAssignableTo <RedirectToRouteResult>()
            .Which
            .RouteName
            .Should()
            .BeEquivalentTo(RouteNames.FeedbackAlreadySubmitted);
        }
        public static void AddServiceRegistrations(this IServiceCollection services, ProvideFeedbackEmployerWebConfiguration configuration)
        {
            services.AddTransient <IEmployerFeedbackRepository, EmployerFeedbackRepository>();
            services.AddTransient <EnsureFeedbackNotSubmitted>();
            services.AddTransient <EnsureFeedbackNotSubmittedRecentlyAttribute>();
            services.AddTransient <EnsureSessionExists>();
            services.AddTransient <ISessionService, SessionService>();
            services.AddTransient <ReviewAnswersOrchestrator>();

            services.AddSingleton <ICommitmentApiConfiguration>(configuration.CommitmentsApiConfiguration);
            services.AddTransient <ICommitmentService, CommitmentService>();
            services.AddHttpClient <SecureHttpClient>();
            services.AddTransient <IAzureClientCredentialHelper, AzureClientCredentialHelper>();

            services.AddTransient <ITrainingProviderService, TrainingProviderService>();

            // Encoding Service
            services.AddSingleton <IEncodingService, EncodingService>();
        }
        public static void AddDatabaseRegistration(this IServiceCollection services, ProvideFeedbackEmployerWebConfiguration configuration, IWebHostEnvironment environment)
        {
            services.AddTransient <IDbConnection>(c =>
            {
                const string azureResource = "https://database.windows.net/";
                string connectionString    = configuration.EmployerFeedbackDatabaseConnectionString;

                if (environment.IsDevelopment())
                {
                    return(new SqlConnection(connectionString));
                }

                AzureServiceTokenProvider azureServiceTokenProvider = new AzureServiceTokenProvider();
                return(new SqlConnection
                {
                    ConnectionString = connectionString,
                    AccessToken = azureServiceTokenProvider.GetAccessTokenAsync(azureResource).Result
                });
            });
        }
        public static IServiceCollection AddDasDataProtection(this IServiceCollection services, ProvideFeedbackEmployerWebConfiguration webConfiguration, IWebHostEnvironment environment)
        {
            if (!environment.IsDevelopment())
            {
                var redisConnectionString      = webConfiguration.RedisConnectionString;
                var dataProtectionKeysDatabase = webConfiguration.DataProtectionKeysDatabase;

                var redis = ConnectionMultiplexer.Connect($"{redisConnectionString},{dataProtectionKeysDatabase}");

                services.AddDataProtection()
                .SetApplicationName("das-employer-provide-feedback")
                .PersistKeysToStackExchangeRedis(redis, "DataProtection-Keys");
            }
            return(services);
        }
Exemple #9
0
        public static IServiceCollection AddCache(this IServiceCollection services, IHostEnvironment environment, ProvideFeedbackEmployerWebConfiguration config)
        {
            if (environment.IsDevelopment())
            {
                services.AddDistributedMemoryCache();
            }
            else
            {
                services.AddStackExchangeRedisCache(
                    options => { options.Configuration = config.RedisConnectionString; });
            }

            return(services);
        }