private async Task Run(IRtmpConnection connection) { var count = 1; var token = _tokenSource.Token; while (!token.IsCancellationRequested) { await Task.Delay(TimeSpan.FromMilliseconds(120000), token); if (token.IsCancellationRequested) return; var date = DateTime.UtcNow.ToString("ddd MMM d yyyy HH:mm:ss 'GMTZ'"); try { var session = _sessionManager.CurrentSession; if (session == null) continue; var invoke = new Invocation<int>("loginService", "performLCDSHeartBeat", session.accountSummary.accountId, session.token, count, date); await invoke.Execute(connection); } catch (AggregateException agg) { agg.Handle(e => e is TaskCanceledException); } count++; } _tokenSource = null; _heartbeat = null; }
public async void Can_return_faults_when_a_service_call_fails() { var connection = new MockRtmpConnection {ShouldSucceed = false}; var failure = new Func<Fault, Exception>(fault => new InvalidOperationException()); var invocation = new Invocation<object>(Invocation.EndpointName, "service", "method", null, failure); await invocation.Execute(connection); }
public void Execute_WithExpression_Executes() { var exp = new Mock <IExpression>(); var subject = new Invocation(exp.Object); subject.Execute(new Mock <IContext>().Object); Assert.That(() => exp.Verify(e => e.Interpret(It.IsAny <IContext>())), Throws.Nothing); }
public async void Can_automatically_cancel_the_invocation_after_a_default_timespan() { var connection = new MockRtmpConnection {ShouldTimeout = true}; var invocation = new Invocation<object>(Invocation.EndpointName, "service", "method") { DefaultTimeout = TimeSpan.FromSeconds(1) }; await invocation.Execute(connection); }
public async Task Logout(IRtmpConnection connection) { if (CurrentSession == null) return; if (string.IsNullOrWhiteSpace(CurrentSession.token)) return; var invoke = new Invocation<AcknowledgeMessage>("loginService", "logout", CurrentSession.token); var message = await invoke.Execute(connection); return; }
public async void Can_execute_a_service_call() { var connection = new MockRtmpConnection {ShouldSucceed = true}; var successful = false; var success = new Action<object>(o => successful = true); var invocation = new Invocation<object>(Invocation.EndpointName, "service", "method", success, null); var result = await invocation.Execute(connection); Assert.That(result, Is.Not.Null); Assert.That(successful, Is.True); }
public async Task<LolSession> Login(IRtmpConnection connection, AuthenticationCredentials credentials) { Credentials = credentials; var invoke = new Invocation<LolSession>("loginService", "login", credentials); CurrentSession = await invoke.Execute(connection); await AuthorizeSession(connection, CurrentSession); if (_action != null) _action(); return CurrentSession; }
public async void Can_manually_cancel_the_invocation() { var connection = new MockRtmpConnection {ShouldTimeout = true}; var invocation = new Invocation<object>(Invocation.EndpointName, "service", "method"); using (var tcs = new CancellationTokenSource()) { var task = invocation.Execute(connection, tcs.Token); // immediately cancel tcs.Cancel(); await task; } }
public async Task Subscribe(IRtmpConnection connection) { var session = _sessionManager.CurrentSession; if (session == null) throw new InvalidOperationException("The session has not been created, yet. Unable to subscribe."); var bcMessage = CreateSubscribeMessage("bc", "bc-" + session.accountSummary.accountId); var cnMessage = CreateSubscribeMessage("cn-" + session.accountSummary.accountId, "cn-" + session.accountSummary.accountId); var gnMessage = CreateSubscribeMessage("gn-" + session.accountSummary.accountId, "gn-" + session.accountSummary.accountId); var bcInvoke = new Invocation<object>(bcMessage); await bcInvoke.Execute(connection); var cnInvoke = new Invocation<object>(cnMessage); await cnInvoke.Execute(connection); var gnInvoke = new Invocation<object>(gnMessage); await gnInvoke.Execute(connection); }
public async void Will_throw_when_an_error_happens_during_success_parsing() { var connection = new MockRtmpConnection {ShouldSucceed = true}; var success = new Action<object>(o => { throw new InvalidOperationException(); }); var invocation = new Invocation<object>(Invocation.EndpointName, "service", "method", success, null); await invocation.Execute(connection); }
public async void Will_cancel_when_disconnected() { var connection = new MockRtmpConnection {ShouldDisconnect = true}; var invocation = new Invocation<object>(Invocation.EndpointName, "service", "method"); await invocation.Execute(connection); }
public async void Will_throw_when_an_error_happens_during_failure_parsing() { var connection = new MockRtmpConnection {ShouldSucceed = false}; var failure = new Func<Fault, Exception>(o => { throw new InvalidOperationException(); }); var invocation = new Invocation<object>(Invocation.EndpointName, "service", "method", null, failure); await invocation.Execute(connection); }