src/fursvp.domain/Validation/ValidateMember.cs
/// <summary>
/// Compares two instances of <see cref="Member"/> and throws an exception if the transition from oldState to newState is not valid.
/// </summary>
/// <param name="oldMemberState">The old member state.</param>
/// <param name="oldEventState">The old event state.</param>
/// <param name="newMemberState">The new member state.</param>
/// <param name="newEventState">The new event state.</param>
Compares two instances of  and throws an exception if the transition from oldState to newState is not valid.
Compares two instances of and throws an exception if the transition from oldState to newState is not valid .
public void ValidateState(Member oldMemberState, Event oldEventState, Member newMemberState, Event newEventState)
        {
            if (oldMemberState == null && newMemberState == null)
            {
                throw new ArgumentNullException(nameof(newMemberState));
            }
            if (newMemberState == null)
            {
                Contract.Requires(oldMemberState != null);
                Assert.That(!oldMemberState.IsAuthor, "The author of an event cannot be removed.");
                return; 
            }
            if (newEventState == null)
            {
                throw new ArgumentNullException(nameof(newEventState));
            }
            Assert.That(!string.IsNullOrWhiteSpace(newMemberState.EmailAddress), "Email address is required.");
            ValidateEmail.Validate(newMemberState.EmailAddress);
            Assert.That(!string.IsNullOrWhiteSpace(newMemberState.Name), "Name is required.");
            Assert.That(newMemberState.IsAuthor || newMemberState.IsOrganizer || newMemberState.IsAttending, "Member must be at least one of these: Attendee, Organizer.");
            Assert.That(newMemberState.Responses != null, "Responses cannot be null.");
            Assert.That(oldMemberState == null || newMemberState == null || oldMemberState.RsvpedAtUtc == default(DateTime) || oldMemberState.RsvpedAtUtc == newMemberState.RsvpedAtUtc, "RsvpedAt cannot be changed once set.");
            foreach (var response in newMemberState.Responses)
            {
                var formPrompt = newEventState.Form.FirstOrDefault(f => f.Id == response.PromptId);
                Assert.That(formPrompt != null, "Response prompt must belong to a prompt on the Event's rsvp form.");
                Assert.That(!response.Responses.Any(string.IsNullOrWhiteSpace), "Response text cannot be null or whitespace.");
                if (formPrompt.Required)
                {
                    Assert.That(response.Responses.Count > 0, "Form response is required.");
                }
                if (formPrompt.Behavior == "Text" || formPrompt.Behavior == "Dropdown")
                {
                    Assert.That(response.Responses.Count <= 1, "Form prompt does not permit multiple answers.");
                }
            }
        }
public void ValidateState ( Member oldMemberState , Event oldEventState , Member newMemberState , Event newEventState ) { if ( oldMemberState == null && newMemberState == null ) { throw new ArgumentNullException ( nameof ( newMemberState ) ) ; } if ( newMemberState == null ) { Contract . Requires ( oldMemberState != null ) ; Assert . That ( ! oldMemberState . IsAuthor , " " ) ; return ; } if ( newEventState == null ) { throw new ArgumentNullException ( nameof ( newEventState ) ) ; } Assert . That ( ! string . IsNullOrWhiteSpace ( newMemberState . EmailAddress ) , " " ) ; ValidateEmail . Validate ( newMemberState . EmailAddress ) ; Assert . That ( ! string . IsNullOrWhiteSpace ( newMemberState . Name ) , " " ) ; Assert . That ( newMemberState . IsAuthor || newMemberState . IsOrganizer || newMemberState . IsAttending , " " ) ; Assert . That ( newMemberState . Responses != null , " " ) ; Assert . That ( oldMemberState == null || newMemberState == null || oldMemberState . RsvpedAtUtc == default ( DateTime ) || oldMemberState . RsvpedAtUtc == newMemberState . RsvpedAtUtc , " " ) ; foreach ( var response in newMemberState . Responses ) { var formPrompt = newEventState . Form . FirstOrDefault ( f => f . Id == response . PromptId ) ; Assert . That ( formPrompt != null , " " ) ; Assert . That ( ! response . Responses . Any ( string . IsNullOrWhiteSpace ) , " " ) ; if ( formPrompt . Required ) { Assert . That ( response . Responses . Count > 0 , " " ) ; } if ( formPrompt . Behavior == " " || formPrompt . Behavior == " " ) { Assert . That ( response . Responses . Count <= 1 , " " ) ; } } }
Compares two instances of  and throws an exception if the transition from oldState to newState is not valid.
Compares two instances of and throws an exception if the transition from oldState to newState is not valid .
// Delete member // This cannot be null if newMemberState is not null // TODO - Get these magic strings out of here
oldMemberState
Member
The old member state.
The old member state .
oldEventState
Event
The old event state.
The old event state .
newMemberState
Member
The new member state.
The new member state .
newEventState
Event
The new event state.
The new event state .