/// <summary> /// Requests the membership. /// </summary> /// <param name="playerId">The player identifier.</param> /// <param name="playerFullName">Full name of the player.</param> /// <param name="playerDateOfBirth">The player date of birth.</param> /// <param name="playerGender">The player gender.</param> /// <param name="requestDateAndTime">The request date and time.</param> /// <exception cref="System.ArgumentOutOfRangeException">Players gender can only be 'M' (Male) or 'F' (Female)</exception> public void RequestMembership(Guid playerId, String playerFullName, DateTime playerDateOfBirth, String playerGender, DateTime requestDateAndTime) { Guid membershipId = Guid.NewGuid(); Guard.ThrowIfInvalidGuid(playerId, typeof(ArgumentNullException), "A membership request must have valid player id"); Guard.ThrowIfNullOrEmpty(playerFullName, typeof(ArgumentNullException), "A membership request must have player full name supplied"); Guard.ThrowIfInvalidDate(playerDateOfBirth, typeof(ArgumentNullException), "A membership request must have player name supplied"); Guard.ThrowIfNullOrEmpty(playerGender, typeof(ArgumentNullException), "A membership request must have player gender supplied"); if (playerGender != "M" && playerGender != "F") { throw new ArgumentOutOfRangeException(playerGender, "Players gender can only be 'M' (Male) or 'F' (Female)"); } this.ValidateAgainstDuplicateMembershipRequest(playerId, playerDateOfBirth, playerGender); try { this.ValidatePlayerDateOfBirth(membershipId, playerId, playerDateOfBirth); this.ValidateMembershipCount(playerId); // Get the membership number String membershipNumber = this.GenerateMembershipNumber(); ClubMembershipRequestAcceptedEvent clubMembershipRequestAcceptedEvent = ClubMembershipRequestAcceptedEvent.Create(this.AggregateId, membershipId, playerId, playerFullName, playerDateOfBirth, playerGender, requestDateAndTime, membershipNumber); this.ApplyAndPend(clubMembershipRequestAcceptedEvent); } catch (InvalidOperationException e) { ClubMembershipRequestRejectedEvent clubMembershipRequestRejectedEvent = ClubMembershipRequestRejectedEvent.Create(this.AggregateId, membershipId, playerId, playerFullName, playerDateOfBirth, playerGender, e.Message, requestDateAndTime); this.ApplyAndPend(clubMembershipRequestRejectedEvent); } }
public void ClubMembershipRequestAcceptedEvent_CanBeCreated_IsCreated() { ClubMembershipRequestAcceptedEvent clubMembershipRequestAcceptedEvent = ClubMembershipRequestAcceptedEvent.Create(GolfClubMembershipTestData.AggregateId, GolfClubMembershipTestData.MembershipId, GolfClubMembershipTestData.PlayerId, GolfClubMembershipTestData.PlayerFullName, GolfClubMembershipTestData.PlayerDateOfBirth, GolfClubMembershipTestData.PlayerGender, GolfClubMembershipTestData.AcceptedDateAndTime, GolfClubMembershipTestData.MembershipNumber); clubMembershipRequestAcceptedEvent.ShouldNotBeNull(); clubMembershipRequestAcceptedEvent.AggregateId.ShouldBe(GolfClubMembershipTestData.AggregateId); clubMembershipRequestAcceptedEvent.EventCreatedDateTime.ShouldNotBe(DateTime.MinValue); clubMembershipRequestAcceptedEvent.EventId.ShouldNotBe(Guid.Empty); clubMembershipRequestAcceptedEvent.PlayerId.ShouldBe(GolfClubMembershipTestData.PlayerId); clubMembershipRequestAcceptedEvent.PlayerGender.ShouldBe(GolfClubMembershipTestData.PlayerGender); clubMembershipRequestAcceptedEvent.PlayerId.ShouldBe(GolfClubMembershipTestData.PlayerId); clubMembershipRequestAcceptedEvent.PlayerDateOfBirth.ShouldBe(GolfClubMembershipTestData.PlayerDateOfBirth); clubMembershipRequestAcceptedEvent.AcceptedDateAndTime.ShouldBe(GolfClubMembershipTestData.AcceptedDateAndTime); clubMembershipRequestAcceptedEvent.MembershipNumber.ShouldBe(GolfClubMembershipTestData.MembershipNumber); }