1using Microsoft.VisualStudio.TestTools.UnitTesting;
3using Microsoft.AspNetCore.Components.Forms;
4using System.Collections.Generic;
20 _testDIContext = TestDIContextFactory.CreateDefaultContext();
28 EditContext editContext =
new EditContext(person);
29 editContext.AddCslaValidation();
35 editContext.Validate();
36 IEnumerable<string> messages = editContext.GetValidationMessages();
39 Assert.AreEqual(1, messages.Count(),
"Incorrect number of validation messages returned! " + ConcatenateMessages(messages));
48 EditContext editContext =
new EditContext(person);
49 editContext.AddCslaValidation();
55 editContext.Validate();
56 IEnumerable<string> messages = editContext.GetValidationMessages();
59 Assert.AreEqual(0, messages.Count(),
"Incorrect number of validation messages returned! " + ConcatenateMessages(messages));
68 EditContext editContext =
new EditContext(person);
69 editContext.AddCslaValidation();
75 editContext.Validate();
76 IEnumerable<string> messages = editContext.GetValidationMessages();
79 Assert.AreEqual(0, messages.Count(),
"Incorrect number of validation messages returned! " + ConcatenateMessages(messages));
88 EditContext editContext =
new EditContext(person);
89 editContext.AddCslaValidation();
92 person.
FirstName =
"This text is more than twenty five characters long";
96 editContext.Validate();
97 IEnumerable<string> messages = editContext.GetValidationMessages();
100 Assert.AreEqual(2, messages.Count(),
"Incorrect number of validation messages returned! " + ConcatenateMessages(messages));
109 EditContext editContext =
new EditContext(person);
110 editContext.AddCslaValidation();
117 editContext.Validate();
118 IEnumerable<string> messages = editContext.GetValidationMessages();
121 Assert.AreEqual(2, messages.Count(),
"Incorrect number of validation messages returned! " + ConcatenateMessages(messages));
130 EditContext editContext =
new EditContext(person);
131 editContext.AddCslaValidation();
137 editContext.Validate();
138 IEnumerable<string> messages = editContext.GetValidationMessages();
141 Assert.AreEqual(1, messages.Count(),
"Incorrect number of validation messages returned! " + ConcatenateMessages(messages));
150 EditContext editContext =
new EditContext(person);
151 editContext.AddCslaValidation();
154 person.
FirstName =
"This text is more than twenty five characters long";
158 editContext.NotifyFieldChanged(
new FieldIdentifier(person, nameof(person.
FirstName)));
159 IEnumerable<string> messages = editContext.GetValidationMessages(
new FieldIdentifier(person, nameof(person.
FirstName)));
162 Assert.AreEqual(1, messages.Count(),
"Incorrect number of validation messages returned! " + ConcatenateMessages(messages));
171 EditContext editContext =
new EditContext(person);
172 editContext.AddCslaValidation();
179 editContext.NotifyFieldChanged(
new FieldIdentifier(person, nameof(person.
HomeTelephone)));
180 IEnumerable<string> messages = editContext.GetValidationMessages(
new FieldIdentifier(person, nameof(person.
HomeTelephone)));
183 Assert.AreEqual(1, messages.Count(),
"Incorrect number of validation messages returned! " + ConcatenateMessages(messages));
192 EditContext editContext =
new EditContext(person);
193 editContext.AddCslaValidation();
199 editContext.NotifyFieldChanged(
new FieldIdentifier(person, nameof(person.
FirstName)));
200 IEnumerable<string> messages = editContext.GetValidationMessages(
new FieldIdentifier(person, nameof(person.
FirstName)));
203 Assert.AreEqual(0, messages.Count(),
"Incorrect number of validation messages returned! " + ConcatenateMessages(messages));
212 EditContext editContext =
new EditContext(person);
213 editContext.AddCslaValidation();
219 editContext.NotifyFieldChanged(
new FieldIdentifier(person, nameof(person.
LastName)));
220 IEnumerable<string> messages = editContext.GetValidationMessages(
new FieldIdentifier(person, nameof(person.
LastName)));
223 Assert.AreEqual(0, messages.Count(),
"Incorrect number of validation messages returned! " + ConcatenateMessages(messages));
232 EditContext editContext =
new EditContext(person);
233 editContext.AddCslaValidation();
240 editContext.NotifyFieldChanged(
new FieldIdentifier(address, nameof(address.
EmailAddress)));
241 IEnumerable<string> messages = editContext.GetValidationMessages(
new FieldIdentifier(address, nameof(address.
EmailAddress)));
244 Assert.AreEqual(1, messages.Count(),
"Incorrect number of validation messages returned! " + ConcatenateMessages(messages));
253 EditContext editContext =
new EditContext(person);
254 editContext.AddCslaValidation();
261 editContext.NotifyFieldChanged(
new FieldIdentifier(address, nameof(address.
EmailAddress)));
262 IEnumerable<string> messages = editContext.GetValidationMessages(
new FieldIdentifier(address, nameof(address.
EmailAddress)));
265 Assert.AreEqual(0, messages.Count(),
"Incorrect number of validation messages returned! " + ConcatenateMessages(messages));
269 #region Helper Methods
277 dataPortal = _testDIContext.CreateDataPortal<
FakePerson>();
278 person = dataPortal.
Create();
287 private string ConcatenateMessages(IEnumerable<string> messages)
289 return string.Join(
"; ", messages);
void ValidateModel_ExcessiveFirstNameEmptyLastName_TwoValidationMessages()
void ValidateField_ExcessiveFirstNameEmptyLastName_OneValidationMessageForFirstName()
void ValidateModel_EmptyChildEmailAddress_OneValidationMessage()
void ValidateField_MissingEmailAddress1_OneValidationMessageForEmailAddress1()
static void ClassInitialize(TestContext context)
void ValidateField_ValidEmailAddress1_NoValidationMessagesForEmailAddress1()
void ValidateModel_ShortLastName_NoValidationMessages()
void ValidateField_NeitherTelephoneProvided_OneValidationMessageForHomeTelephone()
void ValidateModel_EmptyLastName_OneValidationMessage()
void ValidateModel_ShortFirstName_NoValidationMessages()
void ValidateModel_NeitherTelephoneProvided_TwoValidationMessages()
void ValidateField_ShortFirstName_NoValidationMessagesForFirstName()
void ValidateField_ShortLastName_NoValidationMessagesForLastName()
FakePersonEmailAddresses EmailAddresses
Type to carry context information for DI in unit tests
Interface defining the members of the data portal type.
object Create(params object[] criteria)
Called by a factory method in a business class to create a new object, which is loaded with default v...