public async Task GivenValidCredentials_RespondsWithCreatedUserId() { var url = GetRegisterUrl(); const string emailAddress = "*****@*****.**"; const string password = "******"; var register = new TestRegisterRequestBuilder() .WithEmailAddress(emailAddress) .WithPassword(password) .Build(); // Act var response = await HttpClient.PostAsJsonAsync(url, register); // Assert var user = await _userCollection .Find(FilterDefinition <UserEntity> .Empty) .FirstOrDefaultAsync(); Assert.Multiple(() => { Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.NoContent)); Assert.That(user.EmailAddress, Is.EqualTo(emailAddress)); var isPasswordValue = BCrypt.Net.BCrypt.Verify(password, user.Password); Assert.That(isPasswordValue); }); }
public async Task GivenEmailAlreadyUsed_RespondsWithConflict() { var url = GetRegisterUrl(); const string emailAddress = "*****@*****.**"; const string password = "******"; var register = new TestRegisterRequestBuilder() .WithEmailAddress(emailAddress) .WithPassword(password) .Build(); var user = new TestUserEntityBuilder() .WithId(Guid.NewGuid()) .WithEmailAddress(emailAddress) .Build(); await _userCollection.InsertOneAsync(user); // Act var response = await HttpClient.PostAsJsonAsync(url, register); // Assert var responseData = await response.Content.ReadFromJsonAsync <ExceptionResponse>(); Assert.Multiple(() => { Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.Conflict)); Assert.That(responseData.ExceptionCode, Is.EqualTo((int)ExceptionCode.DataAlreadyExists)); Assert.That(responseData.TechnicalMessage, Is.Not.Null); Assert.That(responseData.UserMessage, Is.EqualTo(ExceptionMessages.User.UserExistsWithEmail)); }); }
public async Task GivenNoEmailAddress_RespondsWithModelState() { var url = GetRegisterUrl(); const string emailAddress = null; const string password = "******"; var register = new TestRegisterRequestBuilder() .WithEmailAddress(emailAddress) .WithPassword(password) .Build(); // Act var response = await HttpClient.PostAsJsonAsync(url, register); // Assert var responseData = await response.Content.ReadFromJsonAsync <ValidationResponse>(); Assert.Multiple(() => { Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.BadRequest)); DiagnoseaAssert.Contains(responseData.Errors, nameof(RegisterRequest.EmailAddress), ExceptionMessages.Interchange.Required); }); }