예제 #1
0
        public void FullSequenceTest()
        {
            var customerController = new CustomerController(_customerService, _accountService);

            // Creating the customer
            var result = customerController.CreateCustomer("FirstNameForFullSequence", "lastName");

            Assert.True(result is OkObjectResult);
            var okResult = result as OkObjectResult;

            Assert.True(okResult.Value is CustomerIdDto);

            // Get the customer from name
            result = customerController.GetCustomerId("FirstNameForFullSequence", "lastName");

            Assert.True(result is OkObjectResult);
            okResult = result as OkObjectResult;
            Assert.True(okResult.Value is CustomerIdDto);
            var customerId = okResult.Value as CustomerIdDto;

            // Apply Cash Deposit on Customer's account
            result = customerController.ApplyCashDeposit(customerId, 1000);

            Assert.True(result is OkObjectResult);
            okResult = result as OkObjectResult;
            Assert.True(okResult.Value is OperationDto);
            var operation = okResult.Value as OperationDto;

            Assert.AreEqual(1000, operation.Amount);
            Assert.AreEqual(1000, operation.BalanceAfterApply);
            Assert.AreEqual("Done", operation.Status);
            Assert.True(operation.Description.Contains("CashDeposit"));

            // Apply Cash Withdrawal on Customer's account
            result = customerController.ApplyCashWithdrawal(customerId, 200);

            Assert.True(result is OkObjectResult);
            okResult = result as OkObjectResult;
            Assert.True(okResult.Value is OperationDto);
            operation = okResult.Value as OperationDto;
            Assert.AreEqual(200, operation.Amount);
            Assert.AreEqual(800, operation.BalanceAfterApply);
            Assert.AreEqual("Done", operation.Status);
            Assert.True(operation.Description.Contains("CashWithdrawal"));

            // Get operation History
            result = customerController.OperationHistory(customerId);

            Assert.True(result is OkObjectResult);
            okResult = result as OkObjectResult;
            Assert.True(okResult.Value is List <string>);
            var histo = okResult.Value as List <string>;

            Assert.AreEqual(2, histo.Count);
            Assert.True(histo[0].Contains("CashDeposit"));
            Assert.True(histo[1].Contains("CashWithdrawal"));
        }