Exemple #1
0
        public void CalculatorService_ComputeTotalTransactionValueByCurrency_Throws_Exception_When_Missing_Rate()
        {
            // Arrange
            IEnumerable <BusinessTransaction> transactions = GetTestData.GetTestTransactions();
            IEnumerable <ConversionRate>      rates        = GetTestData.GetTestRates();
            CalculatorService    calculator = new CalculatorService();
            IEnumerable <Amount> amounts    = transactions.Select(t => new Amount {
                Value = t.Amount, Currency = t.Currency
            });

            // Act
            decimal total = calculator.ComputeTotalTransactionValueByCurrency(amounts, rates, CurrencyCode.TRY);

            // Assert - Expects exception
        }
Exemple #2
0
        public void CalculatorService_ComputeTotalTransactionValueByCurrency_Returns_Correct_Total_With_Existing_Rates()
        {
            // Arrange
            IEnumerable <BusinessTransaction> transactions = GetTestData.GetTestTransactions();
            IEnumerable <ConversionRate>      rates        = GetTestData.GetTestRates();
            CalculatorService    calculator = new CalculatorService();
            IEnumerable <Amount> amounts    = transactions.Select(t => new Amount {
                Value = t.Amount, Currency = t.Currency
            });

            // Act
            decimal total = calculator.ComputeTotalTransactionValueByCurrency(amounts, rates, CurrencyCode.EUR);

            //Assert
            Assert.AreEqual(69.13172M, total);
        }
Exemple #3
0
        public async Task ProductsController_GetTransactionsBySKU_Returns_NotFound_When_SKU_Not_Exists()
        {
            // Arrange
            _mockTransactionsService.Setup(p => p.GetTransactionsBySKU(It.IsAny<string>()))
                                    .Returns(Task.FromResult(GetTestData.GetTestTransactions().Where(t => t.SKU == "00000")));
            _mockRatesService.Setup(p => p.GetConversionRates()).Returns(Task.FromResult(GetTestData.GetTestRates()));

            ProductsController controller = new ProductsController(_mockLogger.Object, _mockTransactionsService.Object, _mockRatesService.Object, _mockCalculatorService.Object, _mockPersistenceService.Object);

            // Act
            IActionResult result = await controller.GetTotalTransactionValueBySKU("00000");
            StatusCodeResult statusCodeResult = result as NotFoundResult;

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(result.GetType(), typeof(NotFoundResult));
            Assert.AreEqual(StatusCodes.Status404NotFound, statusCodeResult.StatusCode);
        }
Exemple #4
0
        public async Task ProductsController_GetTransactionsBySKU_Returns_OKResult_With_Correct_Total_Amount()
        {
            // Arrange
            _mockTransactionsService.Setup(p => p.GetTransactionsBySKU(It.IsAny<string>()))
                                    .Returns(Task.FromResult(GetTestData.GetTestTransactions().Where(t => t.SKU == "T2006")));
            _mockRatesService.Setup(p => p.GetConversionRates()).Returns(Task.FromResult(GetTestData.GetTestRates()));
            _mockCalculatorService.Setup(p => p.ComputeTotalTransactionValueByCurrency(It.IsAny<IEnumerable<Amount>>(), It.IsAny<IEnumerable<ConversionRate>>(), It.IsAny<CurrencyCode>())).Returns(10.16M);

            ProductsController controller = new ProductsController(_mockLogger.Object, _mockTransactionsService.Object, _mockRatesService.Object, _mockCalculatorService.Object, _mockPersistenceService.Object);

            // Act
            IActionResult result = await controller.GetTotalTransactionValueBySKU("T2006");
            ObjectResult objectResult = result as ObjectResult;
            decimal? content = objectResult.Value as decimal?;

            // Assert
            Assert.IsNotNull(objectResult);
            Assert.AreEqual(StatusCodes.Status200OK, objectResult.StatusCode);
            Assert.AreEqual(10.16M, content);
        }
Exemple #5
0
        public async Task ProductsController_GetConversionRates_Returns_OKResult_With_Correct_Rates_ObjectType()
        {
            // Arrange
            _mockRatesService.Setup(p => p.GetConversionRates()).Returns(Task.FromResult(GetTestData.GetTestRates()));

            ProductsController controller = new ProductsController(_mockLogger.Object, _mockTransactionsService.Object, _mockRatesService.Object, _mockCalculatorService.Object, _mockPersistenceService.Object);

            // Act
            IActionResult result = await controller.GetRates();
            ObjectResult objectResult = result as ObjectResult;

            // Assert
            Assert.IsNotNull(objectResult);
            Assert.AreEqual(StatusCodes.Status200OK, objectResult.StatusCode);
            Assert.IsInstanceOfType(objectResult.Value, typeof(IEnumerable<ConversionRate>));
        }
Exemple #6
0
        public async Task ProductsController_GetTransactions_Returns_OKResult_With_Correct_Transactions_Number()
        {
            // Arrange
            _mockTransactionsService.Setup(p => p.GetTransactions()).Returns(Task.FromResult(GetTestData.GetTestTransactions()));

            ProductsController controller = new ProductsController(_mockLogger.Object, _mockTransactionsService.Object, _mockRatesService.Object, _mockCalculatorService.Object, _mockPersistenceService.Object);

            // Act
            IActionResult result =  await controller.GetTransactions();
            ObjectResult objectResult = result as ObjectResult;
            IEnumerable<BusinessTransaction> content = objectResult.Value as IEnumerable<BusinessTransaction>;

            // Assert
            Assert.IsNotNull(objectResult);
            Assert.AreEqual(StatusCodes.Status200OK, objectResult.StatusCode);
            Assert.AreEqual(5, content.Count());
        }