예제 #1
0
        public async Task CanConnectAsBarista(Register registerCommand, HireBarista hireBaristaCommand, Guid orderId, MenuItem[] menuItems)
        {
            // Arrange
            await _authTestsHelper.Register(registerCommand);

            await _fixture.SendAsync(hireBaristaCommand);

            var assignBaristaToAccountCommand = new AssignBaristaToAccount
            {
                AccountId = registerCommand.Id,
                BaristaId = hireBaristaCommand.Id
            };

            await _fixture.SendAsync(assignBaristaToAccountCommand);

            var accessToken = (await _authTestsHelper.Login(registerCommand.Email, registerCommand.Password)).TokenString;

            var testConnection = BuildTestConnection(accessToken);

            await testConnection.OpenAsync();

            // Act
            await _toGoOrdersHelper.CreateConfirmedOrder(orderId, menuItems);

            // Assert
            await testConnection
            .VerifyMessageReceived <OrderConfirmed>(
                e => e.Order.Id == orderId &&
                e.Order.OrderedItems.Count == menuItems.Length,
                Times.Once());
        }
예제 #2
0
        public async Task LoginShouldSetProperHttpOnlyCookie(Register register)
        {
            // Arrange
            await _authHelper.Register(register);

            var loginCommand = new Login
            {
                Email    = register.Email,
                Password = register.Password
            };

            // Act
            var response = await _fixture.ExecuteHttpClientAsync <HttpResponseMessage>(client =>
                                                                                       client.PostAsJsonAsync(AuthRoute("login"), loginCommand));

            // Assert
            var token = (await response.ShouldDeserializeTo <LoginResource>()).TokenString;

            response
            .Headers
            .Should()
            .Contain(header =>
                     header.Key == "Set-Cookie" &&
                     header.Value.Any(x => x.Contains(AuthConstants.Cookies.AuthCookieName) && x.Contains(token)));
        }
        public async Task UserTeamVotesAreSentToAllSubscribers(
            Register registerCommand,
            Team teamToVote)
        {
            // Arrange
            await _authTestsHelper.Register(registerCommand);

            await _fixture.ExecuteDbContextAsync(async dbContext =>
            {
                await dbContext.Teams.AddAsync(teamToVote);
                await dbContext.SaveChangesAsync();
            });

            var testConnection = BuildTestConnection();

            var voteForTeamCommand = new VoteForTeam(teamToVote.Id, registerCommand.Id);

            // Act
            await _fixture.SendAsync(voteForTeamCommand);

            // Assert
            testConnection
            .VerifyMessageReceived(
                team => team.UserId == voteForTeamCommand.UserId &&
                team.TeamId == voteForTeamCommand.TeamId,
                Times.Never());
        }
예제 #4
0
        public async Task CanConnectAsManager(Register registerCommand, HireManager hireManagerCommand, HireWaiter hireWaiterCommand)
        {
            // Arrange
            await _authTestsHelper.Register(registerCommand);

            await _fixture.SendAsync(hireManagerCommand);

            var assignManagerToAccountCommand = new AssignManagerToAccount
            {
                AccountId = registerCommand.Id,
                ManagerId = hireManagerCommand.Id
            };

            await _fixture.SendAsync(assignManagerToAccountCommand);

            var accessToken = (await _authTestsHelper.Login(registerCommand.Email, registerCommand.Password)).TokenString;

            var testConnection = BuildTestConnection(accessToken);

            await testConnection.OpenAsync();

            // Act
            await _fixture.SendAsync(hireWaiterCommand);

            // Assert
            await testConnection
            .VerifyMessageReceived <WaiterHired>(
                e => e.Waiter.Id == hireWaiterCommand.Id &&
                e.Waiter.ShortName == hireWaiterCommand.ShortName,
                Times.Once());
        }
예제 #5
0
        private async Task <string> SetupUserWithClaims(Fixture fixture, IEnumerable <Claim> withClaims)
        {
            var registerCommand = fixture
                                  .Create <Register>();

            await _authHelper.Register(registerCommand);

            if (withClaims != null)
            {
                await _authHelper.AddClaimsAsync(registerCommand.Id, withClaims);
            }

            var token = (await _authHelper
                         .Login(registerCommand.Email, registerCommand.Password))
                        .TokenString;

            return(token);
        }