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."));
 }
 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."));
 }
 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."));
 }
        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>());
        }
 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);
 }