public void ExecuteServerStreaming_WhenItMapped_ShouldUpdateResponseMarkup() { // Arrange const string ExpectedMessage = "Unusual Markup Message Server Streaming"; var clientMock = new Mock <TestService.TestServiceClient>(); clientMock.Setup(m => m.ServerStreaming(It.IsAny <HelloRequest>(), It.IsAny <CallOptions>())) .Returns(TestCalls.AsyncServerStreamingCall( new AsyncStreamReaderStub(ExpectedMessage), Task.FromResult(new Metadata()), () => Status.DefaultSuccess, () => new Metadata(), () => { })); host.AddService(clientMock.Object); var component = host.AddComponent <TestWrapper>(); // Act component.Find("button.execute.serverStreaming").Click(); host.WaitForNextRender(); var markup = component.GetMarkup(); // Assert Assert.Contains(ExpectedMessage, markup); }
public async Task AndUserDoesNotExist_NullIsReturnedAsync() { var loggerMock = Mock.Of <ILogger <AccountManagerService> >(); var clientFactoryMock = new Mock <IClientFactory>(); var clientMock = new Moq.Mock <ResourceAccess.ResourceAccessClient>(); var expectedResponse = new GetUserOnUserNameResponse { User = null }; var fakeCall = TestCalls.AsyncUnaryCall <GetUserOnUserNameResponse>(Task.FromResult(new GetUserOnUserNameResponse()), Task.FromResult(new Metadata()), () => Status.DefaultSuccess, () => new Metadata(), () => { }); clientMock.Setup(m => m.GetUserOnUserNameAsync(Moq.It.IsAny <GetUserOnUserNameRequest>(), null, null, CancellationToken.None)).Returns(fakeCall); clientFactoryMock.Setup(c => c.AccountResourceAccessClient()).Returns(clientMock.Object); var appConfig = Mock.Of <IOptions <AppSettings> >(); var service = new AccountManagerService(loggerMock, clientFactoryMock.Object, appConfig); AuthenticateResponse authResponse = await service.Authenticate(new AuthenticateRequest { HashedPassword = "******", IpAddress = "123", UserName = "******" }, null); Assert.True(string.IsNullOrEmpty(authResponse.JwtToken)); Assert.True(string.IsNullOrEmpty(authResponse.RefreshToken)); Assert.True(string.IsNullOrEmpty(authResponse.Role)); Assert.True(string.IsNullOrEmpty(authResponse.UserId)); Assert.True(string.IsNullOrEmpty(authResponse.UserName)); }
private AsyncUnaryCall <TResponse> MockAsyncUnaryCall <TResponse>(TResponse reply) where TResponse : new() { var call = TestCalls.AsyncUnaryCall(Task.FromResult(reply), Task.FromResult(new Metadata()), () => Status.DefaultSuccess, () => new Metadata(), () => { }); return(call); }
public static void Main(string[] args) { var siloPort = 11111; int gatewayPort = 30000; var siloAddress = IPAddress.Loopback; var silo = new SiloHostBuilder() .UseDashboard(options => { options.HostSelf = true; options.HideTrace = false; }) .UseDevelopmentClustering(options => options.PrimarySiloEndpoint = new IPEndPoint(siloAddress, siloPort)) .UseInMemoryReminderService() .ConfigureEndpoints(siloAddress, siloPort, gatewayPort) .Configure <ClusterOptions>(options => { options.ClusterId = "helloworldcluster"; options.ServiceId = "1"; }) .ConfigureApplicationParts(appParts => appParts.AddApplicationPart(typeof(TestCalls).Assembly)) .ConfigureLogging(builder => { builder.AddConsole(); }) .Build(); silo.StartAsync().Wait(); var client = new ClientBuilder() .UseStaticClustering(options => options.Gateways.Add((new IPEndPoint(siloAddress, gatewayPort)).ToGatewayUri())) .Configure <ClusterOptions>(options => { options.ClusterId = "helloworldcluster"; options.ServiceId = "1"; }) .ConfigureApplicationParts(appParts => appParts.AddApplicationPart(typeof(TestCalls).Assembly)) .ConfigureLogging(builder => { builder.AddConsole(); }) .Build(); client.Connect().Wait(); var cts = new CancellationTokenSource(); TestCalls.Make(client, cts); Console.WriteLine("Press key to exit..."); Console.ReadLine(); cts.Cancel(); silo.StopAsync().Wait(); }
public async Task ToAuthenticateAndUserExist_TokenIsReturnedAsync() { var loggerMock = Mock.Of <ILogger <AccountManagerService> >(); var clientFactoryMock = new Mock <IClientFactory>(); var clientMock = new Moq.Mock <ResourceAccess.ResourceAccessClient>(); var expectedResponse = new GetUserOnUserNameResponse { User = new UserMessage { Firstname = "Firstname", Lastname = "Lastname", UserId = Guid.NewGuid().ToString(), Role = "User", UserName = "******", } }; var fakeCall = TestCalls.AsyncUnaryCall <GetUserOnUserNameResponse>(Task.FromResult(expectedResponse), Task.FromResult(new Metadata()), () => Status.DefaultSuccess, () => new Metadata(), () => { }); clientMock.Setup(m => m.GetUserOnUserNameAsync(Moq.It.IsAny <GetUserOnUserNameRequest>(), null, null, CancellationToken.None)).Returns(fakeCall); var expectedUpdateResponse = new UpdateUserResponse { User = new UserMessage { Firstname = "Firstname", Lastname = "Lastname", UserId = Guid.NewGuid().ToString(), Role = "User", UserName = "******" } }; expectedUpdateResponse.User.RefreshTokens.Add(new RefreshTokenMessage { CreatedByIp = "123", Token = "123123", }); var fakeUIpdateCall = TestCalls.AsyncUnaryCall <UpdateUserResponse>(Task.FromResult(expectedUpdateResponse), Task.FromResult(new Metadata()), () => Status.DefaultSuccess, () => new Metadata(), () => { }); clientMock.Setup(m => m.UpdateUserAsync(Moq.It.IsAny <UpdateUserRequest>(), null, null, CancellationToken.None)).Returns(fakeUIpdateCall); clientFactoryMock.Setup(c => c.AccountResourceAccessClient()).Returns(clientMock.Object); var testoption = Options.Create(new AppSettings { SecretString = "secretStuff!ddddddddddddddddddddddddddddddddddddddddddddddddddddddgggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg" }); var service = new AccountManagerService(loggerMock, clientFactoryMock.Object, testoption); AuthenticateResponse authResponse = await service.Authenticate(new AuthenticateRequest { HashedPassword = "******", IpAddress = "123", UserName = "******" }, null); Assert.False(string.IsNullOrEmpty(authResponse.JwtToken)); Assert.False(string.IsNullOrEmpty(authResponse.RefreshToken)); Assert.False(string.IsNullOrEmpty(authResponse.Role)); Assert.False(string.IsNullOrEmpty(authResponse.UserId)); Assert.False(string.IsNullOrEmpty(authResponse.UserName)); }
public override AsyncUnaryCall <RunningParameter> GetRunningParameterAsync(GetRunningParameterRequest request, Metadata headers = null, DateTime?deadline = null, CancellationToken cancellationToken = default) { return(TestCalls.AsyncUnaryCall( Task.FromResult(RunningParameters[request.DeviceId]), Task.FromResult(new Metadata()), () => Status.DefaultSuccess, () => new Metadata(), () => { })); }
public static void Main(string[] args) { var siloPort = 11111; int gatewayPort = 30000; var siloAddress = IPAddress.Loopback; var silo = new SiloHostBuilder() .UseDashboard(options => { options.HostSelf = true; options.HideTrace = false; }) .UseDevelopmentClustering(options => options.PrimarySiloEndpoint = new IPEndPoint(siloAddress, siloPort)) .UseInMemoryReminderService() .UsePerfCounterEnvironmentStatistics() .ConfigureEndpoints(siloAddress, siloPort, gatewayPort) .Configure <ClusterOptions>(options => options.ClusterId = "helloworldcluster") .ConfigureApplicationParts(appParts => appParts.AddApplicationPart(typeof(TestCalls).Assembly)) .ConfigureLogging(builder => { builder.AddConsole(); }) .ConfigureServices(services => { // Workaround for https://github.com/dotnet/orleans/issues/4129 services.AddSingleton(cp => cp.GetRequiredService <IHostEnvironmentStatistics>() as ILifecycleParticipant <ISiloLifecycle>); }) .Build(); silo.StartAsync().Wait(); var client = new ClientBuilder() .UseStaticClustering(options => options.Gateways.Add((new IPEndPoint(siloAddress, gatewayPort)).ToGatewayUri())) .Configure <ClusterOptions>(options => options.ClusterId = "helloworldcluster") .ConfigureApplicationParts(appParts => appParts.AddApplicationPart(typeof(TestCalls).Assembly)) .ConfigureLogging(builder => { builder.AddConsole(); }) .Build(); client.Connect().Wait(); var cts = new CancellationTokenSource(); TestCalls.Make(client, cts); Console.WriteLine("Press key to exit..."); Console.ReadLine(); cts.Cancel(); silo.StopAsync().Wait(); }
public void ClientBaseAsyncUnaryCallCanBeMocked() { var mockClient = new Moq.Mock <Math.MathClient>(); // Use a factory method provided by Grpc.Core.Testing.TestCalls to create an instance of a call. var fakeCall = TestCalls.AsyncUnaryCall <DivReply>(Task.FromResult(new DivReply()), Task.FromResult(new Metadata()), () => Status.DefaultSuccess, () => new Metadata(), () => { }); mockClient.Setup(m => m.DivAsync(Moq.It.IsAny <DivArgs>(), null, null, CancellationToken.None)).Returns(fakeCall); Assert.AreSame(fakeCall, mockClient.Object.DivAsync(new DivArgs())); }
public void ClientBaseClientStreamingCallCanBeMocked() { var mockClient = new Moq.Mock <Math.MathClient>(); var mockRequestStream = new Moq.Mock <IClientStreamWriter <Num> >(); // Use a factory method provided by Grpc.Core.Testing.TestCalls to create an instance of a call. var fakeCall = TestCalls.AsyncClientStreamingCall <Num, Num>(mockRequestStream.Object, Task.FromResult(new Num()), Task.FromResult(new Metadata()), () => Status.DefaultSuccess, () => new Metadata(), () => { }); mockClient.Setup(m => m.Sum(null, null, CancellationToken.None)).Returns(fakeCall); Assert.AreSame(fakeCall, mockClient.Object.Sum()); }
public override AsyncUnaryCall <Switch> GetSwitchAsync(GetSwitchRequest request, Metadata headers = null, DateTime?deadline = null, CancellationToken cancellationToken = default) { Switch switchInfo = Switches[request.DeviceId]; return(TestCalls.AsyncUnaryCall( Task.FromResult(switchInfo.Clone()), Task.FromResult(new Metadata()), () => Status.DefaultSuccess, () => new Metadata(), () => { })); }
public static AsyncUnaryCall <TResponse> AsyncUnaryCall <TResponse>( Task <TResponse> responseAsync, Task <Metadata> responseHeadersAsync = null, Func <Status> getStatusFunc = null, Func <Metadata> getTrailersFunc = null, Action disposeAction = null) { return(TestCalls.AsyncUnaryCall( responseAsync, responseHeadersAsync, getStatusFunc, getTrailersFunc, disposeAction)); }
public void Test1() { var mockClient = new Moq.Mock <ProductInfoClient>(); var fakeCall = TestCalls.AsyncUnaryCall(Task.FromResult(new ProductID()), Task.FromResult(new Metadata()), () => Status.DefaultSuccess, () => new Metadata(), () => { }); mockClient.Setup(m => m.AddProductAsync(Moq.It.IsAny <Product>(), null, null, CancellationToken.None)).Returns(fakeCall); Assert.Same(fakeCall, mockClient.Object.AddProductAsync(new Product())); }
public void ClientBaseServerStreamingCallCanBeMocked() { var mockClient = new Moq.Mock <Math.MathClient>(); var mockResponseStream = new Moq.Mock <IAsyncStreamReader <Num> >(); // Use a factory method provided by Grpc.Core.Testing.TestCalls to create an instance of a call. var fakeCall = TestCalls.AsyncServerStreamingCall <Num>(mockResponseStream.Object, Task.FromResult(new Metadata()), () => Status.DefaultSuccess, () => new Metadata(), () => { }); mockClient.Setup(m => m.Fib(Moq.It.IsAny <FibArgs>(), null, null, CancellationToken.None)).Returns(fakeCall); Assert.AreSame(fakeCall, mockClient.Object.Fib(new FibArgs())); }
private AsyncClientStreamingCall<TReq, TResp> MockStreamCall<TReq, TResp>(Task<TResp> replyTask) where TResp : new() { var mockRequestStream = new Mock<IClientStreamWriter<TReq>>(); mockRequestStream.Setup(m => m.WriteAsync(It.IsAny<TReq>())) .Returns(replyTask); var call = TestCalls.AsyncClientStreamingCall(mockRequestStream.Object, Task.FromResult(new TResp()), Task.FromResult(new Metadata()), () => Status.DefaultSuccess, () => new Metadata(), () => { }); return call; }
public override AsyncUnaryCall <ListDevicesResponse> ListDevicesAsync(ListDevicesRequest request, Metadata headers = null, DateTime?deadline = null, CancellationToken cancellationToken = default) { var response = new ListDevicesResponse(); response.Devices.Add(Devices.Values); return(TestCalls.AsyncUnaryCall( Task.FromResult(response), Task.FromResult(new Metadata()), () => Status.DefaultSuccess, () => new Metadata(), () => { })); }
public override AsyncUnaryCall <ListMetricsResponse> ListMetricsAsync(ListMetricsRequest request, Metadata headers = null, DateTime?deadline = null, CancellationToken cancellationToken = default) { DateTimeOffset endDateTime; if (string.IsNullOrEmpty(request.PageToken)) { endDateTime = request.EndTime?.ToDateTimeOffset() ?? DateTimeOffset.UtcNow; } else { endDateTime = DateTimeOffset.Parse(request.PageToken, CultureInfo.InvariantCulture); } endDateTime = endDateTime.ToUniversalTime(); var startDateTime = request.StartTime?.ToDateTime(); var metrics = new List <Metric>(request.PageSize); for (int i = 0; i < request.PageSize; i++) { endDateTime = endDateTime.Subtract(TimeSpan.FromSeconds(5)); if (startDateTime.HasValue && startDateTime > endDateTime) { break; } metrics.Add(new Metric { CreateTime = Timestamp.FromDateTimeOffset(endDateTime), InputWaterCelsiusDegree = RandomUtils.NextFloat(10, 20), OutputWaterCelsiusDegree = RandomUtils.NextFloat(10, 20), HeaterOutputWaterCelsiusDegree = RandomUtils.NextFloat(10, 20), EnvironmentCelsiusDegree = RandomUtils.NextFloat(10, 20), HeaterPowerKilowatt = RandomUtils.NextFloat(0, 12), WaterPumpFlowRateCubicMeterPerHour = RandomUtils.NextFloat(1, 3), }); } var response = new ListMetricsResponse { NextPageToken = endDateTime.ToUniversalTime().ToString(CultureInfo.InvariantCulture), }; response.Metrics.AddRange(metrics); return(TestCalls.AsyncUnaryCall( Task.FromResult(response), Task.FromResult(new Metadata()), () => Status.DefaultSuccess, () => new Metadata(), () => { })); }
public async Task Reserve_Returns_OK() { var mockClient = new Mock <SDK.SDKClient>(); var mockSdk = new AgonesSDK(); var expected = StatusCode.OK; var fakeCall = TestCalls.AsyncUnaryCall(Task.FromResult(new Empty()), Task.FromResult(new Metadata()), () => Status.DefaultSuccess, () => new Metadata(), () => { }); mockClient.Setup(m => m.ReserveAsync(It.IsAny <Duration>(), It.IsAny <Metadata>(), It.IsAny <DateTime?>(), It.IsAny <CancellationToken>())).Returns(fakeCall); mockSdk.client = mockClient.Object; var result = await mockSdk.ReserveAsync(30); Assert.AreEqual(expected, result.StatusCode); }
public async Task GetGameServer_Returns_OK() { var mockClient = new Mock <SDK.SDKClient>(); var mockSdk = new AgonesSDK(); var expected = new GameServer(); var fakeCall = TestCalls.AsyncUnaryCall(Task.FromResult(expected), Task.FromResult(new Metadata()), () => Status.DefaultSuccess, () => new Metadata(), () => { }); mockClient.Setup(m => m.GetGameServerAsync(It.IsAny <Empty>(), It.IsAny <Metadata>(), It.IsAny <DateTime?>(), It.IsAny <CancellationToken>())).Returns(fakeCall); mockSdk.client = mockClient.Object; var result = await mockSdk.GetGameServerAsync(); Assert.AreSame(expected, result); }
public override AsyncUnaryCall <ListAlarmChangesResponse> ListAlarmChangesAsync(ListAlarmChangesRequest request, Metadata headers = null, DateTime?deadline = null, CancellationToken cancellationToken = default) { DateTimeOffset endDateTime; if (string.IsNullOrEmpty(request.PageToken)) { endDateTime = request.EndTime?.ToDateTimeOffset() ?? DateTimeOffset.UtcNow; } else { endDateTime = DateTimeOffset.Parse(request.PageToken, CultureInfo.InvariantCulture); } endDateTime = endDateTime.ToUniversalTime(); var startDateTime = request.StartTime?.ToDateTime(); var alarmChanges = new List <AlarmChange>(request.PageSize); for (int i = 0; i < request.PageSize; i++) { endDateTime = endDateTime.Subtract(TimeSpan.FromSeconds(5)); if (startDateTime.HasValue && startDateTime > endDateTime) { break; } alarmChanges.Add(new AlarmChange { CreateTime = Timestamp.FromDateTimeOffset(endDateTime), AlarmType = (AlarmType)RandomUtils.Next(1, 7), AlarmChangeDirection = (AlarmChangeDirection)RandomUtils.Next(1, 3), }); } var response = new ListAlarmChangesResponse { NextPageToken = endDateTime.ToUniversalTime().ToString(CultureInfo.InvariantCulture), }; response.AlarmChanges.AddRange(alarmChanges); return(TestCalls.AsyncUnaryCall( Task.FromResult(response), Task.FromResult(new Metadata()), () => Status.DefaultSuccess, () => new Metadata(), () => { })); }
public async Task GetPlayerCapacity_Sends_OK() { var mockClient = new Mock <SDK.SDKClient>(); var mockSdk = new AgonesSDK(); var expected = new Count() { Count_ = 1 }; var fakeCall = TestCalls.AsyncUnaryCall(Task.FromResult(expected), Task.FromResult(new Metadata()), () => Status.DefaultSuccess, () => new Metadata(), () => { }); mockClient.Setup(m => m.GetPlayerCapacityAsync(It.IsAny <Empty>(), It.IsAny <Metadata>(), It.IsAny <DateTime?>(), It.IsAny <CancellationToken>())).Returns(fakeCall); mockSdk.alpha.client = mockClient.Object; var result = await mockSdk.Alpha().GetPlayerCapacityAsync(); Assert.AreEqual(expected.Count_, result); }
public override AsyncUnaryCall <Metric> GetMetricAsync(GetMetricRequest request, Metadata headers = null, DateTime?deadline = null, CancellationToken cancellationToken = default) { return(TestCalls.AsyncUnaryCall( Task.FromResult(new Metric { InputWaterCelsiusDegree = RandomUtils.NextFloat(10, 20), OutputWaterCelsiusDegree = RandomUtils.NextFloat(10, 20), HeaterOutputWaterCelsiusDegree = RandomUtils.NextFloat(10, 20), EnvironmentCelsiusDegree = RandomUtils.NextFloat(10, 20), HeaterPowerKilowatt = RandomUtils.NextFloat(0, 12), WaterPumpFlowRateCubicMeterPerHour = RandomUtils.NextFloat(1, 3), }), Task.FromResult(new Metadata()), () => Status.DefaultSuccess, () => new Metadata(), () => { })); }
public async Task PlayerDisconnect_Sends_OK() { var mockClient = new Mock <SDK.SDKClient>(); var mockSdk = new AgonesSDK(); var expected = new Bool() { Bool_ = true }; var fakeCall = TestCalls.AsyncUnaryCall(Task.FromResult(expected), Task.FromResult(new Metadata()), () => Status.DefaultSuccess, () => new Metadata(), () => { }); mockClient.Setup(m => m.PlayerDisconnectAsync(It.IsAny <PlayerID>(), It.IsAny <Metadata>(), It.IsAny <DateTime?>(), It.IsAny <CancellationToken>())).Returns(fakeCall); mockSdk.alpha.client = mockClient.Object; var result = await mockSdk.Alpha().PlayerDisconnectAsync("test"); Assert.AreEqual(expected.Bool_, result); }
public static void Main(string[] args) { var configuration = ClusterConfiguration.LocalhostPrimarySilo(33333) .RegisterDashboard(); var silo = new SiloHostBuilder() .UseConfiguration(configuration) .UseDashboard(options => { options.HostSelf = true; options.HideTrace = false; }) .ConfigureApplicationParts(appParts => appParts.AddApplicationPart(typeof(TestCalls).Assembly)) .ConfigureLogging(builder => { builder.AddConsole(); }) .Build(); silo.StartAsync().Wait(); var client = new ClientBuilder() .UseConfiguration(ClientConfiguration.LocalhostSilo()) .ConfigureApplicationParts(appParts => appParts.AddApplicationPart(typeof(TestCalls).Assembly)) .ConfigureLogging(builder => { builder.AddConsole(); }) .Build(); client.Connect().Wait(); var cts = new CancellationTokenSource(); TestCalls.Make(client, cts); Console.WriteLine("Press key to exit..."); Console.ReadLine(); cts.Cancel(); silo.StopAsync().Wait(); }
public override AsyncUnaryCall <AuthenticateResponse> AuthenticateAsync( AuthenticateRequest request, Metadata headers = null, DateTime?deadline = null, CancellationToken cancellationToken = default) { if (request.Username == "user" && request.Password == "user") { return(TestCalls.AsyncUnaryCall( Task.FromResult( new AuthenticateResponse() { Nickname = "用户1", Role = UserRole.User, }), Task.FromResult(new Metadata()), () => Status.DefaultSuccess, () => new Metadata(), () => { })); } else if (request.Username == "admin" && request.Password == "admin") { return(TestCalls.AsyncUnaryCall( Task.FromResult( new AuthenticateResponse() { Nickname = "管理员1", Role = UserRole.Administrator, }), Task.FromResult(new Metadata()), () => Status.DefaultSuccess, () => new Metadata(), () => { })); } else { var status = new Status(StatusCode.Unauthenticated, "Invalid username or password."); return(TestCalls.AsyncUnaryCall( Task.FromException <AuthenticateResponse>(new RpcException(status)), Task.FromResult(new Metadata()), () => status, () => new Metadata(), () => { })); } }
public async Task SetLabel_Sends_OK() { var mockClient = new Mock <SDK.SDKClient>(); var mockSdk = new AgonesSDK(); var fakeCall = TestCalls.AsyncUnaryCall(Task.FromResult(new Empty()), Task.FromResult(new Metadata()), () => Status.DefaultSuccess, () => new Metadata(), () => { }); KeyValue expectedKeyValue = new KeyValue(); expectedKeyValue.Key = "Test"; expectedKeyValue.Value = "Test"; KeyValue actualKeyValue = null; mockClient.Setup(m => m.SetLabelAsync(It.IsAny <KeyValue>(), It.IsAny <Metadata>(), It.IsAny <DateTime?>(), It.IsAny <CancellationToken>())).Returns(fakeCall) .Callback( (KeyValue kv, Metadata md, DateTime? dt, CancellationToken ct) => { actualKeyValue = kv; }); mockSdk.client = mockClient.Object; var result = await mockSdk.SetLabelAsync(expectedKeyValue.Key, expectedKeyValue.Value); Assert.AreEqual(expectedKeyValue, actualKeyValue); }
public override AsyncUnaryCall <WorkingMode> UpdateWorkingModeAsync(UpdateWorkingModeRequest request, Metadata headers = null, DateTime?deadline = null, CancellationToken cancellationToken = default) { WorkingMode workingMode = WorkingModes[request.DeviceId]; if (request.UpdateMask == null) { workingMode.MergeFrom(request.WorkingMode); } else { request.UpdateMask.Merge(request.WorkingMode, workingMode); } return(TestCalls.AsyncUnaryCall( Task.FromResult(workingMode), Task.FromResult(new Metadata()), () => Status.DefaultSuccess, () => new Metadata(), () => { })); }
public override AsyncUnaryCall <RunningParameter> UpdateRunningParameterAsync(UpdateRunningParameterRequest request, Metadata headers = null, DateTime?deadline = null, CancellationToken cancellationToken = default) { RunningParameter runningParameter = RunningParameters[request.DeviceId]; if (request.UpdateMask == null) { runningParameter.MergeFrom(request.RunningParameter); } else { request.UpdateMask.Merge(request.RunningParameter, runningParameter); } return(TestCalls.AsyncUnaryCall( Task.FromResult(runningParameter), Task.FromResult(new Metadata()), () => Status.DefaultSuccess, () => new Metadata(), () => { })); }
public async Task GetConnectedPlayers_Sends_OK() { var mockClient = new Mock <SDK.SDKClient>(); var mockSdk = new AgonesSDK(); var expected = new List <string> { "player1", "player2" }; var playerList = new PlayerIDList() { List = { expected } }; var fakeCall = TestCalls.AsyncUnaryCall(Task.FromResult(playerList), Task.FromResult(new Metadata()), () => Status.DefaultSuccess, () => new Metadata(), () => { }); mockClient.Setup(m => m.GetConnectedPlayersAsync(It.IsAny <Empty>(), It.IsAny <Metadata>(), It.IsAny <DateTime?>(), It.IsAny <CancellationToken>())).Returns(fakeCall); mockSdk.alpha.client = mockClient.Object; var result = await mockSdk.Alpha().GetConnectedPlayersAsync(); CollectionAssert.AreEquivalent(expected, result); }
public void WatchGameServer_Returns_OK() { var mockClient = new Mock <SDK.SDKClient>(); var mockResponseStream = new Moq.Mock <IAsyncStreamReader <GameServer> >(); var mockSdk = new AgonesSDK(); var expectedWatchReturn = new GameServer(); GameServer actualWatchReturn = null; var serverStream = TestCalls.AsyncServerStreamingCall <GameServer>(mockResponseStream.Object, Task.FromResult(new Metadata()), () => Status.DefaultSuccess, () => new Metadata(), () => { }); mockClient.Setup(m => m.WatchGameServer(It.IsAny <Empty>(), It.IsAny <Metadata>(), It.IsAny <DateTime?>(), It.IsAny <CancellationToken>())).Returns(serverStream); mockResponseStream.Setup(m => m.Current).Returns(expectedWatchReturn); mockResponseStream.SetupSequence(m => m.MoveNext(It.IsAny <CancellationToken>())) .Returns(Task.FromResult(true)) .Returns(Task.FromResult(false)); mockSdk.client = mockClient.Object; mockSdk.WatchGameServer((gs) => { actualWatchReturn = gs; }); Assert.AreSame(expectedWatchReturn, actualWatchReturn); }
public async Task Reserve_Sends_OK() { var mockClient = new Mock <SDK.SDKClient>(); var mockSdk = new AgonesSDK(); var fakeCall = TestCalls.AsyncUnaryCall(Task.FromResult(new Empty()), Task.FromResult(new Metadata()), () => Status.DefaultSuccess, () => new Metadata(), () => { }); var expectedDuration = new Duration(); expectedDuration.Seconds = 30; Duration actualDuration = null; mockClient.Setup(m => m.ReserveAsync(It.IsAny <Duration>(), It.IsAny <Metadata>(), It.IsAny <DateTime?>(), It.IsAny <CancellationToken>())).Returns(fakeCall) .Callback( (Duration dur, Metadata md, DateTime? dt, CancellationToken ct) => { actualDuration = dur; }); mockSdk.client = mockClient.Object; var result = await mockSdk.ReserveAsync(30); Assert.AreEqual(expectedDuration, actualDuration); }