public void ToEF_Successful() { //ARRANGE var instrument = new InstrumentTO { Id = 4, Name = "Saxophone" }; var libUser = new LibUserTO { Id = 1, IdentityUserId = 24 }; var category = new CategoryTO { Id = 2, Name = "Jazz" }; var sheet = new SheetTO { Id = 3, Name = "Sam's Dixie", Category = category, IsCurrent = true, IsIndependance = true, IsGarde = false, }; var sheetPart = new SheetPartTO { Id = 2, Instrument = instrument, Sheet = sheet, Path = "Path" }; //ACT var instrumentEF = instrument.ToEF(); var libUserEF = libUser.ToEF(); var categoryEF = category.ToEF(); var sheetEF = sheet.ToEF(); var sheetPartEF = sheetPart.ToEF(); //Assert Assert.AreEqual(instrument.Name, instrumentEF.Name); Assert.AreEqual(libUser.IdentityUserId, libUserEF.IdentityUserId); Assert.AreEqual(category.Name, categoryEF.Name); Assert.AreEqual(sheet.Name, sheetEF.Name); Assert.AreEqual(sheetPart.Sheet.Name, sheetPartEF.Sheet.Name); }
public LibUserTO Update(LibUserTO entity) { if (entity is null) { throw new ArgumentNullException(nameof(entity)); } if (entity.Id <= 0) { throw new ArgumentException("LibUser To Update Invalid Id"); } if (!libraryContext.LibraryUsers.Any(x => x.Id == entity.Id)) { throw new KeyNotFoundException($"Update(LibUser) Can't find LibUser to update."); } var editedEntity = libraryContext.LibraryUsers.FirstOrDefault(e => e.Id == entity.Id); if (editedEntity != default) { editedEntity.UpdateFromDetached(entity.ToEF()); } var tracking = libraryContext.LibraryUsers.Update(editedEntity); tracking.State = EntityState.Modified; libraryContext.SaveChanges(); //return editedEntity.ToTransferObject(); return(tracking.Entity.ToTransferObject()); //return editedEntity.ToTransferObject(); }
public void ToTEF_ProvidingNull_ThrowException() { InstrumentTO instrument = null; LibUserTO libUser = null; CategoryTO category = null; SheetTO sheet = null; SheetPartTO sheetPart = null; //ACT Assert.ThrowsException <ArgumentNullException>(() => instrument.ToEF()); Assert.ThrowsException <ArgumentNullException>(() => libUser.ToEF()); Assert.ThrowsException <ArgumentNullException>(() => category.ToEF()); Assert.ThrowsException <ArgumentNullException>(() => sheet.ToEF()); Assert.ThrowsException <ArgumentNullException>(() => sheetPart.ToEF()); }
public LibUserTO Add(LibUserTO entity) { if (entity is null) { throw new ArgumentNullException(); } if (entity.Id != 0) { return(entity); } var entityEF = entity.ToEF(); var result = libraryContext.LibraryUsers.Add(entityEF); libraryContext.SaveChanges(); return(result.Entity.ToTransferObject()); }