Re-arranging files to add test project. Adding WIP cursor list
This commit is contained in:
		
							
								
								
									
										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.Extensions.Hosting; | ||||
| 
 | ||||
| namespace aurora_cradle_sharp | ||||
| namespace Aurora | ||||
| { | ||||
|     public class Program | ||||
|     { | ||||
| @@ -1,6 +1,6 @@ | ||||
| syntax = "proto3"; | ||||
| 
 | ||||
| option csharp_namespace = "aurora_cradle_sharp"; | ||||
| option csharp_namespace = "Aurora.Services.Signal"; | ||||
| 
 | ||||
| package signal; | ||||
| 
 | ||||
| @@ -9,28 +9,38 @@ import "google/protobuf/timestamp.proto"; | ||||
| import "google/protobuf/field_mask.proto"; | ||||
| import "google/protobuf/empty.proto"; | ||||
| 
 | ||||
| service Signal{ | ||||
| 
 | ||||
| service Signal { | ||||
|     //************** | ||||
|     //Party Resource | ||||
|     //************** | ||||
|     //Get Party | ||||
|     rpc ListParties(ListPartiesRequest) returns (ListPartiesResponse); | ||||
| 
 | ||||
|     rpc GetParty(GetPartyRequest) returns (Party); | ||||
| 
 | ||||
|     rpc UpdateParty(UpdatePartyRequest) returns (Party); | ||||
| 
 | ||||
|     rpc CreateParty(CreatePartyRequest) returns (Party); | ||||
| 
 | ||||
|     rpc DeleteParty(DeletePartyRequest) returns (google.protobuf.Empty); | ||||
| 
 | ||||
| 
 | ||||
|     //*************************** | ||||
|     //EventSubscriptions Resource | ||||
|     //*************************** | ||||
|     //List | ||||
|     rpc ListEventSubscriptions(ListEventSubscriptionsRequest) returns (ListEventSubscriptionsResponse); | ||||
| 
 | ||||
|     //Create | ||||
|     rpc SubscribeToEvent(EventSubscriptionRequest) returns (EventSubscription); | ||||
|      | ||||
|     //Delete | ||||
|     rpc DeleteEventSubscription(DeleteEventSubscriptionRequest) returns (google.protobuf.Empty); | ||||
| 
 | ||||
|     //CUSTOM: Create EventSubscription List | ||||
|     rpc SubscribeToEvents(EventSubscriptionListRequest) returns (EventSubscriptionListResponse); | ||||
| 
 | ||||
|     //CUSTOM: Delete all | ||||
|     rpc DeleteAllEventSubscriptions(DeleteAllEventSubscriptionsRequest) returns (google.protobuf.Empty); | ||||
|      | ||||
| @@ -40,6 +50,7 @@ service Signal{ | ||||
|     //Get | ||||
|     rpc GetEventStream(GetEventsRequest) returns (stream BaseEvent) {}; | ||||
| } | ||||
| 
 | ||||
| message Party { | ||||
|     //The resource name of the party | ||||
|     string name = 1; | ||||
| @@ -49,38 +60,48 @@ message Party { | ||||
|     string host_ip = 5; | ||||
|     google.protobuf.Timestamp created_on = 6; | ||||
| } | ||||
| 
 | ||||
| message PartyListItem { | ||||
|     string name = 1; | ||||
|     string party_id = 2; | ||||
| } | ||||
| 
 | ||||
| message ListPartiesRequest { | ||||
|     int32 page_size = 1; | ||||
|     string page_token = 2; | ||||
| } | ||||
| 
 | ||||
| message ListPartiesResponse { | ||||
|     repeated PartyListItem parties = 1; | ||||
|     string next_page_token = 2; | ||||
| } | ||||
| 
 | ||||
| message GetPartyRequest { | ||||
|     string party_id = 1; | ||||
| } | ||||
| 
 | ||||
| message CreatePartyRequest { | ||||
|     string party_id = 1; | ||||
|     Party party = 2; | ||||
| } | ||||
| 
 | ||||
| message DeletePartyRequest { | ||||
|     string party_id = 1; | ||||
| } | ||||
| 
 | ||||
| message UpdatePartyRequest { | ||||
|     Party party = 1; | ||||
|     google.protobuf.FieldMask update_mask = 2; | ||||
| } | ||||
| 
 | ||||
| /* Event Types */ | ||||
| enum EventType { | ||||
|     NewPartiesAvailable = 0; | ||||
| } | ||||
| 
 | ||||
| message NewPartiesAvailableEvent { | ||||
| } | ||||
| 
 | ||||
| message BaseEvent { | ||||
|     //Resource name of the event ? | ||||
|     string name = 1; | ||||
| @@ -89,42 +110,51 @@ message BaseEvent { | ||||
|         NewPartiesAvailableEvent new_parties_available_event = 3; | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| message EventSubscription { | ||||
|     EventType type = 2; | ||||
| } | ||||
| 
 | ||||
| message ListEventSubscriptionsRequest { | ||||
|     //Resource name of parent to the subscription list (The member) | ||||
|     string parent = 1; | ||||
|     int32 page_size = 2; | ||||
|     string page_token = 3; | ||||
| } | ||||
| 
 | ||||
| message ListEventSubscriptionsResponse { | ||||
|     repeated EventSubscription subscriptions = 1; | ||||
|     string next_page_token = 2; | ||||
| } | ||||
| 
 | ||||
| message EventSubscriptionRequest { | ||||
|     //Resource name of the parent to the subscription list (The member) | ||||
|     string parent = 1; | ||||
|     EventSubscription event_subscription = 2; | ||||
| } | ||||
| 
 | ||||
| message DeleteEventSubscriptionRequest { | ||||
|     //Resource name of the subscription to delete | ||||
|     string parent = 1; | ||||
|     EventType type = 2; | ||||
| } | ||||
| 
 | ||||
| message EventSubscriptionListRequest { | ||||
|     //Resource name of the parent to the subscription list (The member) | ||||
|     string parent = 1; | ||||
|     repeated EventSubscription event_subscriptions = 2; | ||||
| } | ||||
| 
 | ||||
| message EventSubscriptionListResponse { | ||||
|     repeated EventSubscription event_subscriptions = 1; | ||||
| } | ||||
| 
 | ||||
| message DeleteAllEventSubscriptionsRequest { | ||||
|     //Resource name of the parent to the subscription list (the member) | ||||
|     string parent = 1; | ||||
| } | ||||
| 
 | ||||
| message GetEventsRequest { | ||||
|     //Resource name of the parent to the event stream (the member) | ||||
|     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 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 CursorList<Party> _partyList; | ||||
|         public SignalService(ILogger<SignalService> logger) | ||||
|         { | ||||
|             _logger = logger; | ||||
|             this._partyList = new CursorList<Party>(); | ||||
|         } | ||||
| 
 | ||||
|     } | ||||
| @@ -7,8 +7,9 @@ using Microsoft.AspNetCore.Hosting; | ||||
| using Microsoft.AspNetCore.Http; | ||||
| using Microsoft.Extensions.DependencyInjection; | ||||
| using Microsoft.Extensions.Hosting; | ||||
| using Aurora.Services.Signal; | ||||
| 
 | ||||
| namespace aurora_cradle_sharp | ||||
| namespace Aurora | ||||
| { | ||||
|     public class Startup | ||||
|     { | ||||
		Reference in New Issue
	
	Block a user