Beispiel #1
0
        public void Difference_ShouldReturnExpectedValue(int oldAmount, int newAmount, int expectedDiff)
        {
            var change = new BatchStockChange
            {
                OldAmount = oldAmount,
                NewAmount = newAmount,
            };

            int actualDiff = change.AmountDifference;



            Assert.Equal(expectedDiff, actualDiff);
        }
Beispiel #2
0
        public async Task <Batch> ExecuteAsync(ModifyBatchStockRequest RequestModel)
        {
            Validate(RequestModel);

            var batch = await unitOfWork.Batches.GetAsync(RequestModel.BatchId);

            if (batch == null)
            {
                throw new KeyNotFoundException($"Batch with id {RequestModel.BatchId} not found");
            }

            var StockChange = new BatchStockChange(batch.RemainingUnits, RequestModel.NewUnitAmount, RequestModel.ReasonForChange);

            batch.RemainingUnits = StockChange.NewAmount;
            batch.History.Add(StockChange);

            await unitOfWork.CompleteAsync();

            return(batch);
        }