forked from aliencube/azure-openai-sdk-proxy
-
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.
[Admin] Add admin event service layer (aliencube#286)
- Loading branch information
Showing
7 changed files
with
223 additions
and
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
using AzureOpenAIProxy.ApiApp.Models; | ||
|
||
namespace AzureOpenAIProxy.ApiApp.Services; | ||
|
||
/// <summary> | ||
/// This provides interfaces to <see cref="AdminEventService"/> class. | ||
/// </summary> | ||
public interface IAdminEventService | ||
{ | ||
/// <summary> | ||
/// Creates a new event. | ||
/// </summary> | ||
/// <param name="eventDetails">Event payload.</param> | ||
/// <returns>Returns the event payload created.</returns> | ||
Task<AdminEventDetails> CreateEvent(AdminEventDetails eventDetails); | ||
|
||
/// <summary> | ||
/// Gets the list of events. | ||
/// </summary> | ||
/// <returns>Returns the list of events.</returns> | ||
Task<List<AdminEventDetails>> GetEvents(); | ||
|
||
/// <summary> | ||
/// Gets the event details. | ||
/// </summary> | ||
/// <param name="eventId">Event ID.</param> | ||
/// <returns>Returns the event details.</returns> | ||
Task<AdminEventDetails> GetEvent(Guid eventId); | ||
|
||
/// <summary> | ||
/// Updates the event details. | ||
/// </summary> | ||
/// <param name="eventId">Event ID.</param> | ||
/// <param name="eventDetails">Event details to update.</param> | ||
/// <returns>Returns the updated event details.</returns> | ||
Task<AdminEventDetails> UpdateEvent(Guid eventId, AdminEventDetails eventDetails); | ||
} | ||
|
||
/// <summary> | ||
/// This represents the service entity for admin event. | ||
/// </summary> | ||
public class AdminEventService : IAdminEventService | ||
{ | ||
/// <inheritdoc /> | ||
public async Task<AdminEventDetails> CreateEvent(AdminEventDetails eventDetails) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public async Task<List<AdminEventDetails>> GetEvents() | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public async Task<AdminEventDetails> GetEvent(Guid eventId) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public async Task<AdminEventDetails> UpdateEvent(Guid eventId, AdminEventDetails eventDetails) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// This represents the extension class for <see cref="IServiceCollection"/> | ||
/// </summary> | ||
public static class AdminEventServiceExtensions | ||
{ | ||
/// <summary> | ||
/// Adds the <see cref="AdminEventService"/> instance to the service collection. | ||
/// </summary> | ||
/// <param name="services"><see cref="IServiceCollection"/> instance.</param> | ||
/// <returns>Returns <see cref="IServiceCollection"/> instance.</returns> | ||
public static IServiceCollection AddAdminEventService(this IServiceCollection services) | ||
{ | ||
services.AddScoped<IAdminEventService, AdminEventService>(); | ||
|
||
return services; | ||
} | ||
} |
80 changes: 80 additions & 0 deletions
80
test/AzureOpenAIProxy.ApiApp.Tests/Services/AdminEventServiceTests.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,80 @@ | ||
using AzureOpenAIProxy.ApiApp.Models; | ||
using AzureOpenAIProxy.ApiApp.Services; | ||
|
||
using FluentAssertions; | ||
|
||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
namespace AzureOpenAIProxy.ApiApp.Tests.Services; | ||
|
||
public class AdminEventServiceTests | ||
{ | ||
[Fact] | ||
public void Given_ServiceCollection_When_AddAdminEventService_Invoked_Then_It_Should_Contain_AdminEventService() | ||
{ | ||
// Arrange | ||
var services = new ServiceCollection(); | ||
|
||
// Act | ||
services.AddAdminEventService(); | ||
|
||
// Assert | ||
services.SingleOrDefault(p => p.ServiceType == typeof(IAdminEventService)).Should().NotBeNull(); | ||
} | ||
|
||
[Fact] | ||
public void Given_Instance_When_CreateEvent_Invoked_Then_It_Should_Throw_Exception() | ||
{ | ||
// Arrange | ||
var eventDetails = new AdminEventDetails(); | ||
var service = new AdminEventService(); | ||
|
||
// Act | ||
Func<Task> func = async () => await service.CreateEvent(eventDetails); | ||
|
||
// Assert | ||
func.Should().ThrowAsync<NotImplementedException>(); | ||
} | ||
|
||
[Fact] | ||
public void Given_Instance_When_GetEvents_Invoked_Then_It_Should_Throw_Exception() | ||
{ | ||
// Arrange | ||
var service = new AdminEventService(); | ||
|
||
// Act | ||
Func<Task> func = async () => await service.GetEvents(); | ||
|
||
// Assert | ||
func.Should().ThrowAsync<NotImplementedException>(); | ||
} | ||
|
||
[Fact] | ||
public void Given_Instance_When_GetEvent_Invoked_Then_It_Should_Throw_Exception() | ||
{ | ||
// Arrange | ||
var eventId = Guid.NewGuid(); | ||
var service = new AdminEventService(); | ||
|
||
// Act | ||
Func<Task> func = async () => await service.GetEvent(eventId); | ||
|
||
// Assert | ||
func.Should().ThrowAsync<NotImplementedException>(); | ||
} | ||
|
||
[Fact] | ||
public void Given_Instance_When_UpdateEvent_Invoked_Then_It_Should_Throw_Exception() | ||
{ | ||
// Arrange | ||
var eventId = Guid.NewGuid(); | ||
var eventDetails = new AdminEventDetails(); | ||
var service = new AdminEventService(); | ||
|
||
// Act | ||
Func<Task> func = async () => await service.UpdateEvent(eventId, eventDetails); | ||
|
||
// Assert | ||
func.Should().ThrowAsync<NotImplementedException>(); | ||
} | ||
} |
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