Exemple #1
0
        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 albumsRepository = new EfDeletableEntityRepository <Album>(dbContext);
            var albumsService    = new AlbumsService(albumsRepository, cloudinary.Object);

            await albumsRepository.AddAsync(new Album
            {
                Name        = "Primo Victoria",
                CoverUrl    = "https://res.cloudinary.com/nikolacgeorgiev/image/upload/v1587375808/albums_photos/Primo_Victoria_xhi3ny.jpg",
                ReleaseDate = DateTime.ParseExact("2005-03-04", "yyyy-MM-dd", CultureInfo.InvariantCulture),
                GroupId     = 4,
            });

            await albumsRepository.SaveChangesAsync();

            var photo       = new Mock <IFormFile>();
            var releaseDate = DateTime.ParseExact("2012-05-22", "yyyy-MM-dd", CultureInfo.InvariantCulture);

            var id = await albumsService.CreateAsync("Carolus Rex", photo.Object, releaseDate, 4);

            var album = new AlbumEditInputModel
            {
                Name        = "Primo Victoria",
                CoverUrl    = "https://res.cloudinary.com/nikolacgeorgiev/image/upload/v1587375808/albums_photos/Primo_Victoria_xhi3ny.jpg",
                ReleaseDate = DateTime.ParseExact("2005-03-04", "yyyy-MM-dd", CultureInfo.InvariantCulture),
                GroupId     = 4,
            };

            await Assert.ThrowsAsync <ArgumentException>(async() =>
            {
                await albumsService.EditAsync(id, album);
            });
        }