protected override void Configure(ServiceStackHost appHost) { var dbFactory = new OrmLiteConnectionFactory(":memory:", SqliteDialect.Provider); appHost.Register <IDbConnectionFactory>(dbFactory); appHost.Register <IAuthRepository>(new OrmLiteAuthRepository(dbFactory)); appHost.Resolve <IAuthRepository>().InitSchema(); }
public void Requires_unique_UserName_and_Email() { ClearSession(); (HostContext.TryResolve <IAuthRepository>() as InMemoryAuthRepository)?.Clear(); var authRepo = new InMemoryAuthRepository(); authRepo.CreateUserAuth(new UserAuth { Email = "*****@*****.**", UserName = "******", }, "password"); appHost.Register <IAuthRepository>(authRepo); var service = new RegisterService { RegistrationValidator = new RegistrationValidator(), }; var request = new Register { DisplayName = "DisplayName", Email = "*****@*****.**", FirstName = "FirstName", LastName = "LastName", Password = "******", UserName = "******", }; var response = PostRegistrationError(service, request); var errors = response.GetFieldErrors(); Assert.That(errors.Count, Is.EqualTo(2)); Assert.That(errors[0].ErrorCode, Is.EqualTo("AlreadyExists")); Assert.That(errors[0].FieldName, Is.EqualTo("UserName")); Assert.That(errors[1].ErrorCode, Is.EqualTo("AlreadyExists")); Assert.That(errors[1].FieldName, Is.EqualTo("Email")); }
public void Requires_unique_UserName_and_Email() { var mockExistingUser = new UserAuth(); var mock = new Mock <IUserAuthRepository>(); mock.Setup(x => x.GetUserAuthByUserName(It.IsAny <string>())) .Returns(() => mockExistingUser); var mockUserAuth = mock.Object; appHost.Register <IAuthRepository>(mockUserAuth); var service = new RegisterService { RegistrationValidator = new RegistrationValidator(), }; var request = new Register { DisplayName = "DisplayName", Email = "*****@*****.**", FirstName = "FirstName", LastName = "LastName", Password = "******", UserName = "******", }; var response = PostRegistrationError(service, request); var errors = response.GetFieldErrors(); Assert.That(errors.Count, Is.EqualTo(2)); Assert.That(errors[0].ErrorCode, Is.EqualTo("AlreadyExists")); Assert.That(errors[0].FieldName, Is.EqualTo("UserName")); Assert.That(errors[1].ErrorCode, Is.EqualTo("AlreadyExists")); Assert.That(errors[1].FieldName, Is.EqualTo("Email")); }
protected override void Configure(ServiceStackHost appHost) { appHost.Register <IAuthRepository>(new InMemoryAuthRepository()); }