public async void GivenJoinSessionIsCalled_WhenConnectionReturnsSuccess_ThenUserIsAddedToCache()
        {
            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 JoinSessionResponse(sessionId, userId, userToken));

            _userCacheProvider.Setup(x => x.AddUser(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>())).Returns(Task.CompletedTask);

            await _planningPokerConnection.Start(CancellationToken.None);

            await _planningPokerConnection.CreateSession("Fred");

            callbackMethod($"PP 1.0\nMessageType:JoinSessionResponse\nSuccess:true\nSessionId:{sessionId}\nUserId:{userId}\nToken:{userToken}");

            Thread.Sleep(500);

            _userCacheProvider.Verify(x => x.AddUser(
                                          It.Is <string>(y => y == sessionId),
                                          It.Is <string>(y => y == userId),
                                          It.Is <string>(y => y == userToken)
                                          ), Times.Once);
        }
 public async void GivenCreateSessionIsCalled_WhenHostNamePassedIsNull_ThenExceptionIsThrown()
 {
     await Assert.ThrowsAsync <ArgumentNullException>(async() =>
     {
         await _planningPokerConnection.CreateSession(null);
     });
 }
Ejemplo n.º 3
0
        //[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);
            }
        }