public TermsOfServiceController_Tests() { var mockOptionsAccessor = Substitute.For <IOptions <IdentityOptions> >(); var mockPasswordHasher = Substitute.For <IPasswordHasher <UserModel> >(); var mockUserValidators = Substitute.For <IEnumerable <IUserValidator <UserModel> > >(); var mockPasswordValidators = Substitute.For <IEnumerable <IPasswordValidator <UserModel> > >(); var mockKeyNormalizer = Substitute.For <ILookupNormalizer>(); var mockErrors = Substitute.For <IdentityErrorDescriber>(); var mockServices = Substitute.For <IServiceProvider>(); var mockUserLogger = Substitute.For <ILogger <UserManager <UserModel> > >(); var fakeA3SContext = new A3SContextFake(new Microsoft.EntityFrameworkCore.DbContextOptions <A3SContext>()); mockConfiguration = Substitute.For <IConfiguration>(); var fakesCustomUserStore = new CustomUserStoreFake(fakeA3SContext, mockConfiguration); fakeUserManager = new CustomUserManagerFake(fakesCustomUserStore, mockOptionsAccessor, mockPasswordHasher, mockUserValidators, mockPasswordValidators, mockKeyNormalizer, mockErrors, mockServices, mockUserLogger); var mockContextAccessor = Substitute.For <IHttpContextAccessor>(); var mocClaimsFactory = Substitute.For <IUserClaimsPrincipalFactory <UserModel> >(); var mockSignInLogger = Substitute.For <ILogger <SignInManager <UserModel> > >(); var mockLdapAuthenticationModeRepository = Substitute.For <LdapAuthenticationModeRepository>(fakeA3SContext, mockConfiguration); var mockLdapConnectionService = Substitute.For <ILdapConnectionService>(); mockAuthenticationSchemeProvider = Substitute.For <IAuthenticationSchemeProvider>(); var mockUserConfirmation = Substitute.For <IUserConfirmation <UserModel> >(); fakeSignInManager = new CustomSignInManagerFake <UserModel>(fakeUserManager, mockContextAccessor, mocClaimsFactory, mockOptionsAccessor, mockSignInLogger, fakeA3SContext, mockAuthenticationSchemeProvider, mockLdapAuthenticationModeRepository, mockLdapConnectionService, mockUserConfirmation); termsOfServiceRepository = Substitute.For <ITermsOfServiceRepository>(); mockClientStore = Substitute.For <IClientStore>(); mockEventService = Substitute.For <IEventService>(); mockIdentityServerInteractionService = Substitute.For <IIdentityServerInteractionService>(); userModel = new UserModel() { UserName = "******", Id = Guid.NewGuid().ToString() }; termsOfServiceModel = new TermsOfServiceModel() { AgreementName = "Test agreement", Version = "2019.1", HtmlContents = "<html />", CssContents = ".my-class { font-size: 2; }" }; // Prepare controller contexts authorizationRequest = new AuthorizationRequest() { IdP = "testIdp", ClientId = "clientId1", LoginHint = "LoginHint" }; client = new Client() { EnableLocalLogin = true }; }
public AccountController_Tests() { var mockOptionsAccessor = Substitute.For <IOptions <IdentityOptions> >(); var mockPasswordHasher = Substitute.For <IPasswordHasher <UserModel> >(); var mockUserValidators = Substitute.For <IEnumerable <IUserValidator <UserModel> > >(); var mockPasswordValidators = Substitute.For <IEnumerable <IPasswordValidator <UserModel> > >(); var mockKeyNormalizer = Substitute.For <ILookupNormalizer>(); var mockErrors = Substitute.For <IdentityErrorDescriber>(); var mockServices = Substitute.For <IServiceProvider>(); var mockUserLogger = Substitute.For <ILogger <UserManager <UserModel> > >(); var fakeA3SContext = new A3SContextFake(new Microsoft.EntityFrameworkCore.DbContextOptions <A3SContext>()); mockConfiguration = Substitute.For <IConfiguration>(); var fakesCustomUserStore = new CustomUserStoreFake(fakeA3SContext, mockConfiguration); fakeUserManager = new CustomUserManagerFake(fakesCustomUserStore, mockOptionsAccessor, mockPasswordHasher, mockUserValidators, mockPasswordValidators, mockKeyNormalizer, mockErrors, mockServices, mockUserLogger); var mockContextAccessor = Substitute.For <IHttpContextAccessor>(); var mocClaimsFactory = Substitute.For <IUserClaimsPrincipalFactory <UserModel> >(); var mockSignInLogger = Substitute.For <ILogger <SignInManager <UserModel> > >(); var mockLdapAuthenticationModeRepository = Substitute.For <LdapAuthenticationModeRepository>(fakeA3SContext, mockConfiguration); var mockLdapConnectionService = Substitute.For <ILdapConnectionService>(); mockAuthenticationSchemeProvider = Substitute.For <IAuthenticationSchemeProvider>(); var mockUserConfirmation = Substitute.For <IUserConfirmation <UserModel> >(); fakeSignInManager = new CustomSignInManagerFake <UserModel>(fakeUserManager, mockContextAccessor, mocClaimsFactory, mockOptionsAccessor, mockSignInLogger, fakeA3SContext, mockAuthenticationSchemeProvider, mockLdapAuthenticationModeRepository, mockLdapConnectionService, mockUserConfirmation); mockIdentityServerInteractionService = Substitute.For <IIdentityServerInteractionService>(); mockClientStore = Substitute.For <IClientStore>(); mockEventService = Substitute.For <IEventService>(); urlTestEncoder = new UrlTestEncoder(); // Prepare controller contexts authorizationRequest = new AuthorizationRequest() { IdP = "testIdp", ClientId = "clientId1", LoginHint = "LoginHint" }; var mockAuthenticationHandler = Substitute.For <IAuthenticationHandler>(); mockAuthenticationSchemeProvider.GetAllSchemesAsync() .Returns(new List <AuthenticationScheme>() { new AuthenticationScheme("testName", AccountOptions.WindowsAuthenticationSchemeName, mockAuthenticationHandler.GetType()) }); client = new Client() { EnableLocalLogin = true }; client.IdentityProviderRestrictions.Add(AccountOptions.WindowsAuthenticationSchemeName); mockClientStore.FindEnabledClientByIdAsync(Arg.Any <string>()).Returns(client); userModel = new UserModel() { UserName = "******", Id = Guid.NewGuid().ToString() }; }