-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
49bd9d1
commit b155848
Showing
6 changed files
with
100 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
tests/CommunityToolkit.Datasync.Client.Test/Live/SampleServerTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System.Net; | ||
using System.Net.Http.Json; | ||
|
||
namespace CommunityToolkit.Datasync.Client.Test.Live; | ||
|
||
[ExcludeFromCodeCoverage] | ||
public class SampleServerTests | ||
{ | ||
private readonly bool liveTestsAreEnabled = Environment.GetEnvironmentVariable("DATASYNC_SERVICE_ENDPOINT") is not null; | ||
private readonly string serviceEndpoint = Environment.GetEnvironmentVariable("DATASYNC_SERVICE_ENDPOINT"); | ||
|
||
[SkippableFact] | ||
public async Task Metadata_GetsSetByServer() | ||
{ | ||
Skip.IfNot(this.liveTestsAreEnabled); | ||
|
||
DateTimeOffset now = DateTimeOffset.UtcNow; | ||
HttpClient client = new(); | ||
TodoItem source = new() { Title = "Test item" }; | ||
HttpResponseMessage response = await client.PostAsJsonAsync($"{this.serviceEndpoint}/tables/TodoItem", source); | ||
|
||
response.Should().HaveHttpStatusCode(HttpStatusCode.Created); | ||
|
||
TodoItem result = await response.Content.ReadFromJsonAsync<TodoItem>(); | ||
result.Id.Should().NotBeNullOrEmpty(); | ||
result.UpdatedAt.Should().NotBeNull().And.BeAfter(now); | ||
result.Version.Should().NotBeNullOrEmpty(); | ||
result.Deleted.Should().BeFalse(); | ||
result.Title.Should().Be("Test item"); | ||
result.IsComplete.Should().BeFalse(); | ||
|
||
response.Headers.Location.Should().NotBeNull().And.BeEquivalentTo(new Uri($"{this.serviceEndpoint}/tables/TodoItem/{result.Id}")); | ||
response.Headers.ETag.ToString().Should().Be($"\"{result.Version}\""); | ||
} | ||
|
||
// This must match the TodoItem class in the server project. | ||
public class TodoItem | ||
{ | ||
public string Id { get; set; } | ||
public DateTimeOffset? UpdatedAt { get; set; } | ||
public string Version { get; set; } | ||
public bool Deleted { get; set; } | ||
public string Title { get; set; } | ||
public bool IsComplete { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters