public async Task CreateAccount_WhenCalledWithAccountingNumberForExistingAccounting_ReturnsPartialViewResultWhereModelIsAccountViewModelWithCreditInfosContainingDataForNextYear() { Controller sut = CreateSut(); PartialViewResult result = (PartialViewResult)await sut.CreateAccount(_fixture.Create <int>()); AccountViewModel accountViewModel = (AccountViewModel)result.Model; short nextYear = (short)(DateTime.Today.Year + 1); short currentMonth = (short)DateTime.Today.Month; if (currentMonth == 1) { Assert.That(accountViewModel.CreditInfos.ContainsKey(nextYear), Is.False); return; } Assert.That(accountViewModel.CreditInfos.ContainsKey(nextYear), Is.True); CreditInfoCollectionViewModel creditInfoCollectionViewModel = accountViewModel.CreditInfos[nextYear]; Assert.That(creditInfoCollectionViewModel, Is.Not.Null); Assert.That(creditInfoCollectionViewModel.Count, Is.EqualTo(currentMonth - 1)); for (short month = 1; month < currentMonth; month++) { CreditInfoViewModel creditInfoViewModel = creditInfoCollectionViewModel.Single(m => m.Year == nextYear && m.Month == month); Assert.That(creditInfoViewModel.EditMode, Is.EqualTo(EditMode.Create)); Assert.That(creditInfoViewModel.Credit, Is.EqualTo(0M)); Assert.That(creditInfoViewModel.Balance, Is.EqualTo(0M)); Assert.That(creditInfoViewModel.Available, Is.EqualTo(0M)); } }
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); } }