public async void GivenJoinSessionIsCalled_WhenConnectionReturnsSuccesfulResult_ThenSuccessCallbackIsInvoked() { var sessionId = "12345"; var userId = "98876"; var userToken = "8482910"; Action <string> callbackMethod = null; _pokerConnection.Setup(x => x.Initialize(It.IsAny <Action <string> >(), It.IsAny <Action>(), It.IsAny <CancellationToken>())) .Callback <Action <string>, Action, CancellationToken>((success, error, cancel) => { callbackMethod = success; }) .Returns(Task.CompletedTask); _pokerConnection.Setup(x => x.Send(It.IsAny <String>())).Returns(Task.CompletedTask); _responseMessageParser.Setup(x => x.Get(It.IsAny <string>())).Returns(new JoinSessionResponse(sessionId, userId, userToken)); var callbackHappened = false; _planningPokerConnection.OnJoinSessionSucceeded(() => { callbackHappened = true; }); await _planningPokerConnection.Start(CancellationToken.None); await _planningPokerConnection.JoinSession(sessionId, "Fred"); callbackMethod($"PP 1.0\nMessageType:JoinSessionResponse\nSuccess:true\nSessionId:{sessionId}\nUserId:{userId}\nUserToken:{userToken}\n"); Thread.Sleep(500); Assert.True(callbackHappened); }
public async void GivenCreateSessionIsCalled_WhenConnectionSendsSuccesfulResponse_OnSuccessIsCalled() { var sessionId = "665330"; var userId = "2db90720-f234-4ec6-88d7-56eeca3be56b"; var userToken = "ABigToken"; Action <string> callbackMethod = null; _pokerConnection.Setup(x => x.Initialize(It.IsAny <Action <string> >(), It.IsAny <Action>(), It.IsAny <CancellationToken>())) .Callback <Action <string>, Action, CancellationToken>((success, error, cancel) => { callbackMethod = success; }) .Returns(Task.CompletedTask); _pokerConnection.Setup(x => x.Send(It.IsAny <String>())).Returns(Task.CompletedTask); _responseMessageParser.Setup(x => x.Get(It.IsAny <string>())).Returns(new NewSessionResponse(sessionId, userId, userToken)); var callbackHappened = false; _planningPokerConnection.OnSessionSuccesfullyCreated((x) => { callbackHappened = true; }); await _planningPokerConnection.Start(CancellationToken.None); await _planningPokerConnection.CreateSession("Fred"); callbackMethod($"PP 1.0\nMessageType:NewSessionResponse\nSuccess:true\nSessionId:{sessionId}\nUserId:{userId}\nToken:{userToken}"); Thread.Sleep(500); Assert.True(callbackHappened); }
public async void GivenConnectedSession_WhenConnectionRaisesRefreshEvent_ThenSessioninformationIsRetrievedUsingSessionService() { _planningPokerConnection.OnSessionInformationUpdated((pokerSession) => { }); _planningPokerService.Setup(x => x.GetSessionDetails(_expectedSessionId)).Returns(Task.FromResult(new PokerSession() { })); await _planningPokerConnection.Start(CancellationToken.None); _callbackMethod($"PP 1.0\nMessageType:RefreshSession\nSuccess:true\nSessionId:{_expectedSessionId}"); Thread.Sleep(500); _planningPokerService.Verify(x => x.GetSessionDetails(It.Is <string>(y => y == _expectedSessionId)), Times.Once); }
public async void GivenSubscribeSessionIsCalled_WhenConnectionReturnsSuccesfulResult_ThenSuccessCallbackIsInvoked() { var sessionId = "1234"; var userId = "5678"; var userToken = "0987654"; var userName = "******"; _userCacheProvider.Setup(x => x.GetUser(sessionId, userId)).ReturnsAsync(new UserCacheItem() { SessionId = sessionId, UserId = userId, UserName = userName, Token = userToken }); _pokerConnection.Setup(x => x.Send(It.IsAny <string>())).Returns(Task.CompletedTask); Action <string> callbackMethod = null; _pokerConnection.Setup(x => x.Initialize(It.IsAny <Action <string> >(), It.IsAny <Action>(), It.IsAny <CancellationToken>())) .Callback <Action <string>, Action, CancellationToken>((success, error, cancel) => { callbackMethod = success; }) .Returns(Task.CompletedTask); _pokerConnection.Setup(x => x.Send(It.IsAny <String>())).Returns(Task.CompletedTask); _responseMessageParser.Setup(x => x.Get(It.IsAny <string>())).Returns(new SubscribeSessionResponse(true, sessionId)); var callbackHappened = false; _planningPokerConnection.OnSessionSubscribeSucceeded(() => { callbackHappened = true; }); await _planningPokerConnection.Start(CancellationToken.None); await _planningPokerConnection.SubscribeSession(userId, sessionId); callbackMethod($"PP 1.0\nMessageType:SubscribeSessionResponse\nSuccess:true\nSessionId:{sessionId}"); Thread.Sleep(500); Assert.True(callbackHappened); }
//[Fact] public async void Test1() { // var connectionSettings = new PokerConnectionSettings // { // PlanningSocketUri = new Uri("wss://planningpokercore.azurewebsites.net/ws"), // PlanningApiUri = new Uri("https://sicarringtonplanningpokerapinew.azurewebsites.net/api") // }; // var optionsMock = new Mock<IOptions<PokerConnectionSettings>>(); // optionsMock.Setup(x => x.Value).Returns(connectionSettings); var builder = new ConfigurationBuilder() //.SetBasePath(env.ContentRootPath) .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true); //.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true) // .AddEnvironmentVariables(); var Configuration = builder.Build(); var serviceCollection = new ServiceCollection(); serviceCollection.AddOptions(); serviceCollection.AddPlanningPokerClient(Configuration); var serviceProvider = serviceCollection.BuildServiceProvider(); var connectionSettings = serviceProvider.GetService <IOptions <PokerConnectionSettings> >(); var responseMessageParser = serviceProvider.GetService <IResponseMessageParser>(); var pokerConnection = serviceProvider.GetService <IPokerConnection>(); var userCacheProvider = serviceProvider.GetService <UserCacheProvider>(); var planningPokerService = serviceProvider.GetService <IPlanningPokerService>(); var planningConnection = new PlanningPokerConnection(connectionSettings, responseMessageParser, pokerConnection, userCacheProvider, planningPokerService); await planningConnection.Start(CancellationToken.None); await planningConnection.CreateSession("Simon"); while (true) { System.Threading.Thread.Sleep(2000); } }