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

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

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

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

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

            BudgetAccountGroupViewModel model  = CreateModel();
            RedirectToActionResult      result = (RedirectToActionResult)await sut.UpdateBudgetAccountGroup(model);

            Assert.That(result.ActionName, Is.EqualTo("BudgetAccountGroups"));
        }
        public async Task UpdateBudgetAccountGroup_WhenCalledWithNumber_AssertQueryAsyncWasCalledOnQueryBus()
        {
            Controller sut = CreateSut();

            int number = _fixture.Create <int>();
            await sut.UpdateBudgetAccountGroup(number);

            _queryBusMock.Verify(m => m.QueryAsync <IGetBudgetAccountGroupQuery, IBudgetAccountGroup>(It.Is <IGetBudgetAccountGroupQuery>(value => value.Number == number)), Times.Once);
        }
        public async Task UpdateBudgetAccountGroup_WhenCalledWithValidModel_ReturnsRedirectToActionResult()
        {
            Controller sut = CreateSut();

            BudgetAccountGroupViewModel model = CreateModel();
            IActionResult result = await sut.UpdateBudgetAccountGroup(model);

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

            BudgetAccountGroupViewModel model = CreateModel();
            await sut.UpdateBudgetAccountGroup(model);

            _commandBusMock.Verify(m => m.PublishAsync(It.Is <IUpdateBudgetAccountGroupCommand>(command => command.Number == model.Number && string.CompareOrdinal(command.Name, model.Name) == 0)), Times.Once);
        }
        public async Task UpdateBudgetAccountGroup_WhenCalledWithInvalidModel_ReturnsViewResultWhereViewNameIsEqualToUpdateBudgetAccountGroup()
        {
            Controller sut = CreateSut(modelIsValid: false);

            BudgetAccountGroupViewModel model = CreateModel();
            ViewResult result = (ViewResult)await sut.UpdateBudgetAccountGroup(model);

            Assert.That(result.ViewName, Is.EqualTo("UpdateBudgetAccountGroup"));
        }
        public async Task UpdateBudgetAccountGroup_WhenCalledWithInvalidModel_AssertPublishAsyncWasNotCalledOnCommandBus()
        {
            Controller sut = CreateSut(modelIsValid: false);

            BudgetAccountGroupViewModel model = CreateModel();
            await sut.UpdateBudgetAccountGroup(model);

            _commandBusMock.Verify(m => m.PublishAsync(It.IsAny <IUpdateBudgetAccountGroupCommand>()), Times.Never);
        }
        public async Task UpdateBudgetAccountGroup_WhenCalledWithInvalidModel_ReturnsViewResultWhereModelIsEqualToInvalidModel()
        {
            Controller sut = CreateSut(modelIsValid: false);

            BudgetAccountGroupViewModel model = CreateModel();
            ViewResult result = (ViewResult)await sut.UpdateBudgetAccountGroup(model);

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

            BudgetAccountGroupViewModel budgetAccountGroupViewModel = (BudgetAccountGroupViewModel)result.Model;

            Assert.That(budgetAccountGroupViewModel, Is.EqualTo(model));
        }
        public async Task UpdateBudgetAccountGroup_WhenCalledWithNumber_ReturnsViewResultWhereModelIsBudgetAccountGroupViewModel()
        {
            int    number = _fixture.Create <int>();
            string name   = _fixture.Create <string>();
            IBudgetAccountGroup budgetAccountGroup = _fixture.BuildBudgetAccountGroupMock(number, name).Object;
            Controller          sut = CreateSut(budgetAccountGroup);

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

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

            BudgetAccountGroupViewModel budgetAccountGroupViewModel = (BudgetAccountGroupViewModel)result.Model;

            Assert.That(budgetAccountGroupViewModel, Is.Not.Null);
            Assert.That(budgetAccountGroupViewModel.Number, Is.EqualTo(number));
            Assert.That(budgetAccountGroupViewModel.Name, Is.EqualTo(name));
            Assert.That(budgetAccountGroupViewModel.EditMode, Is.EqualTo(EditMode.Edit));
        }
        public void UpdateBudgetAccountGroup_WhenCalledWithModelWhereModelIsNull_ThrowsArgumentNullException()
        {
            Controller sut = CreateSut();

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

            Assert.That(result.ParamName, Is.EqualTo("budgetAccountGroupViewModel"));
        }