public void TestFixtureSetUp() { using (var db = new TrackerDataContext()) { var oldUser = db.User .ByEmailAddress("*****@*****.**") .FirstOrDefault(); if (oldUser != null) db.User.DeleteOnSubmit(oldUser); var oldRole = db.Role .ByName("Tester") .FirstOrDefault(); if (oldRole != null) db.Role.DeleteOnSubmit(oldRole); if (oldUser != null || oldRole != null) db.SubmitChanges(); } }
public void SetUp() { using (var db = new TrackerDataContext()) { var user = new User { EmailAddress = "*****@*****.**", FirstName = "Testie", LastName = "McTester", PasswordHash = "aM/Vndh7cYd3Mxq7msArjl9YU8zoR6fF+sVTSUCcsJi2bx+cwOI0/Bkr5hfq9vYfTe3/rlgPpSMg108acpw+qA", PasswordSalt = "=Unc%", IsApproved = true, CreatedDate = DateTime.Now, ModifiedDate = DateTime.Now, LastActivityDate = DateTime.Now, LastLoginDate = DateTime.Now, LastPasswordChangeDate = DateTime.Now, RoleList = new List<Role>() }; db.User.InsertOnSubmit(user); var role = new Role { Name = "Tester", Description = "Does testing.", CreatedDate = DateTime.Now, ModifiedDate = DateTime.Now }; db.Role.InsertOnSubmit(role); user.RoleList.Add(role); db.SubmitChanges(); UserId = user.Id; RoleId = role.Id; } }
public void TearDown() { using (var db = new TrackerDataContext()) { var user = db.User.GetByKey(UserId); if (user != null) db.User.DeleteOnSubmit(user); var role = db.Role.GetByKey(RoleId); if (role != null) db.Role.DeleteOnSubmit(role); db.SubmitChanges(); } }
public void Self() { int parentId; using (var db = new TrackerDataContext()) { var parent = new Self {Name = "Parent"}; db.Self.InsertOnSubmit(parent); db.SubmitChanges(); parentId = parent.Id; var child = new Self {Name = "Child", MySelf = parent}; db.Self.InsertOnSubmit(child); db.SubmitChanges(); } using (var db = new TrackerDataContext()) { var child = db.Self .ByName("Child") .FirstOrDefault(); Assert.AreEqual(parentId, child.MySelf.Id); db.Self.DeleteOnSubmit(child); db.Self.DeleteOnSubmit(child.MySelf); db.SubmitChanges(); } }
public void ObjectTrackingEnabled() { using (var db = new TrackerDataContext { ObjectTrackingEnabled = false }) { var user = db.User .ByFirstName("Testie") .FirstOrDefault(); Assert.IsNotNull(user); try { db.SubmitChanges(); } catch (Exception ex) { Assert.IsTrue(ex.Message.Contains("ObjectTrackingEnabled")); } } }
public void ManyToOneAndOneToMany() { int taskId; using (var db = new TrackerDataContext()) { var priority = db.Priority.GetByKey(Priority.High); var status = db.Status.GetByKey(Status.Completed); var user = db.User.GetByKey(UserId); var task = new Task { CompleteDate = DateTime.Now, CreatedDate = DateTime.Now, Details = "Test'n", DueDate = DateTime.Now, ModifiedDate = DateTime.Now, Priority = priority, StartDate = DateTime.Now, Status = status, Summary = "Test'n", UserCreated = user }; db.Task.InsertOnSubmit(task); db.SubmitChanges(); taskId = task.Id; } using (var db = new TrackerDataContext()) { var user = db.User.GetByKey(UserId); Assert.AreEqual(0, user.TaskAssignedList.Count); Assert.AreEqual(1, user.TaskCreatedList.Count); var task = user.TaskCreatedList.First(); user.TaskAssignedList.Add(task); db.SubmitChanges(); Assert.AreEqual(1, user.TaskAssignedList.Count); } using (var db = new TrackerDataContext()) { var task = db.Task.GetByKey(taskId); db.Task.DeleteOnSubmit(task); db.SubmitChanges(); var user = db.User.GetByKey(UserId); Assert.AreEqual(0, user.TaskAssignedList.Count); Assert.AreEqual(0, user.TaskCreatedList.Count); } }
public void ManyToMany() { using (var db = new TrackerDataContext()) { var user = db.User.GetByKey(UserId); Assert.AreEqual(1, user.RoleList.Count); var role = db.Role.GetByKey(RoleId); user.RoleList.Remove(role); db.SubmitChanges(); Assert.AreEqual(0, user.RoleList.Count); } using (var db = new TrackerDataContext()) { var user = db.User.GetByKey(UserId); Assert.AreEqual(0, user.RoleList.Count); var role = db.Role.GetByKey(RoleId); user.RoleList.Add(role); db.SubmitChanges(); Assert.AreEqual(1, user.RoleList.Count); } using (var db = new TrackerDataContext()) { var user = db.User.GetByKey(UserId); Assert.AreEqual(1, user.RoleList.Count); } }