fixes the tests
This commit is contained in:
parent
7edb2d7915
commit
21a41214b0
11 changed files with 79 additions and 55 deletions
|
|
@ -6,6 +6,7 @@ using Yavsc.Models;
|
|||
using Yavsc.Models.Blog;
|
||||
using Yavsc.Server.Helpers;
|
||||
using Yavsc.Tests.Shared;
|
||||
using Yavsc.Blogs.Tests.Fixtures;
|
||||
|
||||
namespace Yavsc.Blogs.Tests;
|
||||
|
||||
|
|
@ -46,7 +47,7 @@ public sealed class BlogApiTests : IClassFixture<BlogsWebServerFixture>
|
|||
_fixture.SeedUser("tester");
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>Build an authenticated client: a real
|
||||
/// <c>Authorization: Bearer <jwt></c> header where the JWT
|
||||
/// is signed by <see cref="TestTokenIssuer"/> and carries
|
||||
|
|
@ -94,7 +95,7 @@ public sealed class BlogApiTests : IClassFixture<BlogsWebServerFixture>
|
|||
using var http = NewClient();
|
||||
|
||||
var response = await http.GetAsync(
|
||||
_fixture.BlogUrl(),
|
||||
_fixture.BlogSpotUrl(),
|
||||
TestContext.Current.CancellationToken);
|
||||
|
||||
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||
|
|
@ -127,7 +128,7 @@ public sealed class BlogApiTests : IClassFixture<BlogsWebServerFixture>
|
|||
DateModified = DateTime.UtcNow
|
||||
};
|
||||
|
||||
var postResponse = await http.PostAsJsonAsync(_fixture.BlogUrl(), draft,
|
||||
var postResponse = await http.PostAsJsonAsync(_fixture.BlogSpotUrl(), draft,
|
||||
TestContext.Current.CancellationToken);
|
||||
Assert.Equal(HttpStatusCode.Created, postResponse.StatusCode);
|
||||
|
||||
|
|
@ -140,7 +141,7 @@ public sealed class BlogApiTests : IClassFixture<BlogsWebServerFixture>
|
|||
Assert.Equal(draft.Title, created.Title);
|
||||
|
||||
// The list should now contain exactly one entry.
|
||||
var listResponse = await http.GetAsync(_fixture.BlogUrl(),
|
||||
var listResponse = await http.GetAsync(_fixture.BlogSpotUrl(),
|
||||
TestContext.Current.CancellationToken);
|
||||
Assert.Equal(HttpStatusCode.OK, listResponse.StatusCode);
|
||||
|
||||
|
|
@ -168,7 +169,7 @@ public sealed class BlogApiTests : IClassFixture<BlogsWebServerFixture>
|
|||
DateModified = DateTime.UtcNow
|
||||
};
|
||||
|
||||
var postResponse = await http.PostAsJsonAsync(_fixture.BlogUrl(), draft,
|
||||
var postResponse = await http.PostAsJsonAsync(_fixture.BlogSpotUrl(), draft,
|
||||
TestContext.Current.CancellationToken);
|
||||
Assert.Equal(HttpStatusCode.Created, postResponse.StatusCode);
|
||||
|
||||
|
|
@ -178,7 +179,7 @@ public sealed class BlogApiTests : IClassFixture<BlogsWebServerFixture>
|
|||
Assert.NotNull(created);
|
||||
Assert.Equal("tester", created!.AuthorId);
|
||||
|
||||
var listResponse = await http.GetAsync(_fixture.BlogUrl(),
|
||||
var listResponse = await http.GetAsync(_fixture.BlogSpotUrl(),
|
||||
TestContext.Current.CancellationToken);
|
||||
Assert.Equal(HttpStatusCode.OK, listResponse.StatusCode);
|
||||
|
||||
|
|
@ -206,7 +207,7 @@ public sealed class BlogApiTests : IClassFixture<BlogsWebServerFixture>
|
|||
DateModified = DateTime.UtcNow
|
||||
};
|
||||
|
||||
var postResponse = await http.PostAsJsonAsync(_fixture.BlogUrl(), draft,
|
||||
var postResponse = await http.PostAsJsonAsync(_fixture.BlogSpotUrl(), draft,
|
||||
TestContext.Current.CancellationToken);
|
||||
Assert.Equal(HttpStatusCode.Created, postResponse.StatusCode);
|
||||
|
||||
|
|
@ -255,7 +256,7 @@ public sealed class BlogApiTests : IClassFixture<BlogsWebServerFixture>
|
|||
// the framework returns 401. This is the proof that the
|
||||
// production policy is wired in the test host and not
|
||||
// short-circuited by a test-only auth bypass.
|
||||
var response = await http.GetAsync(_fixture.BlogUrl(),
|
||||
var response = await http.GetAsync(_fixture.BlogSpotUrl(),
|
||||
TestContext.Current.CancellationToken);
|
||||
Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
|
||||
}
|
||||
|
|
@ -283,7 +284,7 @@ public sealed class BlogApiTests : IClassFixture<BlogsWebServerFixture>
|
|||
DateCreated = DateTime.UtcNow,
|
||||
DateModified = DateTime.UtcNow
|
||||
};
|
||||
var postResponse = await http.PostAsJsonAsync(_fixture.BlogUrl(), draft,
|
||||
var postResponse = await http.PostAsJsonAsync(_fixture.BlogSpotUrl(), draft,
|
||||
TestContext.Current.CancellationToken);
|
||||
Assert.Equal(HttpStatusCode.Created, postResponse.StatusCode);
|
||||
|
||||
|
|
@ -302,13 +303,13 @@ public sealed class BlogApiTests : IClassFixture<BlogsWebServerFixture>
|
|||
DateCreated = created.DateCreated,
|
||||
DateModified = DateTime.UtcNow
|
||||
};
|
||||
var putResponse = await http.PutAsJsonAsync(_fixture.BlogUrl()+$"/{created.Id}",
|
||||
var putResponse = await http.PutAsJsonAsync(_fixture.BlogSpotUrl()+$"/{created.Id}",
|
||||
update,
|
||||
TestContext.Current.CancellationToken);
|
||||
Assert.Equal(HttpStatusCode.NoContent, putResponse.StatusCode);
|
||||
|
||||
// The list should now reflect the new title.
|
||||
var listResponse = await http.GetAsync(_fixture.BlogUrl(),
|
||||
var listResponse = await http.GetAsync(_fixture.BlogSpotUrl(),
|
||||
TestContext.Current.CancellationToken);
|
||||
Assert.Equal(HttpStatusCode.OK, listResponse.StatusCode);
|
||||
using var doc = JsonDocument.Parse(
|
||||
|
|
@ -336,19 +337,19 @@ public sealed class BlogApiTests : IClassFixture<BlogsWebServerFixture>
|
|||
DateCreated = DateTime.UtcNow,
|
||||
DateModified = DateTime.UtcNow
|
||||
};
|
||||
var postResponse = await http.PostAsJsonAsync(_fixture.BlogUrl(), draft,
|
||||
var postResponse = await http.PostAsJsonAsync(_fixture.BlogSpotUrl(), draft,
|
||||
TestContext.Current.CancellationToken);
|
||||
var created = (await postResponse.Content.ReadFromJsonAsync<BlogPost>(
|
||||
TestContext.Current.CancellationToken
|
||||
))!;
|
||||
|
||||
var deleteResponse = await http.DeleteAsync(_fixture.BlogUrl()+$"/{created.Id}",
|
||||
var deleteResponse = await http.DeleteAsync(_fixture.BlogSpotUrl()+$"/{created.Id}",
|
||||
TestContext.Current.CancellationToken
|
||||
);
|
||||
Assert.Equal(HttpStatusCode.OK, deleteResponse.StatusCode);
|
||||
|
||||
// The list should now be empty.
|
||||
var listResponse = await http.GetAsync(_fixture.BlogUrl(),
|
||||
var listResponse = await http.GetAsync(_fixture.BlogSpotUrl(),
|
||||
TestContext.Current.CancellationToken);
|
||||
String response = await listResponse.Content.ReadAsStringAsync(
|
||||
TestContext.Current.CancellationToken
|
||||
|
|
@ -391,7 +392,7 @@ public sealed class BlogApiTests : IClassFixture<BlogsWebServerFixture>
|
|||
DateModified = DateTime.UtcNow
|
||||
};
|
||||
|
||||
var response = await http.PostAsJsonAsync(_fixture.BlogUrl(), draft,
|
||||
var response = await http.PostAsJsonAsync(_fixture.BlogSpotUrl(), draft,
|
||||
TestContext.Current.CancellationToken);
|
||||
|
||||
// Dump the body on failure so the test name + the response
|
||||
|
|
@ -436,7 +437,7 @@ public sealed class BlogApiTests : IClassFixture<BlogsWebServerFixture>
|
|||
DateModified = DateTime.UtcNow
|
||||
};
|
||||
|
||||
var response = await http.PostAsJsonAsync(_fixture.BlogUrl(), draft,
|
||||
var response = await http.PostAsJsonAsync(_fixture.BlogSpotUrl(), draft,
|
||||
TestContext.Current.CancellationToken);
|
||||
|
||||
if (response.StatusCode != HttpStatusCode.BadRequest)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue