Exemplo n.º 1
0
        public void CreateOrder_Command_ShouldBe_Throw_Exception_When_ProductNotExists()
        {
            _productRepositoryMock.Setup(x => x.FindOneAsync(It.IsAny <Expression <Func <ProductEntity, bool> > >()))
            .ReturnsAsync(default(ProductEntity));

            Assert.ThrowsAsync <ProductNotFoundException>(async() =>
            {
                await _handler.Handle(_createOrderFaker, CancellationToken.None);
            }).Wait();
        }
Exemplo n.º 2
0
    public async Task WhenOrderDoesNotSaveCorrectly_ThenShouldReturnInvalidCommand()
    {
        _repositoryMoq.Setup(x => x.AddAsync(It.IsAny <Order>()))
        .ReturnsAsync((Order)null !);
        var handler = new CreateOrderHandler(_repositoryMoq.Object);

        var result = await handler.Handle(new CreateOrder(_mapper.Map <Order>(Orders.Order1)), default);

        Assert.NotNull(result);
        Assert.Equal(CommandOutcome.InvalidCommand, result.Outcome);
    }
Exemplo n.º 3
0
    public async Task WhenOrderIsCreated_ThenShouldReturnEntity()
    {
        var order = _mapper.Map <Order>(Orders.Order1);

        _repositoryMoq.Setup(x => x.AddAsync(It.IsAny <Order>()))
        .ReturnsAsync(order);
        var handler = new CreateOrderHandler(_repositoryMoq.Object);

        var result = await handler.Handle(new CreateOrder(order), default);

        Assert.NotNull(result);
        Assert.Equal(CommandOutcome.Accepted, result.Outcome);
        Assert.Equal(order.Id, result.Entity !.Id);
    }
        public void CreateOrderHandlerData_ShouldbeTrue_WhenCreated()
        {
            IRepository <Order>          repository = new Mock <IRepository <Order> >().Object;
            ILogger <CreateOrderHandler> logger     = new Mock <ILogger <CreateOrderHandler> >().Object;
            IMediator mediator = new Mock <IMediator>().Object;

            CreateOrderHandler campaignHandler = new CreateOrderHandler(repository, logger, mediator);

            var result = campaignHandler.Handle(new Dtos.Requests.CreateOrderRequest {
                ProductCode = "P1", Price = 10, Quantity = 5
            }, new System.Threading.CancellationToken()).Result;

            Assert.True(result.Data);
        }
Exemplo n.º 5
0
        public async Task Test_Create_Order_OrderIsCorrect_Returns_OrderId()
        {
            var productId    = Guid.NewGuid();
            var defaultOrder = CreateDefaultOrder(productId);
            var orderid      = Guid.NewGuid();

            MockSetUp(orderid, productId);
            var handler = new CreateOrderHandler(Dependencies.Object);
            var result  = await handler.Handle(defaultOrder);

            Assert.True(result.Success);
            Assert.Equal(orderid, result.Value.OrderId);
            VerifyDependencies();
        }
Exemplo n.º 6
0
        public async Task Test_Create_Order_ProductIsInvalid_ReturnsFailure()
        {
            var productId    = Guid.NewGuid();
            var defaultOrder = CreateDefaultOrder(productId);
            var orderid      = Guid.NewGuid();

            MockSetUp(orderid, productId);

            Dependencies
            .Setup(a => a.GetProductByIds(It.IsAny <List <Guid> >()))
            .Returns(Task.FromResult(new List <ProductEntity>().AsEnumerable()));

            var handler = new CreateOrderHandler(Dependencies.Object);
            var result  = await handler.Handle(defaultOrder);

            Assert.False(result.Success);
            Assert.Single(result.Errors);
        }
Exemplo n.º 7
0
 protected override async Task <Result <OrderCreationMessageResponseDto> > CallService(OrderCreationDto objDto)
 {
     return(await _handler.Handle(objDto));
 }