public void RequiredAttributeCheckerInternalCheckTest() { // arrange var expectedFirstnameValid = GetConvertedTestValueAsBool(0) ?? throw new ApplicationException("Could not retrieve expected value."); var expectedFirstnameErrorMessageKey = GetConvertedTestValueAsString(1); var expectedLastnameValid = GetConvertedTestValueAsBool(2) ?? throw new ApplicationException("Could not retrieve expected value."); var expectedLastnameErrorMessageKey = GetConvertedTestValueAsString(3); var expectedFirstnameErrorMessage = string.IsNullOrEmpty(expectedFirstnameErrorMessageKey) ? string.Empty : TestResources.ResourceManager.GetString(expectedFirstnameErrorMessageKey); var expectedLastnameErrorMessage = string.IsNullOrEmpty(expectedLastnameErrorMessageKey) ? string.Empty : TestResources.ResourceManager.GetString(expectedLastnameErrorMessageKey); var item = new TestDataModel { Firstname = GetConvertedTestValueAsString(4), Lastname = GetConvertedTestValueAsString(5), Birthday = GetConvertedTestValueAsDateTime(6) }; var checker = new RequiredAttributeChecker(); var firstNameAttribute = item.GetAttribute <RequiredAttribute>(nameof(TestDataModel.Firstname)); var lastNameAttribute = item.GetAttribute <RequiredAttribute>(nameof(TestDataModel.Lastname)); // act var resultFirstname = checker.Check(firstNameAttribute, item.Firstname); var resultLastname = checker.Check(lastNameAttribute, item.Lastname); // assert Assert.AreEqual(expectedFirstnameValid, resultFirstname.IsValid, "The validity check for firstname failed."); Assert.AreEqual(expectedFirstnameErrorMessage, resultFirstname.ErrorMessage, "The error message for firstname is unexpected."); Assert.AreEqual(expectedLastnameValid, resultLastname.IsValid, "The validity check for lastname failed."); Assert.AreEqual(expectedLastnameErrorMessage, resultLastname.ErrorMessage, "The error message for lastname is unexpected."); }
public void RangeAttributeCheckerInternalCheckTest() { // arrange var expectedValid = GetConvertedTestValueAsBool(0) ?? throw new ApplicationException("Could not retrieve expected value."); var expectedErrorMessageKey = GetConvertedTestValueAsString(1); var expectedErrorMessage = string.IsNullOrEmpty(expectedErrorMessageKey) ? string.Empty : TestResources.ResourceManager.GetString(expectedErrorMessageKey); var item = new TestDataModel { Salary = GetConvertedTestValueAsInt(2) ?? 0 }; var checker = new RangeAttributeChecker(); var keyAttribute = item.GetAttribute <RangeAttribute>(nameof(TestDataModel.Salary)); // act var result = checker.Check(keyAttribute, item.Salary); // assert Assert.AreEqual(expectedValid, result.IsValid, "The validity check for salary failed."); Assert.AreEqual(expectedErrorMessage, result.ErrorMessage, "The error message for salary is unexpected."); }