public void CreateAndDeleteFriendWithNHRepo() { var repo = new NHFriendRepository(_sessionFactory); string testFriendEmailAddress = Guid.NewGuid().ToString(); using (var context = new PluralSightBookContext()) { var initializer = new TestDbInitializer(); initializer.Reseed(context); Guid testUserId = context.Users .FirstOrDefault(u => u.UserName == TestDbInitializer.TEST_USERNAME) .UserId; int initialFriendCount = context.Friends .Count(f => f.UserId == testUserId); repo.Create(testUserId, testFriendEmailAddress); Assert.AreEqual(initialFriendCount + 1, context.Friends.Count(f => f.UserId == testUserId)); var friends = repo.ListFriendsOfUser(testUserId); Assert.AreEqual(friends.Count(), initialFriendCount + 1); var friend = _sessionFactory.OpenSession() .QueryOver<Friend>() .Where(f => f.EmailAddress == testFriendEmailAddress) .List() .FirstOrDefault(); repo.Delete(friend.Id); Assert.AreEqual(initialFriendCount, context.Friends .Count(f => f.UserId == testUserId)); } }
public EfCodeFirstQueryUsersByEmail(PluralSightBookContext context) { this._context = context; }