public void should_delete_user_and_addresses()
        {
            var userRepo = new UserDataRepository();
            var user = new UserData { Email = "*****@*****.**", FirstName = "Unit", LastName = "test", Notes = "Unit test user" };
            userRepo.Add(user);

            UserData returnUser;

            using (ISession session = NBHelper.OpenSession())
                returnUser = session.Get<UserData>(user.Id);

            var addrRepo = new AddressDataRepository();
            var addr = new AddressData { City = "Testville", State = "NJ", Street1 = "Test1", Street2 = "Test2", UserId = returnUser.Id };
            addrRepo.Add(addr);

            AddressData returnAddress;

            using (ISession session = NBHelper.OpenSession())
                returnAddress = session.Get<AddressData>(addr.Id);

            // delete the User
            userRepo.Delete(returnUser);
            using (ISession session = NBHelper.OpenSession())
            {
                var result = session.Get<UserData>(returnUser.Id);
                Assert.IsNull(result);
            }
        }
        public void can_create_new_user_with_address()
        {
            var userRepo = new UserDataRepository();
            var user = new UserData { Email = "*****@*****.**", FirstName = "Unit", LastName = "test", Notes = "Unit test user" };
            userRepo.Add(user);

            UserData returnUser;

            using (ISession session = NBHelper.OpenSession())
            {
                returnUser = session.Get<UserData>(user.Id);
                Assert.IsNotNull(returnUser);
                Assert.IsNotNull(returnUser.Id);
            }

            var addrRepo = new AddressDataRepository();
            // with the User, create an address.
            var addr = new AddressData {City = "Testville", State="NJ", Street1 = "Test1", Street2 = "Test2", UserId = returnUser.Id};
            addrRepo.Add(addr);

            using (ISession session = NBHelper.OpenSession())
            {
                var result = session.Get<AddressData>(addr.Id);
                Assert.IsNotNull(result);
                Assert.IsNotNull(result.Id);
                Assert.AreEqual(returnUser.Id, result.UserId);
            }
        }
        public void can_create_new_record()
        {
            var repo = new UserDataRepository();
            UserData user = new UserData { Email = "*****@*****.**", FirstName = "Unit", LastName = "test", Notes = "Unit test user" };
            repo.Add(user);

            using (ISession session = NBHelper.OpenSession())
            {
                var result = session.Get<UserData>(user.Id);
                Assert.IsNotNull(result);
                Assert.AreNotSame(user, result);
                Assert.AreEqual(user.Email, result.Email);
                Assert.IsNotNull(result.Id);
            }
        }
        // this is used to translate data objects to business obects.
        // Allows the BLL to only care about the data it needs to use thus not all data needs to flow from DAL to the BLL
        // and possibly to the UI to worry about.
        public static User SetEntity(UserData userData)
        {
            if (userData != null)
            {
                return new User
                           {
                               Addresses = Address.SetEntity(userData.Addresses),
                               Tags = Tag.SetEntity(userData.Tags),
                                Email = userData.Email,
                                FirstName = userData.FirstName,
                                Id = userData.Id,
                                LastName = userData.LastName,
                                Notes = userData.Notes,
                                Favorite = userData.Favorite,
                };
            }

            return null;
        }