private QueryHandler CreateSut(IBudgetAccountGroup budgetAccountGroup = null)
        {
            _accountingRepositoryMock.Setup(m => m.GetBudgetAccountGroupAsync(It.IsAny <int>()))
            .Returns(Task.Run(() => budgetAccountGroup ?? _fixture.Create <IBudgetAccountGroup>()));

            return(new QueryHandler(_validatorMock.Object, _accountingRepositoryMock.Object));
        }
        public void ToDomain_WhenCalled_ReturnsBudgetAccountGroup()
        {
            IBudgetAccountGroupCommand sut = CreateSut();

            IBudgetAccountGroup result = sut.ToDomain();

            Assert.That(result, Is.TypeOf <BudgetAccountGroup>());
        }
        protected override async Task ManageRepositoryAsync(ICreateBudgetAccountGroupCommand command)
        {
            NullGuard.NotNull(command, nameof(command));

            IBudgetAccountGroup budgetAccountGroup = command.ToDomain();

            await AccountingRepository.CreateBudgetAccountGroupAsync(budgetAccountGroup);
        }
Exemplo n.º 4
0
        public async Task GetBudgetAccountGroupAsync_WhenCalled_ReturnsBudgetAccountGroup()
        {
            IAccountingRepository sut = CreateSut();

            IBudgetAccountGroup result = await sut.GetBudgetAccountGroupAsync(1);

            Assert.That(result, Is.Not.Null);
        }
Exemplo n.º 5
0
        private Mock <IUpdateBudgetAccountGroupCommand> CreateCommandMock(IBudgetAccountGroup budgetAccountGroup = null)
        {
            Mock <IUpdateBudgetAccountGroupCommand> commandMock = new Mock <IUpdateBudgetAccountGroupCommand>();

            commandMock.Setup(m => m.ToDomain())
            .Returns(budgetAccountGroup ?? _fixture.BuildBudgetAccountGroupMock().Object);
            return(commandMock);
        }
        public BudgetAccount(IAccounting accounting, string accountNumber, string accountName, IBudgetAccountGroup budgetAccountGroup, IBudgetInfoCollection budgetInfoCollection, IPostingLineCollection postingLineCollection)
            : base(accounting, accountNumber, accountName, postingLineCollection)
        {
            NullGuard.NotNull(budgetAccountGroup, nameof(budgetAccountGroup))
            .NotNull(budgetInfoCollection, nameof(budgetInfoCollection));

            BudgetAccountGroup   = budgetAccountGroup;
            BudgetInfoCollection = budgetInfoCollection;
        }
Exemplo n.º 7
0
        public void ToDomain_WhenCalled_ReturnsBudgetAccountWhereBudgetAccountGroupIsEqualToBudgetAccountGroupFromAccountingRepository()
        {
            IBudgetAccountGroup       budgetAccountGroup = _fixture.BuildBudgetAccountGroupMock().Object;
            IBudgetAccountDataCommand sut = CreateSut(budgetAccountGroup: budgetAccountGroup);

            IBudgetAccount budgetAccount = sut.ToDomain(_accountingRepositoryMock.Object);

            Assert.That(budgetAccount.BudgetAccountGroup, Is.EqualTo(budgetAccountGroup));
        }
Exemplo n.º 8
0
        internal static IBudgetAccount ToDomain(this BudgetAccountModel budgetAccountModel, IAccounting accounting, MapperCache mapperCache, IConverter accountingModelConverter)
        {
            NullGuard.NotNull(budgetAccountModel, nameof(budgetAccountModel))
            .NotNull(accounting, nameof(accounting))
            .NotNull(mapperCache, nameof(mapperCache))
            .NotNull(accountingModelConverter, nameof(accountingModelConverter));

            lock (mapperCache.SyncRoot)
            {
                IBudgetAccount budgetAccount = budgetAccountModel.Resolve(mapperCache.BudgetAccountDictionary);
                if (budgetAccount != null)
                {
                    return(budgetAccount);
                }

                IBudgetAccountGroup budgetAccountGroup = accountingModelConverter.Convert <BudgetAccountGroupModel, IBudgetAccountGroup>(budgetAccountModel.BudgetAccountGroup);

                budgetAccount = new BudgetAccount(accounting, budgetAccountModel.AccountNumber, budgetAccountModel.BasicAccount.AccountName, budgetAccountGroup)
                {
                    Description = budgetAccountModel.BasicAccount.Description,
                    Note        = budgetAccountModel.BasicAccount.Note
                };
                budgetAccountModel.CopyAuditInformationTo(budgetAccount);
                budgetAccount.SetDeletable(budgetAccountModel.Deletable);

                mapperCache.BudgetAccountDictionary.Add(budgetAccountModel.BudgetAccountIdentifier, budgetAccount);

                accounting.BudgetAccountCollection.Add(budgetAccount);

                if (budgetAccountModel.BudgetInfos != null)
                {
                    budgetAccount.BudgetInfoCollection.Populate(budgetAccount,
                                                                budgetAccountModel.BudgetInfos
                                                                .Where(budgetInfoModel => budgetInfoModel.Convertible() &&
                                                                       (budgetInfoModel.YearMonth.Year < budgetAccountModel.StatusDateForInfos.Year ||
                                                                        budgetInfoModel.YearMonth.Year == budgetAccountModel.StatusDateForInfos.Year &&
                                                                        budgetInfoModel.YearMonth.Month <= budgetAccountModel.StatusDateForInfos.Month))
                                                                .Select(budgetInfoModel => budgetInfoModel.ToDomain(budgetAccount))
                                                                .ToArray(),
                                                                budgetAccountModel.StatusDate,
                                                                budgetAccountModel.StatusDateForInfos);
                }

                if (budgetAccountModel.PostingLines != null)
                {
                    budgetAccount.PostingLineCollection.Add(budgetAccountModel.PostingLines
                                                            .Where(postingLineModel => postingLineModel.Convertible() &&
                                                                   postingLineModel.PostingDate >= budgetAccountModel.GetFromDateForPostingLines() &&
                                                                   postingLineModel.PostingDate < budgetAccountModel.GetToDateForPostingLines(1))
                                                            .Select(postingLineModel => postingLineModel.ToDomain(accounting, budgetAccount, mapperCache, accountingModelConverter))
                                                            .Where(postingLine => budgetAccount.PostingLineCollection.Contains(postingLine) == false)
                                                            .ToArray());
                }

                return(budgetAccount);
            }
        }
        public async Task QueryAsync_WhenCalled_ReturnsBudgetAccountGroupFromAccountingRepository()
        {
            IBudgetAccountGroup budgetAccountGroup = _fixture.Create <IBudgetAccountGroup>();
            QueryHandler        sut = CreateSut(budgetAccountGroup);

            IGetBudgetAccountGroupQuery query  = CreateQueryMock().Object;
            IBudgetAccountGroup         result = await sut.QueryAsync(query);

            Assert.That(result, Is.EqualTo(budgetAccountGroup));
        }
Exemplo n.º 10
0
        public async Task ExecuteAsync_WhenCalled_AssertUpdateBudgetAccountGroupAsyncWasCalledOnAccountingRepository()
        {
            CommandHandler sut = CreateSut();

            IBudgetAccountGroup budgetAccountGroup   = _fixture.BuildBudgetAccountGroupMock().Object;
            IUpdateBudgetAccountGroupCommand command = CreateCommandMock(budgetAccountGroup).Object;
            await sut.ExecuteAsync(command);

            _accountingRepositoryMock.Verify(m => m.UpdateBudgetAccountGroupAsync(It.Is <IBudgetAccountGroup>(value => value == budgetAccountGroup)), Times.Once);
        }
Exemplo n.º 11
0
        public Task <IBudgetAccountGroup> UpdateBudgetAccountGroupAsync(IBudgetAccountGroup budgetAccountGroup)
        {
            NullGuard.NotNull(budgetAccountGroup, nameof(budgetAccountGroup));

            return(ExecuteAsync(async() =>
            {
                using BudgetAccountGroupModelHandler budgetAccountGroupModelHandler = new BudgetAccountGroupModelHandler(DbContext, AccountingModelConverter.Create());
                return await budgetAccountGroupModelHandler.UpdateAsync(budgetAccountGroup);
            },
                                MethodBase.GetCurrentMethod()));
        }
        public async Task UpdateBudgetAccount_WhenCalledWithAccountingNumberAndAccountNumberForExistingBudgetAccount_ReturnsPartialViewResultWhereModelIsBudgetAccountViewModelWithBudgetAccountGroupMatchingBudgetAccountGroupOnBudgetAccountFromQueryBus()
        {
            int budgetAccountGroupNumber           = _fixture.Create <int>();
            IBudgetAccountGroup budgetAccountGroup = _fixture.BuildBudgetAccountGroupMock(budgetAccountGroupNumber).Object;
            IBudgetAccount      budgetAccount      = _fixture.BuildBudgetAccountMock(budgetAccountGroup: budgetAccountGroup).Object;
            Controller          sut = CreateSut(budgetAccount: budgetAccount);

            PartialViewResult result = (PartialViewResult)await sut.UpdateBudgetAccount(_fixture.Create <int>(), _fixture.Create <string>());

            BudgetAccountViewModel budgetAccountViewModel = (BudgetAccountViewModel)result.Model;

            Assert.That(budgetAccountViewModel.BudgetAccountGroup.Number, Is.EqualTo(budgetAccountGroupNumber));
        }
        private Controller CreateSut(IBudgetAccountGroup budgetAccountGroup = null, bool modelIsValid = true)
        {
            _commandBusMock.Setup(m => m.PublishAsync(It.IsAny <IUpdateBudgetAccountGroupCommand>()))
            .Returns(Task.Run(() => { }));

            _queryBusMock.Setup(m => m.QueryAsync <IGetBudgetAccountGroupQuery, IBudgetAccountGroup>(It.IsAny <IGetBudgetAccountGroupQuery>()))
            .Returns(Task.Run(() => budgetAccountGroup ?? _fixture.BuildBudgetAccountGroupMock().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 UpdateBudgetAccountGroup_WhenCalledWithNumber_ReturnsViewResultWhereModelIsBudgetAccountGroupViewModel()
        {
            int    number = _fixture.Create <int>();
            string name   = _fixture.Create <string>();
            IBudgetAccountGroup budgetAccountGroup = _fixture.BuildBudgetAccountGroupMock(number, name).Object;
            Controller          sut = CreateSut(budgetAccountGroup);

            ViewResult result = (ViewResult)await sut.UpdateBudgetAccountGroup(_fixture.Create <int>());

            Assert.That(result.Model, Is.TypeOf <BudgetAccountGroupViewModel>());

            BudgetAccountGroupViewModel budgetAccountGroupViewModel = (BudgetAccountGroupViewModel)result.Model;

            Assert.That(budgetAccountGroupViewModel, Is.Not.Null);
            Assert.That(budgetAccountGroupViewModel.Number, Is.EqualTo(number));
            Assert.That(budgetAccountGroupViewModel.Name, Is.EqualTo(name));
            Assert.That(budgetAccountGroupViewModel.EditMode, Is.EqualTo(EditMode.Edit));
        }
Exemplo n.º 15
0
        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);
        }
Exemplo n.º 16
0
        internal static IBudgetAccountGroup GetBudgetAccountGroup(this int number, IAccountingRepository accountingRepository, ref IBudgetAccountGroup budgetAccountGroup)
        {
            NullGuard.NotNull(accountingRepository, nameof(accountingRepository));

            return(budgetAccountGroup ??= accountingRepository.GetBudgetAccountGroupAsync(number).GetAwaiter().GetResult());
        }
Exemplo n.º 17
0
        private IBudgetAccountDataCommand 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?budgetAccountGroupNumber = null, IBudgetAccountGroup budgetAccountGroup = null, IEnumerable <IBudgetInfoCommand> budgetInfoCommandCollection = null)
        {
            _accountingRepositoryMock.Setup(m => m.GetAccountingAsync(It.IsAny <int>(), It.IsAny <DateTime>()))
            .Returns(Task.FromResult(accounting ?? _fixture.BuildAccountingMock().Object));
            _accountingRepositoryMock.Setup(m => m.GetBudgetAccountGroupAsync(It.IsAny <int>()))
            .Returns(Task.FromResult(budgetAccountGroup ?? _fixture.BuildBudgetAccountGroupMock().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.BudgetAccountGroupNumber, budgetAccountGroupNumber ?? _fixture.Create <int>())
                   .With(m => m.BudgetInfoCollection, budgetInfoCommandCollection ?? _fixture.CreateMany <IBudgetInfoCommand>(_random.Next(5, 10)).ToArray())
                   .Create());
        }
 public BudgetAccount(IAccounting accounting, string accountNumber, string accountName, IBudgetAccountGroup budgetAccountGroup)
     : this(accounting, accountNumber, accountName, budgetAccountGroup, new BudgetInfoCollection(), new PostingLineCollection())
 {
 }