Exemple #1
0
        public async Task <ActionResult <Guid> > CreateStudentItem(CreateStudentItemCommand itemCommand)
        {
            var vm = await mediator.Send(itemCommand);

            if (vm.Id != null)
            {
                var link = Url.Link("GetStudentItem", new { studentId = vm.Id });
                return(Created(link, vm));
            }
            else
            {
                return(BadRequest(vm));
            }
        }
Exemple #2
0
        public async Task ShouldCreateStudent()
        {
            var command = new CreateStudentItemCommand()
            {
                FirstName = "first",
                LastName  = "last"
            };
            var dto = await SendWithValidationAsync(command, new CreateStudentItemCommandValidator());

            var created = await ExecuteDbContextAsync(db =>
                                                      db.Students.Where(c => c.Id.Equals(dto.Id)).SingleOrDefaultAsync());

            created.ShouldNotBeNull();
            created.FirstName.ShouldBe(command.FirstName);
            created.LastName.ShouldBe(command.LastName);
        }
Exemple #3
0
        public async Task ShouldGetStudentList()
        {
            var createStudentItemCommand = new CreateStudentItemCommand()
            {
                FirstName = "first",
                LastName  = "last"
            };
            var createStudentDto = await SendAsync(createStudentItemCommand);

            var created = await ExecuteDbContextAsync(db =>
                                                      db.Students.Where(c => c.Id.Equals(createStudentDto.Id)).SingleOrDefaultAsync());

            GetStudentListQuery query = new GetStudentListQuery();
            GetObjectListVm <GetStudentItemDto> dto = await SendAsync(query);


            dto.ShouldNotBeNull();
            dto.Count.ShouldBeGreaterThanOrEqualTo(1);
            dto.Data.ShouldContain(d => d.Id.Equals(created.Id));
        }
Exemple #4
0
        public async Task ShouldGetStudentItem()
        {
            var createStudentItemCommand = new CreateStudentItemCommand()
            {
                FirstName = "first",
                LastName  = "last"
            };
            var createStudentDto = await SendAsync(createStudentItemCommand);

            GetStudentItemQuery query = new GetStudentItemQuery()
            {
                Id = createStudentDto.Id
            };
            GetStudentItemDto dto = await SendAsync(query);

            var created = await ExecuteDbContextAsync(db => db.Students.Where(c => c.Id.Equals(dto.Id)).SingleOrDefaultAsync());

            dto.ShouldNotBeNull();
            dto.Id.ShouldBe(created.Id);
            dto.Name.ShouldBe($"{created.FirstName} {created.LastName}");
        }