private QueryHandler CreateSut(IPaymentTerm paymentTerm = null)
        {
            _accountingRepositoryMock.Setup(m => m.GetPaymentTermAsync(It.IsAny <int>()))
            .Returns(Task.Run(() => paymentTerm ?? _fixture.BuildPaymentTermMock().Object));

            return(new QueryHandler(_validatorMock.Object, _accountingRepositoryMock.Object));
        }
        public async Task GetPaymentTermAsync_WhenCalled_ReturnsPaymentTerm()
        {
            IAccountingRepository sut = CreateSut();

            IPaymentTerm result = await sut.GetPaymentTermAsync(1);

            Assert.That(result, Is.Not.Null);
        }
        public void ToDomain_WhenCalled_ReturnsPaymentTerm()
        {
            IPaymentTermCommand sut = CreateSut();

            IPaymentTerm result = sut.ToDomain();

            Assert.That(result, Is.TypeOf <Domain.Accounting.PaymentTerm>());
        }
Beispiel #4
0
        protected override async Task ManageRepositoryAsync(ICreatePaymentTermCommand command)
        {
            NullGuard.NotNull(command, nameof(command));

            IPaymentTerm paymentTerm = command.ToDomain();

            await AccountingRepository.CreatePaymentTermAsync(paymentTerm);
        }
Beispiel #5
0
        private Mock <IUpdatePaymentTermCommand> CreateCommandMock(IPaymentTerm paymentTerm = null)
        {
            Mock <IUpdatePaymentTermCommand> commandMock = new Mock <IUpdatePaymentTermCommand>();

            commandMock.Setup(m => m.ToDomain())
            .Returns(paymentTerm ?? _fixture.BuildPaymentTermMock().Object);
            return(commandMock);
        }
        public void ToDomain_WhenCalled_ReturnsContactWithPaymentTermFromAccountingRepository()
        {
            IPaymentTerm        paymentTerm = _fixture.BuildPaymentTermMock().Object;
            IContactDataCommand sut         = CreateSut(paymentTerm: paymentTerm);

            IPaymentTerm result = sut.ToDomain(_contactRepositoryMock.Object, _accountingRepositoryMock.Object).PaymentTerm;

            Assert.That(result, Is.EqualTo(paymentTerm));
        }
Beispiel #7
0
        public ContactAccount(IAccounting accounting, string accountNumber, string accountName, IPaymentTerm paymentTerm, IContactInfoCollection contactInfoCollection, IPostingLineCollection postingLineCollection)
            : base(accounting, accountNumber, accountName, postingLineCollection)
        {
            NullGuard.NotNull(paymentTerm, nameof(paymentTerm))
            .NotNull(contactInfoCollection, nameof(contactInfoCollection));

            PaymentTerm           = paymentTerm;
            ContactInfoCollection = contactInfoCollection;
        }
Beispiel #8
0
        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));
        }
Beispiel #9
0
        public async Task ExecuteAsync_WhenCalled_AssertUpdatePaymentTermAsyncWasCalledOnAccountingRepository()
        {
            CommandHandler sut = CreateSut();

            IPaymentTerm paymentTerm          = _fixture.BuildPaymentTermMock().Object;
            IUpdatePaymentTermCommand command = CreateCommandMock(paymentTerm).Object;
            await sut.ExecuteAsync(command);

            _accountingRepositoryMock.Verify(m => m.UpdatePaymentTermAsync(It.Is <IPaymentTerm>(value => value == paymentTerm)), Times.Once);
        }
        public async Task QueryAsync_WhenCalled_ReturnsPaymentTermFromAccountingRepository()
        {
            IPaymentTerm paymentTerm = _fixture.BuildPaymentTermMock().Object;
            QueryHandler sut         = CreateSut(paymentTerm);

            IGetPaymentTermQuery query  = CreateQueryMock().Object;
            IPaymentTerm         result = await sut.QueryAsync(query);

            Assert.That(result, Is.EqualTo(paymentTerm));
        }
Beispiel #11
0
        public Task <IPaymentTerm> UpdatePaymentTermAsync(IPaymentTerm paymentTerm)
        {
            NullGuard.NotNull(paymentTerm, nameof(paymentTerm));

            return(ExecuteAsync(async() =>
            {
                using PaymentTermModelHandler paymentTermModelHandler = new PaymentTermModelHandler(DbContext, AccountingModelConverter.Create());
                return await paymentTermModelHandler.UpdateAsync(paymentTerm);
            },
                                MethodBase.GetCurrentMethod()));
        }
        public async Task LoadContact_WhenCountryAndContactWithPaymentTermWasReturnedFromQueryBus_ReturnsPartialViewResultWhereModelIsContactViewModelWherePaymentTermIsMapped()
        {
            IPaymentTerm paymentTerm = _fixture.BuildPaymentTermMock().Object;
            IContact     contact     = _fixture.BuildContactMock(paymentTerm: paymentTerm).Object;
            Controller   sut         = CreateSut(contact: contact);

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

            ContactViewModel contactViewModel = (ContactViewModel)result.Model;

            Assert.That(contactViewModel.PaymentTerm.Number, Is.EqualTo(paymentTerm.Number));
        }
Beispiel #13
0
        private void AddColumns(IPaymentTerm paymentTerm)
        {
            if (paymentTerm != null)
            {
                AddColumnValue(paymentTerm.Number)
                .AddColumnValue(paymentTerm.Name);
                return;
            }

            AddEmptyColumn()
            .AddEmptyColumn();
        }
        public virtual IContact ToDomain(IContactRepository contactRepository, IAccountingRepository accountingRepository)
        {
            NullGuard.NotNull(contactRepository, nameof(contactRepository))
            .NotNull(accountingRepository, nameof(accountingRepository));

            IName    name    = Name?.ToDomain();
            IAddress address = Address != null && Address.IsEmpty() == false?Address.ToDomain() : null;

            IContactGroup contactGroup = GetContactGroupAsync(contactRepository).GetAwaiter().GetResult();
            IPaymentTerm  paymentTerm  = GetPaymentTermAsync(accountingRepository).GetAwaiter().GetResult();

            return(FillContact(address == null ? new Contact(name) : new Contact(name, address), contactGroup, paymentTerm));
        }
        public async Task UpdateContactAccount_WhenCalledWithAccountingNumberAndAccountNumberForExistingContactAccount_ReturnsPartialViewResultWhereModelIsContactAccountViewModelWithPaymentTermMatchingPaymentTermOnContactAccountFromQueryBus()
        {
            int             paymentTermNumber = _fixture.Create <int>();
            IPaymentTerm    paymentTerm       = _fixture.BuildPaymentTermMock(paymentTermNumber).Object;
            IContactAccount contactAccount    = _fixture.BuildContactAccountMock(paymentTerm: paymentTerm).Object;
            Controller      sut = CreateSut(contactAccount: contactAccount);

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

            ContactAccountViewModel contactAccountViewModel = (ContactAccountViewModel)result.Model;

            Assert.That(contactAccountViewModel.PaymentTerm.Number, Is.EqualTo(paymentTermNumber));
        }
Beispiel #16
0
        private Controller CreateSut(IPaymentTerm paymentTerm = null, bool modelIsValid = true)
        {
            _queryBusMock.Setup(m => m.QueryAsync <IGetPaymentTermQuery, IPaymentTerm>(It.IsAny <IGetPaymentTermQuery>()))
            .Returns(Task.Run(() => paymentTerm ?? _fixture.BuildPaymentTermMock().Object));
            _commandBusMock.Setup(m => m.PublishAsync(It.IsAny <IUpdatePaymentTermCommand>()))
            .Returns(Task.Run(() => { }));

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

            if (modelIsValid == false)
            {
                controller.ModelState.AddModelError(_fixture.Create <string>(), _fixture.Create <string>());
            }
            return(controller);
        }
        internal static IContactAccount ToDomain(this ContactAccountModel contactAccountModel, IAccounting accounting, MapperCache mapperCache, IConverter accountingModelConverter)
        {
            NullGuard.NotNull(contactAccountModel, nameof(contactAccountModel))
            .NotNull(accounting, nameof(accounting))
            .NotNull(mapperCache, nameof(mapperCache))
            .NotNull(accountingModelConverter, nameof(accountingModelConverter));

            lock (mapperCache.SyncRoot)
            {
                IContactAccount contactAccount = contactAccountModel.Resolve(mapperCache.ContactAccountDictionary);
                if (contactAccount != null)
                {
                    return(contactAccount);
                }

                IPaymentTerm paymentTerm = accountingModelConverter.Convert <PaymentTermModel, IPaymentTerm>(contactAccountModel.PaymentTerm);

                contactAccount = new ContactAccount(accounting, contactAccountModel.AccountNumber, contactAccountModel.BasicAccount.AccountName, paymentTerm)
                {
                    Description    = contactAccountModel.BasicAccount.Description,
                    Note           = contactAccountModel.BasicAccount.Note,
                    MailAddress    = contactAccountModel.MailAddress,
                    PrimaryPhone   = contactAccountModel.PrimaryPhone,
                    SecondaryPhone = contactAccountModel.SecondaryPhone
                };
                contactAccountModel.CopyAuditInformationTo(contactAccount);
                contactAccount.SetDeletable(contactAccountModel.Deletable);

                mapperCache.ContactAccountDictionary.Add(contactAccountModel.ContactAccountIdentifier, contactAccount);

                accounting.ContactAccountCollection.Add(contactAccount);

                contactAccount.ContactInfoCollection.Populate(contactAccount, contactAccountModel.StatusDate, contactAccountModel.StatusDateForInfos);

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

                return(contactAccount);
            }
        }
Beispiel #18
0
        public override IContactAccount ToDomain(IAccountingRepository accountingRepository)
        {
            NullGuard.NotNull(accountingRepository, nameof(accountingRepository));

            IAccounting  accounting  = GetAccountingAsync(accountingRepository).GetAwaiter().GetResult();
            IPaymentTerm paymentTerm = GetPaymentTermAsync(accountingRepository).GetAwaiter().GetResult();

            return(new ContactAccount(accounting, AccountNumber, AccountName, paymentTerm)
            {
                Description = Description,
                Note = Note,
                MailAddress = MailAddress,
                PrimaryPhone = PrimaryPhone,
                SecondaryPhone = SecondaryPhone
            });
        }
Beispiel #19
0
        public async Task UpdatePaymentTerm_WhenCalledWithNumber_ReturnsViewResultWhereModelIsPaymentTermViewModel()
        {
            int          number      = _fixture.Create <int>();
            string       name        = _fixture.Create <string>();
            IPaymentTerm paymentTerm = _fixture.BuildPaymentTermMock(number, name).Object;
            Controller   sut         = CreateSut(paymentTerm);

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

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

            PaymentTermViewModel paymentTermViewModel = (PaymentTermViewModel)result.Model;

            Assert.That(paymentTermViewModel, Is.Not.Null);
            Assert.That(paymentTermViewModel.Number, Is.EqualTo(number));
            Assert.That(paymentTermViewModel.Name, Is.EqualTo(name));
            Assert.That(paymentTermViewModel.EditMode, Is.EqualTo(EditMode.Edit));
        }
        private IContact FillContact(IContact contact, IContactGroup contactGroup, IPaymentTerm paymentTerm)
        {
            NullGuard.NotNull(contact, nameof(contact))
            .NotNull(contactGroup, nameof(contactGroup))
            .NotNull(paymentTerm, nameof(paymentTerm));

            contact.HomePhone        = string.IsNullOrWhiteSpace(HomePhone) ? null : HomePhone;
            contact.MobilePhone      = string.IsNullOrWhiteSpace(MobilePhone) ? null : MobilePhone;
            contact.Birthday         = Birthday?.Date;
            contact.MailAddress      = string.IsNullOrWhiteSpace(MailAddress) ? null : MailAddress;
            contact.Company          = Company?.ToDomain();
            contact.ContactGroup     = contactGroup;
            contact.Acquaintance     = string.IsNullOrWhiteSpace(Acquaintance) ? null : Acquaintance;
            contact.PersonalHomePage = string.IsNullOrWhiteSpace(PersonalHomePage) ? null : PersonalHomePage;
            contact.LendingLimit     = LendingLimit;
            contact.PaymentTerm      = paymentTerm;

            return(contact);
        }
        internal static IPaymentTerm GetPaymentTerm(this int number, IAccountingRepository accountingRepository, ref IPaymentTerm paymentTerm)
        {
            NullGuard.NotNull(accountingRepository, nameof(accountingRepository));

            return(paymentTerm ??= accountingRepository.GetPaymentTermAsync(number).GetAwaiter().GetResult());
        }
Beispiel #22
0
        public static Mock <IContact> BuildContactMock(this Fixture fixture, bool hasInternalIdentifier = true, string internalIdentifier = null, bool hasExternalIdentifier = true, string externalIdentifier = null, bool hasAddress = true, IAddress address = null, bool hasBirthday = true, DateTime?birthday = null, bool hasCompany = true, ICompany company = null, bool hasContactGroup = true, IContactGroup contactGroup = null, bool hasPaymentTerm = true, IPaymentTerm paymentTerm = null, bool?isMatch = null, bool?hasBirthdayWithinDays = null)
        {
            NullGuard.NotNull(fixture, nameof(fixture));

            Random random = new Random(fixture.Create <int>());

            Mock <IContact> contactMock = new Mock <IContact>();

            contactMock.Setup(m => m.InternalIdentifier)
            .Returns(hasInternalIdentifier ? internalIdentifier ?? fixture.Create <string>() : null);
            contactMock.Setup(m => m.ExternalIdentifier)
            .Returns(hasExternalIdentifier ? externalIdentifier ?? fixture.Create <string>() : null);
            contactMock.Setup(m => m.Name)
            .Returns(fixture.BuildNameMock().Object);
            contactMock.Setup(m => m.Address)
            .Returns(hasAddress ? address ?? fixture.BuildAddressMock().Object : null);
            contactMock.Setup(m => m.PrimaryPhone)
            .Returns(fixture.Create <string>());
            contactMock.Setup(m => m.SecondaryPhone)
            .Returns(fixture.Create <string>());
            contactMock.Setup(m => m.HomePhone)
            .Returns(fixture.Create <string>());
            contactMock.Setup(m => m.MobilePhone)
            .Returns(fixture.Create <string>());
            contactMock.Setup(m => m.Birthday)
            .Returns(hasBirthday ? birthday ?? DateTime.Today.AddYears(random.Next(10, 75) * -1).AddDays(random.Next(0, 365)) : (DateTime?)null);
            contactMock.Setup(m => m.Age)
            .Returns(hasBirthday ? (ushort?)random.Next(10, 75) : null);
            contactMock.Setup(m => m.MailAddress)
            .Returns(fixture.Create <string>());
            contactMock.Setup(m => m.Company)
            .Returns(hasCompany ? company ?? fixture.BuildCompanyMock().Object : null);
            contactMock.Setup(m => m.ContactGroup)
            .Returns(hasContactGroup ? contactGroup ?? fixture.BuildContactGroupMock().Object : null);
            contactMock.Setup(m => m.Acquaintance)
            .Returns(fixture.Create <string>());
            contactMock.Setup(m => m.PersonalHomePage)
            .Returns(fixture.Create <string>());
            contactMock.Setup(m => m.LendingLimit)
            .Returns(fixture.Create <int>());
            contactMock.Setup(m => m.PaymentTerm)
            .Returns(hasPaymentTerm ? paymentTerm ?? fixture.BuildPaymentTermMock().Object : null);
            contactMock.Setup(m => m.CreatedByIdentifier)
            .Returns(fixture.Create <string>());
            contactMock.Setup(m => m.CreatedDateTime)
            .Returns(fixture.Create <DateTime>());
            contactMock.Setup(m => m.ModifiedByIdentifier)
            .Returns(fixture.Create <string>());
            contactMock.Setup(m => m.ModifiedDateTime)
            .Returns(fixture.Create <DateTime>());
            contactMock.Setup(m => m.IsMatch(It.IsAny <string>(), It.IsAny <SearchOptions>()))
            .Returns(isMatch ?? fixture.Create <bool>());
            contactMock.Setup(m => m.HasBirthdayWithinDays(It.IsAny <int>()))
            .Returns(hasBirthdayWithinDays ?? fixture.Create <bool>());
            return(contactMock);
        }
Beispiel #23
0
        private IContactAccountDataCommand 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, bool hasMailAddress = true, string mailAddress = null, bool hasPrimaryPhone = true, string primaryPhone = null, bool hasSecondaryPhone = true, string secondaryPhone = null, int?paymentTermNumber = null, IPaymentTerm paymentTerm = null)
        {
            _accountingRepositoryMock.Setup(m => m.GetAccountingAsync(It.IsAny <int>(), It.IsAny <DateTime>()))
            .Returns(Task.FromResult(accounting ?? _fixture.BuildAccountingMock().Object));
            _accountingRepositoryMock.Setup(m => m.GetPaymentTermAsync(It.IsAny <int>()))
            .Returns(Task.FromResult(paymentTerm ?? _fixture.BuildPaymentTermMock().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.MailAddress, hasMailAddress ? mailAddress ?? _fixture.Create <string>() : null)
                   .With(m => m.PrimaryPhone, hasPrimaryPhone ? primaryPhone ?? _fixture.Create <string>() : null)
                   .With(m => m.SecondaryPhone, hasSecondaryPhone ?  secondaryPhone ?? _fixture.Create <string>() : null)
                   .With(m => m.PaymentTermNumber, paymentTermNumber ?? _fixture.Create <int>())
                   .Create());
        }
        private IContactDataCommand CreateSut(INameCommand nameCommand = null, bool hasAddressCommand = true, IAddressCommand addressCommand = null, bool hasHomePhone = true, string homePhone = null, bool hasMobilePhone = true, string mobilePhone = null, bool hasBirthday = true, DateTime?birthday = null, bool hasMailAddress = true, string mailAddress = null, bool hasCompanyCommand = true, ICompanyCommand companyCommand = null, int?contactGroupIdentifier = null, IContactGroup contactGroup = null, int?paymentTermIdentifier = null, bool hasAcquaintance = true, string acquaintance = null, bool hasPersonalHomePage = true, string personalHomePage = null, int?lendingLimit = null, IPaymentTerm paymentTerm = null)
        {
            _contactRepositoryMock.Setup(m => m.GetContactGroupAsync(It.IsAny <int>()))
            .Returns(Task.Run(() => contactGroup ?? _fixture.BuildContactGroupMock().Object));
            _accountingRepositoryMock.Setup(m => m.GetPaymentTermAsync(It.IsAny <int>()))
            .Returns(Task.Run(() => paymentTerm ?? _fixture.BuildPaymentTermMock().Object));

            return(_fixture.Build <Sut>()
                   .With(m => m.Name, nameCommand ?? CreateNameCommandMock().Object)
                   .With(m => m.Address, hasAddressCommand ? addressCommand ?? CreateAddressCommandMock().Object : null)
                   .With(m => m.HomePhone, hasHomePhone ? homePhone ?? _fixture.Create <string>() : null)
                   .With(m => m.MobilePhone, hasMobilePhone ? mobilePhone ?? _fixture.Create <string>() : null)
                   .With(m => m.Birthday, hasBirthday ? birthday ?? _fixture.Create <DateTime>() : (DateTime?)null)
                   .With(m => m.MailAddress, hasMailAddress ? mailAddress ?? _fixture.Create <string>() : null)
                   .With(m => m.Company, hasCompanyCommand ? companyCommand ?? CreateCompanyCommandMock().Object : null)
                   .With(m => m.ContactGroupIdentifier, contactGroupIdentifier ?? _fixture.Create <int>())
                   .With(m => m.Acquaintance, hasAcquaintance ? acquaintance ?? _fixture.Create <string>() : null)
                   .With(m => m.PersonalHomePage, hasPersonalHomePage ? personalHomePage ?? _fixture.Create <string>() : null)
                   .With(m => m.LendingLimit, lendingLimit ?? _fixture.Create <int>())
                   .With(m => m.PaymentTermIdentifier, paymentTermIdentifier ?? _fixture.Create <int>())
                   .Create());
        }
Beispiel #25
0
 public ContactAccount(IAccounting accounting, string accountNumber, string accountName, IPaymentTerm paymentTerm)
     : this(accounting, accountNumber, accountName, paymentTerm, new ContactInfoCollection(), new PostingLineCollection())
 {
 }