예제 #1
0
        public async Task ShouldNotCreateLocationWhenInstructorIdNotExist()
        {
            var instructorDto1 = await SendAsync(new CreateInstructorItemCommand()
            {
                FirstName = "first",
                LastName  = "last",
                HireDate  = DateTime.UtcNow.DateTimeWithoutMilisecond(),
            });

            var instructorDto2 = await SendAsync(new CreateInstructorItemCommand()
            {
                FirstName = "first1",
                LastName  = "last2",
                HireDate  = DateTime.UtcNow.DateTimeWithoutMilisecond(),
            });


            CreateLocationItemCommand command = new CreateLocationItemCommand()
            {
                IsEnabled       = true,
                Name            = "location1",
                Address         = "address1",
                OpeningTime     = new TimeSpan(0, 19, 0),
                ClosingTime     = new TimeSpan(0, 21, 0),
                InstructorLists = new System.Collections.Generic.List <Guid> {
                    Guid.NewGuid(), Guid.NewGuid(), instructorDto1.Id, instructorDto2.Id
                },
            };

            await SendWithValidationAsync(command, new CreateLocationItemCommandValidator()).ShouldThrowAsync <EntityListCountMismatchException <Core.Domain.Entities.Instructor> >();
        }
예제 #2
0
        public async Task <ActionResult <Guid> > NewLocationItem(CreateLocationItemCommand itemCommand)
        {
            var vm = await mediator.Send(itemCommand);

            if (vm.Id != null)
            {
                var link = Url.Link("GetLocationItem", new { locationId = vm.Id });
                return(Created(link, vm));
            }
            else
            {
                return(BadRequest(vm));
            }
        }
예제 #3
0
        public async Task ShouldCreateLocation()
        {
            var instructorDto1 = await SendAsync(new CreateInstructorItemCommand()
            {
                FirstName = "first",
                LastName  = "last",
                HireDate  = DateTime.UtcNow.DateTimeWithoutMilisecond(),
            });

            var instructorDto2 = await SendAsync(new CreateInstructorItemCommand()
            {
                FirstName = "first1",
                LastName  = "last2",
                HireDate  = DateTime.UtcNow.DateTimeWithoutMilisecond(),
            });


            var command = new CreateLocationItemCommand()
            {
                IsEnabled       = true,
                Name            = "location1",
                Address         = "address1",
                OpeningTime     = new TimeSpan(0, 19, 0),
                ClosingTime     = new TimeSpan(0, 21, 0),
                InstructorLists = new System.Collections.Generic.List <Guid> {
                    instructorDto1.Id, instructorDto2.Id
                },
            };

            var dto = await SendWithValidationAsync(command, new CreateLocationItemCommandValidator());

            var created = await ExecuteDbContextAsync(db => db.Locations.Include(l => l.LocationInstructors).ThenInclude(l => l.Instructor).Where(c => c.Id.Equals(dto.Id)).SingleOrDefaultAsync());

            created.ShouldNotBeNull();
            created.Id.ShouldBe(dto.Id);
            created.Name.ShouldBe(command.Name);
            created.OpeningTime.ShouldBe(command.OpeningTime);
            created.ClosingTime.ShouldBe(command.ClosingTime);
            created.IsEnabled.ShouldBe(command.IsEnabled);
            var instructorIdList = created.LocationInstructors.Select(li => li.InstructorId).ToList();

            instructorIdList.ShouldContain(instructorDto1.Id);
            instructorIdList.ShouldContain(instructorDto2.Id);
        }