// @@@@@ TODO: Make private but allow unit testing public static RaceDay ParseLine(HorseSenseContext context, RaceDay parsedRaceday) { var raceday = FindOrCreateRaceDay(context, parsedRaceday); if (raceday != null) { var race = FindOrCreateRace(context, raceday, parsedRaceday); if (race != null) { var horse = FindOrCreateHorse(context, race, parsedRaceday); } } context.SaveChanges(); return(raceday); }
private static void RemoveOldDuplicateRaceDay(HorseSenseContext context, RaceDay parsedRaceday) { var foundRaceDay = context.RaceDays //.Include(rd => rd.Races) //.ThenInclude(r => r.Horses) .FirstOrDefault (rd => rd.Track.Equals(parsedRaceday.Track) && rd.Date.Equals(parsedRaceday.Date)); if (foundRaceDay != null) { // Cascade delete is enabled by default in Entity Framework, this will remove raceday and its races & horses // @@@@@@ But this doesn't seem to work !!!!! context.RaceDays.Remove(foundRaceDay); context.SaveChanges(); } }
public void DrfParserBaseTest() { // Run the test against one instance of the context using (var context = new HorseSenseContext(GetHorseSenseContextOptionForMethod())) { context.Horses.Add(new Horse { Name = "Horsie" }); context.SaveChanges(); } // Use a separate instance of the context to verify correct data was saved to database using (var context = new HorseSenseContext(GetHorseSenseContextOptionForMethod())) { Assert.AreEqual(1, context.Horses.Count()); Assert.AreEqual("Horsie", context.Horses.Single().Name); } }