private QueryHandler CreateSut(ILetterHead letterHead = null)
        {
            _commonRepositoryMock.Setup(m => m.GetLetterHeadAsync(It.IsAny <int>()))
            .Returns(Task.Run(() => letterHead ?? _fixture.BuildLetterHeadMock().Object));

            return(new QueryHandler(_validatorMock.Object, _commonRepositoryMock.Object));
        }
示例#2
0
        public async Task UpdateLetterHead_WhenCalledWithNumber_ReturnsViewResultWhereModelIsLetterHeadViewModel()
        {
            int         number = _fixture.Create <int>();
            string      name   = _fixture.Create <string>();
            string      line1  = _fixture.Create <string>();
            string      line2  = _fixture.Create <string>();
            string      line3  = _fixture.Create <string>();
            string      line4  = _fixture.Create <string>();
            string      line5  = _fixture.Create <string>();
            string      line6  = _fixture.Create <string>();
            string      line7  = _fixture.Create <string>();
            string      companyIdentificationNumber = _fixture.Create <string>();
            ILetterHead letterHead = _fixture.BuildLetterHeadMock(number, name, line1, line2, line3, line4, line5, line6, line7, companyIdentificationNumber).Object;
            Controller  sut        = CreateSut(letterHead);

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

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

            LetterHeadViewModel letterHeadViewModel = (LetterHeadViewModel)result.Model;

            Assert.That(letterHeadViewModel, Is.Not.Null);
            Assert.That(letterHeadViewModel.Number, Is.EqualTo(number));
            Assert.That(letterHeadViewModel.Name, Is.EqualTo(name));
            Assert.That(letterHeadViewModel.Line1, Is.EqualTo(line1));
            Assert.That(letterHeadViewModel.Line2, Is.EqualTo(line2));
            Assert.That(letterHeadViewModel.Line3, Is.EqualTo(line3));
            Assert.That(letterHeadViewModel.Line4, Is.EqualTo(line4));
            Assert.That(letterHeadViewModel.Line5, Is.EqualTo(line5));
            Assert.That(letterHeadViewModel.Line6, Is.EqualTo(line6));
            Assert.That(letterHeadViewModel.Line7, Is.EqualTo(line7));
            Assert.That(letterHeadViewModel.CompanyIdentificationNumber, Is.EqualTo(companyIdentificationNumber));
            Assert.That(letterHeadViewModel.EditMode, Is.EqualTo(EditMode.Edit));
        }
示例#3
0
        public IAccounting ToDomain(ICommonRepository commonRepository)
        {
            NullGuard.NotNull(commonRepository, nameof(commonRepository));

            ILetterHead letterHead = GetLetterHead(commonRepository).GetAwaiter().GetResult();

            return(new Domain.Accounting.Accounting(AccountingNumber, Name, letterHead, BalanceBelowZero, BackDating));
        }
        public void ToDomain_WhenCalled_ReturnsLetterHead()
        {
            ILetterHeadCommand sut = CreateSut();

            ILetterHead result = sut.ToDomain();

            Assert.That(result, Is.TypeOf <LetterHead>());
        }
示例#5
0
        private Mock <ICreateLetterHeadCommand> CreateCommandMock(ILetterHead letterHead = null)
        {
            Mock <ICreateLetterHeadCommand> commandMock = new Mock <ICreateLetterHeadCommand>();

            commandMock.Setup(m => m.ToDomain())
            .Returns(letterHead ?? _fixture.BuildLetterHeadMock().Object);
            return(commandMock);
        }
示例#6
0
        public async Task GetLetterHeadAsync_WhenCalled_ReturnsLetterHead()
        {
            ICommonRepository sut = CreateSut();

            ILetterHead result = await sut.GetLetterHeadAsync(1);

            Assert.That(result, Is.Not.Null);
        }
        protected override async Task ManageRepositoryAsync(IUpdateLetterHeadCommand command)
        {
            NullGuard.NotNull(command, nameof(command));

            ILetterHead letterHead = command.ToDomain();

            await CommonRepository.UpdateLetterHeadAsync(letterHead);
        }
        public void ToDomain_WhenCalled_ReturnsLetterHeadWithLine4FromCommand()
        {
            string             line4 = _fixture.Create <string>();
            ILetterHeadCommand sut   = CreateSut(line4: line4);

            ILetterHead result = sut.ToDomain();

            Assert.That(result.Line4, Is.EqualTo(line4));
        }
        public void ToDomain_WhenCalled_ReturnsLetterHeadWithNameFromCommand()
        {
            string             name = _fixture.Create <string>();
            ILetterHeadCommand sut  = CreateSut(name: name);

            ILetterHead result = sut.ToDomain();

            Assert.That(result.Name, Is.EqualTo(name));
        }
        public void ToDomain_WhenCalled_ReturnsLetterHeadWithNumberFromCommand()
        {
            int number             = _fixture.Create <int>();
            ILetterHeadCommand sut = CreateSut(number);

            ILetterHead result = sut.ToDomain();

            Assert.That(result.Number, Is.EqualTo(number));
        }
        public void ToDomain_WhenCalled_ReturnsLetterHeadWithCompanyIdentificationNumberFromCommand()
        {
            string             companyIdentificationNumber = _fixture.Create <string>();
            ILetterHeadCommand sut = CreateSut(companyIdentificationNumber: companyIdentificationNumber);

            ILetterHead result = sut.ToDomain();

            Assert.That(result.CompanyIdentificationNumber, Is.EqualTo(companyIdentificationNumber));
        }
示例#12
0
        public void ToDomain_WhenCalled_ReturnsAccountingWithLetterHeadFromCommonRepository()
        {
            ILetterHead        letterHead = _fixture.BuildLetterHeadMock().Object;
            IAccountingCommand sut        = CreateSut(letterHead: letterHead);

            ILetterHead result = sut.ToDomain(_commonRepositoryMock.Object).LetterHead;

            Assert.That(result, Is.EqualTo(letterHead));
        }
示例#13
0
        public async Task ExecuteAsync_WhenCalled_AssertCreateLetterHeadAsyncWasCalledOnCommonRepository()
        {
            CommandHandler sut = CreateSut();

            ILetterHead letterHead           = _fixture.BuildLetterHeadMock().Object;
            ICreateLetterHeadCommand command = CreateCommandMock(letterHead).Object;
            await sut.ExecuteAsync(command);

            _commonRepositoryMock.Verify(m => m.CreateLetterHeadAsync(It.Is <ILetterHead>(value => value == letterHead)), Times.Once);
        }
        public async Task QueryAsync_WhenCalled_ReturnsLetterHeadFromCommonRepository()
        {
            ILetterHead  letterHead = _fixture.BuildLetterHeadMock().Object;
            QueryHandler sut        = CreateSut(letterHead);

            IGetLetterHeadQuery query  = CreateQueryMock().Object;
            ILetterHead         result = await sut.QueryAsync(query);

            Assert.That(result, Is.EqualTo(letterHead));
        }
        public Task <ILetterHead> UpdateLetterHeadAsync(ILetterHead letterHead)
        {
            NullGuard.NotNull(letterHead, nameof(letterHead));

            return(ExecuteAsync(async() =>
            {
                using LetterHeadModelHandler letterHeadModelHandler = new LetterHeadModelHandler(DbContext, CommonModelConverter.Create());
                return await letterHeadModelHandler.UpdateAsync(letterHead);
            },
                                MethodBase.GetCurrentMethod()));
        }
        internal static IAccounting ToDomain(this AccountingModel accountingModel, MapperCache mapperCache, IConverter accountingModelConverter, IConverter commonModelConverter)
        {
            NullGuard.NotNull(accountingModel, nameof(accountingModel))
            .NotNull(mapperCache, nameof(mapperCache))
            .NotNull(accountingModelConverter, nameof(accountingModelConverter))
            .NotNull(commonModelConverter, nameof(commonModelConverter));

            lock (mapperCache.SyncRoot)
            {
                if (mapperCache.AccountingDictionary.TryGetValue(accountingModel.AccountingIdentifier, out IAccounting accounting))
                {
                    return(accounting);
                }

                ILetterHead letterHead = commonModelConverter.Convert <LetterHeadModel, ILetterHead>(accountingModel.LetterHead);

                accounting = new Domain.Accounting.Accounting(accountingModel.AccountingIdentifier, accountingModel.Name, letterHead, accountingModel.BalanceBelowZero, accountingModel.BackDating);
                accounting.AddAuditInformation(accountingModel.CreatedUtcDateTime, accountingModel.CreatedByIdentifier, accountingModel.ModifiedUtcDateTime, accountingModel.ModifiedByIdentifier);
                accounting.SetDeletable(accountingModel.Deletable);

                mapperCache.AccountingDictionary.Add(accounting.Number, accounting);

                if (accountingModel.Accounts != null)
                {
                    accounting.AccountCollection.Add(accountingModel.Accounts
                                                     .Where(accountModel => accountModel.Convertible())
                                                     .Select(accountModel => accountModel.ToDomain(accounting, mapperCache, accountingModelConverter))
                                                     .Where(account => accounting.AccountCollection.Contains(account) == false)
                                                     .ToArray());
                }

                if (accountingModel.BudgetAccounts != null)
                {
                    accounting.BudgetAccountCollection.Add(accountingModel.BudgetAccounts
                                                           .Where(budgetAccountModel => budgetAccountModel.Convertible())
                                                           .Select(budgetAccountModel => budgetAccountModel.ToDomain(accounting, mapperCache, accountingModelConverter))
                                                           .Where(budgetAccount => accounting.BudgetAccountCollection.Contains(budgetAccount) == false)
                                                           .ToArray());
                }

                if (accountingModel.ContactAccounts != null)
                {
                    accounting.ContactAccountCollection.Add(accountingModel.ContactAccounts
                                                            .Where(contactAccountModel => contactAccountModel.Convertible())
                                                            .Select(contactAccountModel => contactAccountModel.ToDomain(accounting, mapperCache, accountingModelConverter))
                                                            .Where(contactAccount => accounting.ContactAccountCollection.Contains(contactAccount) == false)
                                                            .ToArray());
                }

                return(accounting);
            }
        }
示例#17
0
        public async Task <IActionResult> UpdateLetterHead(int number)
        {
            IGetLetterHeadQuery query = new GetLetterHeadQuery
            {
                Number = number
            };
            ILetterHead letterHead = await _queryBus.QueryAsync <IGetLetterHeadQuery, ILetterHead>(query);

            LetterHeadViewModel letterHeadViewModel = _commonViewModelConverter.Convert <ILetterHead, LetterHeadViewModel>(letterHead);

            letterHeadViewModel.EditMode = EditMode.Edit;

            return(View("UpdateLetterHead", letterHeadViewModel));
        }
示例#18
0
        private Controller CreateSut(ILetterHead letterHead = null, bool modelIsValid = true)
        {
            _queryBusMock.Setup(m => m.QueryAsync <IGetLetterHeadQuery, ILetterHead>(It.IsAny <IGetLetterHeadQuery>()))
            .Returns(Task.Run(() => letterHead ?? _fixture.BuildLetterHeadMock().Object));

            _commandBusMock.Setup(m => m.PublishAsync(It.IsAny <IUpdateLetterHeadCommand>()))
            .Returns(Task.Run(() => { }));

            Controller controller = new Controller(_commandBusMock.Object, _queryBusMock.Object);

            if (modelIsValid == false)
            {
                controller.ModelState.AddModelError(_fixture.Create <string>(), _fixture.Create <string>());
            }
            return(controller);
        }
        public Accounting(int number, string name, ILetterHead letterHead, BalanceBelowZeroType balanceBelowZero, int backDating, IAccountCollection accountCollection, IBudgetAccountCollection budgetAccountCollection, IContactAccountCollection contactAccountCollection)
        {
            NullGuard.NotNullOrWhiteSpace(name, nameof(name))
            .NotNull(letterHead, nameof(letterHead))
            .NotNull(accountCollection, nameof(accountCollection))
            .NotNull(budgetAccountCollection, nameof(budgetAccountCollection))
            .NotNull(contactAccountCollection, nameof(contactAccountCollection));

            Number                   = number;
            Name                     = name.Trim();
            LetterHead               = letterHead;
            BalanceBelowZero         = balanceBelowZero;
            BackDating               = backDating;
            AccountCollection        = accountCollection;
            BudgetAccountCollection  = budgetAccountCollection;
            ContactAccountCollection = contactAccountCollection;
        }
示例#20
0
        internal static ILetterHead GetLetterHead(this int number, ICommonRepository commonRepository, ref ILetterHead letterHead)
        {
            NullGuard.NotNull(commonRepository, nameof(commonRepository));

            return(letterHead ??= commonRepository.GetLetterHeadAsync(number).GetAwaiter().GetResult());
        }
示例#21
0
        private IAccountingCommand CreateSut(int?accountingNumber = null, string name = null, int?letterHeadNumber = null, ILetterHead letterHead = null, BalanceBelowZeroType?balanceBelowZero = null, int?backDating = null)
        {
            _commonRepositoryMock.Setup(m => m.GetLetterHeadAsync(It.IsAny <int>()))
            .Returns(Task.Run(() => letterHead ?? _fixture.BuildLetterHeadMock().Object));

            return(_fixture.Build <Sut>()
                   .With(m => m.AccountingNumber, accountingNumber ?? _fixture.Create <int>())
                   .With(m => m.Name, name ?? _fixture.Create <string>())
                   .With(m => m.LetterHeadNumber, letterHeadNumber ?? _fixture.Create <int>())
                   .With(m => m.BalanceBelowZero, balanceBelowZero ?? _fixture.Create <BalanceBelowZeroType>())
                   .With(m => m.BackDating, backDating ?? _fixture.Create <int>())
                   .Create());
        }
 public Accounting(int number, string name, ILetterHead letterHead, BalanceBelowZeroType balanceBelowZero, int backDating)
     : this(number, name, letterHead, balanceBelowZero, backDating, new AccountCollection(), new BudgetAccountCollection(), new ContactAccountCollection())
 {
 }
 public Accounting(int number, string name, ILetterHead letterHead)
     : this(number, name, letterHead, BalanceBelowZeroType.Creditors, 30)
 {
 }