public void When_AccountBalanceUpdated_ReturnUpdateAccount()
        {
            Mock <IDataContext> mockDataContext = new Mock <IDataContext>();

            mockDataContext.Setup(d => d.ProcessRead(It.IsAny <string>()))
            .Returns(Task.FromResult(GetData()));

            VirtualBank virtualBank          = null;
            bool        isProcessWriteCalled = false;

            mockDataContext.Setup(d => d.ProcessWrite(It.IsAny <string>(), It.IsAny <string>()))
            .Callback(() => { isProcessWriteCalled = true;
                              virtualBank.Customers[0].Accounts[0].AvailableBalance = 50; });


            Mock <IConfigurationRoot> mockConfiguration = new Mock <IConfigurationRoot>();

            mockConfiguration.SetupGet(x => x[It.IsAny <string>()]).Returns("Account.json");

            ICustomerAccountRepository customerAccountRepository = new CustomerAccountRepository(mockConfiguration.Object, mockDataContext.Object);
            var contentTask = customerAccountRepository.Load();

            virtualBank = contentTask.Result;
            Assert.IsNotNull(virtualBank);

            customerAccountRepository.UpdateAccountBalance(virtualBank);

            Assert.AreEqual(isProcessWriteCalled, true);
            Assert.AreEqual(virtualBank.Customers[0].Accounts[0].AvailableBalance, 50);
            mockDataContext.Verify(d => d.ProcessWrite(It.IsAny <string>(), It.IsAny <string>()));
        }
        public bool UpdateAccountBalance(VirtualBank vb)
        {
            string content = JsonConvert.SerializeObject(vb, new JsonSerializerSettings()
            {
                TypeNameHandling = TypeNameHandling.Auto
            });

            _dataContext.ProcessWrite(content, _fileName);
            return(true);
        }
        public async Task <VirtualBank> Load()
        {
            var content = await _dataContext.ProcessRead(_fileName);

            VirtualBank virtualBank = JsonConvert.DeserializeObject <VirtualBank>(content, new JsonSerializerSettings()
            {
                TypeNameHandling = TypeNameHandling.Auto
            });

            return(virtualBank);
        }
Esempio n. 4
0
        public void When_Initialise_ReturnsValidVirtualBankInstance()
        {
            CardService cardService = new CardService(_mockCustomerAccountRepository.Object);
            VirtualBank virtualBank = null;

            _mockCustomerAccountRepository.Setup(d => d.Load())
            .Returns(() =>
            {
                var result  = GetRepositoryData();
                virtualBank = result.Result;
                return(result);
            });

            cardService.Initialize();

            _mockCustomerAccountRepository.Verify(repo => repo.Load());
            Assert.IsNotNull(virtualBank);
        }
Esempio n. 5
0
 public void Initialize()
 {
     _virtualBank = _customerAccountRepository.Load().Result;
 }