public TracksController(MediaLibraryContext context) { context.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking; Context = context; Tracks = Context.Tracks.AsNoTracking(); Folders = Context.Folders.AsNoTracking(); }
public void DeleteMedia_Successful() { var connection = Effort.DbConnectionFactory.CreateTransient(); using (var context = new MediaLibraryContext(connection)) { IRepo mediaRepo = new MediaRepo(context); //ARRANGE var media = new MediaTO { Name = "Cendrillon", Type = MediaType.Film, Path = "C:/Films/Animation" }; var media2 = new MediaTO { Name = "C# pour les nulls", Type = MediaType.Book, Path = "C:/Book/Code" }; var media3 = new MediaTO { Name = "The IT Crowd", Type = MediaType.Serie, Path = "C:/Films/Series" }; var result = mediaRepo.CreateMedia(media); var result2 = mediaRepo.CreateMedia(media2); var result3 = mediaRepo.CreateMedia(media3); context.SaveChanges(); //ACT var test = mediaRepo.DeleteMedia(result); context.SaveChanges(); //ASSERT Assert.AreEqual(2, context.Medias.Count()); } }
public static bool IsFileExists(Models.File file) { using (MediaLibraryContext db = new MediaLibraryContext()) { return(db.Files.Any(f => f.Name == file.Name && f.Extension == file.Extension)); } }
public static List <Category> GetCategories(MediaType m) { using (MediaLibraryContext db = new MediaLibraryContext()) { return(db.Categories.Include(c => c.Files).Where(c => c.MediaType == m).ToList()); } }
public static List <Models.File> GetFiles(int id) { using (MediaLibraryContext db = new MediaLibraryContext()) { return(db.Files.Where(f => f.Id_category == id).ToList()); } }
public static List <MediaType> GetMediaTypes() { using (MediaLibraryContext db = new MediaLibraryContext()) { return(db.MediaTypes.Include(m => m.Categories).ToList()); } }
public static void SaveFile(Models.File file) { using (MediaLibraryContext db = new MediaLibraryContext()) { db.Files.Add(file); db.SaveChanges(); } }
public void ModifyMedia_ProvidingNull_ThrowException() { var connection = Effort.DbConnectionFactory.CreateTransient(); using (var context = new MediaLibraryContext(connection)) { IRepo mediaRepo = new MediaRepo(context); Assert.ThrowsException<ArgumentNullException>(() => mediaRepo.ModifyMedia(null)); } }
public void DeleteMedia_ProvidingNull_ThrowException() { var connection = Effort.DbConnectionFactory.CreateTransient(); using (var context = new MediaLibraryContext(connection)) { IRepo mediaRepo = new MediaRepo(context); Assert.ThrowsException <KeyNotFoundException>(() => mediaRepo.DeleteMedia(null)); } }
public void ModifyMedia_ProvidingNonExistingId_ThrowException() { var connection = Effort.DbConnectionFactory.CreateTransient(); using (var context = new MediaLibraryContext(connection)) { IRepo mediaRepo = new MediaRepo(context); var media = new MediaTO {Id=1450, Name = "Cendrillon", Type = MediaType.Film, Path = "C:/Films/Animation" }; Assert.ThrowsException<KeyNotFoundException>(() => mediaRepo.ModifyMedia(media)); } }
public void GetAllMedia_NoMediaInDb_ThrowException() { var connection = Effort.DbConnectionFactory.CreateTransient(); using (var context = new MediaLibraryContext(connection)) { IRepo mediaRepo = new MediaRepo(context); Assert.ThrowsException <ArgumentNullException>(() => mediaRepo.GetAllMedias()); } }
public void GetMediaById_ProvidingNonExistingId_ThrowException() { var connection = Effort.DbConnectionFactory.CreateTransient(); using (var context = new MediaLibraryContext(connection)) { IRepo mediaRepo = new MediaRepo(context); //ASSERT Assert.ThrowsException <ArgumentNullException>(() => mediaRepo.GetById(14)); } }
public void DeleteMedia_ProvidingNonExistingMedia_ThrowException() { var connection = Effort.DbConnectionFactory.CreateTransient(); using (var context = new MediaLibraryContext(connection)) { IRepo mediaRepo = new MediaRepo(context); var media = new MediaTO { Name = "Cendrillon", Type = MediaType.Film, Path = "C:/Films/Animation" }; Assert.ThrowsException <ArgumentException>(() => mediaRepo.DeleteMedia(media)); } }
public void GetMediaById_ProvidingNoId_ThrowException() { var connection = Effort.DbConnectionFactory.CreateTransient(); using (var context = new MediaLibraryContext(connection)) { IRepo mediaRepo = new MediaRepo(context); //ARRANGE var media = new MediaTO { Name = "Cendrillon", Type = MediaType.Film, Path = "C:/Films/Animation" }; //ASSERT Assert.ThrowsException <ArgumentException>(() => mediaRepo.GetById(media.Id)); } }
public void CreateMedia_AddExistingMedia_DoNotInsertTwiceInDb() { var connection = Effort.DbConnectionFactory.CreateTransient(); using (var context = new MediaLibraryContext(connection)) { IRepo mediaRepo = new MediaRepo(context); var media = new MediaTO { Name = "Cendrillon", Type = MediaType.Film, Path = "C:/Films/Animation" }; var addedMedia = mediaRepo.CreateMedia(media); context.SaveChanges(); mediaRepo.CreateMedia(addedMedia); context.SaveChanges(); Assert.AreEqual(1, context.Medias.Count()); } }
public void ModifyMedia_Successful() { var connection = Effort.DbConnectionFactory.CreateTransient(); using (var context = new MediaLibraryContext(connection)) { IRepo mediaRepo = new MediaRepo(context); //ARRANGE var media = new MediaTO { Name = "Cendrillon", Type = MediaType.Film, Path = "C:/Films/Animation" }; var result = mediaRepo.CreateMedia(media); context.SaveChanges(); //ACT result.Name = "Cendrillon Remaster"; var test = mediaRepo.ModifyMedia(result); context.SaveChanges(); //ASSERT Assert.AreEqual("Cendrillon Remaster", test.Name); } }
public void CreateMedia_Successful() { var connection = Effort.DbConnectionFactory.CreateTransient(); using (var context = new MediaLibraryContext(connection)) { IRepo mediaRepo = new MediaRepo(context); //ACT var media = new MediaTO { Name = "Cendrillon", Type = MediaType.Film, Path = "C:/Films/Animation" }; var result = mediaRepo.CreateMedia(media); context.SaveChanges(); //ASSERT Assert.IsNotNull(result); Assert.AreEqual("Cendrillon", result.Name); Assert.AreEqual(1, result.Id); } }
public Repository() { _db = new MediaLibraryContext(); }