Re-arranging files to add test project. Adding WIP cursor list
This commit is contained in:
parent
00ab0323c7
commit
91d0a55d5e
26
AuroraSignal.test/AuroraSignal.test.csproj
Normal file
26
AuroraSignal.test/AuroraSignal.test.csproj
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net5.0</TargetFramework>
|
||||||
|
|
||||||
|
<IsPackable>false</IsPackable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" />
|
||||||
|
<PackageReference Include="xunit" Version="2.4.1" />
|
||||||
|
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
</PackageReference>
|
||||||
|
<PackageReference Include="coverlet.collector" Version="1.3.0">
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
</PackageReference>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\AuroraSignal\aurora-cradle-sharp.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
70
AuroraSignal.test/CursorList.test.cs
Normal file
70
AuroraSignal.test/CursorList.test.cs
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using Xunit;
|
||||||
|
using Aurora;
|
||||||
|
using Aurora.Services.Signal;
|
||||||
|
|
||||||
|
|
||||||
|
namespace AuroraSignal.test
|
||||||
|
{
|
||||||
|
public class CursorListTest
|
||||||
|
{
|
||||||
|
[Theory()]
|
||||||
|
[InlineData(SortDirection.Asc)]
|
||||||
|
[InlineData(SortDirection.Desc)]
|
||||||
|
public void CursorListSortOnStringValue(SortDirection direction)
|
||||||
|
{
|
||||||
|
CursorList<Party> cursor = new CursorList<Party>();
|
||||||
|
cursor.Add(new Party(){Name = "asdf", PartyId = "1111"});
|
||||||
|
cursor.Add(new Party(){Name = "bsdf", PartyId = "2222"});
|
||||||
|
cursor.Add(new Party(){Name = "csdf", PartyId = "3333"});
|
||||||
|
|
||||||
|
List<Party> result = cursor.WithSort("Name", direction).Get();
|
||||||
|
|
||||||
|
if(direction == SortDirection.Desc)
|
||||||
|
{
|
||||||
|
Assert.Collection<Party>(cursor,
|
||||||
|
item => item.Name.Equals("asdf"),
|
||||||
|
item => item.Name.Equals("bsdf"),
|
||||||
|
item => item.Name.Equals("csdf"));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Assert.Collection<Party>(cursor,
|
||||||
|
item => item.Name.Equals("csdf"),
|
||||||
|
item => item.Name.Equals("bsdf"),
|
||||||
|
item => item.Name.Equals("asdf"));
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[Theory()]
|
||||||
|
[InlineData(SortDirection.Asc)]
|
||||||
|
[InlineData(SortDirection.Desc)]
|
||||||
|
public void CursorListSortOnIntValue(SortDirection direction)
|
||||||
|
{
|
||||||
|
CursorList<object> cursor = new CursorList<object>();
|
||||||
|
cursor.Add(new {Name = "asdf", PartyId = 1111});
|
||||||
|
cursor.Add(new {Name = "bsdf", PartyId = 2222});
|
||||||
|
cursor.Add(new {Name = "csdf", PartyId = 3333});
|
||||||
|
|
||||||
|
List<object> result = cursor.WithSort("PartyId", direction).Get();
|
||||||
|
|
||||||
|
if(direction == SortDirection.Desc)
|
||||||
|
{
|
||||||
|
Assert.Collection<object>(cursor,
|
||||||
|
item => item.Equals(new {Name = "asdf", PartyId = 1111}),
|
||||||
|
item => item.Equals(new {Name = "bsdf", PartyId = 2222}),
|
||||||
|
item => item.Equals(new {Name = "csdf", PartyId = 3333}));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Assert.Collection<object>(cursor,
|
||||||
|
item => item.Equals(new {Name = "csdf", PartyId = 3333}),
|
||||||
|
item => item.Equals(new {Name = "bsdf", PartyId = 2222}),
|
||||||
|
item => item.Equals(new {Name = "asdf", PartyId = 1111}));
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
94
AuroraSignal/Src/CursorList.cs
Normal file
94
AuroraSignal/Src/CursorList.cs
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace Aurora
|
||||||
|
{
|
||||||
|
public enum SortDirection {
|
||||||
|
Asc,
|
||||||
|
Desc,
|
||||||
|
}
|
||||||
|
|
||||||
|
public class CursorList<T> : List<T>
|
||||||
|
{
|
||||||
|
private string _orderBy;
|
||||||
|
private SortDirection _direction;
|
||||||
|
private string _previousPageToken;
|
||||||
|
private string _nextPageToken;
|
||||||
|
private int _pageSize;
|
||||||
|
|
||||||
|
public CursorList(){
|
||||||
|
this._direction = SortDirection.Desc;
|
||||||
|
this._orderBy = string.Empty;
|
||||||
|
this._previousPageToken = string.Empty;
|
||||||
|
this._nextPageToken = string.Empty;
|
||||||
|
this._pageSize = 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CursorList<T> WithNextPage(string nextPageToken){
|
||||||
|
this._nextPageToken = nextPageToken;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CursorList<T> WithPreviousPage(string prevPageToken){
|
||||||
|
this._previousPageToken = prevPageToken;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CursorList<T> WithSort(string orderBy, SortDirection direction ) {
|
||||||
|
this._orderBy = orderBy;
|
||||||
|
this._direction = direction;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CursorList<T> WithSize(int size){
|
||||||
|
this._pageSize = size;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<T> Get(){
|
||||||
|
if(this._nextPageToken != string.Empty && this._previousPageToken != string.Empty){
|
||||||
|
throw new System.InvalidOperationException("Cannot specify both next and previous page tokens");
|
||||||
|
}
|
||||||
|
|
||||||
|
List<T> tmpList = new List<T>(this);
|
||||||
|
|
||||||
|
|
||||||
|
tmpList.Sort(delegate(T first, T second){
|
||||||
|
object firstVal = first.GetType().GetProperty(this._orderBy).GetValue(first, null);
|
||||||
|
object secondVal = first.GetType().GetProperty(this._orderBy).GetValue(second, null);
|
||||||
|
int compare = 0;
|
||||||
|
|
||||||
|
if(firstVal == null && secondVal == null)
|
||||||
|
{
|
||||||
|
compare = 0;
|
||||||
|
}
|
||||||
|
else if(firstVal == null)
|
||||||
|
{
|
||||||
|
compare = 1;
|
||||||
|
}
|
||||||
|
else if(secondVal == null)
|
||||||
|
{
|
||||||
|
compare = -1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
|
// Determine number or string types
|
||||||
|
if(firstVal is string)
|
||||||
|
{
|
||||||
|
string firstStr = firstVal as string;
|
||||||
|
string secondStr = secondVal as string;
|
||||||
|
compare = firstStr.CompareTo(secondStr);
|
||||||
|
} else if(firstVal is int)
|
||||||
|
{
|
||||||
|
int? firstInt = firstVal as int?;
|
||||||
|
int? secondInt = secondVal as int?;
|
||||||
|
compare = firstInt > secondInt ? 1 : -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return this._direction == SortDirection.Asc ? compare : compare * -1;
|
||||||
|
});
|
||||||
|
|
||||||
|
return tmpList.GetRange(0, this._pageSize > tmpList.Count ? tmpList.Count : this._pageSize);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -6,7 +6,7 @@ using System.Threading.Tasks;
|
|||||||
using Microsoft.AspNetCore.Hosting;
|
using Microsoft.AspNetCore.Hosting;
|
||||||
using Microsoft.Extensions.Hosting;
|
using Microsoft.Extensions.Hosting;
|
||||||
|
|
||||||
namespace aurora_cradle_sharp
|
namespace Aurora
|
||||||
{
|
{
|
||||||
public class Program
|
public class Program
|
||||||
{
|
{
|
@ -1,6 +1,6 @@
|
|||||||
syntax = "proto3";
|
syntax = "proto3";
|
||||||
|
|
||||||
option csharp_namespace = "aurora_cradle_sharp";
|
option csharp_namespace = "Aurora.Services.Signal";
|
||||||
|
|
||||||
package signal;
|
package signal;
|
||||||
|
|
||||||
@ -9,28 +9,38 @@ import "google/protobuf/timestamp.proto";
|
|||||||
import "google/protobuf/field_mask.proto";
|
import "google/protobuf/field_mask.proto";
|
||||||
import "google/protobuf/empty.proto";
|
import "google/protobuf/empty.proto";
|
||||||
|
|
||||||
service Signal{
|
|
||||||
|
service Signal {
|
||||||
//**************
|
//**************
|
||||||
//Party Resource
|
//Party Resource
|
||||||
//**************
|
//**************
|
||||||
//Get Party
|
//Get Party
|
||||||
rpc ListParties(ListPartiesRequest) returns (ListPartiesResponse);
|
rpc ListParties(ListPartiesRequest) returns (ListPartiesResponse);
|
||||||
|
|
||||||
rpc GetParty(GetPartyRequest) returns (Party);
|
rpc GetParty(GetPartyRequest) returns (Party);
|
||||||
|
|
||||||
rpc UpdateParty(UpdatePartyRequest) returns (Party);
|
rpc UpdateParty(UpdatePartyRequest) returns (Party);
|
||||||
|
|
||||||
rpc CreateParty(CreatePartyRequest) returns (Party);
|
rpc CreateParty(CreatePartyRequest) returns (Party);
|
||||||
|
|
||||||
rpc DeleteParty(DeletePartyRequest) returns (google.protobuf.Empty);
|
rpc DeleteParty(DeletePartyRequest) returns (google.protobuf.Empty);
|
||||||
|
|
||||||
|
|
||||||
//***************************
|
//***************************
|
||||||
//EventSubscriptions Resource
|
//EventSubscriptions Resource
|
||||||
//***************************
|
//***************************
|
||||||
//List
|
//List
|
||||||
rpc ListEventSubscriptions(ListEventSubscriptionsRequest) returns (ListEventSubscriptionsResponse);
|
rpc ListEventSubscriptions(ListEventSubscriptionsRequest) returns (ListEventSubscriptionsResponse);
|
||||||
|
|
||||||
//Create
|
//Create
|
||||||
rpc SubscribeToEvent(EventSubscriptionRequest) returns (EventSubscription);
|
rpc SubscribeToEvent(EventSubscriptionRequest) returns (EventSubscription);
|
||||||
|
|
||||||
//Delete
|
//Delete
|
||||||
rpc DeleteEventSubscription(DeleteEventSubscriptionRequest) returns (google.protobuf.Empty);
|
rpc DeleteEventSubscription(DeleteEventSubscriptionRequest) returns (google.protobuf.Empty);
|
||||||
|
|
||||||
//CUSTOM: Create EventSubscription List
|
//CUSTOM: Create EventSubscription List
|
||||||
rpc SubscribeToEvents(EventSubscriptionListRequest) returns (EventSubscriptionListResponse);
|
rpc SubscribeToEvents(EventSubscriptionListRequest) returns (EventSubscriptionListResponse);
|
||||||
|
|
||||||
//CUSTOM: Delete all
|
//CUSTOM: Delete all
|
||||||
rpc DeleteAllEventSubscriptions(DeleteAllEventSubscriptionsRequest) returns (google.protobuf.Empty);
|
rpc DeleteAllEventSubscriptions(DeleteAllEventSubscriptionsRequest) returns (google.protobuf.Empty);
|
||||||
|
|
||||||
@ -40,6 +50,7 @@ service Signal{
|
|||||||
//Get
|
//Get
|
||||||
rpc GetEventStream(GetEventsRequest) returns (stream BaseEvent) {};
|
rpc GetEventStream(GetEventsRequest) returns (stream BaseEvent) {};
|
||||||
}
|
}
|
||||||
|
|
||||||
message Party {
|
message Party {
|
||||||
//The resource name of the party
|
//The resource name of the party
|
||||||
string name = 1;
|
string name = 1;
|
||||||
@ -49,38 +60,48 @@ message Party {
|
|||||||
string host_ip = 5;
|
string host_ip = 5;
|
||||||
google.protobuf.Timestamp created_on = 6;
|
google.protobuf.Timestamp created_on = 6;
|
||||||
}
|
}
|
||||||
|
|
||||||
message PartyListItem {
|
message PartyListItem {
|
||||||
string name = 1;
|
string name = 1;
|
||||||
string party_id = 2;
|
string party_id = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
message ListPartiesRequest {
|
message ListPartiesRequest {
|
||||||
int32 page_size = 1;
|
int32 page_size = 1;
|
||||||
string page_token = 2;
|
string page_token = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
message ListPartiesResponse {
|
message ListPartiesResponse {
|
||||||
repeated PartyListItem parties = 1;
|
repeated PartyListItem parties = 1;
|
||||||
string next_page_token = 2;
|
string next_page_token = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
message GetPartyRequest {
|
message GetPartyRequest {
|
||||||
string party_id = 1;
|
string party_id = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
message CreatePartyRequest {
|
message CreatePartyRequest {
|
||||||
string party_id = 1;
|
string party_id = 1;
|
||||||
Party party = 2;
|
Party party = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
message DeletePartyRequest {
|
message DeletePartyRequest {
|
||||||
string party_id = 1;
|
string party_id = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
message UpdatePartyRequest {
|
message UpdatePartyRequest {
|
||||||
Party party = 1;
|
Party party = 1;
|
||||||
google.protobuf.FieldMask update_mask = 2;
|
google.protobuf.FieldMask update_mask = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Event Types */
|
/* Event Types */
|
||||||
enum EventType {
|
enum EventType {
|
||||||
NewPartiesAvailable = 0;
|
NewPartiesAvailable = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
message NewPartiesAvailableEvent {
|
message NewPartiesAvailableEvent {
|
||||||
}
|
}
|
||||||
|
|
||||||
message BaseEvent {
|
message BaseEvent {
|
||||||
//Resource name of the event ?
|
//Resource name of the event ?
|
||||||
string name = 1;
|
string name = 1;
|
||||||
@ -89,42 +110,51 @@ message BaseEvent {
|
|||||||
NewPartiesAvailableEvent new_parties_available_event = 3;
|
NewPartiesAvailableEvent new_parties_available_event = 3;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
message EventSubscription {
|
message EventSubscription {
|
||||||
EventType type = 2;
|
EventType type = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
message ListEventSubscriptionsRequest {
|
message ListEventSubscriptionsRequest {
|
||||||
//Resource name of parent to the subscription list (The member)
|
//Resource name of parent to the subscription list (The member)
|
||||||
string parent = 1;
|
string parent = 1;
|
||||||
int32 page_size = 2;
|
int32 page_size = 2;
|
||||||
string page_token = 3;
|
string page_token = 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
message ListEventSubscriptionsResponse {
|
message ListEventSubscriptionsResponse {
|
||||||
repeated EventSubscription subscriptions = 1;
|
repeated EventSubscription subscriptions = 1;
|
||||||
string next_page_token = 2;
|
string next_page_token = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
message EventSubscriptionRequest {
|
message EventSubscriptionRequest {
|
||||||
//Resource name of the parent to the subscription list (The member)
|
//Resource name of the parent to the subscription list (The member)
|
||||||
string parent = 1;
|
string parent = 1;
|
||||||
EventSubscription event_subscription = 2;
|
EventSubscription event_subscription = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
message DeleteEventSubscriptionRequest {
|
message DeleteEventSubscriptionRequest {
|
||||||
//Resource name of the subscription to delete
|
//Resource name of the subscription to delete
|
||||||
string parent = 1;
|
string parent = 1;
|
||||||
EventType type = 2;
|
EventType type = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
message EventSubscriptionListRequest {
|
message EventSubscriptionListRequest {
|
||||||
//Resource name of the parent to the subscription list (The member)
|
//Resource name of the parent to the subscription list (The member)
|
||||||
string parent = 1;
|
string parent = 1;
|
||||||
repeated EventSubscription event_subscriptions = 2;
|
repeated EventSubscription event_subscriptions = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
message EventSubscriptionListResponse {
|
message EventSubscriptionListResponse {
|
||||||
repeated EventSubscription event_subscriptions = 1;
|
repeated EventSubscription event_subscriptions = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
message DeleteAllEventSubscriptionsRequest {
|
message DeleteAllEventSubscriptionsRequest {
|
||||||
//Resource name of the parent to the subscription list (the member)
|
//Resource name of the parent to the subscription list (the member)
|
||||||
string parent = 1;
|
string parent = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
message GetEventsRequest {
|
message GetEventsRequest {
|
||||||
//Resource name of the parent to the event stream (the member)
|
//Resource name of the parent to the event stream (the member)
|
||||||
string parent = 1;
|
string parent = 1;
|
||||||
}
|
}
|
7
AuroraSignal/Src/Services/Signal/Events.cs
Normal file
7
AuroraSignal/Src/Services/Signal/Events.cs
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
namespace Aurora.Services.Signal
|
||||||
|
{
|
||||||
|
public partial class SignalService : Signal.SignalBase
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
34
AuroraSignal/Src/Services/Signal/Party.cs
Normal file
34
AuroraSignal/Src/Services/Signal/Party.cs
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
using System.Threading.Tasks;
|
||||||
|
using Google.Protobuf.WellKnownTypes;
|
||||||
|
using Grpc.Core;
|
||||||
|
|
||||||
|
namespace Aurora.Services.Signal
|
||||||
|
{
|
||||||
|
public partial class SignalService : Signal.SignalBase
|
||||||
|
{
|
||||||
|
public override Task<Party> CreateParty(CreatePartyRequest request, ServerCallContext context)
|
||||||
|
{
|
||||||
|
return base.CreateParty(request, context);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override Task<Empty> DeleteParty(DeletePartyRequest request, ServerCallContext context)
|
||||||
|
{
|
||||||
|
return base.DeleteParty(request, context);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override Task<ListPartiesResponse> ListParties(ListPartiesRequest request, ServerCallContext context)
|
||||||
|
{
|
||||||
|
return base.ListParties(request, context);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override Task<Party> GetParty(GetPartyRequest request, ServerCallContext context)
|
||||||
|
{
|
||||||
|
return base.GetParty(request, context);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override Task<Party> UpdateParty(UpdatePartyRequest request, ServerCallContext context)
|
||||||
|
{
|
||||||
|
return base.UpdateParty(request, context);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -5,14 +5,17 @@ using System.Threading.Tasks;
|
|||||||
using Grpc.Core;
|
using Grpc.Core;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
namespace aurora_cradle_sharp
|
namespace Aurora.Services.Signal
|
||||||
{
|
{
|
||||||
public class SignalService : Signal.SignalBase
|
public partial class SignalService : Signal.SignalBase
|
||||||
{
|
{
|
||||||
private readonly ILogger<SignalService> _logger;
|
private readonly ILogger<SignalService> _logger;
|
||||||
|
|
||||||
|
private CursorList<Party> _partyList;
|
||||||
public SignalService(ILogger<SignalService> logger)
|
public SignalService(ILogger<SignalService> logger)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
|
this._partyList = new CursorList<Party>();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -7,8 +7,9 @@ using Microsoft.AspNetCore.Hosting;
|
|||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Hosting;
|
using Microsoft.Extensions.Hosting;
|
||||||
|
using Aurora.Services.Signal;
|
||||||
|
|
||||||
namespace aurora_cradle_sharp
|
namespace Aurora
|
||||||
{
|
{
|
||||||
public class Startup
|
public class Startup
|
||||||
{
|
{
|
Reference in New Issue
Block a user