示例#1
0
        public async Task Fails_to_add_student_that_is_already_added()
        {
            var group   = Fixture.DataMother.CreateGroup(studentNames: new[] { "Timo Hermans" });
            var request = new StudentAddToGroup.Request
            {
                Name    = "Timo Hermans",
                GroupId = group.Id
            };
            var useCase = new StudentAddToGroup(Fixture.CreateDbContext());

            var result = await useCase.HandleAsync(request);

            result.IsFailure.Should().BeTrue();
            result.Error.Should().Contain("already");
        }
示例#2
0
        public async Task Adds_student_to_group()
        {
            var group   = Fixture.DataMother.CreateGroup();
            var request = new StudentAddToGroup.Request
            {
                Name    = "Timo Hermans",
                GroupId = group.Id
            };
            var useCase = new StudentAddToGroup(Fixture.CreateDbContext());

            var result = await useCase.HandleAsync(request);

            result.IsSuccess.Should().BeTrue();
            Fixture.DataMother.GroupWithStudents()
            .ShouldExist()
            .HasStudent("Timo Hermans");
        }
        private async Task <IActionResult> AddStudentToGroup()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            try
            {
                await _useCase.HandleAsync(Student);
            }
            catch (InvalidOperationException ex)
            {
                ModelState.AddModelError("Summary", ex.Message);
                return(Page());
            }

            return(Page());
        }