public async Task ShouldRequireUniqueName()
        {
            var listId = await SendAsync(new CreateTourListCommand
            {
                City    = "Bogota",
                Country = "Colombia",
                About   = "Lorem Ipsum"
            });

            await SendAsync(new CreateTourPackageCommand
            {
                ListId = listId,
                Name   = "Bike Tour in Bogota"
            });

            await SendAsync(new CreateTourPackageCommand
            {
                ListId = listId,
                Name   = "Salt Cathedral Tour"
            });

            var command = new UpdateTourPackageCommand
            {
                Id   = listId,
                Name = "Salt Cathedral Tour"
            };

            FluentActions.Invoking(() => SendAsync(command))
            .Should()
            .Throw <ValidationException>()
            .Where(ex => ex.Errors.ContainsKey("Name"))
            .And.Errors["Name"]
            .Should()
            .Contain("The specified name already exists.");
        }
        public async Task ShouldUpdateTourPackage()
        {
            var listId = await SendAsync(new CreateTourListCommand
            {
                City    = "Rabat",
                Country = "Morocco",
                About   = "Lorem Ipsum"
            });

            var packageId = await SendAsync(new CreateTourPackageCommand
            {
                ListId              = listId,
                Name                = "Free Walking Tour Rabat",
                Duration            = 2,
                Price               = 10,
                InstantConfirmation = true,
                MapLocation         = "Lorem Ipsum",
                WhatToExpect        = "Lorem Ipsum"
            });

            var command = new UpdateTourPackageCommand
            {
                Id   = packageId,
                Name = "Night Free Walking Tour Rabat"
            };

            await SendAsync(command);

            var item = await FindAsync <TourPackage>(packageId);

            item.Name.Should().Be(command.Name);
            item.WhatToExpect.Should().NotBeNull();
        }
        public void ShouldRequireValidTourPackageId()
        {
            var command = new UpdateTourPackageCommand
            {
                Id   = 4,
                Name = "Free Walking Tour"
            };

            FluentActions.Invoking(() => SendAsync(command)).Should().Throw <NotFoundException>();
        }
コード例 #4
0
        public async Task <ActionResult> Update(int id, UpdateTourPackageCommand command)
        {
            if (id != command.Id)
            {
                return(BadRequest());
            }

            await Mediator.Send(command);

            return(NoContent());
        }