コード例 #1
0
        public void TestCreateBookAndCheckPartsOk()
        {
            //SETUP
            var options = SqliteInMemory.CreateOptionsWithLogging <SqlEventsDbContext>(x => _output.WriteLine(x.Message));

            using (var context = new SqlEventsDbContext(options, null))
            {
                context.Database.EnsureCreated();
                var book = WithEventsEfTestData.CreateDummyBookTwoAuthorsTwoReviews();
                context.Add(book);
                context.SaveChanges();
            }
            using (var context = new SqlEventsDbContext(options, null))
            {
                //ATTEMPT
                var bookWithRelationships = context.Books
                                            .Include(p => p.AuthorsLink).ThenInclude(p => p.Author)
                                            .Include(p => p.Reviews)
                                            .Single();

                //VERIFY
                bookWithRelationships.AuthorsLink.Select(y => y.Author.Name).OrderBy(x => x).ToArray()
                .ShouldEqual(new[] { "Author1", "Author2" });
                bookWithRelationships.Reviews.Count().ShouldEqual(2);
            }
        }
コード例 #2
0
        public void TestCreateBookWithReviewsAndCheckReviewAddedHandlerOk()
        {
            //SETUP
            var showLog = false;
            var options =
                SqliteInMemory.CreateOptionsWithLogging <SqlEventsDbContext>(x =>
            {
                if (showLog)
                {
                    _output.WriteLine(x.DecodeMessage());
                }
            });
            var context = options.CreateDbWithDiForHandlers <SqlEventsDbContext, ReviewAddedHandler>();
            {
                context.Database.EnsureCreated();

                //ATTEMPT
                showLog = true;
                var book = WithEventsEfTestData.CreateDummyBookTwoAuthorsTwoReviews();
                context.Add(book);
                context.SaveChanges();

                //VERIFY
                book.ReviewsCount.ShouldEqual(2);
                book.ReviewsAverageVotes.ShouldEqual(6.0 / 2);
            }
        }
コード例 #3
0
        public void TestBookRemoveReviewCausesEventOk()
        {
            //SETUP
            var options = SqliteInMemory.CreateOptions <SqlEventsDbContext>();

            using (var context = new SqlEventsDbContext(options, null))
            {
                context.Database.EnsureCreated();
                var book = WithEventsEfTestData.CreateDummyBookTwoAuthorsTwoReviews();
                context.Add(book);
                context.SaveChanges();
                book.GetBeforeSaveEventsThenClear();

                //ATTEMPT
                book.RemoveReview(book.Reviews.First().ReviewId);

                //VERIFY
                var dEvent = book.GetBeforeSaveEventsThenClear().Single();
                dEvent.ShouldBeType <BookReviewRemovedEvent>();
            }
        }
コード例 #4
0
        public void TestCreateBookWithReviewsThenRemoveReviewCheckReviewRemovedHandlerOk()
        {
            //SETUP
            var options = SqliteInMemory.CreateOptions <SqlEventsDbContext>();
            {
                var context = options.CreateDbWithDiForHandlers <SqlEventsDbContext, ReviewAddedHandler>();
                context.Database.EnsureCreated();
                var book = WithEventsEfTestData.CreateDummyBookTwoAuthorsTwoReviews();
                context.Add(book);
                context.SaveChanges();

                //ATTEMPT
                var reviewToRemove = book.Reviews.First();
                book.RemoveReview(reviewToRemove.ReviewId);
                context.SaveChanges();

                //VERIFY
                book.ReviewsCount.ShouldEqual(1);
                book.ReviewsAverageVotes.ShouldEqual(1);
            }
        }
コード例 #5
0
        public void TestAuthorChangeNameCausesEventOk()
        {
            //SETUP
            var options = SqliteInMemory.CreateOptions <SqlEventsDbContext>();

            using (var context = new SqlEventsDbContext(options, null))
            {
                context.Database.EnsureCreated();
                var book = WithEventsEfTestData.CreateDummyBookTwoAuthorsTwoReviews();
                context.Add(book);
                context.SaveChanges();
                var author = book.AuthorsLink.First().Author;
                author.GetBeforeSaveEventsThenClear();

                //ATTEMPT
                author.ChangeName("new name");

                //VERIFY
                var dEvent = author.GetBeforeSaveEventsThenClear().Single();
                dEvent.ShouldBeType <AuthorNameUpdatedEvent>();
            }
        }