public void Should_validate_participant_request()
        {
            var testRequest = new BookingsApi.Contract.Requests.ParticipantRequest
            {
                ContactEmail = "*****@*****.**",
                FirstName    = "Adam",
                LastName     = "Adams",
                DisplayName  = "Adam"
            };

            var result = _validator.Validate(testRequest);

            Assert.That(result.Errors.Count == 0);
        }
        public void Should_validate_fields_with_length_zero_as_error()
        {
            var shortString = "";
            var testRequest = new BookingsApi.Contract.Requests.ParticipantRequest
            {
                ContactEmail = shortString,
                DisplayName  = shortString,
                FirstName    = shortString,
                LastName     = shortString
            };
            var result = _validator.Validate(testRequest);

            Assert.That(result.Errors.Any(o => o.ErrorMessage.Contains("must not be empty.")));
            Assert.That(result.Errors.Count == 5);
        }
Esempio n. 3
0
        public async Task Should_not_create_users_that_already_exists()
        {
            var participant = new BookingsApi.Contract.Requests.ParticipantRequest
            {
                Username = "******"
            };

            _userApiClient.Setup(x => x.GetUserByEmailAsync(It.IsAny <string>()))
            .ReturnsAsync(new UserProfile {
                UserName = participant.Username
            });

            await _service.UpdateParticipantUsername(participant);

            _userApiClient.Verify(x => x.CreateUserAsync(It.IsAny <CreateUserRequest>()), Times.Never);
        }
Esempio n. 4
0
        public async Task Should_create_users_if_not_exists()
        {
            var participant = new BookingsApi.Contract.Requests.ParticipantRequest
            {
                FirstName = "First Name Space",
                LastName  = "Last Name Space",
                Username  = "******"
            };

            _userApiClient.Setup(x => x.GetUserByEmailAsync(It.IsAny <string>()))
            .ReturnsAsync((UserProfile)null);
            _userApiClient.Setup(x => x.CreateUserAsync(It.IsAny <CreateUserRequest>()))
            .ReturnsAsync(new NewUserResponse {
                Username = participant.Username
            });

            await _service.UpdateParticipantUsername(participant);

            _userApiClient.Verify(x => x.CreateUserAsync(It.Is <CreateUserRequest>(c =>
                                                                                   c.FirstName == participant.FirstName.Replace(" ", string.Empty) &&
                                                                                   c.LastName == participant.LastName.Replace(" ", string.Empty) &&
                                                                                   !c.IsTestUser
                                                                                   )), Times.Once);
        }
        public void Should_validate_fields_with_length_greater_then_255_as_error()
        {
            const string EMAIL_MSG       = "Email is required in the correct format and between 1 - 255 characters";
            const string DisplayName_MSG = "Display name is required and between 1 - 255 characters";
            const string FirstName_MSG   = "First name is required and between 1 - 255 characters";
            const string LASTNAME_MSG    = "Lastname is required and between 1 - 255 characters";


            var longString  = new String('a', 257);
            var testRequest = new BookingsApi.Contract.Requests.ParticipantRequest
            {
                ContactEmail = longString,
                DisplayName  = longString,
                FirstName    = longString,
                LastName     = longString
            };

            var result = _validator.Validate(testRequest);

            Assert.That(result.Errors.Any(o => o.PropertyName == "ContactEmail" && o.ErrorMessage == EMAIL_MSG));
            Assert.That(result.Errors.Any(o => o.PropertyName == "DisplayName" && o.ErrorMessage == DisplayName_MSG));
            Assert.That(result.Errors.Any(o => o.PropertyName == "FirstName" && o.ErrorMessage == FirstName_MSG));
            Assert.That(result.Errors.Any(o => o.PropertyName == "LastName" && o.ErrorMessage == LASTNAME_MSG));
        }