public async Task Given_ExistingLastPeriod_When_EndDateUpdatedWithDateBeforeStart_Then_ResultIsFailure()
        {
            // Arrange.
            var lastPeriod = new Period(
                new DateTime(2020, 2, 1),
                new DateTime(2020, 2, 29));

            AccountingManager testObject = AccountingManagerFactory.Create(out IAccountingDataAccess accountingDataAccess);

            accountingDataAccess
            .GetLastPeriod()
            .Returns(GetResult <Period> .CreateSuccess(lastPeriod));

            var updateEndDate = new UpdateLastPeriodEndDateDto(lastPeriod.Start.AddDays(-1));

            accountingDataAccess
            .UpdateLastPeriodEndDate(updateEndDate.NewEnd)
            .Returns(ActionResult.CreateSuccess());

            // Act.
            ActionResult result = await testObject.UpdateLastPeriodEndDate(updateEndDate);

            // Assert.
            Assert.IsFalse(result.IsSuccess);
        }
Exemple #2
0
        public async Task Given_NewAccount_When_NameContainsLeadingOrTrailingWhitespace_Then_WhitespaceIsRemoved(string accountName)
        {
            // Arrange.
            AccountingManager testObject = AccountingManagerFactory.Create(out IAccountingDataAccess accountingDataAccess);

            //AccountingManagerFactory.ConfigureDataAccessWithBaseAccounts(accountingDataAccess);

            var newAccount = new NewAccountDto
            {
                Name = accountName,
                ParentAccountQualifiedName = FundsAccountName
            };

            // Act.
            await testObject.AddAccount(newAccount);

            // Assert.
            string expectedQualifiedName = $"{newAccount.ParentAccountQualifiedName}{AccountQualifiedNameSeparator}{accountName.Trim()}";
            string expectedName          = accountName.Trim();

            await accountingDataAccess
            .Received(1)
            .AddAccount(Arg.Is <Account>(a =>
                                         a.QualifiedName.Equals(expectedQualifiedName) &&
                                         a.Name.Equals(expectedName)));
        }
Exemple #3
0
        public async Task Given_NewAccount_When_Added_Then_CreditWhitelistAccountTypesAreSameAsParents()
        {
            // Arrange.
            AccountingManager testObject = AccountingManagerFactory.Create(out IAccountingDataAccess accountingDataAccess);

            var newAccount = new NewAccountDto
            {
                Name = "SomeAccount",
                ParentAccountQualifiedName = FundsAccountName
            };

            // Act.
            await testObject.AddAccount(newAccount);

            // Assert.
            await accountingDataAccess
            .Received(1)
            .AddAccount(Arg.Is <Account>(a =>
                                         a.Name.Equals(newAccount.Name) &&
                                         a.AccountTypesWithCreditPermission.Contains(AccountType.CreateFunds()) &&
                                         a.AccountTypesWithCreditPermission.Contains(AccountType.CreateIncome()) &&
                                         a.AccountTypesWithCreditPermission.Contains(AccountType.CreateDebtor()) &&
                                         a.AccountTypesWithCreditPermission.Contains(AccountType.CreateCreditor())));

            await accountingDataAccess
            .Received(0)
            .AddAccount(Arg.Is <Account>(a =>
                                         a.Name.Equals(newAccount.Name) &&
                                         a.AccountTypesWithCreditPermission.Contains(AccountType.CreateExpense())));
        }
Exemple #4
0
        public async Task Given_NewAccount_When_Added_Then_BalanceIsZero()
        {
            // Arrange.
            AccountingManager testObject = AccountingManagerFactory.Create(out IAccountingDataAccess accountingDataAccess);

            accountingDataAccess
            .GetAccounts(Arg.Any <string[]>())
            .Returns(GetResult <IReadOnlyDictionary <string, Account> > .CreateSuccess(
                         new Dictionary <string, Account>
            {
                { BaseAccountNames[0], new Account() }
            }));

            var newAccount = new NewAccountDto
            {
                Name = "SomeAccount",
                ParentAccountQualifiedName = BaseAccountNames[0]
            };

            // Act.
            await testObject.AddAccount(newAccount);

            // Assert.
            await accountingDataAccess
            .Received()
            .AddAccount(Arg.Is <Account>(a => a.Balance == 0m));
        }
            public void ShouldNotBeEmpty()
            {
                var username = "******";
                var password = "";

                ILoginService            loginService            = new LoginService(new ContpaqLegacySessionProvider());
                ICompanyService          companyService          = new CompanyService(new ContpaqLegacyCompanyProvider());
                IJournalEntryTypeService journalEntryTypeService = new JournalEntryTypeService(new ContpaqLegacyJournalEntryTypeProvider());
                IJournalEntryService     journalEntryService     = new JournalEntryService(new ContpaqLegacyJournalEntryProvider());
                AccountingManager        accountingManager       = new AccountingManager(loginService, companyService,
                                                                                         journalEntryTypeService, journalEntryService);

                var session = accountingManager.DoLogin(username, password);

                Assert.True(session.IsValid);

                var companies = accountingManager.GetCompanies();

                Assert.NotEmpty(companies);

                accountingManager.OpenCompany(session, companies.FirstOrDefault().DBName);

                var journalEntryTypes = accountingManager.GetJournalEntryTypes(session);

                Assert.NotEmpty(journalEntryTypes);
            }
        public void SaveTransactionwithNaN()
        {
            AccountingManager target     = new AccountingManager();
            string            costCenter = "DEP100";
            string            bucket     = "TRAINING";
            float             expected   = 5000f;
            float             actual;

            actual = target.GetBudget(costCenter, bucket);
            Assert.AreEqual(expected, actual);

            //do some trans here
            Transaction transaction = new Transaction();

            transaction.CostCenter  = costCenter;
            transaction.Bucket      = bucket;
            transaction.Amount      = float.NaN;
            transaction.Description = "Testing..";

            try
            {
                target.SaveTransaction(transaction);
                Assert.Fail();
            }
            catch (ArgumentException ex)
            {
                Assert.AreEqual("Unable to save transaction due to invalid transaction amount.", ex.Message);
            }
        }
        public void AccountingManagerGetBudgetNegativeTest()
        {
            AccountingManager accountingManager = new AccountingManager();
            float             budget            = accountingManager.GetBudget("DUMMY", "TRAINING");

            Assert.AreEqual(float.NaN, budget);
        }
        public async Task Given_Transaction_When_ProcessedSuccessfully_Then_ResultIsSuccess()
        {
            // Arrange.
            const string  debitAccountName  = "Funds";
            const string  creditAccountName = "Expense";
            const decimal amount            = 123.45m;

            AccountingManager testObject = AccountingManagerFactory.Create(out IAccountingDataAccess accountingDataAccess);

            AccountingManagerFactory.ConfigureDataAccessWithBaseAccounts(accountingDataAccess);

            Account debitAccount  = accountingDataAccess.GetAccount(debitAccountName).Result.Result;
            Account creditAccount = accountingDataAccess.GetAccount(creditAccountName).Result.Result;

            accountingDataAccess
            .GetAccounts(Arg.Any <IEnumerable <string> >())
            .Returns(GetResult <IReadOnlyDictionary <string, Account> > .CreateSuccess(
                         new Dictionary <string, Account>
            {
                { debitAccountName, debitAccount },
                { creditAccountName, creditAccount }
            }));

            accountingDataAccess
            .GetParentAccountsOrdered(debitAccountName)
            .Returns(GetResult <IEnumerable <Account> > .CreateSuccess(new Account[0]));

            accountingDataAccess
            .GetParentAccountsOrdered(creditAccountName)
            .Returns(GetResult <IEnumerable <Account> > .CreateSuccess(new Account[0]));

            accountingDataAccess
            .UpdateAccountBalances(default)
        public async Task Given_ExistingPeriodWhichIsLastPeriod_When_EndDateUpdated_Then_ResultIsSuccess()
        {
            // Arrange.
            var period = new Period(
                new DateTime(2020, 1, 1),
                new DateTime(2020, 1, 31));

            AccountingManager testObject = AccountingManagerFactory.Create(out IAccountingDataAccess accountingDataAccess);

            accountingDataAccess
            .GetLastPeriod()
            .Returns(GetResult <Period> .CreateSuccess(period));

            var updateEndDate = new UpdateLastPeriodEndDateDto(period.End.AddDays(1));

            accountingDataAccess
            .UpdateLastPeriodEndDate(updateEndDate.NewEnd)
            .Returns(ActionResult.CreateSuccess());

            // Act.
            ActionResult result = await testObject.UpdateLastPeriodEndDate(updateEndDate);

            // Assert.
            Assert.IsTrue(result.IsSuccess);
        }
Exemple #10
0
            public void ShouldReturnValid()
            {
                var username  = "******";
                var password  = "";
                var rfcToFind = "CAC840428RH1";

                ILoginService            loginService            = new LoginService(new ContpaqLegacySessionProvider());
                ICompanyService          companyService          = new CompanyService(new ContpaqLegacyCompanyProvider());
                IJournalEntryTypeService journalEntryTypeService = new JournalEntryTypeService(new ContpaqLegacyJournalEntryTypeProvider());
                IJournalEntryService     journalEntryService     = new JournalEntryService(new ContpaqLegacyJournalEntryProvider());
                AccountingManager        accountingManager       = new AccountingManager(loginService, companyService,
                                                                                         journalEntryTypeService, journalEntryService);


                ISupplierService supplierService = new SupplierService(new ContpaqLegacySupplierProvider());
                SupplierManager  supplierManager = new SupplierManager(supplierService);

                var session = accountingManager.DoLogin(username, password);

                var companies = accountingManager.GetCompanies();

                Assert.NotEmpty(companies);

                accountingManager.OpenCompany(session, companies.FirstOrDefault().DBName);

                Assert.True(session.IsValid);

                var res = supplierManager.GetSupplierByRFC(session, rfcToFind);

                Assert.NotNull(res);
                Assert.Equal(rfcToFind, res.RFC);
            }
        public void SpecialCharactersinCostCenterOrBucketReturnNaN()
        {
            AccountingManager accountingManager = new AccountingManager();

            float actual = accountingManager.GetBudget("DEP100'", "TRAININGTest");

            Assert.AreEqual(float.NaN, actual);
        }
        public void AccountingManagerGetBudgetPositiveTest()
        {
            AccountingManager accountingManager = new AccountingManager();
            float             budget            = accountingManager.GetBudget("DEP100", "TRAINING");

            Assert.AreNotEqual(float.NaN, budget);
            Assert.AreEqual(5000f, budget);
        }
Exemple #13
0
        private async void BtnRunXML_Click(object sender, RoutedEventArgs e)
        {
            var accountingManager = new AccountingManager();

            if (DateStart.SelectedDate == null)
            {
                throw new InputValidationException(DateStart, "Please select a Start Date");
            }
            var formStartDate = (DateTime)DateStart.SelectedDate;

            if (DateEnd.SelectedDate == null)
            {
                throw new InputValidationException(DateStart, "Please select an End Date");
            }
            var formEndDate = (DateTime)DateEnd.SelectedDate;

            if (formStartDate > formEndDate)
            {
                throw new InputValidationException(DateStart, "Start Date must be before the end date.");
            }

            var report = accountingManager.GetAccountingDetails(formStartDate, formEndDate);

            var dlg = new SaveFileDialog
            {
                InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop),
                FileName         = "Report - " +
                                   DateTime.Now.ToShortDateString().Replace("/", "-")
                                   + " at " +
                                   DateTime.Now.ToShortTimeString().Replace(":", "-"),
                DefaultExt = ".xml",
                Filter     = @"Xml Report (.xml)|*.xml"
            };

            // Default file extension
            // Filter files by extension

            // Show save file dialog box
            if (!dlg.ShowDialog().Equals(DialogResult.OK))
            {
                return;
            }

            DateStart.Text = null;
            DateEnd.Text   = null;

            if (report.XmlFile <AccountingDetails>(dlg.FileName))
            {
                await this.ShowMessageDialog("Your Report has been saved successfully.", "Success");
            }
            else
            {
                throw new WanderingTurtleException(this, "There was a problem.  File not written.", "Error");
            }
        }
            public void ShouldReturnValues()
            {
                ILoginService            loginService            = new LoginService(new ContpaqLegacySessionProvider());
                ICompanyService          companyService          = new CompanyService(new ContpaqLegacyCompanyProvider());
                IJournalEntryTypeService journalEntryTypeService = new JournalEntryTypeService(new ContpaqLegacyJournalEntryTypeProvider());
                IJournalEntryService     journalEntryService     = new JournalEntryService(new ContpaqLegacyJournalEntryProvider());
                AccountingManager        accountingManager       = new AccountingManager(loginService, companyService,
                                                                                         journalEntryTypeService, journalEntryService);

                var companies = accountingManager.GetCompanies();

                Assert.NotEmpty(companies);
            }
Exemple #15
0
    public void Init(AccountingManager manager, ContentItemPerson personContentItem)
    {
        this.manager           = manager;
        this.personContentItem = personContentItem;
        thisGameobject         = gameObject;
        currentES = EventSystem.current;

        AddPerson();
        for (int i = 0; i < manager.PeopleAdded.Count - 1; i++)
        {
            AddPerson(manager.PeopleAdded[i]);
        }
    }
Exemple #16
0
    public void Init(AccountingManager manager)
    {
        this.manager = manager;

        dropdown.onValueChanged.AddListener(delegate { manager.LoadMonth(dropdown.captionText.text); });

        dropDownSortedList = new List <string>();
        dropDownSortedList.AddRange(Directory.GetFiles(SaveSystem.SAVE_FOLDER, "*.json"));
        for (int i = 0; i < dropDownSortedList.Count; i++)
        {
            dropDownSortedList[i] = dropDownSortedList[i].Replace(".json", "");
            dropDownSortedList[i] = Path.GetFileName(dropDownSortedList[i]);
        }
        ResetDropdown();
    }
Exemple #17
0
        public async Task Given_BaseAccountsAlreadyExist_When_AccountingManagerInitialised_Then_BaseAccountsAreNotDuplicated()
        {
            // Arrange.
            AccountingManager testObject = AccountingManagerFactory.Create(out IAccountingDataAccess accountingDataAccess);

            // Act.
            await testObject.Initialise();

            // Assert.
            foreach (var name in BaseAccountNames)
            {
                await accountingDataAccess
                .Received(1)
                .AddAccount(Arg.Is <Account>(a => a.Name.Equals(name)));
            }
        }
            public void ShouldBeCorrect()
            {
                var username = "******";
                var password = "";

                ILoginService            loginService            = new LoginService(new ContpaqLegacySessionProvider());
                ICompanyService          companyService          = new CompanyService(new ContpaqLegacyCompanyProvider());
                IJournalEntryTypeService journalEntryTypeService = new JournalEntryTypeService(new ContpaqLegacyJournalEntryTypeProvider());
                IJournalEntryService     journalEntryService     = new JournalEntryService(new ContpaqLegacyJournalEntryProvider());
                AccountingManager        accountingManager       = new AccountingManager(loginService, companyService,
                                                                                         journalEntryTypeService, journalEntryService);

                var session = accountingManager.DoLogin(username, password);

                Assert.True(session.IsValid);
            }
        public async Task Given_ExistingPeriods_When_Retrieved_Then_AllPeriodsArePresent()
        {
            // Arrange.
            var period1 = new Period(
                new DateTime(2020, 2, 1),
                new DateTime(2020, 2, 29));

            var period2 = new Period(
                new DateTime(2020, 3, 1),
                new DateTime(2020, 3, 31));

            AccountingManager testObject = AccountingManagerFactory.Create(out IAccountingDataAccess accountingDataAccess);

            accountingDataAccess
            .GetLastPeriod()
            .Returns(GetResult <Period> .CreateSuccess(period1));

            accountingDataAccess
            .GetAllPeriods()
            .Returns(GetResult <IEnumerable <Period> > .CreateSuccess(new[]
            {
                period1,
                period2
            }));

            // Act.
            GetResult <IEnumerable <PeriodDto> > result = await testObject.GetAllPeriods();

            // Assert.
            Assert.IsTrue(result.IsSuccess);

            IEnumerable <PeriodDto> periods = result.Result;

            Assert.AreEqual(2, periods.Count());

            Assert.IsNotNull(
                periods
                .SingleOrDefault(p =>
                                 p.Start == period1.Start &&
                                 p.End == period1.End));

            Assert.IsNotNull(
                periods
                .SingleOrDefault(p =>
                                 p.Start == period2.Start &&
                                 p.End == period2.End));
        }
Exemple #20
0
        public async Task Given_AccountsExist_When_RetrievingTransactionDebitAccounts_Then_CorrectAccountsAreReturned()
        {
            // Arrange.
            AccountingManager testObject = AccountingManagerFactory.Create(out IAccountingDataAccess accountingDataAccess);

            string someNonBaseAccount = $"{FundsAccountName}{AccountQualifiedNameSeparator}SomeAccount";

            accountingDataAccess
            .GetAccounts(
                isFunds: true,
                isIncome: true,
                isDebtor: true,
                isCreditor: true)
            .Returns(GetResult <IEnumerable <Account> > .CreateSuccess(new[]
            {
                new Account {
                    QualifiedName = FundsAccountName
                },
                new Account {
                    QualifiedName = IncomeAccountName
                },
                new Account {
                    QualifiedName = DebtorAccountName
                },
                new Account {
                    QualifiedName = CreditorAccountName
                },
                new Account {
                    QualifiedName = someNonBaseAccount, ParentAccountQualifiedName = FundsAccountName
                }
            }));

            // Act.
            GetResult <IEnumerable <AccountDto> > accountsResult = await testObject.GetTransactionDebitAccounts();

            // Assert.
            IEnumerable <AccountDto> accounts = accountsResult.Result;

            Assert.IsNull(accounts.SingleOrDefault(a => a.QualifiedName.Equals(FundsAccountName)));

            accounts.Single(a => a.QualifiedName.Equals(IncomeAccountName));
            accounts.Single(a => a.QualifiedName.Equals(DebtorAccountName));
            accounts.Single(a => a.QualifiedName.Equals(CreditorAccountName));
            accounts.Single(a => a.QualifiedName.Equals(someNonBaseAccount));

            Assert.Pass();
        }
        public void AccountingManagerGetTransactionsNegativeTest()
        {
            AccountingManager accountingManager = new AccountingManager();

            Transaction transaction = new Transaction();

            transaction.Amount      = 500f;
            transaction.Bucket      = "UnitTest2";
            transaction.CostCenter  = "UnitTest2";
            transaction.Description = "This was created by a unit test.";
            accountingManager.SaveTransaction(transaction);

            IList <Transaction> transactions = accountingManager.GetTransactions("WrongCc", "WrongBkt");

            Assert.IsNotNull(transactions);
            Assert.AreEqual(0, transactions.Count);
        }
Exemple #22
0
        public async Task Given_NewAccount_When_AddAccountCalledWithInvalidName_Then_ReturnsFailure(string accountName)
        {
            // Arrange.
            AccountingManager testObject = AccountingManagerFactory.Create(out IAccountingDataAccess accountingDataAccess);

            var newAccount = new NewAccountDto
            {
                Name = accountName,
                ParentAccountQualifiedName = BaseAccountNames[0]
            };

            // Act.
            ActionResult result = await testObject.AddAccount(newAccount);

            // Assert.
            Assert.IsFalse(result.IsSuccess);
        }
Exemple #23
0
        public async Task Given_NewAccount_When_ParentAccountDoesNotExist_Then_ReturnsFailure()
        {
            // Arrange.
            AccountingManager testObject = AccountingManagerFactory.Create(out IAccountingDataAccess accountingDataAccess);

            var newAccount = new NewAccountDto
            {
                Name = "SomeName",
                ParentAccountQualifiedName = "SomeInvalidParent"
            };

            // Act.
            ActionResult result = await testObject.AddAccount(newAccount);

            // Assert.
            Assert.IsFalse(result.IsSuccess);
        }
        public void AccountManagerGetRemainingBudgetPositiveTest()
        {
            AccountingManager accountingManager = new AccountingManager();

            Transaction transaction = new Transaction();

            transaction.Amount      = 500f;
            transaction.Bucket      = "TRAINING";
            transaction.CostCenter  = "DEP100";
            transaction.Description = "This was created by a unit test.";
            accountingManager.SaveTransaction(transaction);

            float remainingBudget = accountingManager.GetRemainingBudget("DEP100", "TRAINING");
            float budget          = accountingManager.GetBudget("DEP100", "TRAINING");
            float expectedBudget  = budget - transaction.Amount;

            Assert.AreEqual(expectedBudget, remainingBudget);
        }
            public void ShouldCreateNoMovements()
            {
                var username = "******";
                var password = "";

                ILoginService            loginService            = new LoginService(new ContpaqLegacySessionProvider());
                ICompanyService          companyService          = new CompanyService(new ContpaqLegacyCompanyProvider());
                IJournalEntryTypeService journalEntryTypeService = new JournalEntryTypeService(new ContpaqLegacyJournalEntryTypeProvider());
                IJournalEntryService     journalEntryService     = new JournalEntryService(new ContpaqLegacyJournalEntryProvider());
                AccountingManager        accountingManager       = new AccountingManager(loginService, companyService,
                                                                                         journalEntryTypeService, journalEntryService);

                var session = accountingManager.DoLogin(username, password);

                Assert.True(session.IsValid);

                var companies = accountingManager.GetCompanies();

                Assert.NotEmpty(companies);

                accountingManager.OpenCompany(session, companies.FirstOrDefault().DBName);

                List <JournalEntryMovement> journalEntryMovements = new List <JournalEntryMovement>();
                var journalEntry = new JournalEntry()
                {
                    Type         = "6",
                    Date         = DateTime.Now,
                    Adjust       = false,
                    Affect       = true,
                    Daily        = 0,
                    Guid         = Guid.NewGuid(),
                    Printed      = false,
                    SourceSystem = "11",
                    Concept      = Guid.NewGuid().ToString() + " desde UT",
                    //Number = 2,
                };

                journalEntry.JournalEntryMovement = journalEntryMovements;

                accountingManager.CreateJournalEntry(session, new List <JournalEntry>()
                {
                    journalEntry
                });
            }
        public async Task Given_PeriodWithEndBeforeStart_When_Adding_Then_ResultIsFailure()
        {
            // Arrange.
            AccountingManager testObject = AccountingManagerFactory.Create(out IAccountingDataAccess accountingDataAccess);

            accountingDataAccess
            .GetLastPeriod()
            .Returns(GetResult <Period> .CreateSuccess(null));

            accountingDataAccess.AddPeriod(Arg.Any <Period>()).Returns(ActionResult.CreateSuccess());

            var period = new PeriodDto(DateTime.Now, DateTime.Now.AddDays(-1));

            // Act.
            ActionResult result = await testObject.AddPeriod(period);

            // Assert.
            Assert.IsFalse(result.IsSuccess);
        }
        public void AccountManagerSaveTransactionPositiveTest()
        {
            AccountingManager accountingManager = new AccountingManager();

            Transaction transaction = new Transaction();

            transaction.Amount      = 500f;
            transaction.Bucket      = "UnitTest1";
            transaction.CostCenter  = "UnitTest1";
            transaction.Description = "This was created by a unit test.";
            accountingManager.SaveTransaction(transaction);

            IList <Transaction> transactions = accountingManager.GetTransactions("UnitTest1", "UnitTest1");

            Assert.IsNotNull(transactions);
            Assert.AreEqual(1, transactions.Count);
            Assert.AreEqual(transaction.Amount, transactions[0].Amount);
            Assert.AreEqual(transaction.Bucket, transactions[0].Bucket);
            Assert.AreEqual(transaction.CostCenter, transactions[0].CostCenter);
            Assert.AreEqual(transaction.Description, transactions[0].Description);
        }
Exemple #28
0
        public async Task Given_ExistingAccount_When_AddAccountCalledWithSameAccountDetails_Then_ReturnsFailure()
        {
            // Arrange.
            AccountingManager testObject = AccountingManagerFactory.Create(out IAccountingDataAccess accountingDataAccess);

            var newAccount = new NewAccountDto
            {
                Name = "SomeAccount",
                ParentAccountQualifiedName = BaseAccountNames[0]
            };

            accountingDataAccess
            .AddAccount(Arg.Any <Account>())
            .Throws(new AccountException("Account already exists", ""));

            // Act.
            ActionResult result = await testObject.AddAccount(newAccount);

            // Assert.
            Assert.IsFalse(result.IsSuccess);
        }
Exemple #29
0
        public async Task Given_NewCreditorAccount_When_Added_Then_AccountTypeIsCreditor()
        {
            // Arrange.
            AccountingManager testObject = AccountingManagerFactory.Create(out IAccountingDataAccess accountingDataAccess);

            var newAccount = new NewAccountDto
            {
                Name = "SomeAccount",
                ParentAccountQualifiedName = CreditorAccountName
            };

            // Act.
            await testObject.AddAccount(newAccount);

            // Assert.
            await accountingDataAccess
            .Received(1)
            .AddAccount(Arg.Is <Account>(a =>
                                         a.Name.Equals(newAccount.Name) &&
                                         a.AccountType.IsCreditor));
        }
        public async Task Given_NoExistingPeriods_When_Added_Then_ResultIsSuccess()
        {
            // Arrange.
            AccountingManager testObject = AccountingManagerFactory.Create(out IAccountingDataAccess accountingDataAccess);

            accountingDataAccess
            .GetLastPeriod()
            .Returns(GetResult <Period> .CreateFailure("No periods found"));

            accountingDataAccess
            .AddPeriod(Arg.Any <Period>())
            .Returns(ActionResult.CreateSuccess());

            var period = new PeriodDto(DateTime.Now, DateTime.Now);

            // Act.
            ActionResult result = await testObject.AddPeriod(period);

            // Assert.
            Assert.IsTrue(result.IsSuccess);
        }
        /// <summary>
        /// This function will get all the historical applications from Aneka
        /// </summary>
        /// <param name="data">The type of data to get from Aneka</param>
        /// <param name="fromDate">Limit the result From This Date</param>
        /// <param name="toDate">Limit the result To This Date</param>
        /// <returns></returns>
        public List<IAccountable> getDoneApplications(appQureyType.Type data, DateTime? fromDate, DateTime? toDate)
        {
            List<IAccountable> appViewListResult = new List<IAccountable>();
            try
            {
                List<IAccountable> appViewList = null;

                global::Aneka.Accounting.AccountingManager manager = new AccountingManager(serviceAddress);
                AccountingQueryRequest request;
                if (fromDate == null || toDate == null)
                {
                    request = new AccountingQueryRequest(credentials.Username, QueryMode.USER, 1, 1);
                }
                else
                {
                    request = new AccountingQueryRequest((DateTime)fromDate, (DateTime)toDate);
                }

                //query via the accounting manager
                appViewList = manager.Query(credentials, typeof(global::Aneka.Entity.ApplicationView), request);

                if (data == appQureyType.Type.NonSuccessfulOnly)
                {
                    foreach (global::Aneka.Entity.ApplicationView app in appViewList)
                    {
                        if (app.Total != app.Completed)
                            appViewListResult.Add(app);
                    }
                }
                if (data == appQureyType.Type.ALL)
                    appViewListResult = appViewList;
            }
            catch (Exception)
            {
                throw;
            }

            return appViewListResult;
        }