Beispiel #1
0
 public void InvalidIfAllFieldsAreNull()
 {
     var model = new AccountModel();
     var validationResults = new List<ValidationResult>();
     Assert.That(Validator.TryValidateObject(model, new ValidationContext(model), validationResults), Is.False);
     Assert.That(validationResults.Count, Is.EqualTo(4));
     Assert.That(validationResults[0].ErrorMessage, Is.EqualTo("The UserName field is required."));
     Assert.That(validationResults[1].ErrorMessage, Is.EqualTo("The Password field is required."));
     Assert.That(validationResults[2].ErrorMessage, Is.EqualTo("The ConfirmPassword field is required."));
     Assert.That(validationResults[3].ErrorMessage, Is.EqualTo("The OrganizationName field is required."));
 }
Beispiel #2
0
 public void InvalidPasswordAndConfirmPasswordNotMatching()
 {
     var model = new AccountModel
     {
         UserName = "******",
         Password = "******",
         ConfirmPassword = "******",
         OrganizationName = "MyTest Organization"
     };
     var validationResults = new List<ValidationResult>();
     Assert.That(Validator.TryValidateObject(model, new ValidationContext(model), validationResults, true), Is.False);
     Assert.That(validationResults.Count, Is.EqualTo(1));
     Assert.That(validationResults[0].ErrorMessage, Is.EqualTo("The password and confirmation password do not match."));
 }
Beispiel #3
0
 public void InvalidIfUserNameGreaterThan100Characters()
 {
     var model = new AccountModel
     {
         UserName = "******",
         Password = "******",
         ConfirmPassword = "******",
         OrganizationName = "MyTest Organization"
     };
     var validationResults = new List<ValidationResult>();
     Assert.That(Validator.TryValidateObject(model, new ValidationContext(model), validationResults, true), Is.False);
     Assert.That(validationResults.Count, Is.EqualTo(1));
     Assert.That(validationResults[0].ErrorMessage,
         Is.EqualTo("The field UserName must be a string with a maximum length of 100."));
 }
Beispiel #4
0
        public IHttpActionResult Post(AccountModel accountModel)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            var command = new CreateAccountCommand
            {
                UserName = accountModel.UserName,
                Password = accountModel.Password,
                OrganizationName = accountModel.OrganizationName
            };

            _createAccountCommandHandler.Handle(command);

            return Ok();
        }
        public void ShouldReturnOk()
        {
            var account = new AccountModel
            {
                UserName = "******",
                Password = "******",
                ConfirmPassword = "******",
                OrganizationName = "Test Organization"
            };

            var result = _controller.Post(account);

            _mockCreateAccountCommandHandler.Setup(x => x.Handle(It.Is<CreateAccountCommand>(
                c => c.UserName == account.UserName &&
                c.Password == account.Password &&
                c.OrganizationName == account.OrganizationName))).Returns(new CreateAccountCommandResult(true));

            Assert.That(result, Is.Not.Null);
            Assert.That(result, Is.TypeOf<OkResult>());
        }
Beispiel #6
0
 public void IsValid()
 {
     var model = new AccountModel
     {
         UserName = "******",
         Password = "******",
         ConfirmPassword = "******",
         OrganizationName = "MyTest Organization"
     };
     var validationResults = new List<ValidationResult>();
     Assert.That(Validator.TryValidateObject(model, new ValidationContext(model), validationResults), Is.True);
 }