-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
27 changed files
with
402 additions
and
110 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
2 changes: 1 addition & 1 deletion
2
...odels/v1/LongRunningWorkloads/Progress.cs → ...s/v1/LongRunningWorkloads/ProgressTest.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
6 changes: 6 additions & 0 deletions
6
az-appservice-dotnet.xUnit/services/v1/CosmoDbProcessingStateService/ContainerCollection.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,6 @@ | ||
namespace az_appservice_dotnet.xUnit.services.v1.CosmoDbProcessingStateService; | ||
|
||
[CollectionDefinition("CosmosContainer collection")] | ||
public class ContainerCollection : ICollectionFixture<ContainerFixture> | ||
{ | ||
} |
42 changes: 42 additions & 0 deletions
42
az-appservice-dotnet.xUnit/services/v1/CosmoDbProcessingStateService/ContainerFixture.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,42 @@ | ||
using Microsoft.Azure.Cosmos; | ||
using Microsoft.Extensions.Configuration; | ||
|
||
namespace az_appservice_dotnet.xUnit.services.v1.CosmoDbProcessingStateService; | ||
|
||
public class ContainerFixture : IDisposable | ||
{ | ||
public readonly Container Container; | ||
|
||
public ContainerFixture() | ||
{ | ||
IConfiguration config = new ConfigurationBuilder() | ||
.AddJsonFile("appsettings.json", false) | ||
.Build(); | ||
|
||
string? endpointUri = config.GetSection("CosmosDb")["EndPointUri"]; | ||
if (endpointUri == null) | ||
throw new Exception("App.config is missing the EndPointUri setting"); | ||
|
||
string? primaryKey = config.GetSection("CosmosDb")["PrimaryKey"]; | ||
if (primaryKey == null) | ||
throw new Exception("App.config is missing the PrimaryKey setting"); | ||
|
||
var client = new CosmosClient(endpointUri, primaryKey, new CosmosClientOptions()); | ||
var databaseTask = client.CreateDatabaseIfNotExistsAsync("AkvTraining"); | ||
databaseTask.Wait(); | ||
var database = databaseTask.Result.Database; | ||
var containerTask = database.CreateContainerIfNotExistsAsync("_test_States", "/taskId"); | ||
containerTask.Wait(); | ||
Container = containerTask.Result.Container; | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
Container.DeleteContainerAsync().Wait(); | ||
} | ||
|
||
public az_appservice_dotnet.services.v1.CosmoDbProcessingStateService GetService() | ||
{ | ||
return new az_appservice_dotnet.services.v1.CosmoDbProcessingStateService(Container); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
...pservice-dotnet.xUnit/services/v1/CosmoDbProcessingStateService/CreateInitialStateTest.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,44 @@ | ||
using System.Net; | ||
using az_appservice_dotnet.services; | ||
using Microsoft.Azure.Cosmos; | ||
|
||
namespace az_appservice_dotnet.xUnit.services.v1.CosmoDbProcessingStateService; | ||
|
||
[Collection("CosmosContainer collection")] | ||
public class CreateInitialStateTest | ||
{ | ||
readonly ContainerFixture _containerFixture; | ||
|
||
public CreateInitialStateTest(ContainerFixture containerFixture) | ||
{ | ||
_containerFixture = containerFixture; | ||
} | ||
|
||
[Fact] | ||
public async Task Should_Create() | ||
{ | ||
// Arrange | ||
var sut = _containerFixture.GetService(); | ||
var taskId = 777; | ||
var fileName = "file1.txt"; | ||
// Act | ||
var actual = await sut.CreateInitialState(taskId, fileName); | ||
// Assert | ||
Assert.IsType<IProcessingStateService.State>(actual); | ||
Assert.Equal((int)taskId, (int)actual.TaskId); | ||
Assert.Equal(fileName, actual.FileName); | ||
|
||
var readResponse = await _containerFixture.Container.ReadItemAsync<az_appservice_dotnet.services.v1.CosmoDbProcessingStateService.CosmosState>(actual.Id, | ||
new PartitionKey(actual.TaskId)); | ||
Assert.Equal(HttpStatusCode.OK, readResponse.StatusCode); | ||
var read = readResponse.Resource; | ||
Assert.IsType<az_appservice_dotnet.services.v1.CosmoDbProcessingStateService.CosmosState>(read); | ||
Assert.Equal(actual.Id, read.Id); | ||
Assert.Equal((int)actual.TaskId, read.TaskId); | ||
Assert.Equal(actual.Status, read.Status); | ||
Assert.Equal(actual.OriginalFileUrl, read.OriginalFileUrl); | ||
Assert.Equal(actual.ProcessedFileUrl, read.ProcessedFileUrl); | ||
Assert.Equal(actual.FileName, read.FileName); | ||
} | ||
|
||
} |
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
2 changes: 1 addition & 1 deletion
2
...s/v1/LongRunningWorkloadFactory/Create.cs → .../LongRunningWorkloadFactory/CreateTest.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
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 |
---|---|---|
@@ -1,34 +1,34 @@ | ||
using System.Runtime.CompilerServices; | ||
using az_appservice_dotnet.models; | ||
using az_appservice_dotnet.models; | ||
using az_appservice_dotnet.models.v1; | ||
using az_appservice_dotnet.routing; | ||
using az_appservice_dotnet.routing.v1; | ||
using az_appservice_dotnet.services; | ||
using az_appservice_dotnet.services.v1; | ||
|
||
namespace az_appservice_dotnet; | ||
|
||
static class Program | ||
{ | ||
public static void Main(string[] args) | ||
public static async Task Main(string[] args) | ||
{ | ||
var builder = WebApplication.CreateBuilder(args); | ||
builder.Services.AddSingleton<ILongRunningWorkloadFactory, LongRunningWorkloadFactory>(); | ||
builder.Services.AddSingleton<ILongRunningTasksService, LongRunningTasksService>(); | ||
builder.Services.AddSingleton<IImageProviderService, FakeImageProviderService>(); | ||
builder.Services.AddSingleton<IProcessingStateService, CosmoDbProcessingStateService>(); | ||
var app = builder.Build(); | ||
|
||
app.MapGet("/", () => "Hello World!"); | ||
app.MapGet("/", () => Results.Ok("Hello World!")); | ||
app.MapGroup("/1") | ||
.MapApi1(app); | ||
|
||
app.Run(); | ||
await app.RunAsync(); | ||
} | ||
|
||
static RouteGroupBuilder MapApi1(this RouteGroupBuilder group, WebApplication app) | ||
{ | ||
group.MapPing(); | ||
group.MapBlobs(); | ||
group.MapImages(app.Services.GetService<IImageProviderService>()); | ||
group.MapImages(); | ||
return group; | ||
} | ||
} |
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
...-dotnet/routing/RouteGroupBuilderBlobs.cs → ...tnet/routing/v1/RouteGroupBuilderBlobs.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
20 changes: 20 additions & 0 deletions
20
az-appservice-dotnet/routing/v1/RouteGroupBuilderImages.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,20 @@ | ||
using az_appservice_dotnet.services; | ||
|
||
namespace az_appservice_dotnet.routing.v1; | ||
|
||
public static class RouteGroupBuilderImages | ||
{ | ||
public static RouteGroupBuilder MapImages(this RouteGroupBuilder group) | ||
{ | ||
group.MapPost("/images", Create); | ||
group.MapGet("/images", Create); | ||
return group; | ||
} | ||
|
||
private static IResult Create(IImageProviderService imageProviderService) | ||
{ | ||
var file = imageProviderService.GetFileObject("image", 1); | ||
|
||
return TypedResults.Created($"/images/{file.Name}", new { Name = file.Name }); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...-dotnet/routing/RouteGroupBuilderTasks.cs → ...tnet/routing/v1/RouteGroupBuilderTasks.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
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,20 @@ | ||
namespace az_appservice_dotnet.routing.v1; | ||
|
||
public static class RouterGroupBuilderPing | ||
{ | ||
public static RouteGroupBuilder MapPing(this RouteGroupBuilder group) | ||
{ | ||
group | ||
.MapGet("/ping", () => "pong") | ||
.AddEndpointFilter(async (context, next) => | ||
{ | ||
if (!context.HttpContext.Request.Query.ContainsKey("workload")) | ||
{ | ||
return TypedResults.UnprocessableEntity("Missing workload query parameter"); | ||
} | ||
|
||
return await next(context); | ||
}); | ||
return group; | ||
} | ||
} |
Oops, something went wrong.