コード例 #1
0
        public void ComputePriceBasedOnBottle(
            int buyerId,
            int amount,
            decimal expectedPrice
            )
        {
            // arrange
            using var mock = AutoMock.GetStrict(builder =>
                                                builder.RegisterInstance(MapperProvider.GetMapper()));

            mock.Mock <IBottleRepository>()
            .Setup(repo => repo.GetBottleForPriceModel(100))
            .Returns(Task.FromResult(GetBottle()));

            var transaction = new TransactionForAdditionDto
            {
                BuyerId   = buyerId,
                Amount_ml = amount,
                BottleId  = 100
            };

            var operation = mock.Create <GetTransactionPriceOperation>();

            // act
            decimal actualPrice = operation.Run(transaction).Result;

            // assert
            Assert.AreEqual(expectedPrice, actualPrice, $"Computed price is different from expected price (expected: {expectedPrice}, actual: {actualPrice})");
        }
コード例 #2
0
        public async Task AddTransaction(TransactionForAdditionDto transaction)
        {
            var transactionModelForRepo = mapper.Map <TransactionForAdditionForRepo>(transaction);

            transactionModelForRepo.Price = await getTransactionPriceOperation.Run(transaction);

            await repo.AddTransaction(transactionModelForRepo);
        }
コード例 #3
0
        public decimal Run(TransactionForAdditionDto transaction, BottleForPriceModel bottle)
        {
            var usersSpecialPrice =
                bottle.SpecialPrices
                .FirstOrDefault(sp => sp.UserId == transaction.BuyerId);

            if (usersSpecialPrice is not null)
            {
                return(GetPrice(amount: transaction.Amount_ml.Value, shotPrice: usersSpecialPrice.Price));
            }

            var userIsOwner =
                bottle.Owners.Contains(transaction.BuyerId.Value);

            if (userIsOwner)
            {
                return(GetOwnerPrice(amount: transaction.Amount_ml.Value, bottle));
            }

            return(GetPrice(amount: transaction.Amount_ml.Value, bottle.ShotPrice));
        }
コード例 #4
0
        public async Task <IActionResult> AddTransaction(TransactionForAdditionDto transaction)
        {
            await transactionFacade.AddTransaction(transaction);

            return(Ok(StatusCodes.Status201Created));
        }
コード例 #5
0
        public async Task <decimal> Run(TransactionForAdditionDto transaction)
        {
            var bottle = await bottleRepo.GetBottleForPriceModel(transaction.BottleId.Value);

            return(Run(transaction, bottle));
        }