public async void GetCouriers_Empty()
        {
            _mockedCourierService.Setup(x => x.ListAsync()).ReturnsAsync(new List <Courier>());

            var controllerResponse = await _couriersController.GetAllAsync();

            Expect.Empty(controllerResponse);
            Expect.DeepEqual("[]", controllerResponse);
        }
        public async void GetOrders_Empty()
        {
            _mockedOrderService.Setup(x => x.ListAsync()).ReturnsAsync(new List <Order>());

            var controllerResponse = await _ordersController.ListAsync();

            var okResult       = Expect.IsType <OkObjectResult>(controllerResponse);
            var ordersReturned = Expect.IsType <List <OrderResource> >(okResult.Value);

            Expect.Empty(ordersReturned);
            Expect.DeepEqual("[]", ordersReturned);
        }
        public async void PostCourier_InvalidModelState()
        {
            _couriersController.ModelState.AddModelError("Name", "Name is required");
            var controllerResponse = await _couriersController.PostAsync(new SaveCourierResource { Name = "" });

            var badRequestResult = Expect.IsType <BadRequestObjectResult>(controllerResponse);
            var errorReturned    = Expect.IsType <List <string> >(badRequestResult.Value);

            Expect.DeepEqual(new List <string> {
                "Name is required"
            }, errorReturned);
        }
        public async void GetCouriers()
        {
            var fakeCouriers = GetFakeCouriers();

            _mockedCourierService.Setup(x => x.ListAsync()).ReturnsAsync(fakeCouriers);

            var controllerResponse = await _couriersController.GetAllAsync();

            var expectedResult = _mapper.Map <IEnumerable <Courier>, IEnumerable <CourierResource> >(fakeCouriers);

            Expect.IsType <List <CourierResource> >(controllerResponse);
            Expect.DeepEqual(expectedResult, controllerResponse);
        }
        public async void GetOrders()
        {
            var fakeOrders = GetFakeOrders();

            _mockedOrderService.Setup(x => x.ListAsync()).ReturnsAsync(fakeOrders);

            var controllerResponse = await _ordersController.ListAsync();

            var okResult       = Expect.IsType <OkObjectResult>(controllerResponse);
            var ordersReturned = Expect.IsType <List <OrderResource> >(okResult.Value);
            var expectedResult = _mapper.Map <IEnumerable <Order>, IEnumerable <OrderResource> >(fakeOrders);

            Expect.DeepEqual(expectedResult, ordersReturned);
        }
        public async void DeleteCourier()
        {
            var deletedCourier      = GetFakeCouriers().First();
            var deleteAsyncResponse = new CourierResponse(deletedCourier);

            _mockedCourierService.Setup(x => x.DeleteAsync(1)).ReturnsAsync(deleteAsyncResponse);

            var controllerResponse = await _couriersController.DeleteAsync(1);

            var okResult            = Expect.IsType <OkObjectResult>(controllerResponse);
            var courierReturned     = Expect.IsType <CourierResource>(okResult.Value);
            var expectedReturnValue = _mapper.Map <Courier, CourierResource>(deletedCourier);

            Expect.DeepEqual(expectedReturnValue, courierReturned);
        }
        public async void PutCourier()
        {
            var updatedCourier = GetFakeCouriers().First();

            updatedCourier.Name = "Updated name";
            var updateAsyncResponse = new CourierResponse(updatedCourier);

            _mockedCourierService.Setup(x => x.UpdateAsync(1, It.IsAny <Courier>())).ReturnsAsync(updateAsyncResponse);

            var controllerResponse = await _couriersController.PutAsync(1, new SaveCourierResource { Name = "Updated name" });

            var okResult            = Expect.IsType <OkObjectResult>(controllerResponse);
            var courierReturned     = Expect.IsType <CourierResource>(okResult.Value);
            var expectedReturnValue = _mapper.Map <Courier, CourierResource>(updatedCourier);

            Expect.DeepEqual(expectedReturnValue, courierReturned);
        }
        public async void PostCourier()
        {
            var saveAsyncResponse = new CourierResponse(
                new Courier {
                Id = 3, Name = "FedEx", BussinessId = "3456-78", APIKey = "fedex-api-key"
            }
                );

            _mockedCourierService.Setup(x => x.SaveAsync(It.IsAny <Courier>())).ReturnsAsync(saveAsyncResponse);

            var controllerResponse = await _couriersController.PostAsync(new SaveCourierResource { Name = "FedEx" });

            var okResult            = Expect.IsType <OkObjectResult>(controllerResponse);
            var courierReturned     = Expect.IsType <CourierResource>(okResult.Value);
            var expectedReturnValue = _mapper.Map <Courier, CourierResource>(saveAsyncResponse.Courier);

            Expect.DeepEqual(expectedReturnValue, courierReturned);
        }