public void RequestContextIsSet() { WampPlayground playground = new WampPlayground(); IWampHost host = playground.Host; WampRequestContext context = null; Mock <ICalculator> calculatorMock = new Mock <ICalculator>(); calculatorMock.Setup(x => x.Square(It.IsAny <int>())) .Callback((int x) => context = WampRequestContext.Current) .Returns((int x) => x * x); host.HostService(calculatorMock.Object); host.Open(); IWampChannel <MockRaw> channel = playground.CreateNewChannel(); channel.Open(); ICalculator proxy = channel.GetRpcProxy <ICalculator>(); int sixteen = proxy.Square(4); Assert.That(context.SessionId, Is.EqualTo(channel.GetMonitor().SessionId)); }
public void AsyncAwaitTaskWork() { WampPlayground playground = new WampPlayground(); IWampHost host = playground.Host; WampRequestContext context = null; Mock <INumberProcessor> mock = new Mock <INumberProcessor>(); mock.Setup(x => x.ProcessNumber(It.IsAny <int>())) .Returns(async(int x) => { }); host.HostService(mock.Object); host.Open(); IWampChannel <MockRaw> channel = playground.CreateNewChannel(); channel.Open(); INumberProcessor proxy = channel.GetRpcProxy <INumberProcessor>(); Task task = proxy.ProcessNumber(4); mock.Verify(x => x.ProcessNumber(4)); }
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILog appLog, IApplicationLifetime appLifetime) { IWampHost host = ApplicationContainer.Resolve <IWampHost>(); IWampHostedRealm realm = ApplicationContainer.Resolve <IWampHostedRealm>(); var rpcMethods = ApplicationContainer.Resolve <IRpcMethods>(); appLifetime.ApplicationStopped.Register(() => { ApplicationContainer.Dispose(); }); appLifetime.ApplicationStarted.Register(() => realm.Services.RegisterCallee(rpcMethods).Wait() ); app.UseMvc(); app.UseSwagger(); app.UseSwaggerUi("swagger/ui/index"); app.Map("/ws", builder => { builder.UseWebSockets(new WebSocketOptions { KeepAliveInterval = TimeSpan.FromMinutes(1) }); host.RegisterTransport(new AspNetCoreWebSocketTransport(builder), new JTokenJsonBinding()); }); host.Open(); appLog.WriteInfoAsync("BoxOptionsServer", "Startup.Configure", null, string.Format("Lykke.BoxOptionsServer [{0}] started.", Microsoft.Extensions.PlatformAbstractions.PlatformServices.Default.Application.ApplicationVersion)); }
public void NoAuthenticationThrowsException() { JsonFormatter formatter = new JsonFormatter(); WampCraPlayground <JToken> playground = new WampCraPlayground <JToken> (formatter, new MockWampCraAuthenticaticationBuilder <JToken>()); IWampChannelFactory <JToken> channelFactory = playground.ChannelFactory; IWampHost host = playground.Host; host.HostService(new Sample()); host.Open(); IControlledWampConnection <JToken> connection = playground.CreateClientConnection(); IWampChannel <JToken> channel = channelFactory.CreateChannel(connection); channel.Open(); Task <string> result = channel.GetRpcProxy <ISampleAsync>() .Hello("Foobar"); AggregateException aggregateException = result.Exception; Exception exception = aggregateException.InnerException; WampRpcCallException casted = exception as WampRpcCallException; Assert.IsNotNull(casted); }
public void AuthenticationSuccess() { JsonFormatter formatter = new JsonFormatter(); WampCraPlayground <JToken> playground = new WampCraPlayground <JToken> (formatter, new MockWampCraAuthenticaticationBuilder <JToken>()); IWampChannelFactory <JToken> channelFactory = playground.ChannelFactory; IWampHost host = playground.Host; host.HostService(new Sample()); host.Open(); IControlledWampConnection <JToken> connection = playground.CreateClientConnection(); IWampChannel <JToken> channel = channelFactory.CreateChannel(connection); channel.Open(); channel.GetRpcProxy <IWampCraProcedures>(). Authenticate(formatter, "foobar", null, "secret"); string result = channel.GetRpcProxy <ISample>() .Hello("Foobar"); Assert.That(result, Is.Not.Null.Or.Empty); }
public void SyncClientRpcCallsAsyncServerThrowsException() { WampPlayground playground = new WampPlayground(); IWampHost host = playground.Host; WampRpcCallException exception = new WampRpcCallException("calculator.add", "This is very bad caclulator implementation", null); Mock <IAsyncCalculator> calculatorMock = GetAsyncErrorCalculatorMock(exception); host.HostService(calculatorMock.Object); host.Open(); IWampChannel <MockRaw> channel = playground.CreateNewChannel(); channel.Open(); ICalculator proxy = channel.GetRpcProxy <ICalculator>(); WampRpcCallException thrown = Assert.Throws <WampRpcCallException>(() => proxy.Add(3, 4)); Assert.That(thrown.ProcUri, Is.EqualTo("test/add")); Assert.That(thrown.ErrorDetails, Is.EqualTo(exception.ErrorDetails)); Assert.That(thrown.ErrorUri, Is.EqualTo(exception.ErrorUri)); Assert.That(thrown.Message, Is.EqualTo(exception.Message)); }
public void AsyncClientRpcCallsServer() { WampPlayground playground = new WampPlayground(); IWampHost host = playground.Host; Mock <ICalculator> calculatorMock = GetCalculatorMock(); host.HostService(calculatorMock.Object); host.Open(); IWampChannel <MockRaw> channel = playground.CreateNewChannel(); channel.Open(); IAsyncCalculator proxy = channel.GetRpcProxy <IAsyncCalculator>(); Task <int> sevenTask = proxy.Add(3, 4); int seven = sevenTask.Result; calculatorMock.Verify(x => x.Add(3, 4)); Assert.That(seven, Is.EqualTo(7)); }
public void TopicOnNextCallsSubjectOnNext() { WampPlayground playground = new WampPlayground(); IWampHost host = playground.Host; IWampTopicContainer topicContainer = host.TopicContainer; host.Open(); IWampChannel <MockRaw> channel = playground.CreateNewChannel(); channel.Open(); IWampTopic topic = null; topicContainer.TopicCreated += (sender, args) => topic = args.Topic; object @event = null; string topicUri = "http://example.com/simple"; ISubject <object> subject = channel.GetSubject <object>(topicUri); subject.Subscribe(x => @event = x); Assert.That(topic, Is.Not.Null); Assert.That(topic.TopicUri, Is.EqualTo(topicUri)); string value = "Test :)"; topic.OnNext(value); Assert.That(@event, Is.EqualTo(value)); }
public void AuthenticationFailure() { JsonFormatter formatter = new JsonFormatter(); WampCraPlayground <JToken> playground = new WampCraPlayground <JToken> (formatter, new MockWampCraAuthenticaticationBuilder <JToken>()); IWampChannelFactory <JToken> channelFactory = playground.ChannelFactory; IWampHost host = playground.Host; host.HostService(new Sample()); host.Open(); IControlledWampConnection <JToken> connection = playground.CreateClientConnection(); IWampChannel <JToken> channel = channelFactory.CreateChannel(connection); channel.Open(); IWampCraProcedures proceduresProxy = channel.GetRpcProxy <IWampCraProcedures>(); WampRpcCallException callException = Assert.Throws <WampRpcCallException> (() => proceduresProxy.Authenticate(formatter, "foobar", null, "secret2")); }
// PUBLIC METHODS #region public methods #region Dispose() public void Dispose() { if (_host != null) { _host.Dispose(); _host = null; } }
public WampMiddleware(RequestDelegate next, ILogger <WampMiddleware> logger, IWampHost host, IServiceProvider provider) { _next = next; _logger = logger; var realm = host.RealmContainer.GetRealmByName("realm1"); realm.Services.RegisterCallee(() => provider.CreateScope().ServiceProvider.GetRequiredService <IWeatherForecastService>()); }
public void AsyncClientRpcCallsServerThrowsException() { WampPlayground playground = new WampPlayground(); IWampHost host = playground.Host; WampRpcCallException exception = new WampRpcCallException("calculator.add", "This is very bad caclulator implementation", null); Mock <ICalculator> calculatorMock = GetErrorCalculatorMock(exception); host.HostService(calculatorMock.Object); host.Open(); IWampChannel <MockRaw> channel = playground.CreateNewChannel(); channel.Open(); IAsyncCalculator proxy = channel.GetRpcProxy <IAsyncCalculator>(); Task <int> task = proxy.Add(3, 4); try { task.Wait(); } catch (Exception) { } AggregateException aggregateException = task.Exception; Assert.That(aggregateException, Is.Not.Null); Exception innerException = aggregateException.InnerException; Assert.That(innerException, Is.InstanceOf <WampRpcCallException>()); WampRpcCallException thrown = innerException as WampRpcCallException; Assert.That(thrown.ProcUri, Is.EqualTo("test/add")); Assert.That(thrown.ErrorDetails, Is.EqualTo(exception.ErrorDetails)); Assert.That(thrown.ErrorUri, Is.EqualTo(exception.ErrorUri)); Assert.That(thrown.Message, Is.EqualTo(exception.Message)); }
public static void UseWampHost(this IApplicationBuilder app, IWampHost host) { app.Map("/ws", builder => { builder.UseWebSockets(new WebSocketOptions { KeepAliveInterval = TimeSpan.FromMinutes(1) }); var jsonSettings = new JsonSerializerSettings(); jsonSettings.Converters.Add(new Newtonsoft.Json.Converters.StringEnumConverter()); var jsonSerializer = JsonSerializer.Create(jsonSettings); host.RegisterTransport(new AspNetCoreWebSocketTransport(builder), new JTokenJsonBinding(jsonSerializer), new JTokenMsgpackBinding(jsonSerializer)); }); host.Open(); }
public Router() { _host = new DefaultWampHost(location); IArgumentsService instance = new ArgumentsService(); IWampHostedRealm realm = _host.RealmContainer.GetRealmByName("realm1"); Task <IAsyncDisposable> registrationTask = realm.Services.RegisterCallee(instance); // await registrationTask; registrationTask.Wait(); _host.Open(); //Console.WriteLine("Server is running on " + location); //Console.ReadLine(); }
private static void SetupHost(WampAuthenticationPlayground playground) { IWampHost host = playground.Host; IWampHostedRealm realm = host.RealmContainer.GetRealmByName("realm1"); string[] topics = new[] { "com.example.topic1", "com.example.topic2", "com.foobar.topic1", "com.foobar.topic2" }; foreach (string topic in topics) { realm.TopicContainer.CreateTopicByUri(topic, true); } realm.Services.RegisterCallee(new Add2Service()); host.Open(); }
public WampRunner(IWampHost wampHost) { _wampHost = wampHost; }
/// <summary> /// Registers a given transport for a given host. /// </summary> /// <param name="host">The given host.</param> /// <param name="transport">The given transport to register.</param> /// <param name="binding">The given bindings to activate support with the given transport.</param> public static void RegisterTransport(this IWampHost host, IWampTransport transport, params IWampBinding[] binding) { host.RegisterTransport(transport, binding); }
protected WampCraPlayground(IWampFormatter <TMessage> formatter, MockConnectionListener <TMessage> listener, IWampHost host) : base(formatter, listener, host) { }