public void SignUpRequestModelTest() { IList <ValidationResult> result; // Testing required values result = ValidatorHelper.ValidateModel(new SignUpRequestModel()); Assert.IsTrue(result.Count == 8); // Testing too small, too short result = ValidatorHelper.ValidateModel(new SignUpRequestModel { BirthMonth = 0, BirthYear = 1919, Country = 0, Email = "a@", FirstName = "a", IsSharedTalkMember = true, Gender = "X", Knows = 0, LastName = "b", Learns = 0, LookToLearnWithGames = true, LookToLearnWithMore = true, LookToLearnWithTextChat = true, LookToLearnWithVoiceChat = true, Password = "******", WantsToHelpHellolingo = true }); Assert.IsTrue(result[0].ErrorMessage == "The Email field is not a valid e-mail address."); result.RemoveAt(0); Assert.IsTrue(result[0].ErrorMessage == "PasswordShorterThan6Chars"); result.RemoveAt(0); Assert.IsTrue(result[0].ErrorMessage == "FirstNameShorterThan2Chars"); result.RemoveAt(0); Assert.IsTrue(result[0].ErrorMessage == "GenderNotFOrM"); result.RemoveAt(0); Assert.IsTrue(result[0].ErrorMessage == "MonthNotBetween1And12"); result.RemoveAt(0); Assert.IsTrue(result[0].ErrorMessage == "YearNotBetween1920And2099"); result.RemoveAt(0); Assert.IsTrue(result[0].ErrorMessage == "KnowsAndLearnsAreIdentical"); result.RemoveAt(0); Assert.IsTrue(result.Count == 0); // Testing too high, too long result = ValidatorHelper.ValidateModel(new SignUpRequestModel { BirthMonth = 13, BirthYear = 2119, Country = 0, Email = "*****@*****.**" + new string('a', 257), FirstName = "Bernard" + new string('a', 257), IsSharedTalkMember = true, Gender = "F", Knows = 1, Learns = 2, LastName = "Vanderydt" + new string('a', 257), LookToLearnWithGames = true, LookToLearnWithMore = true, LookToLearnWithTextChat = true, LookToLearnWithVoiceChat = true, WantsToHelpHellolingo = true, Password = "******" + new string('a', 257), }); Assert.IsTrue(result[0].ErrorMessage == "EmailLongerThan256Chars"); result.RemoveAt(0); Assert.IsTrue(result[0].ErrorMessage == "PasswordLongerThan99Chars"); result.RemoveAt(0); Assert.IsTrue(result[0].ErrorMessage == "FirstNameLongerThan25Chars"); result.RemoveAt(0); Assert.IsTrue(result[0].ErrorMessage == "LastNameLongerThan40Chars"); result.RemoveAt(0); Assert.IsTrue(result[0].ErrorMessage == "MonthNotBetween1And12"); result.RemoveAt(0); Assert.IsTrue(result[0].ErrorMessage == "YearNotBetween1920And2099"); result.RemoveAt(0); Assert.IsTrue(result.Count == 0); // Testing good stuff result = ValidatorHelper.ValidateModel(new SignUpRequestModel { BirthMonth = 4, BirthYear = 1999, Country = 100, Email = "*****@*****.**", Password = "******", FirstName = "Bernard", LastName = "Vanderydt", IsSharedTalkMember = true, Gender = "F", Knows = 1, Learns = 2, LookToLearnWithGames = true, LookToLearnWithMore = true, LookToLearnWithTextChat = true, LookToLearnWithVoiceChat = true, WantsToHelpHellolingo = true, }); Assert.IsTrue(result.Count == 0); TestUserInputCleanUp(); }
public void TestLocationCleanUp4() { string locationInput = "...Washington D... C..."; string locationExpected = "Washington D... C."; var model = GetProfileModelWithoutLocation(); model.Location = locationInput; var results = ValidatorHelper.ValidateModel(model); Assert.AreEqual(locationExpected, model.Location, "Wrong location cleaning."); }
private void TestUserInputCleanUp() { IList <ValidationResult> result; //Validate FirstName, LastName, Location cleanUp var modelToValidate = new SignUpRequestModel { BirthMonth = 4, BirthYear = 1999, Country = 100, Email = "*****@*****.**", Password = "******", FirstName = @" -\\-- (*@#$%^&*()_+(%^%^&%^$%^$^%$BE'R^\-NARD \\-- ", LastName = @" -\\-- (..*@#$%^&*()_+(%^%^&%^$%^$^%$V.ander^\- ydt^$%^$^%... \- ", Location = @" &()', K(y)i&',v ,()'& ", IsSharedTalkMember = true, Gender = "F", Knows = 1, Learns = 2, LookToLearnWithGames = true, LookToLearnWithMore = true, LookToLearnWithTextChat = true, LookToLearnWithVoiceChat = true, WantsToHelpHellolingo = true, }; result = ValidatorHelper.ValidateModel(modelToValidate); string expFirstName = @"Ber\-nard"; string expLastName = @"V.ander\- ydt..."; string expLocation = @"K(y)i&',v"; Assert.IsTrue(modelToValidate.FirstName == expFirstName, $"First name cleanup is failed. Result: {modelToValidate.FirstName}, expected: {expFirstName}"); Assert.IsTrue(modelToValidate.LastName == expLastName, $"Last name cleanup is failed. Result: {modelToValidate.LastName}, expected: {expLastName}"); Assert.IsTrue(modelToValidate.Location == expLocation, $"Location cleanup is failed. Result: {modelToValidate.Location}, expected: {expLocation}"); //Validate FirstName, LastName, Location cleanUp with only restricted symbols var modelToValidateWithRestrictedSymbols = new SignUpRequestModel { BirthMonth = 4, BirthYear = 1999, Country = 100, Email = "*****@*****.**", Password = "******", FirstName = @"%^&*()_+(%^%^&%^$%", LastName = @"$%^&*()_+(%^%^", Location = @" &()', ()&', ,()'& ", IsSharedTalkMember = true, Gender = "F", Knows = 1, Learns = 2, LookToLearnWithGames = true, LookToLearnWithMore = true, LookToLearnWithTextChat = true, LookToLearnWithVoiceChat = true, WantsToHelpHellolingo = true, }; result = ValidatorHelper.ValidateModel(modelToValidateWithRestrictedSymbols); Assert.IsTrue(result.Count == 2, $"Validation result must be without Errors. Actual: {result.Count} errors. "); Assert.IsTrue(result[0].ErrorMessage == $"The field {nameof(modelToValidateWithRestrictedSymbols.FirstName)} is invalid."); Assert.IsTrue(result[1].ErrorMessage == $"The field {nameof(modelToValidateWithRestrictedSymbols.LastName)} is invalid."); Assert.IsTrue(modelToValidateWithRestrictedSymbols.Location == null, $"Location cleanup is failed. Result: {modelToValidateWithRestrictedSymbols.Location}, expected: null"); //Validate FirstName, LastName, Location cleanUp with empty strings var modelToValidateWithEmptyStrings = new SignUpRequestModel { BirthMonth = 4, BirthYear = 1999, Country = 100, Email = "*****@*****.**", Password = "******", FirstName = @" ", LastName = @" ", Location = @" ", IsSharedTalkMember = true, Gender = "F", Knows = 1, Learns = 2, LookToLearnWithGames = true, LookToLearnWithMore = true, LookToLearnWithTextChat = true, LookToLearnWithVoiceChat = true, WantsToHelpHellolingo = true, }; result = ValidatorHelper.ValidateModel(modelToValidateWithEmptyStrings); Assert.IsTrue(result.Count == 2, $"Validation result must be without Errors. Actual: {result.Count} errors. "); Assert.IsTrue(result[0].ErrorMessage == $"The field {nameof(modelToValidateWithRestrictedSymbols.FirstName)} is invalid."); Assert.IsTrue(result[1].ErrorMessage == $"The field {nameof(modelToValidateWithRestrictedSymbols.LastName)} is invalid."); Assert.IsTrue(modelToValidateWithEmptyStrings.Location == null, $"Location cleanup is failed. Result: {modelToValidateWithEmptyStrings.Location}, expected: null"); //Validate model with Location equals null. var modelWithLocationNull = new SignUpRequestModel() { BirthMonth = 4, BirthYear = 1999, Country = 100, Email = "*****@*****.**", Password = "******", FirstName = "BERNARD", LastName = "Vanderydt", IsSharedTalkMember = true, Gender = "F", Knows = 1, Learns = 2, LookToLearnWithGames = true, LookToLearnWithMore = true, LookToLearnWithTextChat = true, LookToLearnWithVoiceChat = true, WantsToHelpHellolingo = true, }; var noErrors = ValidatorHelper.ValidateModel(modelWithLocationNull).ToList(); Assert.IsTrue(noErrors.Count == 0, $"Validation result must be without Errors. Actual: {noErrors.Count} errors. "); Assert.IsNull(modelWithLocationNull.Location, "Location must be null"); //Validate model with Location equals empty string. var modelWithLocationEmptyString = new SignUpRequestModel() { BirthMonth = 4, BirthYear = 1999, Country = 100, Location = "", Email = "*****@*****.**", Password = "******", FirstName = "BERNARD", LastName = "Vanderydt", IsSharedTalkMember = true, Gender = "F", Knows = 1, Learns = 2, LookToLearnWithGames = true, LookToLearnWithMore = true, LookToLearnWithTextChat = true, LookToLearnWithVoiceChat = true, WantsToHelpHellolingo = true, }; var noErrorsForEmptyString = ValidatorHelper.ValidateModel(modelWithLocationEmptyString).ToList(); Assert.IsTrue(noErrorsForEmptyString.Count == 0, $"Validation result must be without errors and equal null. Actual: {noErrorsForEmptyString.Count} errors. "); Assert.IsNull(modelWithLocationEmptyString.Location, "Location must be null"); }
public void UserProfileModelTest() { // Testing required values IList <ValidationResult> result; result = ValidatorHelper.ValidateModel(new UserProfileModel()); Assert.AreEqual(result.Count, 5); // Testing valid model IList <ValidationResult> result1; result1 = ValidatorHelper.ValidateModel(new UserProfileModel() { BirthMonth = 4, BirthYear = 1980, Email = "*****@*****.**", CurrentPassword = "******", Knows = 1, Learns = 2, }); Assert.AreEqual(result1.Count, 0, $"Model must be valid, Errors: {string.Join(":", result1)}"); // Testing not valid new password IList <ValidationResult> result2; result2 = ValidatorHelper.ValidateModel(new UserProfileModel() { BirthMonth = 4, BirthYear = 1980, Email = "*****@*****.**", CurrentPassword = "******", Knows = 1, Learns = 2, Password = "******", }); Assert.AreEqual(result2.Count, 1, $"Model must be not valid with errors number: {1}, Errors: {string.Join(":", result2)}"); IList <ValidationResult> result3; result3 = ValidatorHelper.ValidateModel(new UserProfileModel() { BirthMonth = 4, BirthYear = 1980, Email = "*****@*****.**", CurrentPassword = "******", Knows = 1, Learns = 2, Password = "******", }); Assert.AreEqual(result3.Count, 1, $"Model must be not valid with errors number: {1}, Errors: {string.Join(":", result3)}"); IList <ValidationResult> result4; result4 = ValidatorHelper.ValidateModel(new UserProfileModel() { BirthMonth = 4, BirthYear = 1980, Email = "*****@*****.**", CurrentPassword = "******", Knows = 1, Learns = 2, Password = "******", }); Assert.AreEqual(result4.Count, 1, $"Model must be not valid with errors number: {1}, Errors: {string.Join(":", result4)}"); IList <ValidationResult> result5; result5 = ValidatorHelper.ValidateModel(new UserProfileModel() { BirthMonth = 4, BirthYear = 1980, Email = "*****@*****.**", CurrentPassword = "******", Knows = 1, Learns = 2, Learns2 = 2, Knows2 = 2, Password = "******", }); Assert.AreEqual(result5.Count, 2, $"Model must be not valid with errors number: {1}, Errors: {string.Join(":", result5)}"); IList <ValidationResult> result6; result6 = ValidatorHelper.ValidateModel(new UserProfileModel() { BirthMonth = 4, BirthYear = 1980, Email = "*****@*****.**", CurrentPassword = "******", Knows = 1, Learns = 2, Learns2 = 3, Knows2 = 2, Password = "******", }); Assert.AreEqual(result6.Count, 1, $"Model must be not valid with errors number: {1}, Errors: {string.Join(":", result6)}"); IList <ValidationResult> result7; result7 = ValidatorHelper.ValidateModel(new UserProfileModel() { BirthMonth = 4, BirthYear = 1980, Email = "*****@*****.**", CurrentPassword = "******", Knows = 1, Learns = 2, Learns2 = 3, Knows2 = null, Password = "******", }); Assert.AreEqual(result7.Count, 0, $"Model must be not valid with errors number: {1}, Errors: {string.Join(":", result7)}"); //Test error from production log: IList <ValidationResult> result8; result8 = ValidatorHelper.ValidateModel(new UserProfileModel() { BirthMonth = 12, BirthYear = 1987, Email = "*****@*****.**", CurrentPassword = "******", Knows = 2, Learns = 4, Learns2 = 1, Knows2 = 6, Password = "******", Country = 106, Location = "", Introduction = "I am just a spanish normal guy who tries to learn japanese in his free time.If you want to know more about me just drop me a message.\"El saber no ocupa lugar\"", LookToLearnWithTextChat = true, LookToLearnWithGames = true, LookToLearnWithMore = true, LookToLearnWithVoiceChat = true, WantsToHelpHellolingo = true, }); Assert.AreEqual(result8.Count, 0, $"Model must be not valid with errors number: {1}, Errors: {string.Join(":", result8)}"); IList <ValidationResult> resultLocationWithoutDots; string locationWithoutDots = "Kyiv"; var modelWithoutDotLocation = new UserProfileModel() { BirthMonth = 12, BirthYear = 1987, Email = "*****@*****.**", CurrentPassword = "******", Knows = 2, Learns = 4, Learns2 = 1, Knows2 = 6, Password = "******", Country = 106, Location = locationWithoutDots, Introduction = "I am just a spanish normal guy who tries to learn japanese in his free time.If you want to know more about me just drop me a message.\"El saber no ocupa lugar\"", LookToLearnWithTextChat = true, LookToLearnWithGames = true, LookToLearnWithMore = true, LookToLearnWithVoiceChat = true, WantsToHelpHellolingo = true, }; resultLocationWithoutDots = ValidatorHelper.ValidateModel(modelWithoutDotLocation); Assert.AreEqual(resultLocationWithoutDots.Count, 0, $"Model must be not valid with errors number: {1}, Errors: {string.Join(":", resultLocationWithoutDots)}"); Assert.AreEqual(locationWithoutDots, modelWithoutDotLocation.Location, "Wrong location cleaning."); }