public static async Task <string> CreatePokerSession(this IServiceScope scope, string facilitatorPassphrase)
        {
            scope.SetNoAuthenticationInfo();

            var command = new CreatePokerSessionCommand {
                Title = TestContext.CurrentContext.Test.FullName,
                FacilitatorPassphrase = facilitatorPassphrase,
                SymbolSetId           = (await scope.ServiceProvider.GetRequiredService <IPokerTimeDbContext>().SymbolSets.FirstAsync()).Id
            };

            CreatePokerSessionCommandResponse result = await scope.Send(command);

            return(result.Identifier.StringId);
        }
Example #2
0
        public async Task Handle_GivenValidRequest_ShouldSaveSessionWithHash()
        {
            // Given
            var passphraseService = Substitute.For <IPassphraseService>();
            var systemClock       = Substitute.For <ISystemClock>();
            var urlGenerator      = Substitute.For <IUrlGenerator>();
            var handler           = new CreatePokerSessionCommandHandler(this.Context, passphraseService, systemClock, urlGenerator, new NullLogger <CreatePokerSessionCommandHandler>());

            passphraseService.CreateHashedPassphrase("anything").Returns("myhash");
            passphraseService.CreateHashedPassphrase("facilitator password").Returns("facilitatorhash");

            urlGenerator.GenerateUrlToPokerSessionLobby(Arg.Any <SessionIdentifier>()).Returns(new Uri("https://example.com/session/1"));

            systemClock.CurrentTimeOffset.Returns(DateTimeOffset.UnixEpoch);

            var symbolSet = new SymbolSet
            {
                Name = "Test123"
            };

            this.Context.SymbolSets.Add(symbolSet);
            await this.Context.SaveChangesAsync(CancellationToken.None);

            var request = new CreatePokerSessionCommand {
                Passphrase            = "anything",
                FacilitatorPassphrase = "facilitator password",
                Title       = "Hello",
                SymbolSetId = symbolSet.Id
            };

            // When
            CreatePokerSessionCommandResponse result = await handler.Handle(request, CancellationToken.None);

            // Then
            Assert.That(result.Identifier.StringId, Is.Not.Null);
            Assert.That(this.Context.Sessions.Any(), Is.True);
            Assert.That(this.Context.Sessions.First().FacilitatorHashedPassphrase, Is.EqualTo("facilitatorhash"));
            Assert.That(this.Context.Sessions.First().CreationTimestamp, Is.EqualTo(DateTimeOffset.UnixEpoch));
        }