public async void ShouldReturnAsset() { _contentfulClient.Setup(o => o.GetAsset("asset", It.IsAny <QueryBuilder <Asset> >(), It.IsAny <CancellationToken>())) .ReturnsAsync(new Asset()); var assetRepository = new AssetRepository(new ContentfulConfig("", "", ""), _contentfulClientManager.Object, _logger.Object); var asset = await assetRepository.Get("asset"); asset.Should().NotBeNull(); }
public async void ShouldReturnNullIfNoAssetIsFoundAndLogWarning() { _contentfulClient.Setup(o => o.GetAsset("asset-fail", It.IsAny <QueryBuilder <Asset> >(), It.IsAny <CancellationToken>())) .ThrowsAsync(new ContentfulException(500, "There was a problem with getting assetid: asset-fail from contentful")); var assetRepository = new AssetRepository(new ContentfulConfig("", "", ""), _contentfulClientManager.Object, _logger.Object); await assetRepository.Get("asset-fail"); LogTesting.Assert(_logger, LogLevel.Warning, "There was a problem with getting assetId: asset-fail from contentful"); }
public Asset Card([FromBody] int id) { if (id <= 0) { throw new ArgumentOutOfRangeException(nameof(id)); } var model = _repository.Get(id); if (model == null) { throw new InvalidOperationException(); } return(model); }
public async Task <(bool, OrderDTO, string)> CreateOrder(OrderDTO orderDto) { //Necessery info: //Customer, Asset, Dates, Check of Asset before renting; var order = _mapper.Map <Order>(orderDto); //Check asset var asset = await _assetRepo.Get(orderDto.Asset.Id); if (asset == null) { throw new ApiException("Asset not found"); } else { order.Asset = asset; } //Check if returning customer; var customer = await _customerRepo.GetUserByEmail(orderDto?.Customer?.Email); if (customer != null) { order.Customer = customer; } //Check availability: var availability = await CheckAvailability(orderDto); if (!availability) { return(false, orderDto, $"Order refused: Asset already leased for given period"); } //CreateOrder; order.Status = OrderStatus.Active; var savedOrder = await _orderRepo.Add(order); var savedOrderDto = _mapper.Map <OrderDTO>(savedOrder); return(true, savedOrderDto, null); }
public void Get_WhenCalled_ReturnAsset_Test() { var result = _repository.Get(_dbAsset.Id); Assert.That(result, Is.InstanceOf <Asset>()); }