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 SheetPartTO Update(SheetPartTO entity) { if (entity is null) { throw new ArgumentNullException(nameof(entity)); } if (entity.Id <= 0) { throw new ArgumentException("SheetPart To Update Invalid Id"); } if (!libraryContext.SheetParts.Any(x => x.Id == entity.Id)) { throw new KeyNotFoundException($"Update(SheetPartTO) Can't find sheetPart to update."); } var editedEntity = libraryContext.SheetParts.FirstOrDefault(e => e.Id == entity.Id); if (editedEntity != default) { editedEntity.UpdateFromDetached(entity.ToEF()); } var tracking = libraryContext.SheetParts.Update(editedEntity); tracking.State = EntityState.Detached; 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 SheetPartTO Add(SheetPartTO entity) { if (entity is null) { throw new ArgumentNullException(); } if (entity.Id != 0) { return(entity); } var entityEF = entity.ToEF(); entityEF.Instrument = libraryContext.Instruments.First(x => x.Id == entity.Instrument.Id); entityEF.Sheet = libraryContext.Sheets.First(x => x.Id == entity.Sheet.Id); var result = libraryContext.SheetParts.Add(entityEF); libraryContext.SaveChanges(); return(result.Entity.ToTransferObject()); }