public async Task EditeAsyncWithDublicateNameShouldThrowArgumentException() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options; var dbContext = new ApplicationDbContext(options); var cloudinary = new Mock <ICloudinaryService>(); var concertGroupsRepository = new EfRepository <ConcertGroup>(dbContext); var groupsRepository = new EfDeletableEntityRepository <Group>(dbContext); var groupGenresRepository = new EfRepository <GroupGenre>(dbContext); var usertGroupsRepository = new EfRepository <UserGroup>(dbContext); var groupService = new GroupsService(concertGroupsRepository, groupsRepository, groupGenresRepository, usertGroupsRepository, cloudinary.Object); var photo = new Mock <IFormFile>(); await groupService.CreateAsync("Sabaton", photo.Object, "description"); var id = await groupService.CreateAsync("Nightwish", photo.Object, "description"); var model = new GroupEditInputModel { Name = "Sabaton", Photo = photo.Object, Description = "description", }; await Assert.ThrowsAsync <ArgumentException>(async() => { await groupService.EditAsync(id, model); }); }
public async Task <ActionResult <FullGroupDto> > PostGroup(GroupDto group) { var userId = User.FindFirstValue("sub"); var newGroup = await _groupsService.CreateAsync(userId, group); return(CreatedAtAction("GetGroup", new { id = newGroup.Id }, newGroup)); }
public async Task EditAsyncWithCorrectDataShouldReturnCorrectResult() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options; var dbContext = new ApplicationDbContext(options); var cloudinary = new Mock <ICloudinaryService>(); var concertGroupsRepository = new EfRepository <ConcertGroup>(dbContext); var groupsRepository = new EfDeletableEntityRepository <Group>(dbContext); var groupGenresRepository = new EfRepository <GroupGenre>(dbContext); var usertGroupsRepository = new EfRepository <UserGroup>(dbContext); var groupService = new GroupsService(concertGroupsRepository, groupsRepository, groupGenresRepository, usertGroupsRepository, cloudinary.Object); var photo = new Mock <IFormFile>(); var id = await groupService.CreateAsync("Sabaton", photo.Object, "description"); var model = new GroupEditInputModel { Name = "Sabaton", Photo = photo.Object, Description = "other", }; Assert.True(await groupService.EditAsync(id, model)); }
public async Task <IActionResult> Create([Bind("Group_ID,Course_ID,Name")] Groups groups) { if (ModelState.IsValid) { await _servGroups.CreateAsync(groups); return(RedirectToAction(nameof(Index))); } return(View(groups)); }
public async Task CreateAsyncWithCorrectDataShouldReturnCorrectResult() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options; var dbContext = new ApplicationDbContext(options); var cloudinary = new Mock <ICloudinaryService>(); var concertGroupsRepository = new EfRepository <ConcertGroup>(dbContext); var groupsRepository = new EfDeletableEntityRepository <Group>(dbContext); var groupGenresRepository = new EfRepository <GroupGenre>(dbContext); var usertGroupsRepository = new EfRepository <UserGroup>(dbContext); var groupService = new GroupsService(concertGroupsRepository, groupsRepository, groupGenresRepository, usertGroupsRepository, cloudinary.Object); var photo = new Mock <IFormFile>(); var actual = await groupService.CreateAsync("Sabaton", photo.Object, "description"); var expected = 1; Assert.Equal(expected, actual); }
public async Task <IActionResult> CreateAsync([FromBody] List <MatchDto> dtos) { return(Ok(await _service.CreateAsync(dtos))); }