Ejemplo n.º 1
0
        public void Can_Add_Currency()
        {
            // arrage
            currencyRepository.Setup(x => x.CreateAsync(It.IsAny <Currency>()))
            .Returns(Task.CompletedTask)
            .Verifiable();

            // act
            var taskResult = rateService.AddCurrencyAsync(new Currency {
                Name = "EUR", PurchasePrice = 100, SellingPrice = 200
            });

            // assert
            Assert.IsTrue(taskResult.IsCompleted);
            currencyRepository.Verify();
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Post([FromBody] CurrencyPostModel postModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                var currency = mapper.Map <CurrencyPostModel, Currency>(postModel);

                await rateService.AddCurrencyAsync(currency);

                return(Ok());
            }
            catch (Exception ex)
            {
                return(BadRequest(new ErrorResponse {
                    Message = ex.Message
                }));
            }
        }