private QueryHandler CreateSut(IAccountGroup accountGroup = null) { _accountingRepositoryMock.Setup(m => m.GetAccountGroupAsync(It.IsAny <int>())) .Returns(Task.Run(() => accountGroup ?? _fixture.Create <IAccountGroup>())); return(new QueryHandler(_validatorMock.Object, _accountingRepositoryMock.Object)); }
public async Task GetAccountGroupAsync_WhenCalled_ReturnsAccountGroup() { IAccountingRepository sut = CreateSut(); IAccountGroup result = await sut.GetAccountGroupAsync(1); Assert.That(result, Is.Not.Null); }
public void ToDomain_WhenCalled_ReturnsAccountGroup() { IAccountGroupCommand sut = CreateSut(); IAccountGroup result = sut.ToDomain(); Assert.That(result, Is.TypeOf <AccountGroup>()); }
private Mock <ICreateAccountGroupCommand> CreateCommandMock(IAccountGroup accountGroup = null) { Mock <ICreateAccountGroupCommand> commandMock = new Mock <ICreateAccountGroupCommand>(); commandMock.Setup(m => m.ToDomain()) .Returns(accountGroup ?? _fixture.BuildAccountGroupMock().Object); return(commandMock); }
protected override async Task ManageRepositoryAsync(ICreateAccountGroupCommand command) { NullGuard.NotNull(command, nameof(command)); IAccountGroup accountGroup = command.ToDomain(); await AccountingRepository.CreateAccountGroupAsync(accountGroup); }
public void AccountGroupType_WhenCalled_ReturnsAccountGroupTypeFromAccountGroup(AccountGroupType accountGroupType) { IAccountGroup accountGroup = _fixture.BuildAccountGroupMock(accountGroupType: accountGroupType).Object; IAccount sut = CreateSut(accountGroup); AccountGroupType result = sut.AccountGroupType; Assert.That(result, Is.EqualTo(accountGroupType)); }
internal static IAccount ToDomain(this 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)); lock (mapperCache.SyncRoot) { IAccount account = accountModel.Resolve(mapperCache.AccountDictionary); if (account != null) { return(account); } IAccountGroup accountGroup = accountingModelConverter.Convert <AccountGroupModel, IAccountGroup>(accountModel.AccountGroup); account = new Account(accounting, accountModel.AccountNumber, accountModel.BasicAccount.AccountName, accountGroup) { Description = accountModel.BasicAccount.Description, Note = accountModel.BasicAccount.Note }; accountModel.CopyAuditInformationTo(account); account.SetDeletable(accountModel.Deletable); mapperCache.AccountDictionary.Add(accountModel.AccountIdentifier, account); accounting.AccountCollection.Add(account); if (accountModel.CreditInfos != null) { account.CreditInfoCollection.Populate(account, accountModel.CreditInfos .Where(creditInfoModel => creditInfoModel.Convertible() && (creditInfoModel.YearMonth.Year < accountModel.StatusDateForInfos.Year || creditInfoModel.YearMonth.Year == accountModel.StatusDateForInfos.Year && creditInfoModel.YearMonth.Month <= accountModel.StatusDateForInfos.Month)) .Select(creditInfoModel => creditInfoModel.ToDomain(account)) .ToArray(), accountModel.StatusDate, accountModel.StatusDateForInfos); } if (accountModel.PostingLines != null) { account.PostingLineCollection.Add(accountModel.PostingLines .Where(postingLineModel => postingLineModel.Convertible() && postingLineModel.PostingDate >= accountModel.GetFromDateForPostingLines() && postingLineModel.PostingDate < accountModel.GetToDateForPostingLines(1)) .Select(postingLineModel => postingLineModel.ToDomain(accounting, account, mapperCache, accountingModelConverter)) .Where(postingLine => account.PostingLineCollection.Contains(postingLine) == false) .ToArray()); } return(account); } }
public Account(IAccounting accounting, string accountNumber, string accountName, IAccountGroup accountGroup, ICreditInfoCollection creditInfoCollection, IPostingLineCollection postingLineCollection) : base(accounting, accountNumber, accountName, postingLineCollection) { NullGuard.NotNull(accountGroup, nameof(accountGroup)) .NotNull(creditInfoCollection, nameof(creditInfoCollection)); AccountGroup = accountGroup; CreditInfoCollection = creditInfoCollection; }
public void ToDomain_WhenCalled_ReturnsAccountWhereAccountGroupIsEqualToAccountGroupFromAccountingRepository() { IAccountGroup accountGroup = _fixture.BuildAccountGroupMock().Object; IAccountDataCommand sut = CreateSut(accountGroup: accountGroup); IAccount account = sut.ToDomain(_accountingRepositoryMock.Object); Assert.That(account.AccountGroup, Is.EqualTo(accountGroup)); }
public async Task <IAccountGroup> AddOrReplaceAccountGroupAsync(IAccountGroup accountGroup) { await _repository.AddOrReplaceAsync(accountGroup); await UpdateAccountGroupCache(); await _clientNotifyService.NotifyTradingConditionsChanged(accountGroup.TradingConditionId); return(accountGroup); }
public async Task ExecuteAsync_WhenCalled_AssertCreateAccountGroupAsyncWasCalledOnAccountingRepository() { CommandHandler sut = CreateSut(); IAccountGroup accountGroup = _fixture.BuildAccountGroupMock().Object; ICreateAccountGroupCommand command = CreateCommandMock(accountGroup).Object; await sut.ExecuteAsync(command); _accountingRepositoryMock.Verify(m => m.CreateAccountGroupAsync(It.Is <IAccountGroup>(value => value == accountGroup)), Times.Once); }
public async Task QueryAsync_WhenCalled_ReturnsAccountGroupFromAccountingRepository() { IAccountGroup accountGroup = _fixture.Create <IAccountGroup>(); QueryHandler sut = CreateSut(accountGroup); IGetAccountGroupQuery query = CreateQueryMock().Object; IAccountGroup result = await sut.QueryAsync(query); Assert.That(result, Is.EqualTo(accountGroup)); }
public Task <IAccountGroup> UpdateAccountGroupAsync(IAccountGroup accountGroup) { NullGuard.NotNull(accountGroup, nameof(accountGroup)); return(ExecuteAsync(async() => { using AccountGroupModelHandler accountGroupModelHandler = new AccountGroupModelHandler(DbContext, AccountingModelConverter.Create()); return await accountGroupModelHandler.UpdateAsync(accountGroup); }, MethodBase.GetCurrentMethod())); }
public static AccountGroup Create(IAccountGroup src) { return(new AccountGroup { TradingConditionId = src.TradingConditionId, BaseAssetId = src.BaseAssetId, MarginCall = src.MarginCall, StopOut = src.StopOut, DepositTransferLimit = src.DepositTransferLimit, ProfitWithdrawalLimit = src.ProfitWithdrawalLimit }); }
public static AccountGroupEntity Create(IAccountGroup src) { return(new AccountGroupEntity { PartitionKey = GeneratePartitionKey(src.TradingConditionId), RowKey = GenerateRowKey(src.BaseAssetId), MarginCall = (double)src.MarginCall, StopOut = (double)src.StopOut, DepositTransferLimit = (double)src.DepositTransferLimit, ProfitWithdrawalLimit = (double)src.ProfitWithdrawalLimit }); }
public static AccountGroupModel ToBackendContract(this IAccountGroup src) { return(new AccountGroupModel { TradingConditionId = src.TradingConditionId, BaseAssetId = src.BaseAssetId, MarginCall = src.MarginCall, StopOut = src.StopOut, DepositTransferLimit = src.DepositTransferLimit, ProfitWithdrawalLimit = src.ProfitWithdrawalLimit }); }
public async Task UpdateAccount_WhenCalledWithAccountingNumberAndAccountNumberForExistingAccount_ReturnsPartialViewResultWhereModelIsAccountViewModelWithAccountGroupMatchingAccountGroupOnAccountFromQueryBus() { int accountGroupNumber = _fixture.Create <int>(); IAccountGroup accountGroup = _fixture.BuildAccountGroupMock(accountGroupNumber).Object; IAccount account = _fixture.BuildAccountMock(accountGroup: accountGroup).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.AccountGroup.Number, Is.EqualTo(accountGroupNumber)); }
private Controller CreateSut(IAccountGroup accountGroup = null, bool modelIsValid = true) { _commandBusMock.Setup(m => m.PublishAsync(It.IsAny <IUpdateAccountGroupCommand>())) .Returns(Task.Run(() => { })); _queryBusMock.Setup(m => m.QueryAsync <IGetAccountGroupQuery, IAccountGroup>(It.IsAny <IGetAccountGroupQuery>())) .Returns(Task.Run(() => accountGroup ?? _fixture.BuildAccountGroupMock().Object)); Controller controller = new Controller(_commandBusMock.Object, _queryBusMock.Object, _claimResolverMock.Object); if (modelIsValid == false) { controller.ModelState.AddModelError(_fixture.Create <string>(), _fixture.Create <string>()); } return(controller); }
public async Task UpdateAccountGroup_WhenCalledWithNumber_ReturnsViewResultWhereModelIsAccountGroupViewModel() { int number = _fixture.Create <int>(); string name = _fixture.Create <string>(); Domain.Interfaces.Accounting.Enums.AccountGroupType accountGroupType = _fixture.Create <Domain.Interfaces.Accounting.Enums.AccountGroupType>(); IAccountGroup accountGroup = _fixture.BuildAccountGroupMock(number, name, accountGroupType).Object; Controller sut = CreateSut(accountGroup); ViewResult result = (ViewResult)await sut.UpdateAccountGroup(_fixture.Create <int>()); Assert.That(result.Model, Is.TypeOf <AccountGroupViewModel>()); AccountGroupViewModel accountGroupViewModel = (AccountGroupViewModel)result.Model; Assert.That(accountGroupViewModel, Is.Not.Null); Assert.That(accountGroupViewModel.Number, Is.EqualTo(number)); Assert.That(accountGroupViewModel.Name, Is.EqualTo(name)); Assert.That(Convert.ToString(accountGroupViewModel.AccountGroupType), Is.EqualTo(Convert.ToString(accountGroupType))); Assert.That(accountGroupViewModel.EditMode, Is.EqualTo(EditMode.Edit)); }
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); }
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()); }
public async Task AddOrReplaceAsync(IAccountGroup group) { await _tableStorage.InsertOrReplaceAsync(AccountGroupEntity.Create(group)); }
public void setKnownGroup(string key, IAccountGroup value) { if (value != null) { dictionary[key] = value; } else { dictionary.Remove(key); } }
internal static IAccountGroup GetAccountGroup(this int number, IAccountingRepository accountingRepository, ref IAccountGroup accountGroup) { NullGuard.NotNull(accountingRepository, nameof(accountingRepository)); return(accountGroup ??= accountingRepository.GetAccountGroupAsync(number).GetAwaiter().GetResult()); }
private AccountGroupContract Convert(IAccountGroup src) { return(_convertService.Convert <IAccountGroup, AccountGroupContract>(src)); }
private IAccount CreateSut(IAccountGroup accountGroup = null) { return(new Domain.Accounting.Account(_fixture.BuildAccountingMock().Object, _fixture.Create <string>(), _fixture.Create <string>(), accountGroup ?? _fixture.BuildAccountGroupMock().Object)); }
public Account(IAccounting accounting, string accountNumber, string accountName, IAccountGroup accountGroup) : this(accounting, accountNumber, accountName, accountGroup, new CreditInfoCollection(), new PostingLineCollection()) { }