-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #163 from nenoNaninu/support_inheritance
Support inheritance
- Loading branch information
Showing
9 changed files
with
239 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { HubConnectionBuilder } from '@microsoft/signalr' | ||
import { getHubProxyFactory } from '../generated/json/TypedSignalR.Client' | ||
import { MyEnum, MyRequestItem, MyRequestItem2, UserDefinedType } from '../generated/json/TypedSignalR.Client.TypeScript.Tests.Shared'; | ||
import crypto from 'crypto' | ||
|
||
const getRandomInt = (max: number) => { | ||
return Math.floor(Math.random() * max); | ||
} | ||
|
||
const toUTCString = (date: string | Date): string => { | ||
if (typeof date === 'string') { | ||
const d = new Date(date); | ||
return d.toUTCString(); | ||
} | ||
|
||
return date.toUTCString(); | ||
} | ||
|
||
const testMethod = async () => { | ||
const connection = new HubConnectionBuilder() | ||
.withUrl("http://localhost:5000/hubs/InheritHub") | ||
.build(); | ||
|
||
const hubProxy = getHubProxyFactory("IInheritHub") | ||
.createHubProxy(connection); | ||
|
||
try { | ||
await connection.start(); | ||
|
||
const r1 = await hubProxy.get(); | ||
expect(r1).toEqual("TypedSignalR.Client.TypeScript"); | ||
|
||
const x = getRandomInt(1000); | ||
const y = getRandomInt(1000); | ||
|
||
const r2 = await hubProxy.add(x, y); | ||
expect(r2).toEqual(x + y); | ||
|
||
const s1 = "revue"; | ||
const s2 = "starlight"; | ||
|
||
const r3 = await hubProxy.cat(s1, s2);; | ||
|
||
expect(r3).toEqual(s1 + s2); | ||
|
||
const instance: UserDefinedType = { | ||
dateTime: new Date(), | ||
guid: crypto.randomUUID() | ||
} | ||
|
||
const r4 = await hubProxy.echo(instance); | ||
|
||
instance.dateTime = toUTCString(instance.dateTime) | ||
r4.dateTime = toUTCString(r4.dateTime) | ||
|
||
expect(r4).toEqual(instance) | ||
} | ||
finally { | ||
await connection.stop(); | ||
} | ||
} | ||
|
||
test('unary.test', testMethod); |
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,62 @@ | ||
import { HubConnectionBuilder } from '@microsoft/signalr' | ||
import { getHubProxyFactory } from '../generated/msgpack/TypedSignalR.Client' | ||
import { UserDefinedType } from '../generated/msgpack/TypedSignalR.Client.TypeScript.Tests.Shared'; | ||
import crypto from 'crypto' | ||
import { MessagePackHubProtocol } from '@microsoft/signalr-protocol-msgpack'; | ||
|
||
const getRandomInt = (max: number) => { | ||
return Math.floor(Math.random() * max); | ||
} | ||
|
||
const toUTCString = (date: string | Date): string => { | ||
if (typeof date === 'string') { | ||
const d = new Date(date); | ||
return d.toUTCString(); | ||
} | ||
|
||
return date.toUTCString(); | ||
} | ||
|
||
const testMethod = async () => { | ||
const connection = new HubConnectionBuilder() | ||
.withUrl("http://localhost:5000/hubs/InheritHub") | ||
.withHubProtocol(new MessagePackHubProtocol()) | ||
.build(); | ||
|
||
const hubProxy = getHubProxyFactory("IInheritHub") | ||
.createHubProxy(connection); | ||
|
||
try { | ||
await connection.start(); | ||
|
||
const r1 = await hubProxy.get(); | ||
expect(r1).toEqual("TypedSignalR.Client.TypeScript"); | ||
|
||
const x = getRandomInt(1000); | ||
const y = getRandomInt(1000); | ||
|
||
const r2 = await hubProxy.add(x, y); | ||
expect(r2).toEqual(x + y); | ||
|
||
const s1 = "revue"; | ||
const s2 = "starlight"; | ||
|
||
const r3 = await hubProxy.cat(s1, s2);; | ||
|
||
expect(r3).toEqual(s1 + s2); | ||
|
||
const instance: UserDefinedType = { | ||
DateTime: new Date(), | ||
Guid: crypto.randomUUID() | ||
} | ||
|
||
const r4 = await hubProxy.echo(instance); | ||
|
||
expect(r4).toEqual(instance) | ||
} | ||
finally { | ||
await connection.stop(); | ||
} | ||
} | ||
|
||
test('unary.test', testMethod); |
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
27 changes: 27 additions & 0 deletions
27
tests/TypedSignalR.Client.TypeScript.Tests.Server/Hubs/InheritHub.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,27 @@ | ||
using Microsoft.AspNetCore.SignalR; | ||
using TypedSignalR.Client.TypeScript.Tests.Shared; | ||
|
||
namespace TypedSignalR.Client.TypeScript.Tests.Server.Hubs; | ||
|
||
public class InheritHub : Hub<IInheritHubReceiver>, IInheritHub | ||
{ | ||
public Task<int> Add(int x, int y) | ||
{ | ||
return Task.FromResult(x + y); | ||
} | ||
|
||
public Task<string> Cat(string x, string y) | ||
{ | ||
return Task.FromResult(x + y); | ||
} | ||
|
||
public Task<UserDefinedType> Echo(UserDefinedType instance) | ||
{ | ||
return Task.FromResult(instance); | ||
} | ||
|
||
public Task<string> Get() | ||
{ | ||
return Task.FromResult("TypedSignalR.Client.TypeScript"); | ||
} | ||
} |
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
50 changes: 50 additions & 0 deletions
50
tests/TypedSignalR.Client.TypeScript.Tests.Shared/IInheritHub.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,50 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace TypedSignalR.Client.TypeScript.Tests.Shared; | ||
|
||
public interface IHubBaseBase | ||
{ | ||
Task<string> Get(); | ||
} | ||
|
||
public interface IHubBase1 : IHubBaseBase | ||
{ | ||
Task<int> Add(int x, int y); | ||
} | ||
|
||
public interface IHubBase2 : IHubBaseBase | ||
{ | ||
Task<string> Cat(string x, string y); | ||
} | ||
|
||
[Hub] | ||
public interface IInheritHub : IHubBase1, IHubBase2 | ||
{ | ||
Task<UserDefinedType> Echo(UserDefinedType instance); | ||
} | ||
|
||
|
||
public interface IReceiverBaseBase | ||
{ | ||
Task ReceiveMessage(string message, int value); | ||
} | ||
|
||
public interface IReceiverBase1 : IReceiverBaseBase | ||
{ | ||
Task ReceiveCustomMessage(UserDefinedType userDefined); | ||
} | ||
|
||
public interface IReceiverBase2 : IReceiverBaseBase | ||
{ | ||
Task Notify(); | ||
} | ||
|
||
[Receiver] | ||
public interface IInheritHubReceiver : IReceiverBase1, IReceiverBase2 | ||
{ | ||
Task ReceiveMessage2(string message, int value); | ||
} |