-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
271e4f7
commit 4b85f16
Showing
16 changed files
with
347 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
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
22 changes: 22 additions & 0 deletions
22
test/Microsoft.Health.SqlServer.Tests.E2E/Microsoft.Health.SqlServer.Tests.E2E.csproj
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,22 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netcoreapp3.1</TargetFramework> | ||
<IsPackable>false</IsPackable> | ||
<RootNamespace>Microsoft.Health.SqlServer.Tests.E2E</RootNamespace> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" /> | ||
<PackageReference Include="xunit" Version="2.4.0" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" /> | ||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="3.1.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\Microsoft.Health.SqlServer.Api\Microsoft.Health.SqlServer.Api.csproj" /> | ||
<ProjectReference Include="..\..\src\Microsoft.Health.SqlServer\Microsoft.Health.SqlServer.csproj" /> | ||
<ProjectReference Include="..\Microsoft.Health.SqlServer.Web\Microsoft.Health.SqlServer.Web.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
151 changes: 151 additions & 0 deletions
151
test/Microsoft.Health.SqlServer.Tests.E2E/SchemaTests.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,151 @@ | ||
// ------------------------------------------------------------------------------------------------- | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information. | ||
// ------------------------------------------------------------------------------------------------- | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Net; | ||
using System.Net.Http; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Mvc.Testing; | ||
using Microsoft.Health.SqlServer.Web; | ||
using Newtonsoft.Json.Linq; | ||
using Xunit; | ||
|
||
namespace Microsoft.Health.SqlServer.Tests.E2E | ||
{ | ||
public class SchemaTests : IClassFixture<WebApplicationFactory<Startup>> | ||
{ | ||
private readonly WebApplicationFactory<Startup> _factory; | ||
private readonly HttpClient _client; | ||
|
||
public SchemaTests(WebApplicationFactory<Startup> factory) | ||
{ | ||
_factory = factory; | ||
_client = factory.CreateClient(); | ||
} | ||
|
||
public static IEnumerable<object[]> Data => | ||
new List<object[]> | ||
{ | ||
new object[] { "_schema/compatibility" }, | ||
new object[] { "_schema/versions/current" }, | ||
}; | ||
|
||
[Fact] | ||
public async Task GivenAServerThatHasSchemas_WhenRequestingAvailable_JsonShouldBeReturned() | ||
{ | ||
var request = new HttpRequestMessage | ||
{ | ||
Method = HttpMethod.Get, | ||
RequestUri = new Uri(_client.BaseAddress, "_schema/versions"), | ||
}; | ||
|
||
HttpResponseMessage response = await _client.SendAsync(request); | ||
|
||
Assert.Equal(HttpStatusCode.OK, response.StatusCode); | ||
|
||
var jArrayResponse = JArray.Parse(await response.Content.ReadAsStringAsync()); | ||
|
||
Assert.NotEmpty(jArrayResponse); | ||
|
||
JToken firstResult = jArrayResponse.First; | ||
string scriptUrl = $"/_schema/versions/{firstResult["id"]}/script"; | ||
Assert.Equal(scriptUrl, firstResult["script"]); | ||
} | ||
|
||
[Theory] | ||
[MemberData(nameof(Data))] | ||
public async Task GivenGetMethod_WhenRequestingSchema_TheServerShouldReturnNotImplemented(string path) | ||
{ | ||
await SendAndVerifyStatusCode(HttpMethod.Get, path, HttpStatusCode.NotImplemented); | ||
} | ||
|
||
[Theory] | ||
[MemberData(nameof(Data))] | ||
public async Task GivenPostMethod_WhenRequestingSchema_TheServerShouldReturnNotFound(string path) | ||
{ | ||
await SendAndVerifyStatusCode(HttpMethod.Post, path, HttpStatusCode.NotFound); | ||
} | ||
|
||
[Theory] | ||
[MemberData(nameof(Data))] | ||
public async Task GivenPutMethod_WhenRequestingSchema_TheServerShouldReturnNotFound(string path) | ||
{ | ||
await SendAndVerifyStatusCode(HttpMethod.Put, path, HttpStatusCode.NotFound); | ||
} | ||
|
||
[Theory] | ||
[MemberData(nameof(Data))] | ||
public async Task GivenDeleteMethod_WhenRequestingSchema_TheServerShouldReturnNotFound(string path) | ||
{ | ||
await SendAndVerifyStatusCode(HttpMethod.Delete, path, HttpStatusCode.NotFound); | ||
} | ||
|
||
[Fact] | ||
public async Task GivenNonIntegerVersion_WhenRequestingScript_TheServerShouldReturnNotFound() | ||
{ | ||
await SendAndVerifyStatusCode(HttpMethod.Get, "_schema/versions/abc/script", HttpStatusCode.NotFound); | ||
} | ||
|
||
[Fact] | ||
public async Task GivenPostMethod_WhenRequestingScript_TheServerShouldReturnNotFound() | ||
{ | ||
await SendAndVerifyStatusCode(HttpMethod.Post, "_schema/versions/1/script", HttpStatusCode.NotFound); | ||
} | ||
|
||
[Fact] | ||
public async Task GivenPutMethod_WhenRequestingScript_TheServerShouldReturnNotFound() | ||
{ | ||
await SendAndVerifyStatusCode(HttpMethod.Put, "_schema/versions/1/script", HttpStatusCode.NotFound); | ||
} | ||
|
||
[Fact] | ||
public async Task GivenDeleteMethod_WhenRequestingScript_TheServerShouldReturnNotFound() | ||
{ | ||
await SendAndVerifyStatusCode(HttpMethod.Delete, "_schema/versions/1/script", HttpStatusCode.NotFound); | ||
} | ||
|
||
[Fact] | ||
public async Task GivenSchemaIdFound_WhenRequestingScript_TheServerShouldReturnScript() | ||
{ | ||
var request = new HttpRequestMessage | ||
{ | ||
Method = HttpMethod.Get, | ||
RequestUri = new Uri(_client.BaseAddress, "_schema/versions/1/script"), | ||
}; | ||
HttpResponseMessage response = await _client.SendAsync(request); | ||
|
||
Assert.Equal(HttpStatusCode.OK, response.StatusCode); | ||
|
||
string script = response.Content.ToString(); | ||
|
||
Assert.NotEmpty(script); | ||
} | ||
|
||
[Fact] | ||
public async Task GivenSchemaIdNotFound_WhenRequestingScript_TheServerShouldReturnNotFoundException() | ||
{ | ||
await SendAndVerifyStatusCode(HttpMethod.Get, "_schema/versions/0/script", HttpStatusCode.NotFound); | ||
} | ||
|
||
private async Task SendAndVerifyStatusCode(HttpMethod httpMethod, string path, HttpStatusCode httpStatusCode) | ||
{ | ||
var request = new HttpRequestMessage | ||
{ | ||
Method = httpMethod, | ||
RequestUri = new Uri(_client.BaseAddress, path), | ||
}; | ||
|
||
// Setting the contentType explicitly because POST/PUT/PATCH throws UnsupportedMediaType | ||
using (var content = new StringContent(" ", Encoding.UTF8, "application/json")) | ||
{ | ||
request.Content = content; | ||
HttpResponseMessage response = await _client.SendAsync(request); | ||
Assert.Equal(httpStatusCode, response.StatusCode); | ||
} | ||
} | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
test/Microsoft.Health.SqlServer.Web/Features/Schema/Migrations/1.sql
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 @@ | ||
SELECT 1 |
13 changes: 13 additions & 0 deletions
13
test/Microsoft.Health.SqlServer.Web/Features/Schema/SchemaVersion.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,13 @@ | ||
// ------------------------------------------------------------------------------------------------- | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information. | ||
// ------------------------------------------------------------------------------------------------- | ||
|
||
namespace Microsoft.Health.SqlServer.Web.Features.Schema | ||
{ | ||
public enum SchemaVersion | ||
{ | ||
Version1 = 1, | ||
Version2 = 2, | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
test/Microsoft.Health.SqlServer.Web/Microsoft.Health.SqlServer.Web.csproj
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,25 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netcoreapp3.1</TargetFramework> | ||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.1.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\Microsoft.Health.SqlServer.Api\Microsoft.Health.SqlServer.Api.csproj" /> | ||
<ProjectReference Include="..\..\src\Microsoft.Health.SqlServer\Microsoft.Health.SqlServer.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<None Remove="Features\Schema\Migrations\1.sql" /> | ||
<EmbeddedResource Include="Features\Schema\Migrations\1.sql" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Folder Include="Properties" /> | ||
</ItemGroup> | ||
</Project> |
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,22 @@ | ||
// ------------------------------------------------------------------------------------------------- | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information. | ||
// ------------------------------------------------------------------------------------------------- | ||
|
||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.Extensions.Hosting; | ||
|
||
namespace Microsoft.Health.SqlServer.Web | ||
{ | ||
public static class Program | ||
{ | ||
public static void Main(string[] args) | ||
{ | ||
CreateHostBuilder(args).Build().Run(); | ||
} | ||
|
||
public static IHostBuilder CreateHostBuilder(string[] args) => | ||
Host.CreateDefaultBuilder(args) | ||
.ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup<Startup>(); }); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
test/Microsoft.Health.SqlServer.Web/Properties/launchSettings.json
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,11 @@ | ||
{ | ||
"profiles": { | ||
"Microsoft.Health.SqlServer.Web": { | ||
"commandName": "Project", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
}, | ||
"applicationUrl": "https://localhost:63637/" | ||
} | ||
} | ||
} |
Oops, something went wrong.