public void WhenInstantiated_ThenShouldBeOfCorrectType()
    {
        var handler = new GetOrderHandler(_repositoryMock.Object);

        Assert.NotNull(handler);
        Assert.IsType <GetOrderHandler>(handler);
    }
        public async void GetOrderHandlerSuccess()
        {
            var             mockOrder       = new MockOrderData();
            var             createOrder     = mockOrder.CreateOrder();
            GetOrderQuery   getOrderQuery   = new GetOrderQuery(createOrder.OrderId);
            GetOrderHandler getOrderHandler = new GetOrderHandler();
            var             actual          = await getOrderHandler.Handle(getOrderQuery, new CancellationToken());

            Assert.Equal(createOrder.OrderId, actual.OrderId);
        }
        public async void GetOrderHandlerFailure()
        {
            var             mockOrder       = new MockOrderData();
            var             createOrderOne  = mockOrder.CreateOrder();
            var             createOrderTwo  = mockOrder.CreateOrder();
            GetOrderQuery   getOrderQuery   = new GetOrderQuery(createOrderOne.OrderId);
            GetOrderHandler getOrderHandler = new GetOrderHandler();
            var             actual          = await getOrderHandler.Handle(getOrderQuery, new CancellationToken());

            Assert.NotEqual(createOrderTwo.OrderId, actual.OrderId);
        }
    public async Task WhenRetrievingEntity_ThenEntityShouldBeReturned()
    {
        var expected = _mapper.Map <Order>(Orders.Order1);

        _repositoryMock.Setup(x => x.GetAsync(It.IsAny <Guid>()))
        .ReturnsAsync(expected);

        var handler = new GetOrderHandler(_repositoryMock.Object);

        var actual = await handler.Handle(new GetOrder(Guid.Empty), default);

        Assert.Equal(expected, actual);
    }
        public void GetOrderHandler_ShouldGetProduct()
        {
            IQueryable <Order> prd = new List <Order>
            {
                new Order {
                    ProductCode = "P1", Price = 10, Quantity = 5
                }
            }.AsQueryable();

            var repoMock = new Mock <IRepository <Order> >();

            repoMock.Setup(x => x.GetWhereAsync(It.IsAny <Expression <Func <Order, bool> > >())).Returns <Expression <Func <Order, bool> > >(predicate => Task.FromResult(prd.Where(predicate).ToList().AsEnumerable()));
            IRepository <Order>       repository = repoMock.Object;
            ILogger <GetOrderHandler> logger     = new Mock <ILogger <GetOrderHandler> >().Object;
            IMediator mediator = new Mock <IMediator>().Object;

            GetOrderHandler productHandler = new GetOrderHandler(repository, logger);

            var result = productHandler.Handle(new Dtos.Requests.GetOrderRequest("P1"), new System.Threading.CancellationToken()).Result;

            Assert.True(result.Data != null);
        }
 public void SetUp()
 {
     _orderRepository = new Mock <IOrderRepository>();
     _getOrderHandler = new GetOrderHandler(_orderRepository.Object);
 }