public void email_should_be_valid(string email, bool shouldBeValid)
        {
            var input = new JoinInput { Email = email };

            validator.Validate(input).Errors
                .Where(x => x.PropertyName == "Email")
                .Where(x => x.ErrorMessage.Contains("not a valid"))
                .Count().Should().Be(shouldBeValid ? 0 : 1);
        }
        public void email_confirmation_should_match_email()
        {
            var input = new JoinInput {Email = "any", ConfirmEmail = "any other"};

            var errors = validator.Validate(input).Errors;

            errors.Where(x => x.PropertyName == "ConfirmEmail")
                .Where(x => x.ErrorMessage.Contains("should match Email"))
                .Count().Should().Be(1);
        }
        public void email_should_be_unique()
        {
            repository.SetupGet(x => x.Users).Returns(new[] { new User("", "", "email") }.AsQueryable);

            var unavailableEmail = new JoinInput { Email = "email" };
            validator.Validate(unavailableEmail).Errors
                .Where(x => x.PropertyName == "Email")
                .Where(x => x.ErrorMessage.Contains("already"))
                .Count().Should().Be(1);

            var availableEmail = new JoinInput { Email = "otherEmail" };
            validator.Validate(availableEmail).Errors
                .Where(x => x.PropertyName == "Email")
                .Where(x => x.ErrorMessage.Contains("already"))
                .Count().Should().Be(0);
        }
示例#4
0
        public async Task <IActionResult> PostAsync([FromBody] JoinInput input, string id)
        {
            // Check if bot exists
            var bot = await _storage.GetBotAsync(input.BotToken);

            if (bot == null)
            {
                // Invalid bot token
                return(StatusCode(403));
            }

            // Check for correct board
            var board = await _storage.GetBoardAsync(id);

            if (board == null)
            {
                // Invalid board id
                return(StatusCode(404));
            }

            // Check if board is full
            if (board.IsFull())
            {
                return(StatusCode(409));
            }

            // Check if bot is already on board
            if (board.HasBot(bot))
            {
                return(StatusCode(409));
            }

            board.AddBot(bot);
            await _storage.UpdateBoardAsync(board);

            SetExpireCallbackForBot(bot, id);

            return(Ok());
        }
        public void password_confirmation_should_match_password()
        {
            var input = new JoinInput { Password = "******", ConfirmPassword = "******" };

            var errors = validator.Validate(input).Errors;

            errors.Where(x => x.PropertyName == "ConfirmPassword")
                .Where(x => x.ErrorMessage.Contains("should match Password"))
                .Count().Should().Be(1);
        }