Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,8 @@ public virtual async Task<IActionResult> CreateAsync(CancellationToken cancellat
Logger.LogInformation("CreateAsync: {entity}", entity.ToJsonString());

await AuthorizeRequestAsync(TableOperation.Create, entity, cancellationToken).ConfigureAwait(false);

await AccessControlProvider.PreCommitHookAsync(TableOperation.Create, entity, cancellationToken).ConfigureAwait(false);

await Repository.CreateAsync(entity, cancellationToken).ConfigureAwait(false);

await PostCommitHookAsync(TableOperation.Create, entity, cancellationToken).ConfigureAwait(false);

Logger.LogInformation("CreateAsync: created {entity}", entity.ToJsonString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ public virtual async Task<IActionResult> ReplaceAsync([FromRoute] string id, Can
await Repository.ReplaceAsync(entity, version, cancellationToken).ConfigureAwait(false);
await PostCommitHookAsync(TableOperation.Update, entity, cancellationToken).ConfigureAwait(false);

Logger.LogInformation("ReplaceAsync: replaced {entity}", entity.ToJsonString());
return Ok(entity);
// Under certain (repository specific) circumstances, the entity may not be modified by the ReplaceAsync
// operation, so we have to do an additional GET to ensure we are getting the right version of the entity
TEntity? updatedEntity = await Repository.ReadAsync(id, cancellationToken).ConfigureAwait(false);

Logger.LogInformation("ReplaceAsync: replaced {entity}", updatedEntity.ToJsonString());
return Ok(updatedEntity);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public async Task ReplaceAsync_Works(bool includeIfMatch, bool includeLastModifi
await accessProvider.Received(1).PostCommitHookAsync(TableOperation.Update, Arg.Any<TableData>(), Arg.Any<CancellationToken>());
firedEvents.Should().ContainSingle();

await repository.Received(1).ReadAsync(entity.Id, Arg.Any<CancellationToken>());
await repository.Received(2).ReadAsync(entity.Id, Arg.Any<CancellationToken>());
await repository.Received(1).ReplaceAsync(Arg.Any<TableData>(), Arg.Any<byte[]>(), Arg.Any<CancellationToken>());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#define CAPTURE_STRING_JSON

using CommunityToolkit.Datasync.TestCommon;
using CommunityToolkit.Datasync.TestCommon.Databases;
using CommunityToolkit.Datasync.TestCommon.Models;
using CommunityToolkit.Datasync.TestService.AccessControlProviders;
using Microsoft.AspNetCore.Localization;
using System.Net;
using System.Net.Http.Json;
using System.Text;
Expand All @@ -24,9 +24,14 @@ public async Task Replace_Returns200()
HttpResponseMessage response = await this.client.PutAsJsonAsync($"{this.factory.MovieEndpoint}/{existingMovie.Id}", existingMovie, this.serializerOptions);
response.Should().HaveStatusCode(HttpStatusCode.OK);

#if CAPTURE_STRING_JSON
string jsonContent = await response.Content.ReadAsStringAsync();
ClientMovie clientMovie = JsonSerializer.Deserialize<ClientMovie>(jsonContent, this.serializerOptions);
#else
ClientMovie clientMovie = await response.Content.ReadFromJsonAsync<ClientMovie>(this.serializerOptions);
#endif

clientMovie.Should().NotBeNull().And.HaveChangedMetadata(existingMovie, this.StartTime).And.BeEquivalentTo<IMovie>(existingMovie);

InMemoryMovie inMemoryMovie = this.factory.GetServerEntityById<InMemoryMovie>(clientMovie.Id);
clientMovie.Should().HaveEquivalentMetadataTo(inMemoryMovie).And.BeEquivalentTo<IMovie>(inMemoryMovie);
response.Headers.ETag.Should().BeETag($"\"{clientMovie.Version}\"");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:6523",
"sslPort": 44367
}
},
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "weatherforecast",
"launchUrl": "api/in-memory/movies",
"applicationUrl": "http://localhost:5082",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
Expand All @@ -23,16 +15,8 @@
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "weatherforecast",
"applicationUrl": "https://localhost:7186;http://localhost:5082",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "weatherforecast",
"launchUrl": "api/in-memory/movies",
"applicationUrl": "https://localhost:5001;http://localhost:5082",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
Expand Down
Loading