public BaseAccountingDemo() { // reset all global states, to allow model switching ServiceManager.Init(); m_vmST = ServiceManager.ComputeNode.VMSpacetimeForUnitTest; //m_namingSvc = NamingSvcClient.Instance; m_accountingInvoker = InvocationBuilder.Build<IAccounting>(); }
public async Task CalculateAsync_WhenCalledOnPostingLineWithContactAccount_ReturnsSamePostingLineWhereContactAccountValuesAtPostingDateIsNotNull() { IAccounting accounting = _fixture.BuildAccountingMock().Object; IAccount account = _fixture.BuildAccountMock(accounting).Object; IContactAccount contactAccount = _fixture.BuildContactAccountMock(accounting, statusDate: DateTime.MinValue).Object; IPostingLine sut = CreateSut(account: account, contactAccount: contactAccount); IPostingLine result = await sut.CalculateAsync(DateTime.Now.AddDays(_random.Next(1, 365) * -1)); Assert.That(result.ContactAccountValuesAtPostingDate, Is.Not.Null); }
public async Task CalculateAsync_WhenCalledOnPostingLineWithAccounting_ReturnsSamePostingLineWhereAccountingHasNotBeenChanged() { IAccounting calculatedAccounting = _fixture.BuildAccountingMock().Object; IAccounting accounting = _fixture.BuildAccountingMock(statusDate: DateTime.MinValue, calculatedAccounting: calculatedAccounting).Object; IAccount account = _fixture.BuildAccountMock(accounting).Object; IPostingLine sut = CreateSut(account: account); IPostingLine result = await sut.CalculateAsync(DateTime.Now.AddDays(_random.Next(1, 365) * -1)); Assert.That(result.Accounting, Is.SameAs(accounting)); }
public async Task CalculateAsync_WhenCalledOnPostingLineWithContactAccount_AssertStatusDateWasCalledOnContactAccount() { IAccounting accounting = _fixture.BuildAccountingMock().Object; IAccount account = _fixture.BuildAccountMock(accounting).Object; Mock <IContactAccount> contactAccountMock = _fixture.BuildContactAccountMock(accounting); IPostingLine sut = CreateSut(account: account, contactAccount: contactAccountMock.Object); await sut.CalculateAsync(DateTime.Now.AddDays(_random.Next(1, 365) * -1)); contactAccountMock.Verify(m => m.StatusDate, Times.Once); }
public async Task CalculateAsync_WhenCalledOnPostingLineWithBudgetAccount_ReturnsSamePostingLineWhereBudgetAccountValuesAtPostingDateHasNotBeenChanged() { IAccounting accounting = _fixture.BuildAccountingMock().Object; IAccount account = _fixture.BuildAccountMock(accounting).Object; IBudgetAccount budgetAccount = _fixture.BuildBudgetAccountMock(accounting, statusDate: DateTime.MinValue).Object; IPostingLine sut = CreateSut(account: account, budgetAccount: budgetAccount); IBudgetInfoValues budgetAccountValuesAtPostingDate = sut.BudgetAccountValuesAtPostingDate; IPostingLine result = await sut.CalculateAsync(DateTime.Now.AddDays(_random.Next(1, 365) * -1)); Assert.That(result.BudgetAccountValuesAtPostingDate, Is.SameAs(budgetAccountValuesAtPostingDate)); }
public async Task CalculateAsync_WhenCalledOnPostingLineWithContactAccountWhereStatusDateMatchesStatusDateFromArgument_AssertCalculateAsyncWasNotCalledOnContactAccount() { DateTime statusDate = DateTime.Now.AddDays(_random.Next(1, 365) * -1); IAccounting accounting = _fixture.BuildAccountingMock().Object; IAccount account = _fixture.BuildAccountMock(accounting).Object; Mock <IContactAccount> contactAccountMock = _fixture.BuildContactAccountMock(accounting, statusDate: statusDate); IPostingLine sut = CreateSut(account: account, contactAccount: contactAccountMock.Object); await sut.CalculateAsync(statusDate); contactAccountMock.Verify(m => m.CalculateAsync(It.IsAny <DateTime>()), Times.Never); }
public async Task CalculateAsync_WhenCalledOnPostingLineWithBudgetAccountWhereStatusDateDoesNotMatchStatusDateFromArgument_AssertCalculateAsyncWasCalledOnBudgetAccount() { IAccounting accounting = _fixture.BuildAccountingMock().Object; IAccount account = _fixture.BuildAccountMock(accounting).Object; Mock <IBudgetAccount> budgetAccountMock = _fixture.BuildBudgetAccountMock(accounting, statusDate: DateTime.MinValue); IPostingLine sut = CreateSut(account: account, budgetAccount: budgetAccountMock.Object); DateTime statusDate = DateTime.Now.AddDays(_random.Next(1, 365) * -1); await sut.CalculateAsync(statusDate); budgetAccountMock.Verify(m => m.CalculateAsync(It.Is <DateTime>(value => value == statusDate.Date)), Times.Once); }
public async Task CreateContactAccount_WhenCalledWithAccountingNumberForExistingAccounting_ReturnsPartialViewResultWhereModelIsContactAccountViewModelWithAccountingMatchingAccountingFromQueryBus() { int accountingNumber = _fixture.Create <int>(); IAccounting accounting = _fixture.BuildAccountingMock(accountingNumber).Object; Controller sut = CreateSut(accounting: accounting); PartialViewResult result = (PartialViewResult)await sut.CreateContactAccount(_fixture.Create <int>()); ContactAccountViewModel contactAccountViewModel = (ContactAccountViewModel)result.Model; Assert.That(contactAccountViewModel.Accounting.AccountingNumber, Is.EqualTo(accountingNumber)); }
public async Task LoadAccounting_WhenAccountingWasReturnedFromQueryBus_ReturnsPartialViewResultWhereModelIsAccountingViewModelWithAccountingNumberEqualToAccountingNumberOnAccountingFromQueryBus() { int accountingNumber = _fixture.Create <int>(); IAccounting accounting = _fixture.BuildAccountingMock(accountingNumber).Object; Controller sut = CreateSut(accounting: accounting); PartialViewResult result = (PartialViewResult)await sut.LoadAccounting(_fixture.Create <int>()); AccountingViewModel accountingViewModel = (AccountingViewModel)result.Model; Assert.That(accountingViewModel.AccountingNumber, Is.EqualTo(accountingNumber)); }
protected AccountBase(IAccounting accounting, string accountNumber, string accountName, IPostingLineCollection postingLineCollection) { NullGuard.NotNull(accounting, nameof(accounting)) .NotNullOrWhiteSpace(accountNumber, nameof(accountNumber)) .NotNullOrWhiteSpace(accountName, nameof(accountName)) .NotNull(postingLineCollection, nameof(postingLineCollection)); Accounting = accounting; AccountNumber = accountNumber.Trim().ToUpper(); AccountName = accountName.Trim(); PostingLineCollection = postingLineCollection; }
internal static IPostingLine ToDomain(this PostingLineModel postingLineModel, MapperCache mapperCache, IConverter accountingModelConverter) { NullGuard.NotNull(postingLineModel, nameof(postingLineModel)) .NotNull(mapperCache, nameof(mapperCache)) .NotNull(accountingModelConverter, nameof(accountingModelConverter)); lock (mapperCache.SyncRoot) { IAccounting accounting = accountingModelConverter.Convert <AccountingModel, IAccounting>(postingLineModel.Accounting); return(postingLineModel.ToDomain(accounting, mapperCache, accountingModelConverter)); } }
internal static IBudgetAccount ToDomain(this BudgetAccountModel budgetAccountModel, MapperCache mapperCache, IConverter accountingModelConverter) { NullGuard.NotNull(budgetAccountModel, nameof(budgetAccountModel)) .NotNull(mapperCache, nameof(mapperCache)) .NotNull(accountingModelConverter, nameof(accountingModelConverter)); lock (mapperCache.SyncRoot) { IAccounting accounting = accountingModelConverter.Convert <AccountingModel, IAccounting>(budgetAccountModel.Accounting); return(budgetAccountModel.ToDomain(accounting, mapperCache, accountingModelConverter)); } }
public async Task CalculateAsync_WhenCalledMultipleTimesOnPostingLineWithBudgetAccount_AssertStatusDateWasCalledOnlyOnceOnBudgetAccount() { IAccounting accounting = _fixture.BuildAccountingMock().Object; IAccount account = _fixture.BuildAccountMock(accounting).Object; Mock <IBudgetAccount> budgetAccountMock = _fixture.BuildBudgetAccountMock(accounting); IPostingLine sut = CreateSut(account: account, budgetAccount: budgetAccountMock.Object); DateTime statusDate = DateTime.Now.AddDays(_random.Next(1, 365) * -1); await(await(await sut.CalculateAsync(statusDate)).CalculateAsync(statusDate)).CalculateAsync(statusDate); budgetAccountMock.Verify(m => m.StatusDate, Times.Once); }
public async Task UpdateAccount_WhenCalledWithAccountingNumberAndAccountNumberForExistingAccount_ReturnsPartialViewResultWhereModelIsAccountViewModelWithAccountingMatchingAccountingOnAccountFromQueryBus() { int accountingNumber = _fixture.Create <int>(); IAccounting accounting = _fixture.BuildAccountingMock(accountingNumber).Object; IAccount account = _fixture.BuildAccountMock(accounting).Object; Controller sut = CreateSut(account: account); PartialViewResult result = (PartialViewResult)await sut.UpdateAccount(_fixture.Create <int>(), _fixture.Create <string>()); AccountViewModel accountViewModel = (AccountViewModel)result.Model; Assert.That(accountViewModel.Accounting.AccountingNumber, Is.EqualTo(accountingNumber)); }
public async Task <ActionResult <AccountingModel> > AccountingAsync(int accountingNumber, DateTimeOffset?statusDate = null) { IGetAccountingQuery query = new GetAccountingQuery { AccountingNumber = accountingNumber, StatusDate = statusDate?.LocalDateTime.Date ?? DateTime.Today }; IAccounting accounting = await _queryBus.QueryAsync <IGetAccountingQuery, IAccounting>(query); AccountingModel accountingModel = _accountingModelConverter.Convert <IAccounting, AccountingModel>(accounting); return(new OkObjectResult(accountingModel)); }
public Task <IPostingLine> ApplyCalculationAsync(IAccounting calculatedAccounting) { NullGuard.NotNull(calculatedAccounting, nameof(calculatedAccounting)); return(Task.Run <IPostingLine>(() => { lock (_syncRoot) { Accounting = calculatedAccounting; } return this; })); }
public async Task ResolveContactAccount_WhenContactAccountWasReturnedFromQueryBus_ReturnsOkObjectResultWhereValueIsContactAccountViewModelWithAccountingNumberEqualToAccountingNumberOnContactAccountFromQueryBus() { int accountingNumber = _fixture.Create <int>(); IAccounting accounting = _fixture.BuildAccountingMock(accountingNumber).Object; IContactAccount contactAccount = _fixture.BuildContactAccountMock(accounting).Object; Controller sut = CreateSut(contactAccount: contactAccount); OkObjectResult result = (OkObjectResult)await sut.ResolveContactAccount(_fixture.Create <int>(), _fixture.Create <string>(), DateTime.Today.AddDays(_random.Next(0, 7) * -1)); ContactAccountViewModel contactAccountViewModel = (ContactAccountViewModel)result.Value; Assert.That(contactAccountViewModel.Accounting, Is.Not.Null); Assert.That(contactAccountViewModel.Accounting.AccountingNumber, Is.EqualTo(accountingNumber)); }
public async Task AccountingInformation_WhenAccountingWasReturnedFromQueryBus_ReturnsPartialViewResultWhereModelIsAccountingPresentationViewModel() { int accountingNumber = _fixture.Create <int>(); IAccounting accounting = _fixture.BuildAccountingMock(accountingNumber).Object; Controller sut = CreateSut(accounting: accounting); PartialViewResult result = (PartialViewResult)await sut.AccountingInformation(_fixture.Create <int>()); Assert.That(result.Model, Is.TypeOf <AccountingPresentationViewModel>()); AccountingPresentationViewModel accountingPresentationViewModel = (AccountingPresentationViewModel)result.Model; Assert.That(accountingPresentationViewModel, Is.Not.Null); Assert.That(accountingPresentationViewModel.AccountingNumber, Is.EqualTo(accountingNumber)); }
private IEnumerable <IContactAccount> BuildContactAccounts(IAccounting accounting, string contactAccountNumber) { NullGuard.NotNull(accounting, nameof(accounting)); return(new[] { _fixture.BuildContactAccountMock(accounting, isEmpty: true).Object, _fixture.BuildContactAccountMock(accounting, isEmpty: true).Object, _fixture.BuildContactAccountMock(accounting, isEmpty: true).Object, _fixture.BuildContactAccountMock(accounting, string.IsNullOrWhiteSpace(contactAccountNumber) ? null : contactAccountNumber.ToUpper(), isEmpty: true).Object, _fixture.BuildContactAccountMock(accounting, isEmpty: true).Object, _fixture.BuildContactAccountMock(accounting, isEmpty: true).Object, _fixture.BuildContactAccountMock(accounting, isEmpty: true).Object }); }
public async Task AccountingAsync_WhenCalled_AssertOkObjectResultContainsAccounting() { IAccounting accountingMock = _fixture.BuildAccountingMock().Object; Controller sut = CreateSut(accountingMock); OkObjectResult result = (OkObjectResult)(await sut.AccountingAsync(_fixture.Create <int>())).Result; Assert.That(result.Value, Is.Not.Null); AccountingModel accountingModel = (AccountingModel)result.Value; Assert.That(accountingModel, Is.Not.Null); Assert.That(accountingModel.Number, Is.EqualTo(accountingMock.Number)); Assert.That(accountingModel.Name, Is.EqualTo(accountingMock.Name)); }
private static IAccount ResolveAccount(AccountModel accountModel, IAccounting accounting, MapperCache mapperCache, IConverter accountingModelConverter) { NullGuard.NotNull(accountModel, nameof(accountModel)) .NotNull(accounting, nameof(accounting)) .NotNull(mapperCache, nameof(mapperCache)) .NotNull(accountingModelConverter, nameof(accountingModelConverter)); IAccount account = accountModel.Resolve(mapperCache.AccountDictionary) ?? accountModel.ToDomain(accounting, mapperCache, accountingModelConverter); if (accounting.AccountCollection.Contains(account) == false) { accounting.AccountCollection.Add(account); } return(account); }
public override IContactAccount ToDomain(IAccountingRepository accountingRepository) { NullGuard.NotNull(accountingRepository, nameof(accountingRepository)); IAccounting accounting = GetAccountingAsync(accountingRepository).GetAwaiter().GetResult(); IPaymentTerm paymentTerm = GetPaymentTermAsync(accountingRepository).GetAwaiter().GetResult(); return(new ContactAccount(accounting, AccountNumber, AccountName, paymentTerm) { Description = Description, Note = Note, MailAddress = MailAddress, PrimaryPhone = PrimaryPhone, SecondaryPhone = SecondaryPhone }); }
public IPostingJournal ToDomain(IAccountingRepository accountingRepository) { NullGuard.NotNull(accountingRepository, nameof(accountingRepository)); IAccounting accounting = GetAccountingAsync(accountingRepository).GetAwaiter().GetResult(); IPostingLineCollection postingLineCollection = new PostingLineCollection { PostingLineCollection.AsParallel() .Select(applyPostingLineCommand => applyPostingLineCommand.ToDomain(accounting)) .OrderBy(postingLine => postingLine.PostingDate) .ThenBy(postingLine => postingLine.SortOrder) .ToArray() }; return(new PostingJournal(postingLineCollection)); }
public async Task CreateContactAccountAsync_WhenCalled_CreatesContactAccount() { IAccountingRepository sut = CreateSut(); IAccounting accounting = await sut.GetAccountingAsync(WithExistingAccountingNumber(), DateTime.Today); IPaymentTerm[] paymentTermCollection = (await sut.GetPaymentTermsAsync()).ToArray(); IContactAccount contactAccount = new ContactAccount(accounting, WithExistingAccountNumberForContactAccount(), _fixture.Create <string>(), paymentTermCollection[_random.Next(0, paymentTermCollection.Length - 1)]) { Description = _fixture.Create <string>(), PrimaryPhone = _fixture.Create <string>() }; IContactAccount result = await sut.CreateContactAccountAsync(contactAccount); Assert.That(result, Is.Not.Null); }
private IAccountDataCommand CreateSut(int?accountingNumber = null, IAccounting accounting = null, string accountNumber = null, string accountName = null, bool hasDescription = true, string description = null, bool hasNote = true, string note = null, int?accountGroupNumber = null, IAccountGroup accountGroup = null, IEnumerable <ICreditInfoCommand> creditInfoCommandCollection = null) { _accountingRepositoryMock.Setup(m => m.GetAccountingAsync(It.IsAny <int>(), It.IsAny <DateTime>())) .Returns(Task.FromResult(accounting ?? _fixture.BuildAccountingMock().Object)); _accountingRepositoryMock.Setup(m => m.GetAccountGroupAsync(It.IsAny <int>())) .Returns(Task.FromResult(accountGroup ?? _fixture.BuildAccountGroupMock().Object)); return(_fixture.Build <Sut>() .With(m => m.AccountingNumber, accountingNumber ?? _fixture.Create <int>()) .With(m => m.AccountNumber, accountNumber ?? _fixture.Create <string>().ToUpper()) .With(m => m.AccountName, accountName ?? _fixture.Create <string>()) .With(m => m.Description, hasDescription ? description ?? _fixture.Create <string>() : null) .With(m => m.Note, hasNote ? note ?? _fixture.Create <string>() : null) .With(m => m.AccountGroupNumber, accountGroupNumber ?? _fixture.Create <int>()) .With(m => m.CreditInfoCollection, creditInfoCommandCollection ?? _fixture.CreateMany <ICreditInfoCommand>(_random.Next(5, 10)).ToArray()) .Create()); }
private async Task <IPostingJournal> BuildPostingJournalAsync(IAccountingRepository accountingRepository) { NullGuard.NotNull(accountingRepository, nameof(accountingRepository)); IAccounting accounting = await accountingRepository.GetAccountingAsync(WithExistingAccountingNumber(), DateTime.Today); IAccount primaryAccount = accounting.AccountCollection.Single(account => string.CompareOrdinal(account.AccountNumber, WithExistingAccountNumberForAccount()) == 0); IBudgetAccount primaryBudgetAccount = accounting.BudgetAccountCollection.Single(budgetAccount => string.CompareOrdinal(budgetAccount.AccountNumber, WithExistingAccountNumberForBudgetAccount()) == 0); IPostingLineCollection postingLineCollection = new PostingLineCollection { new PostingLine(Guid.NewGuid(), DateTime.Today, null, primaryAccount, "Testing apply posting journal", primaryBudgetAccount, 25000M, 0M, null, 1), new PostingLine(Guid.NewGuid(), DateTime.Today, null, primaryAccount, "Testing apply posting journal", primaryBudgetAccount, 0M, 25000M, null, 2) }; return(new PostingJournal(postingLineCollection)); }
public async Task <IActionResult> AccountingInformation(int accountingNumber) { IGetAccountingQuery query = new GetAccountingQuery { AccountingNumber = accountingNumber, StatusDate = DateTime.Today }; IAccounting accounting = await _queryBus.QueryAsync <IGetAccountingQuery, IAccounting>(query); if (accounting == null) { return(BadRequest()); } AccountingPresentationViewModel accountingPresentationViewModel = _homeViewModelConverter.Convert <IAccounting, AccountingPresentationViewModel>(accounting); return(PartialView("_AccountingPresentationPartial", accountingPresentationViewModel)); }
public async Task GetPostingLinesAsync_WhenCalled_AssertPostingLineCollectionWasCalledOnEachAccountInAccountCollection() { Mock <IAccount>[] accountMockCollection = { _fixture.BuildAccountMock(), _fixture.BuildAccountMock(), _fixture.BuildAccountMock() }; IAccounting sut = CreateSut(accountMockCollection.Select(accountMock => accountMock.Object).ToArray()); DateTime statusDate = DateTime.Today.AddDays(_random.Next(1, 7) * -1); await sut.GetPostingLinesAsync(statusDate); foreach (Mock <IAccount> accountMock in accountMockCollection) { accountMock.Verify(m => m.PostingLineCollection, Times.Once); } }
private IContactAccountDataCommand CreateSut(int?accountingNumber = null, IAccounting accounting = null, string accountNumber = null, string accountName = null, bool hasDescription = true, string description = null, bool hasNote = true, string note = null, bool hasMailAddress = true, string mailAddress = null, bool hasPrimaryPhone = true, string primaryPhone = null, bool hasSecondaryPhone = true, string secondaryPhone = null, int?paymentTermNumber = null, IPaymentTerm paymentTerm = null) { _accountingRepositoryMock.Setup(m => m.GetAccountingAsync(It.IsAny <int>(), It.IsAny <DateTime>())) .Returns(Task.FromResult(accounting ?? _fixture.BuildAccountingMock().Object)); _accountingRepositoryMock.Setup(m => m.GetPaymentTermAsync(It.IsAny <int>())) .Returns(Task.FromResult(paymentTerm ?? _fixture.BuildPaymentTermMock().Object)); return(_fixture.Build <Sut>() .With(m => m.AccountingNumber, accountingNumber ?? _fixture.Create <int>()) .With(m => m.AccountNumber, accountNumber ?? _fixture.Create <string>().ToUpper()) .With(m => m.AccountName, accountName ?? _fixture.Create <string>()) .With(m => m.Description, hasDescription ? description ?? _fixture.Create <string>() : null) .With(m => m.Note, hasNote ? note ?? _fixture.Create <string>() : null) .With(m => m.MailAddress, hasMailAddress ? mailAddress ?? _fixture.Create <string>() : null) .With(m => m.PrimaryPhone, hasPrimaryPhone ? primaryPhone ?? _fixture.Create <string>() : null) .With(m => m.SecondaryPhone, hasSecondaryPhone ? secondaryPhone ?? _fixture.Create <string>() : null) .With(m => m.PaymentTermNumber, paymentTermNumber ?? _fixture.Create <int>()) .Create()); }
public override IBudgetAccount ToDomain(IAccountingRepository accountingRepository) { NullGuard.NotNull(accountingRepository, nameof(accountingRepository)); IAccounting accounting = GetAccountingAsync(accountingRepository).GetAwaiter().GetResult(); IBudgetAccountGroup budgetAccountGroup = GetBudgetAccountGroupAsync(accountingRepository).GetAwaiter().GetResult(); IBudgetAccount budgetAccount = new BudgetAccount(accounting, AccountNumber, AccountName, budgetAccountGroup) { Description = Description, Note = Note }; IBudgetInfo[] budgetInfoCollection = (BudgetInfoCollection ?? Array.Empty <IBudgetInfoCommand>()) .AsParallel() .Select(budgetInfo => budgetInfo.ToDomain(budgetAccount)) .ToArray(); budgetAccount.BudgetInfoCollection.Add(budgetInfoCollection); return(budgetAccount); }
public override IAccount ToDomain(IAccountingRepository accountingRepository) { NullGuard.NotNull(accountingRepository, nameof(accountingRepository)); IAccounting accounting = GetAccountingAsync(accountingRepository).GetAwaiter().GetResult(); IAccountGroup accountGroup = GetAccountGroupAsync(accountingRepository).GetAwaiter().GetResult(); IAccount account = new Account(accounting, AccountNumber, AccountName, accountGroup) { Description = Description, Note = Note }; ICreditInfo[] creditInfoCollection = (CreditInfoCollection ?? Array.Empty <ICreditInfoCommand>()) .AsParallel() .Select(creditInfo => creditInfo.ToDomain(account)) .ToArray(); account.CreditInfoCollection.Add(creditInfoCollection); return(account); }
public TwoSpacetimeTests() { m_accountingInvoker = InvocationBuilder.Build<IAccounting>(); ServiceManager.Init(); }
public TriggerTests() { m_accountingInvoker = InvocationBuilder.Build<IAccounting>(); ServiceManager.Init(); }