public void ShouldAddNewPerson() { using (new TransactionScope()) { using (TrailsContext context = new TrailsContext()) { DbSet<Person> persons = context.Persons; persons.Load(); int priorCount = persons.Local.Count; Person newPerson = new Person { FirstName = "testFirstName", LastName = "testLastName", DateOfBirth = DateTime.Today.AddYears(-32), Gender = "M" }; // Add the new person to the context Person person = persons.Add(newPerson); // Save the context to the database, causing the database to be updated context.SaveChanges(); // At this stage, the database has the new row, so the identity has been incremented and assigned Assert.IsTrue(person.Id > 0); Assert.IsTrue(newPerson.Id > 0); persons.Load(); int postCount = persons.Local.Count; Assert.AreEqual(postCount, priorCount + 1); } // Rollback the transaction, to make the test repeatable } }
public void ShouldGetAllTransportTypes() { using (TrailsContext context = new TrailsContext()) { DbSet<TransportType> transportTypes = context.TransportTypes; transportTypes.Load(); Assert.IsTrue(transportTypes.Local.Count > 0); Console.WriteLine("There are {0} Transport Types", transportTypes.Count()); } }
public void ShouldGetAllRegions() { using (TrailsContext context = new TrailsContext()) { DbSet<Region> regions = context.Regions; regions.Load(); Assert.IsTrue(regions.Local.Count > 0); Console.WriteLine("There are {0} regions", regions.Count()); } }
public void ShouldGetAllLocations() { using (TrailsContext context = new TrailsContext()) { DbSet<Location> locations = context.Locations; locations.Load(); Assert.IsTrue(locations.Local.Count > 0); Console.WriteLine("There are {0} locations", locations.Count()); } }
public void ShouldGetAllDifficulties() { using (TrailsContext context = new TrailsContext()) { DbSet<Difficulty> difficultys = context.Difficulties; difficultys.Load(); Assert.IsTrue(difficultys.Local.Count > 0); Console.WriteLine("There are {0} difficulty levels", difficultys.Count()); } }
public void ShouldGetAllTrails() { using (TrailsContext context = new TrailsContext()) { DbSet<Trail> trails = context.Set<Trail>(); // or use context.Trails; trails.Load(); Assert.IsTrue(trails.Local.Count > 0); Console.WriteLine("There are {0} trails", trails.Count()); } }
public void ShouldGetAllPersons() { using (TrailsContext context = new TrailsContext()) { DbSet<Person> persons = context.Set<Person>(); // or use context.Persons; persons.Load(); Assert.IsTrue(persons.Local.Count > 0); Console.WriteLine("There are {0} persons", persons.Count()); } }
public void ShouldGetTrailById() { const int id = 1; using (TrailsContext context = new TrailsContext()) { DbSet<Trail> trails = context.Trails; if (trails != null) { Trail trail = trails.Find(id); Assert.AreEqual(trail.Id, id); Console.WriteLine("Trail found: id = {0}, Name = {1}, Location = {2}, Region = {3}, TrailType = {4}, Difficulty = {5}", trail.Id, trail.Name, trail.Location.Name, trail.Location.Region.Name, trail.TrailType.TrailTypeName, trail.Difficulty.DifficultyType); } } }
public void ShouldGetTripById() { const int id = 1; using (TrailsContext context = new TrailsContext()) { DbSet<Trip> trips = context.Trips; if (trips != null) { Trip trip = trips.Find(id); Assert.AreEqual(trip.Id, id); Console.WriteLine("Trip found: id = {0}, Date = {1}, TimeTaken = {2}, Transport Type = {3}, Number of people on trip = {4}", trip.Id, trip.Date, trip.TimeTaken??0, trip.TransportType.TransportTypeName, trip.Persons.Count); } } }
public void ShouldGetPersonById() { const int id = 1; using (TrailsContext context = new TrailsContext()) { DbSet<Person> persons = context.Persons; if (persons != null) { Person person = persons.Find(id); Assert.AreEqual(person.Id, id); Console.WriteLine("Person found: id = {0}, Full Name = {1}", person.Id, person.FullName); } } }
public void ShouldGetLocationById() { const int id = 1; using (TrailsContext context = new TrailsContext()) { DbSet<Location> locations = context.Locations; if (locations != null) { Location location = locations.Find(id); Assert.IsNotNull(location); Assert.AreEqual(location.Id, id); Assert.IsNotNull(location.Region); Console.WriteLine("Location found: id = {0}, Name = {1}, Region = {2}", location.Id, location.Name, location.Region.Name); } } }
public void ShouldAddNewTrip() { // To turn on DTS on my computer, // see http://alexduggleby.com/2008/08/24/msdtc-unavailable-for-sql-express-transactions-or-who-took-my-msdtc-settings-on-vista/ // or http://geekswithblogs.net/narent/archive/2006/10/09/93544.aspx using (new TransactionScope()) { using (TrailsContext context = new TrailsContext()) { DbSet<Trip> trips = context.Trips; trips.Load(); int priorCount = trips.Local.Count; DbSet<Person> persons = context.Persons; persons.Load(); Trip newTrip = new Trip { Date = DateTime.Today, TimeTaken = 3.1M, TransportTypeId = 1, TrailId = 1, Persons = new List<Person>{persons.Local.ElementAt(0), persons.Local.ElementAt(2)} }; // Add the new trip to the context Trip trip = trips.Add(newTrip); // Save the context to the database, causing the database to be updated context.SaveChanges(); // At this stage, the database has the new row, so the identity has been incremented and assigned Assert.IsTrue(trip.Id > 0); Assert.IsTrue(newTrip.Id > 0); trips.Load(); int postCount = trips.Local.Count; Assert.AreEqual(postCount, priorCount + 1); } // Rollback the transaction, to make the test repeatable } }
public void ShouldAddNewTrail() { using (new TransactionScope()) { using (TrailsContext context = new TrailsContext()) { DbSet<Trail> trails = context.Trails; trails.Load(); int priorCount = trails.Local.Count; Trail newTrail = new Trail { Name = "testTrailName", Description = "testDescription", Distance = 32, ElevationGain = 3000M, TrailTypeId = 1, LocationId = 1, DifficultyId = 1 }; // Add the new trail to the context Trail trail = trails.Add(newTrail); // Save the context to the database, causing the database to be updated context.SaveChanges(); // At this stage, the database has the new row, so the identity has been incremented and assigned Assert.IsTrue(trail.Id > 0); Assert.IsTrue(newTrail.Id > 0); trails.Load(); int postCount = trails.Local.Count; Assert.AreEqual(postCount, priorCount + 1); } // Rollback the transaction, to make the test repeatable } }
public void ShouldGetTrailsByName() { using (TrailsContext context = new TrailsContext()) { DbSet<Trail> trails = context.Trails; var trailQuery = from p in trails where p.Name.Contains("Lake") select p; List<Trail> trailList = trailQuery.ToList(); Assert.IsTrue(trailList.Count > 0); Console.WriteLine("There are {0} trails with the specified name", trailList.Count()); } }
public void ShouldGetTripsByTransportType() { using (TrailsContext context = new TrailsContext()) { DbSet<Trip> trips = context.Trips; var tripQuery = from p in trips where p.TransportType.TransportTypeName.Contains("Hike") select p; List<Trip> tripList = tripQuery.ToList(); Assert.IsTrue(tripList.Count > 0); Console.WriteLine("There are {0} trips with the specified transport type", tripList.Count()); } }
public void ShouldGetPersonsByLastName() { using (TrailsContext context = new TrailsContext()) { DbSet<Person> persons = context.Persons; var personQuery = from p in persons where p.LastName == "Smith" select p; List<Person> personList = personQuery.ToList(); Assert.IsTrue(personList.Count > 0); Console.WriteLine("There are {0} people with the specified name", personList.Count()); } }