- 
                Notifications
    You must be signed in to change notification settings 
- Fork 18
[Backend API] Implement endpoint for create event details #213 #281
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 47 commits
e93e518
              b507d99
              75d7042
              f4172b7
              b94bd2c
              45b8e0c
              eaa6972
              290d971
              9177a70
              9ad61bf
              b729ad0
              c158308
              9b82301
              954c43e
              419a973
              30e911c
              f17bd29
              719d973
              a521674
              ec396dd
              b6f66f2
              ada1f22
              9385d2f
              69f35d3
              17c9799
              9548f5f
              9b50e75
              ca183e0
              1c6c2d6
              9bef6ab
              a836420
              7a7d848
              55db6d6
              473da19
              2b466c7
              d77ca2c
              3f4b1e1
              74d9674
              9516436
              a083391
              6274ead
              bbdbd68
              0ff2663
              f695a7c
              4b5a1bd
              78ffc92
              e503167
              1988f7f
              2587bd6
              File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -1,27 +1,30 @@ | ||
| { | ||
| "Logging": { | ||
| "LogLevel": { | ||
| "Default": "Information", | ||
| "Microsoft.AspNetCore": "Warning" | ||
| } | ||
| }, | ||
|  | ||
| "Azure": { | ||
| "OpenAI": { | ||
| "Instances": [ | ||
| { | ||
| "Endpoint": "https://{{location}}.api.cognitive.microsoft.com/", | ||
| "ApiKey": "{{api-key}}", | ||
| "DeploymentNames": [ | ||
| "deployment-name-1", | ||
| "deployment-name-2" | ||
| ] | ||
| } | ||
| ] | ||
| }, | ||
| "KeyVault": { | ||
| "VaultUri": "https://{{key-vault-name}}.vault.azure.net/", | ||
| "SecretName": "azure-openai-instances" | ||
| } | ||
| } | ||
| } | ||
| { | ||
| "Logging": { | ||
| "LogLevel": { | ||
| "Default": "Information", | ||
| "Microsoft.AspNetCore": "Warning" | ||
| } | ||
| }, | ||
|  | ||
| "Azure": { | ||
| "OpenAI": { | ||
| "Instances": [ | ||
| { | ||
| "Endpoint": "https://{{location}}.api.cognitive.microsoft.com/", | ||
| "ApiKey": "{{api-key}}", | ||
| "DeploymentNames": [ | ||
| "deployment-name-1", | ||
| "deployment-name-2" | ||
| ] | ||
| } | ||
| ] | ||
| }, | ||
| "KeyVault": { | ||
| "VaultUri": "https://{{key-vault-name}}.vault.azure.net/", | ||
| "SecretNames": { | ||
| "OpenAI": "azure-openai-instances", | ||
| "Storage": "storage-connection-string" | ||
| } | ||
| } | ||
| } | ||
| } | 
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -37,7 +37,7 @@ | |
| var tableServiceClient = default(TableServiceClient); | ||
|  | ||
| // Act | ||
| Action action = () => new AdminEventRepository(tableServiceClient, settings); | ||
| Check warning on line 40 in test/AzureOpenAIProxy.ApiApp.Tests/Repositories/AdminEventRepositoryTests.cs 
     | ||
|  | ||
| // Assert | ||
| action.Should().Throw<ArgumentNullException>(); | ||
|  | @@ -51,26 +51,53 @@ | |
| var tableServiceClient = Substitute.For<TableServiceClient>(); | ||
|  | ||
| // Act | ||
| Action action = () => new AdminEventRepository(tableServiceClient, settings); | ||
| Check warning on line 54 in test/AzureOpenAIProxy.ApiApp.Tests/Repositories/AdminEventRepositoryTests.cs 
     | ||
|  | ||
| // Assert | ||
| action.Should().Throw<ArgumentNullException>(); | ||
| } | ||
|  | ||
| [Fact] | ||
| public void Given_Instance_When_CreateEvent_Invoked_Then_It_Should_Throw_Exception() | ||
| public async Task Given_Instance_When_CreateEvent_Invoked_Then_It_Should_Not_Throw_Exception() | ||
| { | ||
| // Arrange | ||
| var settings = Substitute.For<StorageAccountSettings>(); | ||
| var tableServiceClient = Substitute.For<TableServiceClient>(); | ||
| var tableClient = Substitute.For<TableClient>(); | ||
| tableServiceClient.GetTableClient(Arg.Any<string>()).Returns(tableClient); | ||
| tableClient.AddEntityAsync<AdminEventDetails>(Arg.Any<AdminEventDetails>()) | ||
| .Returns(Task.FromResult(default(Response))); | ||
| var eventDetails = new AdminEventDetails(); | ||
| var repository = new AdminEventRepository(tableServiceClient, settings); | ||
|  | ||
| // Act | ||
| Func<Task> func = () => repository.CreateEvent(eventDetails); | ||
|  | ||
| // Assert | ||
| await func.Should().NotThrowAsync<InvalidOperationException>(); | ||
| } | ||
|          | ||
|  | ||
| [Fact] | ||
| public async Task Given_Failure_In_Add_Entity_When_CreateEvent_Invoked_Then_It_Should_Throw_Exception() | ||
| { | ||
| // Arrange | ||
| var settings = Substitute.For<StorageAccountSettings>(); | ||
| var tableServiceClient = Substitute.For<TableServiceClient>(); | ||
| var repository = new AdminEventRepository(tableServiceClient, settings); | ||
| var eventDetails = new AdminEventDetails(); | ||
|  | ||
| var exception = new InvalidOperationException("Invalid Operation Error : check duplicate, null or empty values"); | ||
|  | ||
| var tableClient = Substitute.For<TableClient>(); | ||
| tableServiceClient.GetTableClient(Arg.Any<string>()).Returns(tableClient); | ||
| tableClient.AddEntityAsync<AdminEventDetails>(Arg.Any<AdminEventDetails>()) | ||
| .ThrowsAsync(exception); | ||
|  | ||
| // Act | ||
| Func<Task> func = async () => await repository.CreateEvent(eventDetails); | ||
| Func<Task> func = () => repository.CreateEvent(eventDetails); | ||
|  | ||
| // Assert | ||
| func.Should().ThrowAsync<NotImplementedException>(); | ||
| await func.Should().ThrowAsync<InvalidOperationException>(); | ||
| } | ||
|  | ||
| [Fact] | ||
|  | ||
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -6,6 +6,8 @@ | |
|  | ||
| using FluentAssertions; | ||
|  | ||
| using Microsoft.AspNetCore.Authentication; | ||
|  | ||
| using Microsoft.Extensions.DependencyInjection; | ||
|  | ||
| using NSubstitute; | ||
|  | @@ -29,18 +31,39 @@ public void Given_ServiceCollection_When_AddAdminEventService_Invoked_Then_It_Sh | |
| } | ||
|  | ||
| [Fact] | ||
| public void Given_Instance_When_CreateEvent_Invoked_Then_It_Should_Throw_Exception() | ||
| public async Task Given_Instance_When_CreateEvent_Invoked_Then_It_Should_Not_Throw_Exception() | ||
| { | ||
| // Arrange | ||
| var eventDetails = new AdminEventDetails(); | ||
|         
                  justinyoo marked this conversation as resolved.
              Show resolved
            Hide resolved | ||
|  | ||
| var repository = Substitute.For<IAdminEventRepository>(); | ||
| var service = new AdminEventService(repository); | ||
|  | ||
| repository.CreateEvent(Arg.Any<AdminEventDetails>()).Returns(eventDetails); | ||
|  | ||
| // Act | ||
| Func<Task> func = async () => await service.CreateEvent(eventDetails); | ||
| Func<Task> func = () => service.CreateEvent(eventDetails); | ||
|  | ||
| // Assert | ||
| func.Should().ThrowAsync<NotImplementedException>(); | ||
| await func.Should().NotThrowAsync<InvalidOperationException>(); | ||
| } | ||
|          | ||
|  | ||
| [Fact] | ||
| public async Task Given_Failure_In_Add_Entity_When_CreateEvent_Invoked_Then_It_Should_Throw_Exception() | ||
| { | ||
| // Arrange | ||
| var eventDetails = new AdminEventDetails(); | ||
| var repository = Substitute.For<IAdminEventRepository>(); | ||
| var service = new AdminEventService(repository); | ||
|  | ||
| var exception = new InvalidOperationException("Invalid Operation Error : check duplicate, null or empty values"); | ||
| repository.CreateEvent(Arg.Any<AdminEventDetails>()).ThrowsAsync(exception); | ||
|  | ||
| // Act | ||
| Func<Task> func = () => service.CreateEvent(eventDetails); | ||
|  | ||
| // Assert | ||
| await func.Should().ThrowAsync<InvalidOperationException>(); | ||
| } | ||
|  | ||
| [Fact] | ||
|  | ||
Uh oh!
There was an error while loading. Please reload this page.