Exemple #1
0
        public void MgaUpdateEntityValid()
        {
            // arrange
            var key = Fake.GetKey();

            var entity = MgaMock.Get(key);

            MockRepository.Add(entity);

            MockRepository.Commit();

            var key2  = Fake.GetKey();
            var model = MgaInputModelMock.Get(key2);

            // act
            Update(entity.Id, model);

            // assertation
            var entities       = MockRepository.Query <Mga>().ToList();
            var entityExpected = MgaMock.Get(key2);

            entities.Should().BeEquivalentToEntity(new List <Mga>()
            {
                entityExpected
            });
        }
Exemple #2
0
        public void Handle_ReserveBookCommandd_Default()
        {
            // arrange
            var key = MockBuilder.Key;

            var copy = CopyMock.Get(key);

            MockRepository.Add(copy);

            MockRepository.Commit();

            var command = ReserveBookCommandMock.Get(key);

            // act
            var result = Handle(command);

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

            var reservations = MockRepository.Query <Reservation>()
                               .Include(x => x.Loans)
                               .ThenInclude(x => x.Copy)
                               .ThenInclude(x => x.Book)
                               .Include(x => x.Member)
                               .ToList();
            var reservationExpected = ReservationMock.Get(key);

            reservations.Should().BeEquivalentToEntity(MockBuilder.List(reservationExpected));

            var publishReservationEventCommands        = Bus.GetAllSent <PublishReservationEventCommand>(ContextNames.Queue.Library);
            var PublishReservationEventCommandExpected = PublishReservationEventCommandMock.Get(key);

            PublishReservationEventCommandExpected.ReservationId = reservations[0].Id;
            publishReservationEventCommands.Should().BeEquivalentToMessage(MockBuilder.List(PublishReservationEventCommandExpected));
        }
Exemple #3
0
        public void Handle_UpdateBookCommand_Default()
        {
            // arrange
            var key = MockBuilder.Key;

            var book = BookMock.Get(key);

            MockRepository.Add(book);

            MockRepository.Commit();

            var key2    = MockBuilder.Key;
            var command = UpdateBookCommandMock.Get(key2);

            command.Title = book.Title;

            // act
            var result = Handle(command);

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

            var books        = MockRepository.Query <Book>().ToList();
            var bookExpected = BookMock.Get(key2);

            bookExpected.Title = book.Title;
            books.Should().BeEquivalentToEntity(MockBuilder.List(bookExpected));
        }
Exemple #4
0
        public void Handle_BookCommand_Book_Exist()
        {
            // arrange
            var key = MockBuilder.Key;

            var book = BookMock.Get(key);

            MockRepository.Add(book);

            MockRepository.Commit();

            var key2    = MockBuilder.Key;
            var command = SaveBookCommandMock.Get(key2);

            command.Title = book.Title;

            // act
            var result = Handle(command);

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

            var books        = MockRepository.Query <Domain.Entities.Book>().ToList();
            var bookExpected = BookMock.Get(key2);

            bookExpected.Title = book.Title;
            books.Should().BeEquivalentToEntity(MockBuilder.List(bookExpected));

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

            eventExpected.Title = book.Title;
            events.Should().BeEquivalentToMessage(MockBuilder.List(eventExpected));
        }
Exemple #5
0
        public void Handle_PurchaseBookCommand_Update()
        {
            // arrange
            var key = MockBuilder.Key;

            var order = OrderMock.Get(key);

            MockRepository.Add(order);

            MockRepository.Commit();

            var key2    = MockBuilder.Key;
            var command = PurchaseBookCommandMock.Get(key2);

            command.Number = order.Number;

            // act
            var result = Handle(command);

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

            var orders = MockRepository.Query <Order>()
                         .Include(x => x.Items)
                         .Include(x => x.Customer)
                         .ToList();
            var orderExpected = OrderMock.Create(key)
                                .BaseOrder()
                                .WithItem(key2)
                                .Build();

            orderExpected.Number = order.Number;
            orders.Should().BeEquivalentToEntity(MockBuilder.List(orderExpected));

            var publishShippingEventCommands        = Bus.GetAllSent <PublishShippingEventCommand>(ContextNames.Queue.Bookstore);
            var publishShippingEventCommandExpected = PublishShippingEventCommandMock.Get(key);

            publishShippingEventCommandExpected.OrderId = orders[0].Id;
            publishShippingEventCommands.Should().BeEquivalentToMessage(MockBuilder.List(publishShippingEventCommandExpected));

            var dropCopyNumberEvents        = Bus.GetAllPublished <DropCopyNumberEvent>(ContextNames.Exchange.Bookstore);
            var dropCopyNumberEventExpected = DropCopyNumberEventMock.Get(key2);

            dropCopyNumberEvents.Should().BeEquivalentToMessage(MockBuilder.List(dropCopyNumberEventExpected));
        }
Exemple #6
0
        public void Handle_CheckDueCommand_Default()
        {
            // arrange
            var key = MockBuilder.Key;

            var reservation = ReservationMock.Get(key);

            MockRepository.Add(reservation);

            MockRepository.Commit();

            var command = CheckDueCommandMock.Get(key);

            // act
            var result = Handle(command);

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

            var expireReservationCommands = Bus.GetAllSent <ExpireReservationCommand>(ContextNames.Queue.Library);

            expireReservationCommands.Should().BeEmpty();
        }
Exemple #7
0
        public void Handle_GetBookQuery_Default()
        {
            // arrange
            var key = MockBuilder.Key;

            var book = BookMock.Get(key);

            MockRepository.Add(book);

            MockRepository.Commit();

            var query = GetBookQueryMock.Get(key);

            // act
            var dto = Handle(query);

            dto.Should().NotBeNull();

            var dtoExpected = BookDtoMock.Get(key);

            dto.Should().BeEquivalentTo(dtoExpected);
        }
Exemple #8
0
        public void Handle_PublishReservationEventCommandd_Default()
        {
            // arrange
            var key = MockBuilder.Key;

            var reservation = ReservationMock.Get(key);

            MockRepository.Add(reservation);

            MockRepository.Commit();

            var command = PublishReservationEventCommandMock.Get(key);

            // act
            var result = Handle(command);

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

            var events        = Bus.GetAllPublished <CreateReservationEvent>(ContextNames.Exchange.Library);
            var eventExpected = CreateReservationEventMock.Get(key);

            events.Should().BeEquivalentToMessage(MockBuilder.List(eventExpected));
        }
Exemple #9
0
        public void Handle_PublishShippingEventCommand_Default()
        {
            // arrange
            var key = MockBuilder.Key;

            var order = OrderMock.Get(key);

            MockRepository.Add(order);

            MockRepository.Commit();

            var command = PublishShippingEventCommandMock.Get(key);

            // act
            var result = Handle(command);

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

            var events        = Bus.GetAllPublished <CreateShippingEvent>(ContextNames.Exchange.Bookstore);
            var eventExpected = CreateShippingEventMock.Get(key);

            events.Should().BeEquivalentToMessage(MockBuilder.List(eventExpected));
        }
Exemple #10
0
        public void ContractEstablishTwoEntityValid()
        {
            // arrange
            var key     = Fake.GetKey();
            var carrier = CarrierMock.Get(key);

            MockRepository.Add(carrier);

            var key2 = Fake.GetKey();
            var mga  = MgaMock.Get(key2);

            MockRepository.Add(mga);

            MockRepository.Commit();

            var model = ContractInputModelMock.Get(carrier.Id, mga.Id);

            // act
            Establish(model);

            // assertation
            var contracts        = MockRepository.Query <Contract>().ToList();
            var contractExpected = ContractMock.Get(carrier.Id, mga.Id);

            contracts.Should().BeEquivalentToEntity(new List <Contract>()
            {
                contractExpected
            });
        }