public void Update_WhenNoImageSupplied_ShouldKeepExistingOne()
		{
			var book = GetBookThatExistsInSession();

			var dto = new UpdateBookDto {Id = book.Id, Genre = book.Genre.Id};

			updater.Update(dto);

			Session.SaveChanges();

			SessionShouldHaveBookWithImage(book.Id, book.Image);
		}
		public void Update_WhenImageSupplied_ShouldReplaceExistingOne()
		{
			var book = GetBookThatExistsInSession();

			var newImage = new[] { (byte)88, (byte)11, (byte)0 };
			
			var dto = new UpdateBookDto {Id = book.Id, Genre = book.Genre.Id, Image = newImage};

			updater.Update(dto);

			Session.SaveChanges();

			SessionShouldHaveBookWithImage(book.Id, newImage);
		}
		public void Update(UpdateBookDto dto)
		{
			var existingBook = session.Load<Book>(dto.Id);
			session.Advanced.Evict(existingBook);

			var genre = session.Load<Genre>(dto.Genre);
			var updatedBook = 
				new Book(dto.Title, dto.Authors, dto.Description, genre, dto.Status, GetImage(existingBook, dto))
					{
						Id = existingBook.Id,
						Rating = dto.Rating
					};

			session.Store(updatedBook);
		}
		public FubuContinuation Post(UpdateBookInputModel model)
		{
			var dto = new UpdateBookDto
			          	{
			          		Authors = model.Authors.ToStrings(),
			          		Status  = model.BookStatus,
			          		Image   = model.Image == null || model.Image.ContentLength == 0 ? null : FileUploader.GetBytes(model.Image),
							Genre   = model.Genre,
							Id      = model.Id,
							Title   = model.Title,
							Rating  = model.Rating,
			          		Description = model.Description_BigText,
			          	};
			
			updater.Update(dto);

			return FubuContinuation.RedirectTo(new ViewBookLinkModel {Id = model.Id});
		}
		public void Update_GivenDtoForBookInSession_ShouldUpdateBookInSession()
		{
			var book = GetBookThatExistsInSession();

			var dto = new UpdateBookDto
			          	{
			          		Id          = book.Id,
							Genre       = book.Genre.Id,
			          		Authors     = new[] {"hey", "hooo", "haaaa"},
			          		Description = "Update description - dfkjldkj fldjflkd ",
			          		Status      = (BookStatus) ((int) book.Status) + 1,
			          		Title       = "Update title",
							Rating      = 3
			          	};

			updater.Update(dto);

			Session.SaveChanges();

			SessionShouldContainBookWithUpdatedValuesFrom(dto);
		}
		private void SessionShouldContainBookWithUpdatedValuesFrom(UpdateBookDto dto)
		{
			var updatedBook = Session.Load<Book>(dto.Id);

			Assert.AreEqual(dto.Authors, updatedBook.Authors);
			Assert.AreEqual(dto.Description, updatedBook.Review);
			Assert.AreEqual(dto.Genre, updatedBook.Genre.Id);
			Assert.AreEqual(dto.Status, updatedBook.Status);
			Assert.AreEqual(dto.Title, updatedBook.Title);
			Assert.AreEqual(dto.Rating, updatedBook.Rating);

			Assert.IsNotNull(updatedBook);
		}
		private byte[] GetImage(Book existingBook, UpdateBookDto dto)
		{
			return dto.Image ?? existingBook.Image;
		}
		private static void HasMatchingAuthors(UpdateBookInputModel model, UpdateBookDto dto)
		{
			// TODO -  move this logic into a list comparer - it has been implemented in the creater
			Assert.AreEqual(model.Authors.Count(), dto.Authors.Count());
			var y = dto.Authors.ToList();
			Assert.That(y.All(a => model.Authors.Any(x => a == x)), Is.True);
		}