public void OrganizationWithNoOwner_Should_ValidateAsInvalid() { // Arrange var model = new OrganizationModel() { Owners = new List <OwnerModel>() }; // Act var result = model.IsValid(); // Assert Assert.False(result); Assert.AreNotEqual(model.ValidationResult.FindByMessage("Owner missing"), null); }
public void OrganizationWithNullOwner_Should_NotThrowErrorWhenValidate() { // Arrange var model = new OrganizationModel() { Owners = null }; // Act var result = model.IsValid(); // Assert Assert.False(result); Assert.AreNotEqual(model.ValidationResult.FindByMessage("Owner missing"), null); }
public void OrganizationWithValidName_Should_Validate(string param) { // Arrange var model = new OrganizationModel() { Name = param }; // Act var result = model.IsValid(); // Assert Assert.False(result); Assert.AreNotEqual(model.ValidationResult.Errors.SingleOrDefault(t => t.Value == "Invalid Name"), null); }
public void OrganizationWithNoItem_Should_ValidateAsValid() { // Arrange var modelWithNoItem = new OrganizationModel() { ItemsNeeded = new List <ItemModel>(), Owners = new List <OwnerModel>() { new OwnerModel() { Name = "a", Phone = "b", DocumentIdentification = "c" } }, Address = new AddressModel() { Street = "b", AdditionalInfo = "v", StreetNumber = 2 }, Name = "q", PhoneNumber = "123" }; var modelWithNullItem = new OrganizationModel() { ItemsNeeded = null, Owners = new List <OwnerModel>() { new OwnerModel() { Name = "a", Phone = "b", DocumentIdentification = "c" } }, Address = new AddressModel() { Street = "b", AdditionalInfo = "v", StreetNumber = 2 }, Name = "q", PhoneNumber = "123" }; // Act var resultNoItem = modelWithNoItem.IsValid(); var resultNullItem = modelWithNullItem.IsValid(); // Assert Assert.True(resultNoItem); Assert.True(resultNullItem); }
public void OrganizationWithInvalidAddress_Should_HaveAllAddressValidationErrors() { // Arrange var model = new OrganizationModel() { Address = new AddressModel() }; // Act var result = model.IsValid(); // Assert Assert.False(result); foreach (var error in model.Address.ValidationResult.Errors) { Assert.AreNotEqual(model.ValidationResult.FindByKey(error.Key), null); } }
public OrganizationModel Update(OrganizationModel model) { try { if (!model.IsValid()) { LogError(model); } else { new OrganizationBlockBaseCommand(model).Update(); } return(model); } catch (Exception ex) { return(ErrorHandler.LogError <OrganizationModel>(ex)); } }