private Controller CreateSut(bool hasContactAccount = true, IContactAccount contactAccount = null) { _queryBusMock.Setup(m => m.QueryAsync <IGetContactAccountQuery, IContactAccount>(It.IsAny <IGetContactAccountQuery>())) .Returns(Task.FromResult(hasContactAccount ? contactAccount ?? _fixture.BuildContactAccountMock().Object : null)); return(new Controller(_commandBusMock.Object, _queryBusMock.Object, _claimResolverMock.Object)); }
public async Task <ActionResult <ContactAccountModel> > ContactAccountAsync(int accountingNumber, string accountNumber, DateTimeOffset?statusDate = null) { if (string.IsNullOrWhiteSpace(accountNumber)) { throw new IntranetExceptionBuilder(ErrorCode.ValueCannotBeNullOrWhiteSpace, nameof(accountNumber)) .WithValidatingType(typeof(string)) .WithValidatingField(nameof(accountNumber)) .Build(); } IGetContactAccountQuery query = new GetContactAccountQuery { AccountingNumber = accountingNumber, AccountNumber = accountNumber, StatusDate = statusDate?.LocalDateTime.Date ?? DateTime.Today }; IContactAccount contactAccount = await _queryBus.QueryAsync <IGetContactAccountQuery, IContactAccount>(query); if (contactAccount == null) { throw new IntranetExceptionBuilder(ErrorCode.ValueShouldBeKnown, nameof(accountNumber)) .WithValidatingType(typeof(string)) .WithValidatingField(nameof(accountNumber)) .Build(); } ContactAccountModel contactAccountModel = _accountingModelConverter.Convert <IContactAccount, ContactAccountModel>(contactAccount); return(Ok(contactAccountModel)); }
public async Task ApplyCalculationAsync_WhenCalled_AssertAccountingWasCalledOnEachPostingLine() { IPostingLineCollection sut = CreateSut(); int accountingNumber = _fixture.Create <int>(); string accountNumber = _fixture.Create <string>(); IAccounting accounting = _fixture.BuildAccountingMock(accountingNumber).Object; IContactAccount contactAccount = _fixture.BuildContactAccountMock(accounting, accountNumber).Object; IEnumerable <Mock <IPostingLine> > postingLineMockCollection = new List <Mock <IPostingLine> > { _fixture.BuildPostingLineMock(account: _fixture.BuildAccountMock(accounting).Object, contactAccount: contactAccount), _fixture.BuildPostingLineMock(account: _fixture.BuildAccountMock(accounting).Object, contactAccount: contactAccount), _fixture.BuildPostingLineMock(account: _fixture.BuildAccountMock(accounting).Object, contactAccount: contactAccount), _fixture.BuildPostingLineMock(account: _fixture.BuildAccountMock(accounting).Object, contactAccount: contactAccount), _fixture.BuildPostingLineMock(account: _fixture.BuildAccountMock(accounting).Object, contactAccount: contactAccount), _fixture.BuildPostingLineMock(account: _fixture.BuildAccountMock(accounting).Object, contactAccount: contactAccount), _fixture.BuildPostingLineMock(account: _fixture.BuildAccountMock(accounting).Object, contactAccount: contactAccount) }; sut.Add(postingLineMockCollection.Select(postingLineMock => postingLineMock.Object).ToArray()); IContactAccount calculatedContactAccount = _fixture.BuildContactAccountMock(accounting, accountNumber).Object; await sut.ApplyCalculationAsync(calculatedContactAccount); foreach (Mock <IPostingLine> postingLineMock in postingLineMockCollection) { postingLineMock.Verify(m => m.Accounting, Times.Once); } }
public ContactInfo(IContactAccount contactAccount, short year, short month) : base(year, month) { NullGuard.NotNull(contactAccount, nameof(contactAccount)); ContactAccount = contactAccount; }
private QueryHandler CreateSut(bool hasContactAccount = true, IContactAccount contactAccount = null) { _accountingRepositoryMock.Setup(m => m.GetContactAccountAsync(It.IsAny <int>(), It.IsAny <string>(), It.IsAny <DateTime>())) .Returns(Task.FromResult(hasContactAccount ? contactAccount ?? _fixture.BuildContactAccountMock().Object : null)); return(new QueryHandler(_validatorMock.Object, _accountingRepositoryMock.Object)); }
private IContactInfo CreateSut(IContactAccount contactAccount = null, short?year = null, short?month = null) { return(new Domain.Accounting.ContactInfo( contactAccount ?? _fixture.BuildContactAccountMock().Object, year ?? (short)_random.Next(InfoBase <IContactInfo> .MinYear, InfoBase <IContactInfo> .MaxYear), month ?? (short)_random.Next(InfoBase <IContactInfo> .MinMonth, InfoBase <IContactInfo> .MaxMonth))); }
public PostingLine(Guid identifier, DateTime postingDate, string reference, IAccount account, string details, IBudgetAccount budgetAccount, decimal debit, decimal credit, IContactAccount contactAccount, int sortOrder, ICreditInfoValues accountValuesAtPostingDate = null, IBudgetInfoValues budgetAccountValuesAtPostingDate = null, IContactInfoValues contactAccountValuesAtPostingDate = null) { NullGuard.NotNull(account, nameof(account)) .NotNullOrWhiteSpace(details, nameof(details)); if (postingDate.Year < InfoBase <ICreditInfo> .MinYear || postingDate.Year > InfoBase <ICreditInfo> .MaxYear) { throw new ArgumentException($"Year for the posting data should be between {InfoBase<ICreditInfo>.MinYear} and {InfoBase<ICreditInfo>.MaxYear}.", nameof(postingDate)); } if (postingDate.Month < InfoBase <ICreditInfo> .MinMonth || postingDate.Month > InfoBase <ICreditInfo> .MaxMonth) { throw new ArgumentException($"Month for the posting data should be between {InfoBase<ICreditInfo>.MinMonth} and {InfoBase<ICreditInfo>.MaxMonth}.", nameof(postingDate)); } if (budgetAccount != null && budgetAccount.Accounting.Number != account.Accounting.Number) { throw new ArgumentException("Accounting on the given budget account does not match the accounting on the given account.", nameof(budgetAccount)); } if (debit < 0M) { throw new ArgumentException("Debit cannot be lower than 0.", nameof(debit)); } if (credit < 0M) { throw new ArgumentException("Credit cannot be lower than 0.", nameof(credit)); } if (contactAccount != null && contactAccount.Accounting.Number != account.Accounting.Number) { throw new ArgumentException("Accounting on the given contact account does not match the accounting on the given account.", nameof(contactAccount)); } if (sortOrder < 0) { throw new ArgumentException("Sort order cannot be lower than 0.", nameof(sortOrder)); } Identifier = identifier; Accounting = account.Accounting; PostingDate = postingDate.Date; Reference = string.IsNullOrWhiteSpace(reference) ? null : reference.Trim(); Account = account; AccountValuesAtPostingDate = accountValuesAtPostingDate ?? new CreditInfoValues(0M, 0M); Details = details.Trim(); BudgetAccount = budgetAccount; BudgetAccountValuesAtPostingDate = budgetAccount != null ? budgetAccountValuesAtPostingDate ?? new BudgetInfoValues(0M, 0M) : null; Debit = debit; Credit = credit; ContactAccount = contactAccount; ContactAccountValuesAtPostingDate = contactAccount != null ? contactAccountValuesAtPostingDate ?? new ContactInfoValues(0M) : null; SortOrder = sortOrder; _calculateAccountValuesAtPostingDate = accountValuesAtPostingDate == null; _calculateBudgetAccountValuesAtPostingDate = budgetAccountValuesAtPostingDate == null; _calculateContactAccountValuesAtPostingDate = contactAccountValuesAtPostingDate == null; }
protected override Task ManageRepositoryAsync(ICreateContactAccountCommand command) { NullGuard.NotNull(command, nameof(command)); IContactAccount contactAccount = command.ToDomain(AccountingRepository); return(AccountingRepository.CreateContactAccountAsync(contactAccount)); }
private Mock <ICreateContactAccountCommand> CreateCommandMock(IContactAccount contactAccount = null) { Mock <ICreateContactAccountCommand> commandMock = new Mock <ICreateContactAccountCommand>(); commandMock.Setup(m => m.ToDomain(It.IsAny <IAccountingRepository>())) .Returns(contactAccount ?? _fixture.BuildContactAccountMock().Object); return(commandMock); }
public async Task GetContactAccountAsync_WhenAccountingNumberDoesNotExist_ReturnsNull() { IAccountingRepository sut = CreateSut(); IContactAccount result = await sut.GetContactAccountAsync(WithNonExistingAccountingNumber(), WithExistingAccountNumberForContactAccount(), DateTime.Today); Assert.That(result, Is.Null); }
public async Task DeleteContactAccountAsync_WhenCalled_DeletesContactAccount() { IAccountingRepository sut = CreateSut(); IContactAccount result = await sut.DeleteContactAccountAsync(WithExistingAccountingNumber(), WithExistingAccountNumberForContactAccount()); Assert.That(result, Is.Null); }
public async Task CalculateAsync_WhenCalled_ReturnsSameContactAccount() { IContactAccount sut = CreateSut(); IContactAccount result = await sut.CalculateAsync(DateTime.Now.AddDays(_random.Next(1, 365) * -1)); Assert.That(result, Is.SameAs(sut)); }
public void ToDomain_WhenSecondaryPhoneWasNotGivenInContactAccountDataCommand_ReturnsContactAccountWhereSecondaryPhoneIsNull() { IContactAccountDataCommand sut = CreateSut(hasSecondaryPhone: false); IContactAccount contactAccount = sut.ToDomain(_accountingRepositoryMock.Object); Assert.That(contactAccount.SecondaryPhone, Is.Null); }
public void ToDomain_WhenDescriptionWasNotGivenInContactAccountDataCommand_ReturnsContactAccountWhereDescriptionIsNull() { IContactAccountDataCommand sut = CreateSut(hasDescription: false); IContactAccount contactAccount = sut.ToDomain(_accountingRepositoryMock.Object); Assert.That(contactAccount.Description, Is.Null); }
public void ValuesAtStatusDate_WhenCalled_ReturnsNotNull() { IContactAccount sut = CreateSut(); IContactInfoValues result = sut.ValuesAtStatusDate; Assert.That(result, Is.Not.Null); }
public void ToDomain_WhenCalled_ReturnsContactAccount() { IContactAccountDataCommand sut = CreateSut(); IContactAccount contactAccount = sut.ToDomain(_accountingRepositoryMock.Object); Assert.That(contactAccount, Is.TypeOf <ContactAccount>()); }
public void ToDomain_WhenMailAddressWasNotGivenInContactAccountDataCommand_ReturnsContactAccountWhereMailAddressIsNull() { IContactAccountDataCommand sut = CreateSut(hasMailAddress: false); IContactAccount contactAccount = sut.ToDomain(_accountingRepositoryMock.Object); Assert.That(contactAccount.MailAddress, Is.Null); }
private static IContactInfo BuildContactInfo(IContactAccount contactAccount, short year, short month) { NullGuard.NotNull(contactAccount, nameof(contactAccount)); IContactInfo contactInfo = new ContactInfo(contactAccount, year, month); contactInfo.AddAuditInformation(contactAccount.CreatedDateTime.ToUniversalTime(), contactAccount.CreatedByIdentifier, contactAccount.ModifiedDateTime.ToUniversalTime(), contactAccount.ModifiedByIdentifier); return(contactInfo); }
public async Task CalculateAsync_WhenCalled_AssertApplyCalculationAsyncWasCalledOnPostingLineCollection() { Mock <IPostingLineCollection> postingLineCollectionMock = _fixture.BuildPostingLineCollectionMock(); IContactAccount sut = CreateSut(postingLineCollection: postingLineCollectionMock.Object); await sut.CalculateAsync(DateTime.Now.AddDays(_random.Next(1, 365) * -1)); postingLineCollectionMock.Verify(m => m.ApplyCalculationAsync(It.Is <IContactAccount>(value => value != null && value == sut)), Times.Once); }
public async Task ApplyCalculationAsync_WhenCalled_ReturnsSamePostingLineWhereContactAccountIsEqualToCalculatedContactAccount() { IPostingLine sut = CreateSut(); IContactAccount calculatedContactAccount = _fixture.BuildContactAccountMock().Object; IPostingLine result = await sut.ApplyCalculationAsync(calculatedContactAccount); Assert.That(result.ContactAccount, Is.EqualTo(calculatedContactAccount)); }
public void ToDomain_WhenCalled_ReturnsContactAccountWhereAccountNumberIsEqualToAccountNumberFromContactAccountDataCommand() { string accountNumber = _fixture.Create <string>().ToUpper(); IContactAccountDataCommand sut = CreateSut(accountNumber: accountNumber); IContactAccount contactAccount = sut.ToDomain(_accountingRepositoryMock.Object); Assert.That(contactAccount.AccountNumber, Is.EqualTo(accountNumber)); }
public void ToDomain_WhenCalled_ReturnsContactAccountWhereAccountingIsEqualToAccountingFromAccountingRepository() { IAccounting accounting = _fixture.BuildAccountingMock().Object; IContactAccountDataCommand sut = CreateSut(accounting: accounting); IContactAccount contactAccount = sut.ToDomain(_accountingRepositoryMock.Object); Assert.That(contactAccount.Accounting, Is.EqualTo(accounting)); }
public void ToDomain_WhenCalled_ReturnsContactAccountWherePaymentTermIsEqualToPaymentTermFromAccountingRepository() { IPaymentTerm paymentTerm = _fixture.BuildPaymentTermMock().Object; IContactAccountDataCommand sut = CreateSut(paymentTerm: paymentTerm); IContactAccount contactAccount = sut.ToDomain(_accountingRepositoryMock.Object); Assert.That(contactAccount.PaymentTerm, Is.EqualTo(paymentTerm)); }
public void ToDomain_WhenSecondaryPhoneWasGivenInContactAccountDataCommand_ReturnsContactAccountWhereSecondaryPhoneIsEqualToSecondaryPhoneContactAccountDataCommand() { string secondaryPhone = _fixture.Create <string>(); IContactAccountDataCommand sut = CreateSut(secondaryPhone: secondaryPhone); IContactAccount contactAccount = sut.ToDomain(_accountingRepositoryMock.Object); Assert.That(contactAccount.SecondaryPhone, Is.EqualTo(secondaryPhone)); }
public void ToDomain_WhenPrimaryPhoneWasGivenInContactAccountDataCommand_ReturnsContactAccountWherePrimaryPhoneIsEqualToPrimaryPhoneFromContactAccountDataCommand() { string primaryPhone = _fixture.Create <string>(); IContactAccountDataCommand sut = CreateSut(primaryPhone: primaryPhone); IContactAccount contactAccount = sut.ToDomain(_accountingRepositoryMock.Object); Assert.That(contactAccount.PrimaryPhone, Is.EqualTo(primaryPhone)); }
public void ToDomain_WhenMailAddressWasGivenInContactAccountDataCommand_ReturnsContactAccountWhereMailAddressIsEqualToMailAddressFromContactAccountDataCommand() { string mailAddress = _fixture.Create <string>(); IContactAccountDataCommand sut = CreateSut(mailAddress: mailAddress); IContactAccount contactAccount = sut.ToDomain(_accountingRepositoryMock.Object); Assert.That(contactAccount.MailAddress, Is.EqualTo(mailAddress)); }
public void ToDomain_WhenNoteWasGivenInContactAccountDataCommand_ReturnsContactAccountWhereNoteIsEqualToNoteFromContactAccountDataCommand() { string note = _fixture.Create <string>(); IContactAccountDataCommand sut = CreateSut(note: note); IContactAccount contactAccount = sut.ToDomain(_accountingRepositoryMock.Object); Assert.That(contactAccount.Note, Is.EqualTo(note)); }
public void ToDomain_WhenDescriptionWasGivenInContactAccountDataCommand_ReturnsContactAccountWhereDescriptionIsEqualToDescriptionFromContactAccountDataCommand() { string description = _fixture.Create <string>(); IContactAccountDataCommand sut = CreateSut(description: description); IContactAccount contactAccount = sut.ToDomain(_accountingRepositoryMock.Object); Assert.That(contactAccount.Description, Is.EqualTo(description)); }
public async Task QueryAsync_WhenNoContactAccountWasReturnedFromAccountingRepository_ReturnsNull() { QueryHandler sut = CreateSut(false); IGetContactAccountQuery query = CreateQuery(); IContactAccount result = await sut.QueryAsync(query); Assert.That(result, Is.Null); }
public void ValuesAtStatusDate_WhenCalled_ReturnsSameContactInfoValuesAsValuesAtStatusDateOnContactInfoCollection() { IContactInfoCollection contactInfoCollection = _fixture.BuildContactInfoCollectionMock().Object; IContactAccount sut = CreateSut(contactInfoCollection); IContactInfoValues result = sut.ValuesAtStatusDate; Assert.That(result, Is.SameAs(contactInfoCollection.ValuesAtStatusDate)); }