Beispiel #1
0
        public async Task CreateContactAccount_WhenCalledWithAccountingNumberForExistingAccounting_ReturnsPartialViewResultWhereModelIsContactAccountViewModelWithBalanceInfosContainingDataForNextYear()
        {
            Controller sut = CreateSut();

            PartialViewResult result = (PartialViewResult)await sut.CreateContactAccount(_fixture.Create <int>());

            ContactAccountViewModel contactAccountViewModel = (ContactAccountViewModel)result.Model;

            short nextYear     = (short)(DateTime.Today.Year + 1);
            short currentMonth = (short)DateTime.Today.Month;

            if (currentMonth == 1)
            {
                Assert.That(contactAccountViewModel.BalanceInfos.ContainsKey(nextYear), Is.False);

                return;
            }

            Assert.That(contactAccountViewModel.BalanceInfos.ContainsKey(nextYear), Is.True);

            BalanceInfoCollectionViewModel balanceInfoCollectionViewModel = contactAccountViewModel.BalanceInfos[nextYear];

            Assert.That(balanceInfoCollectionViewModel, Is.Not.Null);
            Assert.That(balanceInfoCollectionViewModel.Count, Is.EqualTo(currentMonth - 1));
            for (short month = 1; month < currentMonth; month++)
            {
                BalanceInfoViewModel balanceInfoViewModel = balanceInfoCollectionViewModel.Single(m => m.Year == nextYear && m.Month == month);
                Assert.That(balanceInfoViewModel.EditMode, Is.EqualTo(EditMode.Create));
                Assert.That(balanceInfoViewModel.Balance, Is.EqualTo(0M));
            }
        }
        public async Task UpdateContactAccount_WhenCalledWithAccountingNumberAndAccountNumberForExistingContactAccount_ReturnsPartialViewResultWhereModelIsContactAccountViewModelWithPostingLinesNotEqualToNull()
        {
            Controller sut = CreateSut();

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

            ContactAccountViewModel contactAccountViewModel = (ContactAccountViewModel)result.Model;

            Assert.That(contactAccountViewModel.PostingLines, Is.Not.Null);
        }
        public async Task UpdateContactAccount_WhenContactAccountViewModelIsValid_ReturnsNotNull()
        {
            Controller sut = CreateSut();

            ContactAccountViewModel contactAccountViewModel = CreateContactAccountViewModel();

            IActionResult result = await sut.UpdateContactAccount(contactAccountViewModel);

            Assert.That(result, Is.Not.Null);
        }
        public async Task UpdateContactAccount_WhenContactAccountViewModelIsValid_ReturnsRedirectToActionResultWhereRouteValuesContainsAccountingNumber()
        {
            Controller sut = CreateSut();

            ContactAccountViewModel contactAccountViewModel = CreateContactAccountViewModel();

            RedirectToActionResult result = (RedirectToActionResult)await sut.UpdateContactAccount(contactAccountViewModel);

            Assert.That(result.RouteValues.ContainsKey("accountingNumber"), Is.True);
        }
        public async Task UpdateContactAccount_WhenContactAccountViewModelIsValid_ReturnsRedirectToActionResultWhereActionNameIsEqualToAccountings()
        {
            Controller sut = CreateSut();

            ContactAccountViewModel contactAccountViewModel = CreateContactAccountViewModel();

            RedirectToActionResult result = (RedirectToActionResult)await sut.UpdateContactAccount(contactAccountViewModel);

            Assert.That(result.ActionName, Is.EqualTo("Accountings"));
        }
Beispiel #6
0
        public async Task CreateContactAccount_WhenCalledWithAccountingNumberForExistingAccounting_ReturnsPartialViewResultWhereModelIsContactAccountViewModelWithEditModeEqualToCreate()
        {
            Controller sut = CreateSut();

            PartialViewResult result = (PartialViewResult)await sut.CreateContactAccount(_fixture.Create <int>());

            ContactAccountViewModel contactAccountViewModel = (ContactAccountViewModel)result.Model;

            Assert.That(contactAccountViewModel.EditMode, Is.EqualTo(EditMode.Create));
        }
Beispiel #7
0
        public async Task CreateContactAccount_WhenCalledWithAccountingNumberForExistingAccounting_ReturnsPartialViewResultWhereModelIsContactAccountViewModelWithPaymentTermsNotEqualToNull()
        {
            Controller sut = CreateSut();

            PartialViewResult result = (PartialViewResult)await sut.CreateContactAccount(_fixture.Create <int>());

            ContactAccountViewModel contactAccountViewModel = (ContactAccountViewModel)result.Model;

            Assert.That(contactAccountViewModel.PaymentTerms, Is.Not.Null);
        }
Beispiel #8
0
        public async Task CreateContactAccount_WhenCalledWithAccountingNumberForExistingAccounting_ReturnsPartialViewResultWhereModelIsContactAccountViewModelWithValuesAtEndOfLastYearFromStatusDateEqualToNull()
        {
            Controller sut = CreateSut();

            PartialViewResult result = (PartialViewResult)await sut.CreateContactAccount(_fixture.Create <int>());

            ContactAccountViewModel contactAccountViewModel = (ContactAccountViewModel)result.Model;

            Assert.That(contactAccountViewModel.ValuesAtEndOfLastYearFromStatusDate, Is.Null);
        }
        public async Task UpdateContactAccount_WhenContactAccountViewModelIsValid_ReturnsRedirectToActionResultWhereRouteValuesIsNotNull()
        {
            Controller sut = CreateSut();

            ContactAccountViewModel contactAccountViewModel = CreateContactAccountViewModel();

            RedirectToActionResult result = (RedirectToActionResult)await sut.UpdateContactAccount(contactAccountViewModel);

            Assert.That(result.RouteValues, Is.Not.Null);
        }
        public async Task UpdateContactAccount_WhenContactAccountViewModelIsValid_ReturnsRedirectToActionResult()
        {
            Controller sut = CreateSut();

            ContactAccountViewModel contactAccountViewModel = CreateContactAccountViewModel();

            IActionResult result = await sut.UpdateContactAccount(contactAccountViewModel);

            Assert.That(result, Is.TypeOf <RedirectToActionResult>());
        }
        public async Task UpdateContactAccount_WhenContactAccountViewModelIsValidWithSecondaryPhone_AssertPublishAsyncWasCalledOnCommandBusWithUpdateContactAccountCommandContainingSecondaryPhoneFromContactAccountViewModel()
        {
            Controller sut = CreateSut();

            string secondaryPhone = _fixture.Create <string>();
            ContactAccountViewModel contactAccountViewModel = CreateContactAccountViewModel(secondaryPhone: secondaryPhone);

            await sut.UpdateContactAccount(contactAccountViewModel);

            _commandBusMock.Verify(m => m.PublishAsync(It.Is <IUpdateContactAccountCommand>(command => command != null && string.CompareOrdinal(command.SecondaryPhone, secondaryPhone) == 0)), Times.Once);
        }
        public async Task UpdateContactAccount_WhenContactAccountViewModelIsValidWithMailAddress_AssertPublishAsyncWasCalledOnCommandBusWithUpdateContactAccountCommandContainingMailAddressFromContactAccountViewModel()
        {
            Controller sut = CreateSut();

            string mailAddress = _fixture.Create <string>();
            ContactAccountViewModel contactAccountViewModel = CreateContactAccountViewModel(mailAddress: mailAddress);

            await sut.UpdateContactAccount(contactAccountViewModel);

            _commandBusMock.Verify(m => m.PublishAsync(It.Is <IUpdateContactAccountCommand>(command => command != null && string.CompareOrdinal(command.MailAddress, mailAddress) == 0)), Times.Once);
        }
        public async Task UpdateContactAccount_WhenContactAccountViewModelIsValidWithDescription_AssertPublishAsyncWasCalledOnCommandBusWithUpdateContactAccountCommandContainingDescriptionFromContactAccountViewModel()
        {
            Controller sut = CreateSut();

            string description = _fixture.Create <string>();
            ContactAccountViewModel contactAccountViewModel = CreateContactAccountViewModel(description: description);

            await sut.UpdateContactAccount(contactAccountViewModel);

            _commandBusMock.Verify(m => m.PublishAsync(It.Is <IUpdateContactAccountCommand>(command => command != null && string.CompareOrdinal(command.Description, description) == 0)), Times.Once);
        }
        public async Task UpdateContactAccount_WhenContactAccountViewModelIsValid_AssertPublishAsyncWasCalledOnCommandBusWithUpdateContactAccountCommandContainingAccountNumberFromContactAccountViewModel()
        {
            Controller sut = CreateSut();

            string accountNumber = _fixture.Create <string>();
            ContactAccountViewModel contactAccountViewModel = CreateContactAccountViewModel(accountNumber: accountNumber);

            await sut.UpdateContactAccount(contactAccountViewModel);

            _commandBusMock.Verify(m => m.PublishAsync(It.Is <IUpdateContactAccountCommand>(command => command != null && string.CompareOrdinal(command.AccountNumber, accountNumber.ToUpper()) == 0)), Times.Once);
        }
Beispiel #15
0
        public async Task CreateContactAccount_WhenCalledWithAccountingNumberForExistingAccounting_ReturnsPartialViewResultWhereModelIsContactAccountViewModelWithPaymentTermsMatchingPaymentTermCollectionFromQueryBus()
        {
            IEnumerable <IPaymentTerm> paymentTermCollection = _fixture.CreateMany <IPaymentTerm>(_random.Next(5, 10)).ToArray();
            Controller sut = CreateSut(paymentTermCollection: paymentTermCollection);

            PartialViewResult result = (PartialViewResult)await sut.CreateContactAccount(_fixture.Create <int>());

            ContactAccountViewModel contactAccountViewModel = (ContactAccountViewModel)result.Model;

            Assert.That(paymentTermCollection.All(paymentTerm => contactAccountViewModel.PaymentTerms.SingleOrDefault(m => m.Number == paymentTerm.Number) != null), Is.True);
        }
Beispiel #16
0
        public async Task CreateContactAccount_WhenContactAccountViewModelIsValidWithNote_AssertPublishAsyncWasCalledOnCommandBusWithCreateContactAccountCommandContainingNoteFromContactAccountViewModel()
        {
            Controller sut = CreateSut();

            string note = _fixture.Create <string>();
            ContactAccountViewModel contactAccountViewModel = CreateContactAccountViewModel(note: note);

            await sut.CreateContactAccount(contactAccountViewModel);

            _commandBusMock.Verify(m => m.PublishAsync(It.Is <ICreateContactAccountCommand>(command => command != null && string.CompareOrdinal(command.Note, note) == 0)), Times.Once);
        }
        public async Task UpdateContactAccount_WhenContactAccountViewModelIsValidWithoutSecondaryPhone_AssertPublishAsyncWasCalledOnCommandBusWithUpdateContactAccountCommandWhereSecondaryPhoneIsEqualToNull()
        {
            Controller sut = CreateSut();

            ContactAccountViewModel contactAccountViewModel = CreateContactAccountViewModel(hasSecondaryPhone: false);

            await sut.UpdateContactAccount(contactAccountViewModel);

            // ReSharper disable MergeIntoPattern
            _commandBusMock.Verify(m => m.PublishAsync(It.Is <IUpdateContactAccountCommand>(command => command != null && command.SecondaryPhone == null)), Times.Once);
            // ReSharper restore MergeIntoPattern
        }
Beispiel #18
0
        public async Task CreateContactAccount_WhenCalledWithAccountingNumberForExistingAccounting_ReturnsPartialViewResultWhereModelIsContactAccountViewModelWithAccountingMatchingAccountingFromQueryBus()
        {
            int         accountingNumber = _fixture.Create <int>();
            IAccounting accounting       = _fixture.BuildAccountingMock(accountingNumber).Object;
            Controller  sut = CreateSut(accounting: accounting);

            PartialViewResult result = (PartialViewResult)await sut.CreateContactAccount(_fixture.Create <int>());

            ContactAccountViewModel contactAccountViewModel = (ContactAccountViewModel)result.Model;

            Assert.That(contactAccountViewModel.Accounting.AccountingNumber, Is.EqualTo(accountingNumber));
        }
        public async Task UpdateContactAccount_WhenContactAccountViewModelIsValid_AssertPublishAsyncWasCalledOnCommandBusWithUpdateContactAccountCommandContainingPaymentTermNumberFromContactAccountViewModel()
        {
            Controller sut = CreateSut();

            int paymentTermNumber = _fixture.Create <int>();
            PaymentTermViewModel    paymentTermViewModel    = CreatePaymentTermViewModel(paymentTermNumber);
            ContactAccountViewModel contactAccountViewModel = CreateContactAccountViewModel(paymentTermViewModel: paymentTermViewModel);

            await sut.UpdateContactAccount(contactAccountViewModel);

            _commandBusMock.Verify(m => m.PublishAsync(It.Is <IUpdateContactAccountCommand>(command => command != null && command.PaymentTermNumber == paymentTermNumber)), Times.Once);
        }
        public async Task UpdateContactAccount_WhenContactAccountViewModelIsValid_AssertPublishAsyncWasCalledOnCommandBusWithUpdateContactAccountCommandContainingAccountingNumberFromContactAccountViewModel()
        {
            Controller sut = CreateSut();

            int accountingNumber = _fixture.Create <int>();
            AccountingIdentificationViewModel accountingIdentificationViewModel = CreateAccountingIdentificationViewModel(accountingNumber);
            ContactAccountViewModel           contactAccountViewModel           = CreateContactAccountViewModel(accountingIdentificationViewModel);

            await sut.UpdateContactAccount(contactAccountViewModel);

            _commandBusMock.Verify(m => m.PublishAsync(It.Is <IUpdateContactAccountCommand>(command => command != null && command.AccountingNumber == accountingNumber)), Times.Once);
        }
        public async Task UpdateContactAccount_WhenContactAccountViewModelIsValid_ReturnsRedirectToActionResultWhereRouteValuesContainsAccountingNumberWithAccountingNumberFromAccountViewModel()
        {
            Controller sut = CreateSut();

            int accountingNumber = _fixture.Create <int>();
            AccountingIdentificationViewModel accountingIdentificationViewModel = CreateAccountingIdentificationViewModel(accountingNumber);
            ContactAccountViewModel           contactAccountViewModel           = CreateContactAccountViewModel(accountingIdentificationViewModel);

            RedirectToActionResult result = (RedirectToActionResult)await sut.UpdateContactAccount(contactAccountViewModel);

            Assert.That(result.RouteValues["accountingNumber"], Is.EqualTo(accountingNumber));
        }
Beispiel #22
0
        public async Task CreateContactAccount_WhenContactAccountViewModelIsValidWithoutMailAddress_AssertPublishAsyncWasCalledOnCommandBusWithCreateContactAccountCommandWhereMailAddressIsEqualToNull()
        {
            Controller sut = CreateSut();

            ContactAccountViewModel contactAccountViewModel = CreateContactAccountViewModel(hasMailAddress: false);

            await sut.CreateContactAccount(contactAccountViewModel);

            // ReSharper disable MergeIntoPattern
            _commandBusMock.Verify(m => m.PublishAsync(It.Is <ICreateContactAccountCommand>(command => command != null && command.MailAddress == null)), Times.Once);
            // ReSharper restore MergeIntoPattern
        }
Beispiel #23
0
        public async Task ResolveContactAccount_WhenContactAccountWasReturnedFromQueryBus_ReturnsOkObjectResultWhereValueIsContactAccountViewModelWithAccountNumberEqualToAccountNumberOnContactAccountFromQueryBus()
        {
            string          accountNumber  = _fixture.Create <string>();
            IContactAccount contactAccount = _fixture.BuildContactAccountMock(accountNumber: accountNumber).Object;
            Controller      sut            = CreateSut(contactAccount: contactAccount);

            OkObjectResult result = (OkObjectResult)await sut.ResolveContactAccount(_fixture.Create <int>(), _fixture.Create <string>(), DateTime.Today.AddDays(_random.Next(0, 7) * -1));

            ContactAccountViewModel contactAccountViewModel = (ContactAccountViewModel)result.Value;

            Assert.That(contactAccountViewModel.AccountNumber, Is.EqualTo(accountNumber));
        }
        public async Task UpdateContactAccount_WhenCalledWithAccountingNumberAndAccountNumberForExistingContactAccount_ReturnsPartialViewResultWhereModelIsContactAccountViewModelWithAccountNumberMatchingAccountNumberOnContactAccountFromQueryBus()
        {
            string          accountNumber  = _fixture.Create <string>();
            IContactAccount contactAccount = _fixture.BuildContactAccountMock(accountNumber: accountNumber).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.AccountNumber, Is.EqualTo(accountNumber));
        }
        public async Task UpdateContactAccount_WhenCalledWithAccountingNumberAndAccountNumberForExistingContactAccount_ReturnsPartialViewResultWhereModelIsContactAccountViewModelWithBalanceInfosContainingDataFromContactInfoCollectionOnContactAccountFromQueryBus()
        {
            IContactInfo[]         contactInfos          = _fixture.BuildContactInfoCollectionMock().Object.ToArray();
            IContactInfoCollection contactInfoCollection = _fixture.BuildContactInfoCollectionMock(contactInfoCollection: contactInfos).Object;
            IContactAccount        contactAccount        = _fixture.BuildContactAccountMock(contactInfoCollection: contactInfoCollection).Object;
            Controller             sut = CreateSut(contactAccount: contactAccount);

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

            ContactAccountViewModel contactAccountViewModel = (ContactAccountViewModel)result.Model;

            foreach (IGrouping <short, IContactInfo> group in contactInfos.GroupBy(contactInfo => contactInfo.Year))
            {
                Assert.That(contactAccountViewModel.BalanceInfos.ContainsKey(group.Key), Is.True);

                BalanceInfoCollectionViewModel balanceInfoCollectionViewModel = contactAccountViewModel.BalanceInfos[group.Key];
                Assert.That(balanceInfoCollectionViewModel, Is.Not.Null);
                Assert.That(balanceInfoCollectionViewModel.All(balanceInfoViewModel => group.SingleOrDefault(m => m.Month == balanceInfoViewModel.Month) != null), Is.True);
            }
        }