public static void AddMembers(AroundMooContext context) { var member = new Member("admin", "*****@*****.**", "admin!", MemberRole.Admin.ToString()); context.Members.AddOrUpdate(member); var user1 = new Member("user1", "*****@*****.**", "user1!", MemberRole.User.ToString()); context.Members.AddOrUpdate(user1); var user2 = new Member("user2", "*****@*****.**", "user2!", MemberRole.User.ToString()); context.Members.AddOrUpdate(user2); //add infos var info1 = new Comment(user1, "This is the best house in the world", -37.88114, 144.749646); context.Comments.AddOrUpdate(info1); var info2 = new Comment(user1, "Be careful when driving around here", -37.88214, 144.749746); context.Comments.AddOrUpdate(info2); //member retrieve infos var memberComment1 = new MemberComment(user1, info1); var memberComment2 = new MemberComment(user1, info2); var memberComment3 = new MemberComment(user2, info1); var memberComment4 = new MemberComment(user2, info2); context.MemberComments.Add(memberComment1); context.MemberComments.Add(memberComment2); context.MemberComments.Add(memberComment3); context.MemberComments.Add(memberComment4); context.SaveChanges(); }
public AroundMooContext CreateContext() { // create the database from scratch if it has not been initialised if (!DatabaseInitialized) { // get the path to the .SDF file var fullPath = GetRealDatabaseFilePath(DatabaseName); // delete it if it already exists if (File.Exists(fullPath)) File.Delete(fullPath); // get the SQL CE connection string string connectionString = GetRealDatabaseConnectionString(DatabaseName); // NEED TO SET THIS TO MAKE DATABASE CREATION WORK WITH SQL CE!!! Database.DefaultConnectionFactory = new SqlCeConnectionFactory("System.Data.SqlServerCe.4.0"); using (var context = new AroundMooContext()) { context.Database.Create(); } // Set the initialised flag so that we don't re-create the database again for this instance of the class DatabaseInitialized = true; } // create the DbContext with the SQL CE connection string return new AroundMooContext(); }
public void Dispose(AroundMooContext context) { try { Dispose(); } finally { if (context != null) { context.Dispose(); } } }
public void SetupTest() { // create the test strategy. This will initialise a new database _testDatabaseStrategy = CreateTestStrategy(); // add test data to the database instance using (_context = _testDatabaseStrategy.CreateContext()) { ProductsTestData.AddMembers(_context); _context.SaveChanges(); } // initialise the repository we are testing _context = _testDatabaseStrategy.CreateContext(); _requestCommentRepository = new RequestCommentRepository(_context); }
public void CleanupTest() { // dispose of the database and connection _testDatabaseStrategy.Dispose(_context); _context = null; }