Exemplo n.º 1
0
        public void AddOrderCommandHandler_success()
        {
            _orderRepositoryMock.Setup(orderRepo => orderRepo.AddNew(It.IsAny <Order>()))
            .Returns(FakeOrder());

            _orderRepositoryMock.Setup(orderRepo => orderRepo.UnitOfWork.SaveChangesAsync(default(CancellationToken)))
            .Returns(Task.FromResult(1));

            //Act
            var handler  = new AddOrderCommandHandler(_orderRepositoryMock.Object);
            var cltToken = new CancellationToken();

            Exception ex = null;

            try
            {
                var result = handler.Handle(FakeCommand(), cltToken);
            }
            catch (Exception e)
            {
                ex = e;
            }

            Assert.Null(ex);
        }
        public void AddOrder_ReturnOrderVm_Successfully()
        {
            OrderServiceMock.Setup(order => order.CreateOrder(It.IsAny <CreateOrder>())).Returns(GetGuid());
            var command = new AddOrderCommandHandler(OrderServiceMock.Object);

            var response = command.Handle(new AddOrderCommand(Guid.NewGuid(), GetProductOrders()), default);
            var result   = response.Result.Data;

            Assert.IsNotNull(result);
            Assert.IsInstanceOf <OrderVm>(result);
        }
        public void AddOrder_ReturnOrderVm_Fail()
        {
            OrderServiceMock.Setup(order => order.CreateOrder(It.IsAny <CreateOrder>())).Returns(GetEmptyGuid());

            var command  = new AddOrderCommandHandler(OrderServiceMock.Object);
            var response = command.Handle(new AddOrderCommand(Guid.NewGuid(), GetProductOrders()), default);
            var result   = response.Result;

            Assert.IsFalse(result.Success);
            Assert.IsInstanceOf <Response <OrderVm> >(result);
            Assert.AreEqual(StatusCodes.Status500InternalServerError, result.StatusCode);
        }
Exemplo n.º 4
0
        public void AddOrder_AddressDoesntExist_Exception(int _clientId)
        {
            var testSessionToken = SessionRepository.StartNewSession(_clientId);

            DatabaseQueryProcessor.Erase();
            Shared.FillTheDatabase();

            var testOrderEntry = new OrderEntryDto
            {
                key      = 0,
                name     = "Lavazza",
                quantity = 1,
                price    = 15
            };
            var testOrderEntries = new OrderEntryDto[1];

            testOrderEntries[0] = testOrderEntry;

            var testAddress = new AddressDto
            {
                key             = 0,
                country         = "Poland",
                city            = "Gdansk",
                street          = "Rzemieslnicza",
                ZIPCode         = 30445,
                buildingNumber  = 12,
                apartmentNumber = "1a"
            };

            var addOrderCommand = new AddOrderCommand
            {
                sessionToken = testSessionToken,
                orderEntries = testOrderEntries,
                totalPrice   = "15.00",
                address      = testAddress
            };

            var          handler = new AddOrderCommandHandler();
            TestDelegate result  = () => handler.Handle(addOrderCommand);

            DatabaseQueryProcessor.Erase();

            SessionRepository.RemoveSession(testSessionToken);

            Assert.Throws <Exception>(result);
        }
        public async void Adds_New_Order_Successfully()
        {
            //Arrange
            var contact = Context.Contacts.First();
            var user    = Context.Users.First();

            UserAccessor.Setup(x => x.GetLoggedUser()).ReturnsAsync(user);
            OperationsRepository.Setup(x => x.Add(It.IsAny <Operation>(), user)).ReturnsAsync(true).Verifiable();
            Mediator.Setup(x => x.Send(It.IsAny <AddOrderCommand>(), new CancellationToken()))
            .ReturnsAsync(Unit.Value);

            //Act
            var addOrderCommand = new AddOrderCommand(contact, true, "test", 10, 100, "");
            var handler         = new AddOrderCommandHandler(Context, UserAccessor.Object, OperationsRepository.Object);
            var result          = await handler.Handle(addOrderCommand, new CancellationToken());

            //Assert
            result.Should()
            .BeOfType <Unit>()
            .Equals(Unit.Value);

            DbContextFactory.Destroy(Context);
        }
        public void Handle(Command command)
        {
            switch (command)
            {
            case AddCustomerCommand ac:
                addCustomerCommandHandler.Handle(ac);
                break;

            case AddOrderCommand ao:
                addOrderCommandHandler.Handle(ao);
                break;

            case AddProductCommand ap:
                addProductCommandHandler.Handle(ap);
                break;

            case AddProductToOrder apo:
                addProductToOrderCommandHandler.Handle(apo);
                break;

            default:
                throw new Exception($"Unknown command {command.GetType().Name}");
            }
        }
Exemplo n.º 7
0
        public void AddOrder_CorrectAttributes_Success(int _clientId)
        {
            int    _key             = 0;
            string _country         = "Poland";
            string _city            = "Gdynia";
            string _street          = "Rzemieslnicza";
            int    _ZIPCode         = 30445;
            int    _buildingNumber  = 12;
            string _apartmentNumber = "1a";

            var testSessionToken = SessionRepository.StartNewSession(_clientId);

            DatabaseQueryProcessor.Erase();
            Shared.FillTheDatabase();

            var testOrderEntry = new OrderEntryDto
            {
                key      = 0,
                name     = "Lavazza",
                quantity = 1,
                price    = 15
            };
            var testOrderEntries = new OrderEntryDto[1];

            testOrderEntries[0] = testOrderEntry;

            var testAddress = new AddressDto
            {
                key             = _key,
                country         = _country,
                city            = _city,
                street          = _street,
                ZIPCode         = _ZIPCode,
                buildingNumber  = _buildingNumber,
                apartmentNumber = _apartmentNumber
            };


            var addOrderCommand = new AddOrderCommand
            {
                sessionToken = testSessionToken,
                orderEntries = testOrderEntries,
                totalPrice   = "15.00",
                address      = testAddress
            };

            var addressId = DatabaseQueryProcessor.GetAddress(_clientId,
                                                              _country,
                                                              _city,
                                                              _street,
                                                              _ZIPCode,
                                                              _buildingNumber,
                                                              _apartmentNumber);

            var handler = new AddOrderCommandHandler();
            var result  = (SuccessInfoDto)handler.Handle(addOrderCommand);

            var expectedOrder = DatabaseQueryProcessor.GetTheMostRecentOrder(_clientId);

            SessionRepository.RemoveSession(testSessionToken);
            DatabaseQueryProcessor.Erase();


            Assert.IsTrue(result.isSuccess);
        }