public async Task UpdateAccount_WhenCalledWithAccountingNumberAndAccountNumberForNonExistingAccount_ReturnsNotNull()
        {
            Controller sut = CreateSut(false);

            IActionResult result = await sut.UpdateAccount(_fixture.Create <int>(), _fixture.Create <string>());

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

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

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

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

            Assert.That(result.ViewName, Is.EqualTo("_EditAccountPartial"));
        }
        public async Task UpdateAccount_WhenCalledWithAccountingNumberAndAccountNumberForExistingAccount_ReturnsPartialViewResult()
        {
            Controller sut = CreateSut();

            IActionResult result = await sut.UpdateAccount(_fixture.Create <int>(), _fixture.Create <string>());

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

            await sut.UpdateAccount(_fixture.Create <int>(), _fixture.Create <string>());

            _queryBusMock.Verify(m => m.QueryAsync <EmptyQuery, IEnumerable <IAccountGroup> >(It.IsNotNull <EmptyQuery>()), Times.Once);
        }
Exemplo n.º 6
0
        public async Task UpdateAccount_WhenAccountViewModelIsValid_ReturnsRedirectToActionResultWhereRouteValuesContainsAccountingNumber()
        {
            Controller sut = CreateSut();

            AccountViewModel accountViewModel = CreateAccountViewModel();

            RedirectToActionResult result = (RedirectToActionResult)await sut.UpdateAccount(accountViewModel);

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

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

            AccountViewModel accountViewModel = (AccountViewModel)result.Model;

            Assert.That(accountViewModel.AccountGroups, Is.Not.Null);
        }
Exemplo n.º 8
0
        public async Task UpdateAccount_WhenAccountViewModelIsValid_ReturnsRedirectToActionResult()
        {
            Controller sut = CreateSut();

            AccountViewModel accountViewModel = CreateAccountViewModel();

            IActionResult result = await sut.UpdateAccount(accountViewModel);

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

            int    accountingNumber = _fixture.Create <int>();
            string accountNumber    = _fixture.Create <string>();
            await sut.UpdateAccount(accountingNumber, accountNumber);

            _queryBusMock.Verify(m => m.QueryAsync <IGetAccountQuery, IAccount>(It.Is <IGetAccountQuery>(query => query != null && query.AccountingNumber == accountingNumber && string.CompareOrdinal(query.AccountNumber, accountNumber.ToUpper()) == 0 && query.StatusDate == DateTime.Today)), Times.Once);
        }
Exemplo n.º 10
0
        public async Task UpdateAccount_WhenAccountViewModelIsValid_ReturnsRedirectToActionResultWhereActionNameIsEqualToAccountings()
        {
            Controller sut = CreateSut();

            AccountViewModel accountViewModel = CreateAccountViewModel();

            RedirectToActionResult result = (RedirectToActionResult)await sut.UpdateAccount(accountViewModel);

            Assert.That(result.ActionName, Is.EqualTo("Accountings"));
        }
Exemplo n.º 11
0
        public async Task UpdateAccount_WhenAccountViewModelIsValid_ReturnsNotNull()
        {
            Controller sut = CreateSut();

            AccountViewModel accountViewModel = CreateAccountViewModel();

            IActionResult result = await sut.UpdateAccount(accountViewModel);

            Assert.That(result, Is.Not.Null);
        }
Exemplo n.º 12
0
        public async Task UpdateAccount_WhenAccountViewModelIsValid_ReturnsRedirectToActionResultWhereRouteValuesIsNotNull()
        {
            Controller sut = CreateSut();

            AccountViewModel accountViewModel = CreateAccountViewModel();

            RedirectToActionResult result = (RedirectToActionResult)await sut.UpdateAccount(accountViewModel);

            Assert.That(result.RouteValues, Is.Not.Null);
        }
Exemplo n.º 13
0
        public async Task UpdateAccount_WhenAccountViewModelIsValidWithCreditInfosOnlyContainingDataForYearToDate_AssertPublishAsyncWasCalledOnCommandBusWithUpdateAccountCommandContainingCreditInfoCollectionWithCreditInfoForCurrentMonth()
        {
            Controller sut = CreateSut();

            CreditInfoDictionaryViewModel creditInfoDictionaryViewModel = CreateCreditInfoDictionaryViewModel(CreateCreditInfoViewModelCollectionForYearToDate());
            AccountViewModel accountViewModel = CreateAccountViewModel(creditInfoDictionaryViewModel: creditInfoDictionaryViewModel);

            await sut.UpdateAccount(accountViewModel);

            _commandBusMock.Verify(m => m.PublishAsync(It.Is <IUpdateAccountCommand>(command => command != null && command.CreditInfoCollection.All(creditInfo => creditInfo.Year == (short)DateTime.Today.Year && creditInfo.Month == (short)DateTime.Today.Month))), Times.Once);
        }
Exemplo n.º 14
0
        public async Task UpdateAccount_WhenAccountViewModelIsValidWithCreditInfosOnlyContainingDataForLastYear_AssertPublishAsyncWasCalledOnCommandBusWithUpdateAccountCommandContainingEmptyCreditInfoCollection()
        {
            Controller sut = CreateSut();

            CreditInfoDictionaryViewModel creditInfoDictionaryViewModel = CreateCreditInfoDictionaryViewModel(CreateCreditInfoViewModelCollectionForLastYear());
            AccountViewModel accountViewModel = CreateAccountViewModel(creditInfoDictionaryViewModel: creditInfoDictionaryViewModel);

            await sut.UpdateAccount(accountViewModel);

            _commandBusMock.Verify(m => m.PublishAsync(It.Is <IUpdateAccountCommand>(command => command != null && command.CreditInfoCollection.Any() == false)), Times.Once);
        }
Exemplo n.º 15
0
        public async Task UpdateAccount_WhenAccountViewModelIsValidWithNote_AssertPublishAsyncWasCalledOnCommandBusWithUpdateAccountCommandContainingNoteFromAccountViewModel()
        {
            Controller sut = CreateSut();

            string           note             = _fixture.Create <string>();
            AccountViewModel accountViewModel = CreateAccountViewModel(note: note);

            await sut.UpdateAccount(accountViewModel);

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

            string           accountNumber    = _fixture.Create <string>();
            AccountViewModel accountViewModel = CreateAccountViewModel(accountNumber: accountNumber);

            await sut.UpdateAccount(accountViewModel);

            _commandBusMock.Verify(m => m.PublishAsync(It.Is <IUpdateAccountCommand>(command => command != null && string.CompareOrdinal(command.AccountNumber, accountNumber.ToUpper()) == 0)), Times.Once);
        }
        public async Task UpdateAccount_WhenCalledWithAccountingNumberAndAccountNumberForExistingAccount_ReturnsPartialViewResultWhereModelIsAccountViewModelWithAccountGroupsMatchingAccountGroupCollectionFromQueryBus()
        {
            IEnumerable <IAccountGroup> accountGroupCollection = _fixture.CreateMany <IAccountGroup>(_random.Next(5, 10)).ToArray();
            Controller sut = CreateSut(accountGroupCollection: accountGroupCollection);

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

            AccountViewModel accountViewModel = (AccountViewModel)result.Model;

            Assert.That(accountGroupCollection.All(accountGroup => accountViewModel.AccountGroups.SingleOrDefault(m => m.Number == accountGroup.Number) != null), Is.True);
        }
Exemplo n.º 18
0
        public async Task UpdateAccount_WhenAccountViewModelIsValidWithCreditInfosOnlyContainingDataForNext11Months_AssertPublishAsyncWasCalledOnCommandBusWithUpdateAccountCommandContainingCreditInfoCollectionWithCreditInfoForNext11Months()
        {
            Controller sut = CreateSut();

            CreditInfoViewModel[]         creditInfoViewModelCollection = CreateCreditInfoViewModelCollectionForNext11Months().ToArray();
            CreditInfoDictionaryViewModel creditInfoDictionaryViewModel = CreateCreditInfoDictionaryViewModel(creditInfoViewModelCollection);
            AccountViewModel accountViewModel = CreateAccountViewModel(creditInfoDictionaryViewModel: creditInfoDictionaryViewModel);

            await sut.UpdateAccount(accountViewModel);

            _commandBusMock.Verify(m => m.PublishAsync(It.Is <IUpdateAccountCommand>(command => command != null && command.CreditInfoCollection.All(creditInfo => creditInfoViewModelCollection.SingleOrDefault(creditInfoViewModel => creditInfoViewModel.Year == creditInfo.Year && creditInfoViewModel.Month == creditInfo.Month) != null))), Times.Once);
        }
        public async Task UpdateAccount_WhenCalledWithAccountingNumberAndAccountNumberForExistingAccount_ReturnsPartialViewResultWhereModelIsAccountViewModelWithAccountNumberMatchingAccountNumberOnAccountFromQueryBus()
        {
            string     accountNumber = _fixture.Create <string>();
            IAccount   account       = _fixture.BuildAccountMock(accountNumber: accountNumber).Object;
            Controller sut           = CreateSut(account: account);

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

            AccountViewModel accountViewModel = (AccountViewModel)result.Model;

            Assert.That(accountViewModel.AccountNumber, Is.EqualTo(accountNumber));
        }
Exemplo n.º 20
0
        public async Task UpdateAccount_WhenAccountViewModelIsValidWithoutNote_AssertPublishAsyncWasCalledOnCommandBusWithUpdateAccountCommandWhereNoteIsEqualToNull()
        {
            Controller sut = CreateSut();

            AccountViewModel accountViewModel = CreateAccountViewModel(hasNote: false);

            await sut.UpdateAccount(accountViewModel);

            // ReSharper disable MergeIntoPattern
            _commandBusMock.Verify(m => m.PublishAsync(It.Is <IUpdateAccountCommand>(command => command != null && command.Note == null)), Times.Once);
            // ReSharper restore MergeIntoPattern
        }
Exemplo n.º 21
0
        public async Task UpdateAccount_WhenAccountViewModelIsValid_AssertPublishAsyncWasCalledOnCommandBusWithUpdateAccountCommandContainingAccountingNumberFromAccountViewModel()
        {
            Controller sut = CreateSut();

            int accountingNumber = _fixture.Create <int>();
            AccountingIdentificationViewModel accountingIdentificationViewModel = CreateAccountingIdentificationViewModel(accountingNumber);
            AccountViewModel accountViewModel = CreateAccountViewModel(accountingIdentificationViewModel);

            await sut.UpdateAccount(accountViewModel);

            _commandBusMock.Verify(m => m.PublishAsync(It.Is <IUpdateAccountCommand>(command => command != null && command.AccountingNumber == accountingNumber)), Times.Once);
        }
Exemplo n.º 22
0
        public async Task UpdateAccount_WhenAccountViewModelIsValid_AssertPublishAsyncWasCalledOnCommandBusWithUpdateAccountCommandContainingCreditInfoCollectionNotEqualToNull()
        {
            Controller sut = CreateSut();

            AccountViewModel accountViewModel = CreateAccountViewModel();

            await sut.UpdateAccount(accountViewModel);

            // ReSharper disable MergeIntoPattern
            _commandBusMock.Verify(m => m.PublishAsync(It.Is <IUpdateAccountCommand>(command => command != null && command.CreditInfoCollection != null)), Times.Once);
            // ReSharper restore MergeIntoPattern
        }
Exemplo n.º 23
0
        public async Task UpdateAccount_WhenAccountViewModelIsValid_ReturnsRedirectToActionResultWhereRouteValuesContainsAccountingNumberWithAccountingNumberFromAccountViewModel()
        {
            Controller sut = CreateSut();

            int accountingNumber = _fixture.Create <int>();
            AccountingIdentificationViewModel accountingIdentificationViewModel = CreateAccountingIdentificationViewModel(accountingNumber);
            AccountViewModel accountViewModel = CreateAccountViewModel(accountingIdentificationViewModel);

            RedirectToActionResult result = (RedirectToActionResult)await sut.UpdateAccount(accountViewModel);

            Assert.That(result.RouteValues["accountingNumber"], Is.EqualTo(accountingNumber));
        }
        public async Task UpdateAccount_WhenCalledWithAccountingNumberAndAccountNumberForExistingAccount_ReturnsPartialViewResultWhereModelIsAccountViewModelWithCreditInfosContainingDataFromCreditInfoCollectionOnAccountFromQueryBus()
        {
            ICreditInfo[]         creditInfos          = _fixture.BuildCreditInfoCollectionMock().Object.ToArray();
            ICreditInfoCollection creditInfoCollection = _fixture.BuildCreditInfoCollectionMock(creditInfoCollection: creditInfos).Object;
            IAccount   account = _fixture.BuildAccountMock(creditInfoCollection: creditInfoCollection).Object;
            Controller sut     = CreateSut(account: account);

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

            AccountViewModel accountViewModel = (AccountViewModel)result.Model;

            foreach (IGrouping <short, ICreditInfo> group in creditInfos.GroupBy(creditInfo => creditInfo.Year))
            {
                Assert.That(accountViewModel.CreditInfos.ContainsKey(group.Key), Is.True);

                CreditInfoCollectionViewModel creditInfoCollectionViewModel = accountViewModel.CreditInfos[group.Key];
                Assert.That(creditInfoCollectionViewModel, Is.Not.Null);
                Assert.That(creditInfoCollectionViewModel.All(creditInfoViewModel => group.SingleOrDefault(m => m.Month == creditInfoViewModel.Month) != null), Is.True);
            }
        }
Exemplo n.º 25
0
        public void UpdateAccount_WhenAccountViewModelIsInvalid_ThrowsIntranetSystemExceptionWhereInnerExceptionIsNull()
        {
            Controller sut = CreateSut(false);

            IntranetSystemException result = Assert.ThrowsAsync <IntranetSystemException>(async() => await sut.UpdateAccount(CreateAccountViewModel()));

            // ReSharper disable PossibleNullReferenceException
            Assert.That(result.InnerException, Is.Null);
            // ReSharper restore PossibleNullReferenceException
        }
Exemplo n.º 26
0
        public void UpdateAccount_WhenAccountViewModelIsInvalid_ThrowsIntranetSystemExceptionWhereMessageEndsWithErrorMessagesFromModelState()
        {
            string     errorMessage = _fixture.Create <string>();
            Controller sut          = CreateSut(false, errorMessage: errorMessage);

            IntranetSystemException result = Assert.ThrowsAsync <IntranetSystemException>(async() => await sut.UpdateAccount(CreateAccountViewModel()));

            // ReSharper disable PossibleNullReferenceException
            Assert.That(result.Message.EndsWith(errorMessage), Is.True);
            // ReSharper restore PossibleNullReferenceException
        }
Exemplo n.º 27
0
        public void UpdateAccount_WhenAccountViewModelIsInvalid_ThrowsIntranetSystemExceptionWhereErrorCodeIsEqualToInternalError()
        {
            Controller sut = CreateSut(false);

            IntranetSystemException result = Assert.ThrowsAsync <IntranetSystemException>(async() => await sut.UpdateAccount(CreateAccountViewModel()));

            // ReSharper disable PossibleNullReferenceException
            Assert.That(result.ErrorCode, Is.EqualTo(ErrorCode.InternalError));
            // ReSharper restore PossibleNullReferenceException
        }
Exemplo n.º 28
0
        public void UpdateAccount_WhenAccountViewModelIsNull_ThrowsArgumentNullException()
        {
            Controller sut = CreateSut();

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

            // ReSharper disable PossibleNullReferenceException
            Assert.That(result.ParamName, Is.EqualTo("accountViewModel"));
            // ReSharper restore PossibleNullReferenceException
        }
        public void UpdateAccount_WhenAccountingNumberIsWhiteSpace_ThrowsArgumentNullException()
        {
            Controller sut = CreateSut();

            ArgumentNullException result = Assert.ThrowsAsync <ArgumentNullException>(async() => await sut.UpdateAccount(_fixture.Create <int>(), " "));

            // ReSharper disable PossibleNullReferenceException
            Assert.That(result.ParamName, Is.EqualTo("accountNumber"));
            // ReSharper restore PossibleNullReferenceException
        }