Exemple #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));
            }
        }
Exemple #2
0
        public async Task CreateContactAccount_WhenCalledWithAccountingNumberForNonExistingAccounting_ReturnsBadRequestResult()
        {
            Controller sut = CreateSut(false);

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

            Assert.That(result, Is.TypeOf <BadRequestResult>());
        }
Exemple #3
0
        public async Task CreateContactAccount_WhenCalledWithAccountingNumberForExistingAccounting_ReturnsPartialViewResultWhereViewNameIsEqualToEditContactAccountPartial()
        {
            Controller sut = CreateSut();

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

            Assert.That(result.ViewName, Is.EqualTo("_EditContactAccountPartial"));
        }
Exemple #4
0
        public async Task CreateContactAccount_WhenCalledWithAccountingNumberForExistingAccounting_ReturnsNotNull()
        {
            Controller sut = CreateSut();

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

            Assert.That(result, Is.Not.Null);
        }
Exemple #5
0
        public async Task CreateContactAccount_WhenCalledWithAccountingNumberForExistingAccounting_ReturnsPartialViewResultWhereModelIsContactAccountViewModel()
        {
            Controller sut = CreateSut();

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

            Assert.That(result.Model, Is.TypeOf <ContactAccountViewModel>());
        }
Exemple #6
0
        public async Task CreateContactAccount_WhenCalledWithAccountingNumber_AssertQueryAsyncWasCalledOnQueryBusWithEmptyQueryForPaymentTermCollection()
        {
            Controller sut = CreateSut();

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

            _queryBusMock.Verify(m => m.QueryAsync <EmptyQuery, IEnumerable <IPaymentTerm> >(It.IsNotNull <EmptyQuery>()), Times.Once);
        }
Exemple #7
0
        public async Task CreateContactAccount_WhenCalledWithAccountingNumber_AssertQueryAsyncWasCalledOnQueryBusWithGetAccountingQuery()
        {
            Controller sut = CreateSut();

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

            _queryBusMock.Verify(m => m.QueryAsync <IGetAccountingQuery, IAccounting>(It.Is <IGetAccountingQuery>(query => query != null && query.AccountingNumber == accountingNumber)), Times.Once);
        }
Exemple #8
0
        public async Task CreateContactAccount_WhenContactAccountViewModelIsValid_ReturnsRedirectToActionResultWhereRouteValuesIsNotNull()
        {
            Controller sut = CreateSut();

            ContactAccountViewModel contactAccountViewModel = CreateContactAccountViewModel();

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

            Assert.That(result.RouteValues, Is.Not.Null);
        }
Exemple #9
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));
        }
Exemple #10
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);
        }
Exemple #11
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);
        }
Exemple #12
0
        public async Task CreateContactAccount_WhenContactAccountViewModelIsValid_ReturnsRedirectToActionResultWhereRouteValuesContainsAccountingNumber()
        {
            Controller sut = CreateSut();

            ContactAccountViewModel contactAccountViewModel = CreateContactAccountViewModel();

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

            Assert.That(result.RouteValues.ContainsKey("accountingNumber"), Is.True);
        }
Exemple #13
0
        public async Task CreateContactAccount_WhenContactAccountViewModelIsValid_ReturnsRedirectToActionResultWhereActionNameIsEqualToAccountings()
        {
            Controller sut = CreateSut();

            ContactAccountViewModel contactAccountViewModel = CreateContactAccountViewModel();

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

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

            ContactAccountViewModel contactAccountViewModel = CreateContactAccountViewModel();

            IActionResult result = await sut.CreateContactAccount(contactAccountViewModel);

            Assert.That(result, Is.TypeOf <RedirectToActionResult>());
        }
Exemple #15
0
        public async Task CreateContactAccount_WhenContactAccountViewModelIsValid_ReturnsNotNull()
        {
            Controller sut = CreateSut();

            ContactAccountViewModel contactAccountViewModel = CreateContactAccountViewModel();

            IActionResult result = await sut.CreateContactAccount(contactAccountViewModel);

            Assert.That(result, Is.Not.Null);
        }
Exemple #16
0
        public async Task CreateContactAccount_WhenContactAccountViewModelIsValidWithDescription_AssertPublishAsyncWasCalledOnCommandBusWithCreateContactAccountCommandContainingDescriptionFromContactAccountViewModel()
        {
            Controller sut = CreateSut();

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

            await sut.CreateContactAccount(contactAccountViewModel);

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

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

            await sut.CreateContactAccount(contactAccountViewModel);

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

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

            await sut.CreateContactAccount(contactAccountViewModel);

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

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

            await sut.CreateContactAccount(contactAccountViewModel);

            _commandBusMock.Verify(m => m.PublishAsync(It.Is <ICreateContactAccountCommand>(command => command != null && string.CompareOrdinal(command.AccountNumber, accountNumber.ToUpper()) == 0)), Times.Once);
        }
Exemple #20
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);
        }
Exemple #21
0
        public async Task CreateContactAccount_WhenContactAccountViewModelIsValidWithoutSecondaryPhone_AssertPublishAsyncWasCalledOnCommandBusWithCreateContactAccountCommandWhereSecondaryPhoneIsEqualToNull()
        {
            Controller sut = CreateSut();

            ContactAccountViewModel contactAccountViewModel = CreateContactAccountViewModel(hasSecondaryPhone: false);

            await sut.CreateContactAccount(contactAccountViewModel);

            // ReSharper disable MergeIntoPattern
            _commandBusMock.Verify(m => m.PublishAsync(It.Is <ICreateContactAccountCommand>(command => command != null && command.SecondaryPhone == null)), Times.Once);
            // ReSharper restore MergeIntoPattern
        }
Exemple #22
0
        public async Task CreateContactAccount_WhenContactAccountViewModelIsValid_AssertPublishAsyncWasCalledOnCommandBusWithCreateContactAccountCommandContainingPaymentTermNumberFromContactAccountViewModel()
        {
            Controller sut = CreateSut();

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

            await sut.CreateContactAccount(contactAccountViewModel);

            _commandBusMock.Verify(m => m.PublishAsync(It.Is <ICreateContactAccountCommand>(command => command != null && command.PaymentTermNumber == paymentTermNumber)), Times.Once);
        }
Exemple #23
0
        public async Task CreateContactAccount_WhenContactAccountViewModelIsValid_ReturnsRedirectToActionResultWhereRouteValuesContainsAccountingNumberWithAccountingNumberFromAccountViewModel()
        {
            Controller sut = CreateSut();

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

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

            Assert.That(result.RouteValues["accountingNumber"], Is.EqualTo(accountingNumber));
        }
Exemple #24
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));
        }
Exemple #25
0
        public async Task CreateContactAccount_WhenContactAccountViewModelIsValid_AssertPublishAsyncWasCalledOnCommandBusWithCreateContactAccountCommandContainingAccountingNumberFromContactAccountViewModel()
        {
            Controller sut = CreateSut();

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

            await sut.CreateContactAccount(contactAccountViewModel);

            _commandBusMock.Verify(m => m.PublishAsync(It.Is <ICreateContactAccountCommand>(command => command != null && command.AccountingNumber == accountingNumber)), Times.Once);
        }
Exemple #26
0
        public void CreateContactAccount_WhenContactAccountViewModelIsInvalid_ThrowsIntranetSystemExceptionWhereMessageEndsWithErrorMessagesFromModelState()
        {
            string     errorMessage = _fixture.Create <string>();
            Controller sut          = CreateSut(false, errorMessage: errorMessage);

            IntranetSystemException result = Assert.ThrowsAsync <IntranetSystemException>(async() => await sut.CreateContactAccount(CreateContactAccountViewModel()));

            // ReSharper disable PossibleNullReferenceException
            Assert.That(result.Message.EndsWith(errorMessage), Is.True);
            // ReSharper restore PossibleNullReferenceException
        }
Exemple #27
0
        public void CreateContactAccount_WhenContactAccountViewModelIsNull_ThrowsArgumentNullException()
        {
            Controller sut = CreateSut();

            ArgumentNullException result = Assert.ThrowsAsync <ArgumentNullException>(async() => await sut.CreateContactAccount(null));

            // ReSharper disable PossibleNullReferenceException
            Assert.That(result.ParamName, Is.EqualTo("contactAccountViewModel"));
            // ReSharper restore PossibleNullReferenceException
        }
Exemple #28
0
        public void CreateContactAccount_WhenContactAccountViewModelIsInvalid_ThrowsIntranetSystemExceptionWhereErrorCodeIsEqualToInternalError()
        {
            Controller sut = CreateSut(false);

            IntranetSystemException result = Assert.ThrowsAsync <IntranetSystemException>(async() => await sut.CreateContactAccount(CreateContactAccountViewModel()));

            // ReSharper disable PossibleNullReferenceException
            Assert.That(result.ErrorCode, Is.EqualTo(ErrorCode.InternalError));
            // ReSharper restore PossibleNullReferenceException
        }
Exemple #29
0
        public void CreateContactAccount_WhenContactAccountViewModelIsInvalid_ThrowsIntranetSystemExceptionWhereInnerExceptionIsNull()
        {
            Controller sut = CreateSut(false);

            IntranetSystemException result = Assert.ThrowsAsync <IntranetSystemException>(async() => await sut.CreateContactAccount(CreateContactAccountViewModel()));

            // ReSharper disable PossibleNullReferenceException
            Assert.That(result.InnerException, Is.Null);
            // ReSharper restore PossibleNullReferenceException
        }