public void TestAddReviewToBookOk() { //SETUP1 var options = SqliteInMemory.CreateOptions <PocoOnlyDbContext>(); using (var context = new PocoOnlyDbContext(options)) { context.Database.EnsureCreated(); var book = new Book("test", null, DateTime.UtcNow, "Me", 123, null, new List <Author> { new Author("Me", "*****@*****.**") }); context.Add(book); context.SaveChanges(); } using (var context = new PocoOnlyDbContext(options)) { var rep = new Repository(context, null); //ATTEMPT var ok = rep.AddReview(1, 2, "OK", "Me"); //VERIFY ok.ShouldBeTrue(); } using (var context = new PocoOnlyDbContext(options)) { context.Set <Review>().Count().ShouldEqual(1); context.Books.Include(x => x.Reviews) .Single().Reviews.SingleOrDefault().VoterName.ShouldEqual("Me"); } }
public void TestCreateBookWithAuthorOk() { //SETUP1 var options = SqliteInMemory.CreateOptions <PocoOnlyDbContext>(); using (var context = new PocoOnlyDbContext(options)) { context.Database.EnsureCreated(); //ATTEMPT var book = new Book("test", null, DateTime.UtcNow, "Me", 123, null, new List <Author> { new Author("Me", "*****@*****.**") }); context.Add(book); context.SaveChanges(); } using (var context = new PocoOnlyDbContext(options)) { //VERIFY context.Books.Count().ShouldEqual(1); context.Authors.Count().ShouldEqual(1); context.Books.Include(x => x.AuthorsLink).ThenInclude(x => x.Author) .Single().AuthorsLink.SingleOrDefault().Author.Name.ShouldEqual("Me"); } }
public IStatusGeneric PlaceOrder(PlaceOrderDto dto) { var bookOrders = dto.LineItems.Select(x => new OrderBooksDto(x.BookId, _context.Find <Book>(x.BookId), x.NumBooks)); var user = _context.Find <User>(dto.UserId); var orderStatus = Order.CreateOrder(user.UserName, bookOrders); if (!orderStatus.IsValid) { return(orderStatus); } _context.Add(orderStatus.Result); _context.SaveChanges(); _mailService.SendMail(user, "..."); return(orderStatus); }