Skip to content

Instantly share code, notes, and snippets.

@undrcrxwn
Created October 18, 2023 16:54
Show Gist options
  • Save undrcrxwn/03f9c7d84c6598f5922d9c82fdb18134 to your computer and use it in GitHub Desktop.
Save undrcrxwn/03f9c7d84c6598f5922d9c82fdb18134 to your computer and use it in GitHub Desktop.
public async Task Update_Positive(){
var registerRequest = new Register.Command("zanli_0", "Степной ишак", "qwerty123!", avatarUrl: null); var registerMessage = await _client.PostAsJsonAsync("/api/v1/users/register", registerRequest);
var registerResponse = await registerMessage.Content.ReadFromJsonAsync<Register.Response>()!;
var data = new Dictionary<string, string> {
{ "grant_type", "password" }, { "username", "zanli_0" },
{ "password", "qwerty123!" } };
var exchangeMessage = await _client.PostAsync("~/connect/token") _client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
var updateRequest = new Update.Command(
registerResponse!.Id, Username: "akavi",
DisplayName: "Akavi", AvatarUrl: "https://example.com/avatar.jpg",
OldPassword: null, NewPassword: null);
var updateMessage = await _client.PutAsJsonAsync($"/api/v1/users/{updateRequest.Id}", updateRequest);
updateMessage.Should().HaveStatusCode(HttpStatusCode.OK);
var updateResponse = await updateMessage.Content.ReadFromJsonAsync<Update.Response>(); updateResponse.Should().Be(new Update.Response(
updateRequest.Id, updateRequest.Username!,
updateRequest.DisplayName!, updateRequest.AvatarUrl));
var userUpdatedEvent = await _harness.Published.LastOrDefaultAsync<UserUpdatedEvent>();
userUpdatedEvent.Should().Be(new UserUpdatedEvent( updateResponse!.Id.ToString(),
updateResponse.Username, updateResponse.DisplayName,
updateResponse.AvatarUrl));
var getByIdMessage = await _client.GetAsync($"/api/v1/users/{registerResponse.Id}"); getByIdMessage.Should().HaveStatusCode(HttpStatusCode.OK);
var getByIdResponse = await getByIdMessage.Content.ReadFromJsonAsync<GetById.Response>();
getByIdResponse.Should().Be(new GetById.Response( updateRequest.Id,
updateRequest.Username!, updateRequest.DisplayName!,
updateRequest.AvatarUrl));}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment