Ejemplo n.º 1
0
        public void SaveAsync_Book_Insert_Valid()
        {
            var key      = FakeHelper.Key;
            var category = BookCategoryMock.Get(key);

            MockRepository.Add(category);

            var model = BookMessageMock.Create(key)
                        .Default()
                        .WithCategory()
                        .Build();

            var message = SaveAsync(model);

            message.Should().NotBeNull();

            var entity = Db.Books.FirstOrDefault(x => x.Title == Fake.GetTitle(key));

            entity.Should().NotBeNull();

            var expected = BookMock.Get(key);

            expected.Id = entity.Id;
            var expectedCategory = BookCategoryBookMock.Get(expected, entity.Categories[0].Category);

            expectedCategory.Id = entity.Categories[0].Id;
            expected.Categories.Add(expectedCategory);
            entity.Should().BeEquivalentToEntity(expected);

            var messageExpected = BookUpdateMessageMock.Get(key);

            messageExpected.Id = entity.Id;
            message.Should().BeEquivalentToMessage(messageExpected);
        }
Ejemplo n.º 2
0
        public void SaveAsync_Book_Insert_FlagTableAtuthor_Author_NotExist()
        {
            var key      = FakeHelper.Key;
            var category = BookCategoryMock.Get(key);

            MockRepository.Add(category);

            var model = BookMessageMock.Get(key);

            var settings = Settings.Empty;

            settings.FeatureFlags.TryAdd(FeatureFlags.AddTableAtuthor, true);

            var message = SaveAsync(model, settings);

            message.Should().NotBeNull();

            var entity = Db.Books.FirstOrDefault(x => x.Title == Fake.GetTitle(key));

            entity.Should().NotBeNull();

            var expected = BookMock.Get(key);

            expected.Id         = entity.Id;
            expected.Author     = BookAuthorMock.Get(key);
            expected.Author.Id  = entity.Author.Id;
            expected.AuthorName = null;
            entity.Should().BeEquivalentToEntity(expected);

            var messageExpected = BookUpdateMessageMock.Get(key);

            messageExpected.Id = entity.Id;
            message.Should().BeEquivalentToMessage(messageExpected);
        }
Ejemplo n.º 3
0
        public void Handle_BookCommand_With_Category_Existing_Category()
        {
            // arrange
            var key = MockBuilder.Key;

            var category = BookCategoryMock.Get(key);

            MockRepository.Add(category);

            MockRepository.Commit();

            var command = SaveBookCommandMock.Create(key)
                          .Default()
                          .WithCategory()
                          .Build();

            // act
            var result = Handle(command);

            // assert
            result.Should().BeTrue();

            var books = MockRepository.Query <Domain.Entities.Book>()
                        .Include(x => x.Categories)
                        .ThenInclude(x => x.Category)
                        .ToList();
            var bookExpected = BookMock.Create(key)
                               .Default()
                               .WithCategory(books[0].Categories[0].Category)
                               .Build();

            books.Should().BeEquivalentToEntity(MockBuilder.List(bookExpected));

            var events        = Bus.GetAllPublished <UpdateBookEvent>(ContextNames.Exchange.Book);
            var eventExpected = UpdateBookEventMock.Get(key);

            events.Should().BeEquivalentToMessage(MockBuilder.List(eventExpected));
        }