public GetOrdersQueryHandlerTest()
 {
     mapper             = new Mock <IMapper>();
     searchOrderService = new Mock <ISearchOrderService>();
     query        = new GetOrdersQuery(It.IsAny <FilteringData>());
     queryHandler = new GetOrdersQueryHandler(searchOrderService.Object, mapper.Object);
     orders       = new List <Order> {
         new Order(), new Order()
     };
     ordersDto = new List <GetOrdersDto> {
         new GetOrdersDto(), new GetOrdersDto()
     };
 }
Beispiel #2
0
        public void GetOrders_IncorrectClientId_Exception(int _clientId)
        {
            var testSessionToken = SessionRepository.StartNewSession(_clientId);

            var getOrdersQuery = new GetOrdersQuery
            {
                sessionToken = testSessionToken,
            };

            var          handler = new GetOrdersQueryHandler();
            TestDelegate result  = () => handler.Handle(getOrdersQuery);

            SessionRepository.RemoveSession(testSessionToken);

            Assert.Throws <Exception>(result);
        }
Beispiel #3
0
        public async Task GetAllAsync()
        {
            var dataAccess = new OrderDataAccess(this.Context);

            //Act
            var sutCreate    = new CreateOrderCommandHandler(dataAccess);
            var resultCreate = await sutCreate.Handle(new CreateOrderCommand
            {
                Data = OrderTestData.OrderDataDTO
            }, CancellationToken.None);

            //Act
            var sutGetAll    = new GetOrdersQueryHandler(dataAccess);
            var resultGetAll = await sutGetAll.Handle(new GetOrdersQuery(), CancellationToken.None);

            Assert.IsTrue(resultGetAll?.Data.Count == 1);
        }
Beispiel #4
0
        public void GetOrders_ClientDoesntExist_Exception(int _clientId)
        {
            DatabaseQueryProcessor.Erase();
            Shared.FillTheDatabase();

            int clientId         = _clientId;
            var testSessionToken = SessionRepository.StartNewSession(clientId);

            var getOrdersQuery = new GetOrdersQuery
            {
                sessionToken = testSessionToken,
            };

            var          handler = new GetOrdersQueryHandler();
            TestDelegate result  = () => handler.Handle(getOrdersQuery);

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

            Assert.Throws <Exception>(result);
        }
Beispiel #5
0
        public void GetOrders_ClientExists_Success(int _clientId)
        {
            var expectedOrderEntry = new OrderEntryDto
            {
                key      = 2,
                name     = "Vergnano",
                quantity = 1,
                price    = 25
            };
            var expectedOrderEntries = new OrderEntryDto[1];

            expectedOrderEntries[0] = expectedOrderEntry;

            var expectedAddress = new AddressDto
            {
                key             = 2,
                country         = "Poland",
                city            = "Cracow",
                street          = "Krakowska",
                ZIPCode         = 30000,
                buildingNumber  = 1,
                apartmentNumber = ""
            };

            var expectedOrder = new OrderDto
            {
                key          = 2,
                orderEntries = expectedOrderEntries,
                totalPrice   = 25,
                address      = expectedAddress,
                status       = 0,
                openDate     = "2018-06-12",
                closeDate    = ""
            };

            var expectedOrders = new OrderDto[1];

            expectedOrders[0] = expectedOrder;

            var expectedOrderDto = new OrdersDto
            {
                isSuccess = true,
                orders    = expectedOrders
            };

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

            int clientId         = _clientId;
            var testSessionToken = SessionRepository.StartNewSession(clientId);

            var getOrdersQuery = new GetOrdersQuery
            {
                sessionToken = testSessionToken,
            };

            var handler = new GetOrdersQueryHandler();
            var result  = (OrdersDto)handler.Handle(getOrdersQuery);

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

            Assert.IsTrue(result.isSuccess);
            Assert.AreEqual(result.orders.Length, expectedOrderDto.orders.Length);
            Assert.AreEqual(result.orders[0].orderEntries.Length, expectedOrderDto.orders[0].orderEntries.Length);
            Assert.AreEqual(result.orders[0].status, expectedOrderDto.orders[0].status);
            Assert.AreEqual(result.orders[0].address.apartmentNumber, expectedOrderDto.orders[0].address.apartmentNumber);
        }