public IActionResult Registration(RegistrationCredential registrationCred) { User loginningUserName = _sqlUserHandler.GetUser(registrationCred.UserName); bool isLoginningUserEmailTaken = _sqlUserHandler.GetUsers().Any(x => x.Email == registrationCred.Email); if (loginningUserName != null || isLoginningUserEmailTaken) { return(BadRequest("username or email already taken")); } Address userAddress = new Address(registrationCred.City, registrationCred.Street, registrationCred.HouseNumber, registrationCred.PostCode); User user = new User(registrationCred.UserName, registrationCred.Email, userAddress, registrationCred.Password); // we should validate the password as well if it strong enough _sqlUserHandler.AddUser(user); return(Ok("successful registration")); }
public async Task Test13_Registration_UsedUsernameCredential_ShouldNotReturnOk() { // Arrange string url = "api/registration"; Address address = new Address("city", "street", 55, "11"); RegistrationCredential registrationCred = new RegistrationCredential("username", "password", "*****@*****.**", "city", "street", 11, "postCode"); string output = JsonConvert.SerializeObject(registrationCred); var req = new HttpRequestMessage(HttpMethod.Post, url) { Content = new StringContent(output, Encoding.UTF8, "application/json") }; // Act var response = await _client.SendAsync(req); // Assert Assert.IsFalse(response.StatusCode == HttpStatusCode.OK); }