예제 #1
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);
        }
        public async Task GetAllCategoryAsync_PagingInfo_ReturnsReturnPagingInfo_ReadCategoryModel(PagingInfo pagingInfo)
        {
            //Arrange
            var listOfEvents      = CategoryDumbData.GetRandomEntities(5);
            var paging            = ReturnPagingInfoDumbData.GetForModel(pagingInfo, listOfEvents);
            var expectedValue     = ReturnPagingInfoDumbData.GetWithModels <ReadCategoryModel, Category>(paging, _mapper);
            var cancellationToken = new CancellationToken();

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

            // Act
            var response = await _categoryService.GetAllCategoryAsync(pagingInfo, cancellationToken);

            // Assert
            _categoryRepository.Verify(x => x.GetAllDataAsync(It.IsAny <PagingInfo>(), cancellationToken), Times.Once);
            response.Should().BeEquivalentTo(expectedValue);
        }