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>());
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 6
0
        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);
            }
        }
Exemplo n.º 8
0
        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));
        }
Exemplo n.º 10
0
        public async Task <IAccountGroup> AddOrReplaceAccountGroupAsync(IAccountGroup accountGroup)
        {
            await _repository.AddOrReplaceAsync(accountGroup);

            await UpdateAccountGroupCache();

            await _clientNotifyService.NotifyTradingConditionsChanged(accountGroup.TradingConditionId);

            return(accountGroup);
        }
Exemplo n.º 11
0
        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));
        }
Exemplo n.º 13
0
        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()));
        }
Exemplo n.º 14
0
 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
     });
 }
Exemplo n.º 15
0
 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
     });
 }
Exemplo n.º 16
0
 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));
        }
Exemplo n.º 18
0
        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);
        }
Exemplo n.º 19
0
        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));
        }
Exemplo n.º 20
0
        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());
        }
Exemplo n.º 22
0
 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);
     }
 }
Exemplo n.º 24
0
        internal static IAccountGroup GetAccountGroup(this int number, IAccountingRepository accountingRepository, ref IAccountGroup accountGroup)
        {
            NullGuard.NotNull(accountingRepository, nameof(accountingRepository));

            return(accountGroup ??= accountingRepository.GetAccountGroupAsync(number).GetAwaiter().GetResult());
        }
Exemplo n.º 25
0
 private AccountGroupContract Convert(IAccountGroup src)
 {
     return(_convertService.Convert <IAccountGroup, AccountGroupContract>(src));
 }
Exemplo n.º 26
0
 private IAccount CreateSut(IAccountGroup accountGroup = null)
 {
     return(new Domain.Accounting.Account(_fixture.BuildAccountingMock().Object, _fixture.Create <string>(), _fixture.Create <string>(), accountGroup ?? _fixture.BuildAccountGroupMock().Object));
 }
Exemplo n.º 27
0
 public Account(IAccounting accounting, string accountNumber, string accountName, IAccountGroup accountGroup)
     : this(accounting, accountNumber, accountName, accountGroup, new CreditInfoCollection(), new PostingLineCollection())
 {
 }