public StudentControllerTest() { MapperHelper.SetUpMapper(); _randomStudent = SetUpMockHelper.SetupStudents(); _unitOfWork = SetUpMockHelper.SetUpUnitOfWork(); _urlHelper = SetupUrlHelper(); httpContext = SetHttpContext().Object; }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddSingleton(Configuration); services.Configure<MongoDbSettings>(Configuration.GetSection("MongoDb")); services.AddSingleton<IUserStore<MongoIdentityUser>>(provider => { var options = provider.GetService<IOptions<MongoDbSettings>>(); var client = new MongoClient(options.Value.ConnectionString); var database = client.GetDatabase(options.Value.DatabaseName); return new MongoUserStore<MongoIdentityUser>(database); }); services.Configure<IdentityOptions>(options => { //var dataProtectionPath = Path.Combine(_env.WebRootPath, "identity-artifacts"); options.Cookies.ApplicationCookie.AuthenticationScheme = "ApplicationCookie"; //options.Cookies.ApplicationCookie.DataProtectionProvider = DataProtectionProvider.Create(dataProtectionPath); options.Lockout.AllowedForNewUsers = true; options.Password.RequireDigit = true; options.Password.RequireLowercase = false; options.Password.RequireUppercase = false; options.Password.RequireNonAlphanumeric = false; options.Password.RequiredLength = 6; }); // Services used by identity services.AddAuthentication(options => { // This is the Default value for ExternalCookieAuthenticationScheme options.SignInScheme = new IdentityCookieOptions().ExternalCookieAuthenticationScheme; }); // Hosting doesn't add IHttpContextAccessor by default services.TryAddSingleton<IHttpContextAccessor, HttpContextAccessor>(); services.AddOptions(); services.AddDataProtection(); services.TryAddSingleton<IdentityMarkerService>(); services.TryAddSingleton<IUserValidator<MongoIdentityUser>, UserValidator<MongoIdentityUser>>(); services.TryAddSingleton<IPasswordValidator<MongoIdentityUser>, PasswordValidator<MongoIdentityUser>>(); services.TryAddSingleton<IPasswordHasher<MongoIdentityUser>, PasswordHasher<MongoIdentityUser>>(); services.TryAddSingleton<ILookupNormalizer, UpperInvariantLookupNormalizer>(); services.TryAddSingleton<IdentityErrorDescriber>(); services.TryAddSingleton<ISecurityStampValidator, SecurityStampValidator<MongoIdentityUser>>(); services.TryAddSingleton<IUserClaimsPrincipalFactory<MongoIdentityUser>, UserClaimsPrincipalFactory<MongoIdentityUser>>(); services.TryAddSingleton<UserManager<MongoIdentityUser>, UserManager<MongoIdentityUser>>(); services.TryAddScoped<SignInManager<MongoIdentityUser>, SignInManager<MongoIdentityUser>>(); AddDefaultTokenProviders(services); services.AddMvc(); // Add application services. services.AddTransient<IEmailSender, AuthMessageSender>(); services.AddTransient<ISmsSender, AuthMessageSender>(); if (_env.EnvironmentName.Equals("Test")) { //services.AddScoped<IStudentRepository, LibraryRepository>(); services.AddScoped<IUnitOfWork>(serviceProvider => SetUpMockHelper.SetUpUnitOfWork()); services.AddSingleton<IActionContextAccessor, ActionContextAccessor>(); services.AddScoped<IUrlHelper>(implementationFactory => { var actionContext = implementationFactory.GetService<IActionContextAccessor>() .ActionContext; return new UrlHelper(actionContext); }); } }