public async Task DeclineOrderRequestAsync_ValidGuid(Guid id)
        {
            //Arrange
            var user         = UserDumbData.GetRandomEntity();
            var order        = OrderDumbData.GetRandomEntity();
            var requestOrder = RequestOrderDumbData.GetEntity(user.Id, order.Id);

            id = requestOrder.Id;
            var cancellationToken = new CancellationToken();

            _requestOrderRepository.Setup(x => x.GetByIdAsync(It.IsAny <Guid>(), cancellationToken)).Returns(Task.FromResult(requestOrder));
            _userRepository.Setup(x => x.GetByIdAsync(It.IsAny <Guid>(), cancellationToken)).Returns(Task.FromResult(user));
            _orderRepository.Setup(x => x.GetByIdAsync(It.IsAny <Guid>(), cancellationToken)).Returns(Task.FromResult(order));
            _userRepository.Setup(x => x.Update(It.IsAny <User>()));
            _requestOrderRepository.Setup(x => x.Update(It.IsAny <RequestOrder>()));
            _unitOfWork.Setup(x => x.SaveChangesAsync(cancellationToken)).Returns(Task.CompletedTask);

            // Act
            await _requestOrderService.DeclineOrderRequestAsync(id, cancellationToken);

            // Assert
            _requestOrderRepository.Verify(x => x.GetByIdAsync(It.IsAny <Guid>(), cancellationToken), Times.Once);
            _userRepository.Verify(x => x.GetByIdAsync(It.IsAny <Guid>(), cancellationToken), Times.Once);
            _orderRepository.Verify(x => x.GetByIdAsync(It.IsAny <Guid>(), cancellationToken), Times.Once);
            _userRepository.Verify(x => x.Update(It.IsAny <User>()), Times.Once);
            _requestOrderRepository.Verify(x => x.Update(It.IsAny <RequestOrder>()), Times.Once);
            _unitOfWork.Verify(x => x.SaveChangesAsync(cancellationToken), Times.Once);
        }
Exemplo n.º 2
0
        public async Task UpdateOrderAsync_UpdateOrderModel_ReturnsReadOrderModel(UpdateOrderModel model)
        {
            //Arrange
            var order          = OrderDumbData.GetEntity(model);
            var categoriesList = CategoryDumbData.GetRandomEntities(2);

            model.CategoryIds = categoriesList.Select(x => x.Id).ToList();
            var expectedValue = _mapper.Map <ReadOrderModel>(order);

            expectedValue.Categories = _mapper.Map <List <ReadCategoryModel> >(categoriesList);
            var cancellationToken = new CancellationToken();

            _orderRepository.Setup(x => x.GetByIdAsync(It.IsAny <Guid>(), cancellationToken)).Returns(Task.FromResult(order));
            _fileService.Setup(x => x.AddOrUpdateFileByIdAsync(It.IsAny <IFormFile>(), It.IsAny <Guid?>(), cancellationToken)).Returns(Task.FromResult((Guid?)expectedValue.IconId));
            _categoryRepository.Setup(x => x.GetByIdAsync(It.IsAny <Guid>(), cancellationToken)).Returns((Guid x) => Task.FromResult(categoriesList.FirstOrDefault(y => y.Id == x)));
            _orderRepository.Setup(x => x.Update(It.IsAny <Order>()));
            _unitOfWork.Setup(x => x.SaveChangesAsync(cancellationToken)).Returns(Task.CompletedTask);

            // Act
            var response = await _orderService.UpdateOrderAsync(model, order.Id, cancellationToken);

            // Assert
            _categoryRepository.Verify(x => x.GetByIdAsync(It.IsAny <Guid>(), cancellationToken), Times.Exactly(2));
            _fileService.Verify(x => x.AddOrUpdateFileByIdAsync(It.IsAny <IFormFile>(), It.IsAny <Guid?>(), cancellationToken), Times.Once);
            _orderRepository.Verify(x => x.GetByIdAsync(It.IsAny <Guid>(), cancellationToken), Times.Once);
            _orderRepository.Verify(x => x.Update(It.IsAny <Order>()), Times.Once);
            _unitOfWork.Verify(x => x.SaveChangesAsync(cancellationToken), Times.Once);
            response.Should().BeEquivalentTo(expectedValue);
        }
Exemplo n.º 3
0
        public async Task GetOrderByIdAsync_ValidOrderId(Guid orderId)
        {
            //Arrange
            var order             = OrderDumbData.GetRandomEntity();
            var cancellationToken = new CancellationToken();

            _orderRepository.Setup(x => x.GetByIdAsync(It.IsAny <Guid>(), cancellationToken)).ReturnsAsync(order);

            // Act
            await _orderService.GetOrderByIdAsync(orderId, cancellationToken);

            // Assert
            _orderRepository.Verify(x => x.GetByIdAsync(It.IsAny <Guid>(), cancellationToken), Times.Once);
        }
Exemplo n.º 4
0
        public async Task GetAllOrderAsync_ValidOrderId(PagingInfo pagingInfo)
        {
            //Arrange
            var orders            = OrderDumbData.GetRandomEntities(5);
            var cancellationToken = new CancellationToken();

            var expectedOrders = ReturnPagingInfoDumbData.GetForModel(pagingInfo, orders);
            var expectedValue  = ReturnPagingInfoDumbData.GetWithModels <ReadOrderModel, Order>(expectedOrders, _mapper);

            _orderRepository.Setup(x => x.GetAllDataAsync(It.IsAny <PagingInfo>(), cancellationToken)).Returns(Task.FromResult(expectedOrders));

            // Act
            var response = await _orderService.GetAllOrderAsync(pagingInfo, cancellationToken);

            // Assert
            _orderRepository.Verify(x => x.GetAllDataAsync(It.IsAny <PagingInfo>(), cancellationToken), Times.Once);
        }
        public async Task AddAsync_CreateRequestOrderModel_ReturnsOkResponse(CreateRequestOrderModel model, Guid userId)
        {
            //Arrange
            var user = UserDumbData.GetRandomEntity();

            userId = user.Id;
            var order = OrderDumbData.GetRandomEntity();

            model.OrderId = order.Id;
            var enoughXP          = user.XP < order.Price;
            var cancellationToken = new CancellationToken();

            ICollection <string> emailCollection = new List <string> {
                RandomHelper.GetRandomString(),
                                 RandomHelper.GetRandomString(),
            };

            _userRepository.Setup(x => x.GetByIdAsync(It.IsAny <Guid>(), cancellationToken)).Returns(Task.FromResult(user));
            _orderRepository.Setup(x => x.GetByIdAsync(It.IsAny <Guid>(), cancellationToken)).Returns(Task.FromResult(order));
            _userRepository.Setup(x => x.GetAdminsEmailsAsync(cancellationToken)).Returns(Task.FromResult(emailCollection));
            _unitOfWork.Setup(x => x.SaveChangesAsync(cancellationToken)).Returns(Task.CompletedTask);
            _emailService.Setup(x => x.SendEmailsAsync(It.IsAny <string>(), It.IsAny <string>(), cancellationToken, It.IsAny <string[]>())).Returns(Task.CompletedTask);
            string key             = "RequestOrderPage";
            var    localizedString = new LocalizedString(key, key);

            _stringLocalizer.Setup(_ => _[key]).Returns(localizedString);

            // Act
            var response = await _requestOrderService.AddAsync(model, userId, cancellationToken);

            // Assert
            _userRepository.Verify(x => x.GetByIdAsync(It.IsAny <Guid>(), cancellationToken), Times.Once);
            _orderRepository.Verify(x => x.GetByIdAsync(It.IsAny <Guid>(), cancellationToken), Times.Once);
            if (enoughXP)
            {
                response.Should().BeOfType <NotAllowedResponse>();
            }
            else
            {
                _userRepository.Verify(x => x.GetAdminsEmailsAsync(cancellationToken), Times.Once);
                _stringLocalizer.Verify(_ => _[key], Times.Once);
                _unitOfWork.Verify(x => x.SaveChangesAsync(cancellationToken), Times.Once);
                _emailService.Verify(x => x.SendEmailsAsync(It.IsAny <string>(), It.IsAny <string>(), cancellationToken, It.IsAny <string[]>()), Times.Once);
                response.Should().BeOfType <OkResponse>();
            }
        }
Exemplo n.º 6
0
        public async Task DeleteOrderAsync_ValidOrderId(Guid orderId)
        {
            //Arrange
            var order             = OrderDumbData.GetRandomEntity();
            var cancellationToken = new CancellationToken();

            _orderRepository.Setup(x => x.GetByIdAsync(It.IsAny <Guid>(), cancellationToken)).ReturnsAsync(order);
            _orderRepository.Setup(x => x.Delete(It.IsAny <Order>()));
            _unitOfWork.Setup(x => x.SaveChangesAsync(cancellationToken)).Returns(Task.CompletedTask);

            // Act
            await _orderService.DeleteOrderAsync(orderId, cancellationToken);

            // Assert
            _orderRepository.Verify(x => x.GetByIdAsync(It.IsAny <Guid>(), cancellationToken), Times.Once);
            _orderRepository.Verify(x => x.Delete(It.IsAny <Order>()), Times.Once);
            _unitOfWork.Verify(x => x.SaveChangesAsync(cancellationToken), Times.Once);
        }
        public async Task GetAllAsync_ValidOrderId()
        {
            //Arrange
            var users             = UserDumbData.GetRandomEntities(5);
            var orders            = OrderDumbData.GetRandomEntities(users.Count);
            var requestOrders     = RequestOrderDumbData.GetEntities(users, orders);
            var cancellationToken = new CancellationToken();

            var expectedRequestOrders = ReturnPagingInfoDumbData.GetForModel(new PagingInfo(), requestOrders);
            var expectedValue         = ReturnPagingInfoDumbData.GetWithModels <ReadRequestOrderModel, RequestOrder>(expectedRequestOrders, _mapper);

            _requestOrderRepository.Setup(x => x.GetAllDataAsync(It.IsAny <PagingInfo>(), cancellationToken)).Returns(Task.FromResult(expectedRequestOrders));
            _userRepository.Setup(x => x.GetByIdAsync(It.IsAny <Guid>(), cancellationToken)).Returns((Guid x) => Task.FromResult(users.FirstOrDefault(y => y.Id == x)));
            _orderRepository.Setup(x => x.GetByIdAsync(It.IsAny <Guid>(), cancellationToken)).Returns((Guid x) => Task.FromResult(orders.FirstOrDefault(y => y.Id == x)));


            // Act
            var response = await _requestOrderService.GetAllAsync(cancellationToken);

            // Assert
            _requestOrderRepository.Verify(x => x.GetAllDataAsync(It.IsAny <PagingInfo>(), cancellationToken), Times.Once);
            _userRepository.Verify(x => x.GetByIdAsync(It.IsAny <Guid>(), cancellationToken), Times.Exactly(users.Count));
            _orderRepository.Verify(x => x.GetByIdAsync(It.IsAny <Guid>(), cancellationToken), Times.Exactly(orders.Count));
        }