public async Task UpdateBudgetAccount_WhenCalledWithAccountingNumberAndAccountNumberForExistingBudgetAccount_ReturnsPartialViewResult()
        {
            Controller sut = CreateSut();

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

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

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

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

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

            _queryBusMock.Verify(m => m.QueryAsync <EmptyQuery, IEnumerable <IBudgetAccountGroup> >(It.IsNotNull <EmptyQuery>()), Times.Once);
        }
        public async Task UpdateBudgetAccount_WhenCalledWithAccountingNumberAndAccountNumberForExistingBudgetAccount_ReturnsPartialViewResultWhereViewNameIsEqualToEditBudgetAccountPartial()
        {
            Controller sut = CreateSut();

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

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

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

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

            BudgetAccountViewModel budgetAccountViewModel = CreateBudgetAccountViewModel();

            RedirectToActionResult result = (RedirectToActionResult)await sut.UpdateBudgetAccount(budgetAccountViewModel);

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

            BudgetAccountViewModel budgetAccountViewModel = CreateBudgetAccountViewModel();

            RedirectToActionResult result = (RedirectToActionResult)await sut.UpdateBudgetAccount(budgetAccountViewModel);

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

            BudgetAccountViewModel budgetAccountViewModel = CreateBudgetAccountViewModel();

            RedirectToActionResult result = (RedirectToActionResult)await sut.UpdateBudgetAccount(budgetAccountViewModel);

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

            BudgetAccountViewModel budgetAccountViewModel = CreateBudgetAccountViewModel();

            IActionResult result = await sut.UpdateBudgetAccount(budgetAccountViewModel);

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

            BudgetAccountViewModel budgetAccountViewModel = CreateBudgetAccountViewModel();

            IActionResult result = await sut.UpdateBudgetAccount(budgetAccountViewModel);

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

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

            BudgetAccountViewModel budgetAccountViewModel = (BudgetAccountViewModel)result.Model;

            Assert.That(budgetAccountViewModel.BudgetAccountGroups, Is.Not.Null);
        }
        public async Task UpdateBudgetAccount_WhenCalledWithAccountingNumberAndAccountNumber_AssertQueryAsyncWasCalledOnQueryBusWithGetBudgetAccountQuery()
        {
            Controller sut = CreateSut();

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

            _queryBusMock.Verify(m => m.QueryAsync <IGetBudgetAccountQuery, IBudgetAccount>(It.Is <IGetBudgetAccountQuery>(query => query != null && query.AccountingNumber == accountingNumber && string.CompareOrdinal(query.AccountNumber, accountNumber.ToUpper()) == 0 && query.StatusDate == DateTime.Today)), Times.Once);
        }
Exemple #13
0
        public async Task UpdateBudgetAccount_WhenBudgetAccountViewModelIsValidWithBudgetInfosOnlyContainingDataForYearToDate_AssertPublishAsyncWasCalledOnCommandBusWithUpdateBudgetAccountCommandContainingBudgetInfoCollectionWithBudgetInfoForCurrentMonth()
        {
            Controller sut = CreateSut();

            BudgetInfoDictionaryViewModel budgetInfoDictionaryViewModel = CreateBudgetInfoDictionaryViewModel(CreateBudgetInfoViewModelCollectionForYearToDate());
            BudgetAccountViewModel        budgetAccountViewModel        = CreateBudgetAccountViewModel(budgetInfoDictionaryViewModel: budgetInfoDictionaryViewModel);

            await sut.UpdateBudgetAccount(budgetAccountViewModel);

            _commandBusMock.Verify(m => m.PublishAsync(It.Is <IUpdateBudgetAccountCommand>(command => command != null && command.BudgetInfoCollection.All(budgetInfo => budgetInfo.Year == (short)DateTime.Today.Year && budgetInfo.Month == (short)DateTime.Today.Month))), Times.Once);
        }
Exemple #14
0
        public async Task UpdateBudgetAccount_WhenBudgetAccountViewModelIsValidWithBudgetInfosOnlyContainingDataForYearToDate_AssertPublishAsyncWasCalledOnCommandBusWithUpdateBudgetAccountCommandContainingBudgetInfoCollectionWithOneBudgetInfo()
        {
            Controller sut = CreateSut();

            BudgetInfoDictionaryViewModel budgetInfoDictionaryViewModel = CreateBudgetInfoDictionaryViewModel(CreateBudgetInfoViewModelCollectionForYearToDate());
            BudgetAccountViewModel        budgetAccountViewModel        = CreateBudgetAccountViewModel(budgetInfoDictionaryViewModel: budgetInfoDictionaryViewModel);

            await sut.UpdateBudgetAccount(budgetAccountViewModel);

            _commandBusMock.Verify(m => m.PublishAsync(It.Is <IUpdateBudgetAccountCommand>(command => command != null && command.BudgetInfoCollection.Count() == 1)), Times.Once);
        }
Exemple #15
0
        public async Task UpdateBudgetAccount_WhenBudgetAccountViewModelIsValidWithNote_AssertPublishAsyncWasCalledOnCommandBusWithUpdateBudgetAccountCommandContainingNoteFromBudgetAccountViewModel()
        {
            Controller sut = CreateSut();

            string note = _fixture.Create <string>();
            BudgetAccountViewModel budgetAccountViewModel = CreateBudgetAccountViewModel(note: note);

            await sut.UpdateBudgetAccount(budgetAccountViewModel);

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

            string accountNumber = _fixture.Create <string>();
            BudgetAccountViewModel budgetAccountViewModel = CreateBudgetAccountViewModel(accountNumber: accountNumber);

            await sut.UpdateBudgetAccount(budgetAccountViewModel);

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

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

            BudgetAccountViewModel budgetAccountViewModel = (BudgetAccountViewModel)result.Model;

            Assert.That(budgetAccountGroupCollection.All(budgetAccountGroup => budgetAccountViewModel.BudgetAccountGroups.SingleOrDefault(m => m.Number == budgetAccountGroup.Number) != null), Is.True);
        }
Exemple #18
0
        public async Task UpdateBudgetAccount_WhenBudgetAccountViewModelIsValid_AssertPublishAsyncWasCalledOnCommandBusWithUpdateBudgetAccountCommandContainingBudgetInfoCollectionNotEqualToNull()
        {
            Controller sut = CreateSut();

            BudgetAccountViewModel budgetAccountViewModel = CreateBudgetAccountViewModel();

            await sut.UpdateBudgetAccount(budgetAccountViewModel);

            // ReSharper disable MergeIntoPattern
            _commandBusMock.Verify(m => m.PublishAsync(It.Is <IUpdateBudgetAccountCommand>(command => command != null && command.BudgetInfoCollection != null)), Times.Once);
            // ReSharper restore MergeIntoPattern
        }
        public async Task UpdateBudgetAccount_WhenCalledWithAccountingNumberAndAccountNumberForExistingBudgetAccount_ReturnsPartialViewResultWhereModelIsBudgetAccountViewModelWithAccountNumberMatchingAccountNumberOnBudgetAccountFromQueryBus()
        {
            string         accountNumber = _fixture.Create <string>();
            IBudgetAccount budgetAccount = _fixture.BuildBudgetAccountMock(accountNumber: accountNumber).Object;
            Controller     sut           = CreateSut(budgetAccount: budgetAccount);

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

            BudgetAccountViewModel budgetAccountViewModel = (BudgetAccountViewModel)result.Model;

            Assert.That(budgetAccountViewModel.AccountNumber, Is.EqualTo(accountNumber));
        }
Exemple #20
0
        public async Task UpdateBudgetAccount_WhenBudgetAccountViewModelIsValid_ReturnsRedirectToActionResultWhereRouteValuesContainsAccountingNumberWithAccountingNumberFromAccountViewModel()
        {
            Controller sut = CreateSut();

            int accountingNumber = _fixture.Create <int>();
            AccountingIdentificationViewModel accountingIdentificationViewModel = CreateAccountingIdentificationViewModel(accountingNumber);
            BudgetAccountViewModel            budgetAccountViewModel            = CreateBudgetAccountViewModel(accountingIdentificationViewModel);

            RedirectToActionResult result = (RedirectToActionResult)await sut.UpdateBudgetAccount(budgetAccountViewModel);

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

            BudgetInfoViewModel[]         budgetInfoViewModelCollection = CreateBudgetInfoViewModelCollectionForNext11Months().ToArray();
            BudgetInfoDictionaryViewModel budgetInfoDictionaryViewModel = CreateBudgetInfoDictionaryViewModel(budgetInfoViewModelCollection);
            BudgetAccountViewModel        budgetAccountViewModel        = CreateBudgetAccountViewModel(budgetInfoDictionaryViewModel: budgetInfoDictionaryViewModel);

            await sut.UpdateBudgetAccount(budgetAccountViewModel);

            _commandBusMock.Verify(m => m.PublishAsync(It.Is <IUpdateBudgetAccountCommand>(command => command != null && command.BudgetInfoCollection.All(budgetInfo => budgetInfoViewModelCollection.SingleOrDefault(budgetInfoViewModel => budgetInfoViewModel.Year == budgetInfo.Year && budgetInfoViewModel.Month == budgetInfo.Month) != null))), Times.Once);
        }
Exemple #22
0
        public async Task UpdateBudgetAccount_WhenBudgetAccountViewModelIsValidWithoutNote_AssertPublishAsyncWasCalledOnCommandBusWithUpdateBudgetAccountCommandWhereNoteIsEqualToNull()
        {
            Controller sut = CreateSut();

            BudgetAccountViewModel budgetAccountViewModel = CreateBudgetAccountViewModel(hasNote: false);

            await sut.UpdateBudgetAccount(budgetAccountViewModel);

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

            int accountingNumber = _fixture.Create <int>();
            AccountingIdentificationViewModel accountingIdentificationViewModel = CreateAccountingIdentificationViewModel(accountingNumber);
            BudgetAccountViewModel            budgetAccountViewModel            = CreateBudgetAccountViewModel(accountingIdentificationViewModel);

            await sut.UpdateBudgetAccount(budgetAccountViewModel);

            _commandBusMock.Verify(m => m.PublishAsync(It.Is <IUpdateBudgetAccountCommand>(command => command != null && command.AccountingNumber == accountingNumber)), Times.Once);
        }
        public async Task UpdateBudgetAccount_WhenCalledWithAccountingNumberAndAccountNumberForExistingBudgetAccount_ReturnsPartialViewResultWhereModelIsBudgetAccountViewModelWithBudgetInfosContainingDataFromBudgetInfoCollectionOnBudgetAccountFromQueryBus()
        {
            IBudgetInfo[]         budgetInfos          = _fixture.BuildBudgetInfoCollectionMock().Object.ToArray();
            IBudgetInfoCollection budgetInfoCollection = _fixture.BuildBudgetInfoCollectionMock(budgetInfoCollection: budgetInfos).Object;
            IBudgetAccount        budgetAccount        = _fixture.BuildBudgetAccountMock(budgetInfoCollection: budgetInfoCollection).Object;
            Controller            sut = CreateSut(budgetAccount: budgetAccount);

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

            BudgetAccountViewModel budgetAccountViewModel = (BudgetAccountViewModel)result.Model;

            foreach (IGrouping <short, IBudgetInfo> group in budgetInfos.GroupBy(budgetInfo => budgetInfo.Year))
            {
                Assert.That(budgetAccountViewModel.BudgetInfos.ContainsKey(group.Key), Is.True);

                BudgetInfoCollectionViewModel budgetInfoCollectionViewModel = budgetAccountViewModel.BudgetInfos[group.Key];
                Assert.That(budgetInfoCollectionViewModel, Is.Not.Null);
                Assert.That(budgetInfoCollectionViewModel.All(budgetInfoViewModel => group.SingleOrDefault(m => m.Month == budgetInfoViewModel.Month) != null), Is.True);
            }
        }
Exemple #25
0
        public void UpdateBudgetAccount_WhenBudgetAccountViewModelIsInvalid_ThrowsIntranetSystemExceptionWhereErrorCodeIsEqualToInternalError()
        {
            Controller sut = CreateSut(false);

            IntranetSystemException result = Assert.ThrowsAsync <IntranetSystemException>(async() => await sut.UpdateBudgetAccount(CreateBudgetAccountViewModel()));

            // ReSharper disable PossibleNullReferenceException
            Assert.That(result.ErrorCode, Is.EqualTo(ErrorCode.InternalError));
            // ReSharper restore PossibleNullReferenceException
        }
        public void UpdateBudgetAccount_WhenAccountingNumberIsWhiteSpace_ThrowsArgumentNullException()
        {
            Controller sut = CreateSut();

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

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

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

            // ReSharper disable PossibleNullReferenceException
            Assert.That(result.ParamName, Is.EqualTo("budgetAccountViewModel"));
            // ReSharper restore PossibleNullReferenceException
        }
Exemple #28
0
        public void UpdateBudgetAccount_WhenBudgetAccountViewModelIsInvalid_ThrowsIntranetSystemExceptionWhereMessageEndsWithErrorMessagesFromModelState()
        {
            string     errorMessage = _fixture.Create <string>();
            Controller sut          = CreateSut(false, errorMessage: errorMessage);

            IntranetSystemException result = Assert.ThrowsAsync <IntranetSystemException>(async() => await sut.UpdateBudgetAccount(CreateBudgetAccountViewModel()));

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

            IntranetSystemException result = Assert.ThrowsAsync <IntranetSystemException>(async() => await sut.UpdateBudgetAccount(CreateBudgetAccountViewModel()));

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