public void GolfClubAggregate_CreateGolfClub_DuplicateCreateGolfClubCalled_ErrorThrown()
        {
            GolfClubAggregate aggregate = GolfClubAggregate.Create(GolfClubTestData.AggregateId);

            Should.NotThrow(() =>
            {
                aggregate.CreateGolfClub(GolfClubTestData.Name,
                                         GolfClubTestData.AddressLine1,
                                         GolfClubTestData.AddressLine2,
                                         GolfClubTestData.Town,
                                         GolfClubTestData.Region,
                                         GolfClubTestData.PostalCode,
                                         GolfClubTestData.TelephoneNumber,
                                         GolfClubTestData.Website,
                                         GolfClubTestData.EmailAddress);
            });

            Should.Throw <InvalidOperationException>(() =>
            {
                aggregate.CreateGolfClub(GolfClubTestData.Name,
                                         GolfClubTestData.AddressLine1,
                                         GolfClubTestData.AddressLine2,
                                         GolfClubTestData.Town,
                                         GolfClubTestData.Region,
                                         GolfClubTestData.PostalCode,
                                         GolfClubTestData.TelephoneNumber,
                                         GolfClubTestData.Website,
                                         GolfClubTestData.EmailAddress);
            });
        }
        /// <summary>
        /// Handles the command.
        /// </summary>
        /// <param name="command">The command.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns></returns>
        private async Task HandleCommand(CreateGolfClubCommand command,
                                         CancellationToken cancellationToken)
        {
            Guid golfClubAggregateId = command.GolfClubId;

            // Rehydrate the aggregate
            GolfClubAggregate golfClubAggregate = await this.GolfClubRepository.GetLatestVersion(golfClubAggregateId, cancellationToken);

            // Call the aggregate method
            golfClubAggregate.CreateGolfClub(command.CreateGolfClubRequest.Name,
                                             command.CreateGolfClubRequest.AddressLine1,
                                             command.CreateGolfClubRequest.AddressLine2,
                                             command.CreateGolfClubRequest.Town,
                                             command.CreateGolfClubRequest.Region,
                                             command.CreateGolfClubRequest.PostalCode,
                                             command.CreateGolfClubRequest.TelephoneNumber,
                                             command.CreateGolfClubRequest.Website,
                                             command.CreateGolfClubRequest.EmailAddress);

            // Record club admin user against aggregate
            golfClubAggregate.CreateGolfClubAdministratorSecurityUser(command.SecurityUserId);

            // Save the changes
            await this.GolfClubRepository.SaveChanges(golfClubAggregate, cancellationToken);

            // Setup the response
            command.Response = new CreateGolfClubResponse
            {
                GolfClubId = golfClubAggregateId
            };
        }
        public void GolfClubAggregate_CreateGolfClub_GolfClubCreated()
        {
            GolfClubAggregate aggregate = GolfClubAggregate.Create(GolfClubTestData.AggregateId);

            aggregate.CreateGolfClub(GolfClubTestData.Name,
                                     GolfClubTestData.AddressLine1,
                                     GolfClubTestData.AddressLine2,
                                     GolfClubTestData.Town,
                                     GolfClubTestData.Region,
                                     GolfClubTestData.PostalCode,
                                     GolfClubTestData.TelephoneNumber,
                                     GolfClubTestData.Website,
                                     GolfClubTestData.EmailAddress);

            aggregate.ShouldNotBeNull();
            aggregate.AggregateId.ShouldBe(GolfClubTestData.AggregateId);
            aggregate.Name.ShouldBe(GolfClubTestData.Name);
            aggregate.AddressLine1.ShouldBe(GolfClubTestData.AddressLine1);
            aggregate.AddressLine2.ShouldBe(GolfClubTestData.AddressLine2);
            aggregate.Town.ShouldBe(GolfClubTestData.Town);
            aggregate.Region.ShouldBe(GolfClubTestData.Region);
            aggregate.PostalCode.ShouldBe(GolfClubTestData.PostalCode);
            aggregate.TelephoneNumber.ShouldBe(GolfClubTestData.TelephoneNumber);
            aggregate.Website.ShouldBe(GolfClubTestData.Website);
            aggregate.EmailAddress.ShouldBe(GolfClubTestData.EmailAddress);
            aggregate.HasBeenCreated.ShouldBeTrue();
        }
        public void GolfClubAggregate_CreateGolfClub_InvalidData_ErrorThrown(String name,
                                                                             String addressLine1,
                                                                             String town,
                                                                             String region,
                                                                             String postalCode)
        {
            GolfClubAggregate aggregate = GolfClubAggregate.Create(GolfClubTestData.AggregateId);

            Should.Throw <ArgumentNullException>(() =>
            {
                aggregate.CreateGolfClub(name,
                                         addressLine1,
                                         GolfClubTestData.AddressLine2,
                                         town,
                                         region,
                                         postalCode,
                                         GolfClubTestData.TelephoneNumber,
                                         GolfClubTestData.Website,
                                         GolfClubTestData.EmailAddress);
            });
        }