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 membersRepository = new EfDeletableEntityRepository <Member>(dbContext); var service = new MembersService(membersRepository, cloudinary.Object); var photo = new Mock <IFormFile>(); await service.CreateAsync("Lars Ulrich", photo.Object, "description", 2); var id = await service.CreateAsync("Kirk Hammett", photo.Object, "description", 2); var model = new MemberEditInputModel { FullName = "Lars Ulrich", Photo = photo.Object, Description = "description", GroupId = 2, }; await Assert.ThrowsAsync <ArgumentException>(async() => { await service.EditAsync(id, model); }); }
public async Task CreateAsyncWithCorrectDataShouldThrowArgumentException() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options; var dbContext = new ApplicationDbContext(options); var cloudinary = new Mock <ICloudinaryService>(); var membersRepository = new EfDeletableEntityRepository <Member>(dbContext); var service = new MembersService(membersRepository, cloudinary.Object); var photo = new Mock <IFormFile>(); await service.CreateAsync("Lars Ulrich", photo.Object, "description", 2); await Assert.ThrowsAsync <ArgumentException>(async() => { await service.CreateAsync("Lars Ulrich", photo.Object, "description", 2); }); }
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 membersRepository = new EfDeletableEntityRepository <Member>(dbContext); var service = new MembersService(membersRepository, cloudinary.Object); var photo = new Mock <IFormFile>(); var actual = await service.CreateAsync("Kirk Hammett", photo.Object, "description", 2); var expected = 1; Assert.Equal(expected, actual); }
public async Task <IActionResult> RegisterPrivate(MembersRegisterPrivateVM membersRegisterPrivateVM) { if (!ModelState.IsValid) { ViewBag.BackButton = true; return(View(membersRegisterPrivateVM)); } var isAdded = await membersService.CreateAsync(membersRegisterPrivateVM); if (!isAdded) { ViewBag.BackButton = true; return(View(membersRegisterPrivateVM)); } return(RedirectToAction(nameof(Index))); }
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 membersRepository = new EfDeletableEntityRepository <Member>(dbContext); var service = new MembersService(membersRepository, cloudinary.Object); var photo = new Mock <IFormFile>(); var id = await service.CreateAsync("Kirk Hammett", photo.Object, "description", 2); var model = new MemberEditInputModel { FullName = "Kirk Hammett", Photo = photo.Object, Description = "Other", GroupId = 1, }; Assert.True(await service.EditAsync(id, model)); }