/// <summary> /// Inserts a user-movie object into the repository. /// </summary> /// <param name="userMovie">The user-movie object to insert.</param> public void Insert(UserMovie userMovie) { if (userMovie == null) throw new ArgumentNullException("userMovie"); if (userMovie.User == null) throw new ArgumentNullException("user"); if (userMovie.Movie == null) throw new ArgumentNullException("movie"); CurrentSession.Save(userMovie); }
public void ShouldRetrieveInsertedUserMovieAfterInsert() { var user = new User {FirstName = "blah", LastName = "lastname", EmailAddress = "email", Identity = "identity", Password = "******"}; var movie = new Movie {Name = "boo", Year = DateTime.Now, DateAdded = DateTime.Now, FileLocation = "file", Description = "description"}; var userMovie = new UserMovie {User = user, Movie = movie, IsFavorite = false}; _sut.Insert(userMovie); var retrieved = InMemorySession.Query<UserMovie>().ToArray(); Assert.AreEqual(retrieved.Length, 1); Assert.AreEqual(retrieved.First().User.FirstName, user.FirstName); Assert.AreEqual(retrieved.First().Movie.Name, movie.Name); }
public void ShouldRetrieveNothingOnGetForUserWithDifferentUser() { var first = new User { FirstName = "first", LastName = "lastname", EmailAddress = "email", Identity = "identity", Password = "******" }; var second = new User { FirstName = "second", LastName = "lastname", EmailAddress = "email", Identity = "identity", Password = "******" }; var movie = new Movie {Name = "boo", Year = DateTime.Now, DateAdded = DateTime.Now, FileLocation = "file", Description = "description"}; var userMovie = new UserMovie { User = first, Movie = movie }; using (var transaction = InMemorySession.BeginTransaction()) { InMemorySession.Save(userMovie); transaction.Commit(); } var retrieved = _sut.GetForUser(second).ToArray(); Assert.AreEqual(retrieved.Length, 0); }
public void ShouldRetrievePreviouslyInsertedUserMoviesOnGetAll() { var user = new User { FirstName = "blah", LastName = "lastname", EmailAddress = "email", Identity = "identity", Password = "******" }; var movie = new Movie {Name = "boo", Year = DateTime.Now, DateAdded = DateTime.Now, FileLocation = "file", Description = "description"}; var userMovie = new UserMovie {User = user, Movie = movie, IsFavorite = false}; using (var transaction = InMemorySession.BeginTransaction()) { InMemorySession.Save(userMovie); transaction.Commit(); } var retrieved = _sut.GetForUser(user).ToArray(); Assert.AreEqual(retrieved.Length, 1); Assert.AreEqual(retrieved.First().User.FirstName, user.FirstName); Assert.AreEqual(retrieved.First().Movie.Name, movie.Name); }