public void TestMethodCalculate()
        {
            ICreditInfo _creditInfo = _serviceContainer.GetInstance <ICreditInfo>();

            _creditInfo.Calculate(_сreditData._simplePaymentsInMonth36Sum10000Rate12);
            //Assert.AreEqual(_creditInfo.Calculate(_сreditData._simplePaymentsInMonth36Sum10000Rate12), 1);
        }
コード例 #2
0
        public void Add_WhenInfoCollectionIsNotNullAndOneInfoDoesExistWithinCollection_ThrowsIntranetSystemException()
        {
            IInfoCollection <ICreditInfo, Sut> sut = CreateSut();

            IList <ICreditInfo> infoCollection = new List <ICreditInfo>
            {
                _fixture.BuildCreditInfoMock().Object,
                                _fixture.BuildCreditInfoMock().Object,
                                _fixture.BuildCreditInfoMock().Object,
                                _fixture.BuildCreditInfoMock().Object,
                                _fixture.BuildCreditInfoMock().Object,
                                _fixture.BuildCreditInfoMock().Object,
                                _fixture.BuildCreditInfoMock().Object
            };

            ICreditInfo existingInfo = infoCollection[_random.Next(0, infoCollection.Count - 1)];

            sut.Add(existingInfo);

            IntranetSystemException result = Assert.Throws <IntranetSystemException>(() => sut.Add(existingInfo));

            // ReSharper disable PossibleNullReferenceException
            Assert.That(result.Message.Contains(existingInfo.GetType().Name), Is.True);
            Assert.That(result.ErrorCode, Is.EqualTo(ErrorCode.ObjectAlreadyExists));
            Assert.That(result.InnerException, Is.Null);
            // ReSharper restore PossibleNullReferenceException
        }
コード例 #3
0
 public HomeController(ILogger <HomeController> logger)
 {
     _logger           = logger;
     _serviceContainer = new Container().GetServiceContainer;
     _payinfo          = new AllPayments();
     _creditInfo       = _serviceContainer.GetInstance <ICreditInfo>();
 }
コード例 #4
0
        public async Task CalculateAsync_WhenCalled_ReturnsSameCreditInfo()
        {
            ICreditInfo sut = CreateSut();

            ICreditInfo result = await sut.CalculateAsync(DateTime.Now.AddDays(_random.Next(1, 365) * -1));

            Assert.That(result, Is.SameAs(sut));
        }
コード例 #5
0
        public void Credit_WhenSetterCalledWithValueEqualToZero_SetValueToZero()
        {
            ICreditInfo sut = CreateSut();

            sut.Credit = 0M;

            Assert.That(sut.Credit, Is.EqualTo(0M));
        }
コード例 #6
0
        private Mock <ICreditInfoCommand> CreateCreditInfoCommandMock(ICreditInfo creditInfo = null)
        {
            Mock <ICreditInfoCommand> creditInfoCommandMock = new Mock <ICreditInfoCommand>();

            creditInfoCommandMock.Setup(m => m.ToDomain(It.IsAny <IAccount>()))
            .Returns(creditInfo ?? _fixture.BuildCreditInfoMock().Object);
            return(creditInfoCommandMock);
        }
コード例 #7
0
        public void ToDomain_WhenAccountIsNotNull_ReturnsCreditInfo()
        {
            ICreditInfoCommand sut = CreateSut();

            ICreditInfo result = sut.ToDomain(_fixture.BuildAccountMock().Object);

            Assert.That(result, Is.TypeOf <CreditInfo>());
        }
コード例 #8
0
        public void ToDomain_WhenAccountIsNotNull_ReturnsCreditInfoWhereAccountIsEqualToArgument()
        {
            ICreditInfoCommand sut = CreateSut();

            IAccount    account = _fixture.BuildAccountMock().Object;
            ICreditInfo result  = sut.ToDomain(account);

            Assert.That(result.Account, Is.EqualTo(account));
        }
コード例 #9
0
        public void ToDomain_WhenAccountIsNotNull_ReturnsCreditInfoWhereMonthIsEqualToMonthInCreditInfoCommand()
        {
            short month            = (short)_random.Next(CreditInfo.MinMonth, CreditInfo.MaxMonth);
            ICreditInfoCommand sut = CreateSut(month: month);

            ICreditInfo result = sut.ToDomain(_fixture.BuildAccountMock().Object);

            Assert.That(result.Month, Is.EqualTo(month));
        }
コード例 #10
0
        public void ToDomain_WhenAccountIsNotNull_ReturnsCreditInfoWhereCreditIsEqualToCreditInCreditInfoCommand()
        {
            decimal            credit = _fixture.Create <decimal>();
            ICreditInfoCommand sut    = CreateSut(credit: credit);

            ICreditInfo result = sut.ToDomain(_fixture.BuildAccountMock().Object);

            Assert.That(result.Credit, Is.EqualTo(credit));
        }
コード例 #11
0
        public void Credit_WhenSetterCalledWithValueBelowZero_ThrowsArgumentException()
        {
            ICreditInfo sut = CreateSut();

            ArgumentException result = Assert.Throws <ArgumentException>(() => sut.Credit = Math.Abs(_fixture.Create <decimal>() + 0.75M) * -1);

            Assert.That(result.Message.StartsWith("The credit value cannot be below 0."), Is.True);
            Assert.That(result.ParamName, Is.EqualTo("value"));
        }
コード例 #12
0
        public async Task CalculateAsync_WhenCalled_AssertPostingLineCollectionWasCalledOnAccount()
        {
            Mock <IAccount> accountMock = _fixture.BuildAccountMock();
            ICreditInfo     sut         = CreateSut(accountMock.Object);

            await sut.CalculateAsync(DateTime.Now.AddDays(_random.Next(1, 365) * -1));

            accountMock.Verify(m => m.PostingLineCollection, Times.Once);
        }
コード例 #13
0
        public async Task CalculateAsync_WhenCalled_ReturnsSameCreditInfoWhereStatusDateEqualDateFromCall()
        {
            ICreditInfo sut = CreateSut();

            DateTime    statusDate = DateTime.Now.AddDays(_random.Next(1, 365) * -1);
            ICreditInfo result     = await sut.CalculateAsync(statusDate);

            Assert.That(result.StatusDate, Is.EqualTo(statusDate.Date));
        }
コード例 #14
0
        public void ToDomain_WhenAccountIsNotNull_ReturnsCreditInfoWhereYearIsEqualToYearInCreditInfoCommand()
        {
            short year             = (short)_random.Next(CreditInfo.MinYear, CreditInfo.MaxYear);
            ICreditInfoCommand sut = CreateSut(year);

            ICreditInfo result = sut.ToDomain(_fixture.BuildAccountMock().Object);

            Assert.That(result.Year, Is.EqualTo(year));
        }
コード例 #15
0
        public void Add_WhenInfoIsNotNullAndDoesNotExistWithinCollection_AddsInfoToCollection()
        {
            IInfoCollection <ICreditInfo, Sut> sut = CreateSut();

            ICreditInfo creditInfo = _fixture.BuildCreditInfoMock().Object;

            sut.Add(creditInfo);

            Assert.That(sut.Contains(creditInfo), Is.True);
        }
コード例 #16
0
        public void Credit_WhenSetterCalledWithValueGreaterToZero_SetValueToGivenValue()
        {
            ICreditInfo sut = CreateSut();

            decimal value = Math.Abs(_fixture.Create <decimal>() + 0.75M);

            sut.Credit = value;

            Assert.That(sut.Credit, Is.EqualTo(value));
        }
コード例 #17
0
        public async Task ApplyCalculationAsync_WhenCalledOnPostingLineWhereAccountValuesAtPostingDateWasNotGivenAndCalculatedAccountHasCreditInfoForPostingDate_ReturnsSamePostingLineWhereCreditOnAccountValuesAtPostingDateEqualToCreditFromCreditInfoForPostingDate()
        {
            IPostingLine sut = CreateSut();

            ICreditInfo           creditInfo           = _fixture.BuildCreditInfoMock().Object;
            ICreditInfoCollection creditInfoCollection = _fixture.BuildCreditInfoCollectionMock(creditInfoForFind: creditInfo).Object;
            IAccount     calculatedAccount             = _fixture.BuildAccountMock(creditInfoCollection: creditInfoCollection).Object;
            IPostingLine result = await sut.ApplyCalculationAsync(calculatedAccount);

            Assert.That(result.AccountValuesAtPostingDate.Credit, Is.EqualTo(creditInfo.Credit));
        }
コード例 #18
0
        internal static IPostingLine ToDomain(this PostingLineModel postingLineModel, IAccount account, IBudgetAccount budgetAccount, IContactAccount contactAccount, MapperCache mapperCache)
        {
            NullGuard.NotNull(postingLineModel, nameof(postingLineModel))
            .NotNull(account, nameof(account))
            .NotNull(mapperCache, nameof(mapperCache));

            Guid postingLineIdentification = Guid.Parse(postingLineModel.PostingLineIdentification);

            lock (mapperCache.SyncRoot)
            {
                if (mapperCache.PostingLineDictionary.TryGetValue(postingLineIdentification, out IPostingLine postingLine))
                {
                    return(postingLine);
                }

                ICreditInfo       creditInfo = account.CreditInfoCollection.Find(postingLineModel.PostingDate);
                ICreditInfoValues accountValuesAtPostingDate = new CreditInfoValues(creditInfo?.Credit ?? 0M, postingLineModel.PostingValueForAccount);

                IBudgetInfoValues budgetAccountValuesAtPostingDate = null;
                if (budgetAccount != null)
                {
                    IBudgetInfo budgetInfo = budgetAccount.BudgetInfoCollection.Find(postingLineModel.PostingDate);
                    budgetAccountValuesAtPostingDate = new BudgetInfoValues(budgetInfo?.Budget ?? 0M, postingLineModel.PostingValueForBudgetAccount ?? 0M);
                }

                IContactInfoValues contactAccountValuesAtPostingDate = null;
                if (contactAccount != null)
                {
                    contactAccountValuesAtPostingDate = new ContactInfoValues(postingLineModel.PostingValueForContactAccount ?? 0M);
                }

                postingLine = new PostingLine(postingLineIdentification, postingLineModel.PostingDate, postingLineModel.Reference, account, postingLineModel.Details, budgetAccount, postingLineModel.Debit ?? 0M, postingLineModel.Credit ?? 0M, contactAccount, postingLineModel.PostingLineIdentifier, accountValuesAtPostingDate, budgetAccountValuesAtPostingDate, contactAccountValuesAtPostingDate);
                postingLine.AddAuditInformation(postingLineModel.CreatedUtcDateTime, postingLineModel.CreatedByIdentifier, postingLineModel.ModifiedUtcDateTime, postingLineModel.ModifiedByIdentifier);

                mapperCache.PostingLineDictionary.Add(postingLineIdentification, postingLine);

                if (account.PostingLineCollection.Contains(postingLine) == false)
                {
                    account.PostingLineCollection.Add(postingLine);
                }

                if (budgetAccount != null && budgetAccount.PostingLineCollection.Contains(postingLine) == false)
                {
                    budgetAccount.PostingLineCollection.Add(postingLine);
                }

                if (contactAccount != null && contactAccount.PostingLineCollection.Contains(postingLine) == false)
                {
                    contactAccount.PostingLineCollection.Add(postingLine);
                }

                return(postingLine);
            }
        }
コード例 #19
0
        public void Add_WhenInfoIsNotNullAndDoesExistWithinCollection_ThrowsIntranetSystemException()
        {
            IInfoCollection <ICreditInfo, Sut> sut = CreateSut();

            ICreditInfo creditInfo = _fixture.BuildCreditInfoMock().Object;

            sut.Add(creditInfo);

            IntranetSystemException result = Assert.Throws <IntranetSystemException>(() => sut.Add(creditInfo));

            // ReSharper disable PossibleNullReferenceException
            Assert.That(result.Message.Contains(creditInfo.GetType().Name), Is.True);
            Assert.That(result.ErrorCode, Is.EqualTo(ErrorCode.ObjectAlreadyExists));
            Assert.That(result.InnerException, Is.Null);
            // ReSharper restore PossibleNullReferenceException
        }
コード例 #20
0
        public async Task CalculateAsync_WhenCalled_AssertBalanceIsCalculated()
        {
            DateTime today           = DateTime.Today;
            DateTime calculationDate = DateTime.Today.AddMonths(_random.Next(1, 5) * -1).AddDays(today.Day * -1).AddDays(1);

            int year  = calculationDate.Year;
            int month = calculationDate.Month;

            decimal calculatedPostingValue = _fixture.Create <decimal>();
            IPostingLineCollection postingLineCollection = _fixture.BuildPostingLineCollectionMock(calculatedPostingValue: calculatedPostingValue).Object;
            IAccount    account = _fixture.BuildAccountMock(postingLineCollection: postingLineCollection).Object;
            ICreditInfo sut     = CreateSut(account, (short)year, (short)month);

            ICreditInfo result = await sut.CalculateAsync(calculationDate);

            Assert.That(result.Balance, Is.EqualTo(calculatedPostingValue));
        }
コード例 #21
0
        public async Task UpdateAccountAsync_WhenCalled_UpdatesAccount()
        {
            IAccountingRepository sut = CreateSut();

            IAccountGroup[] accountGroupCollection = (await sut.GetAccountGroupsAsync()).ToArray();

            DateTime today = DateTime.Today;

            IAccount account = await sut.GetAccountAsync(WithExistingAccountingNumber(), WithExistingAccountNumberForAccount(), today);

            account.Description  = _fixture.Create <string>();
            account.Note         = _fixture.Create <string>();
            account.AccountGroup = accountGroupCollection[_random.Next(0, accountGroupCollection.Length - 1)];

            decimal credit = _random.Next(50, 70) * 1000;

            ICreditInfo creditInfo = account.CreditInfoCollection.Single(m => m.Year == today.AddMonths(-3).Year&& m.Month == today.AddMonths(-3).Month);

            creditInfo.Credit = credit;

            creditInfo        = account.CreditInfoCollection.Next(creditInfo);
            creditInfo.Credit = credit;

            creditInfo        = account.CreditInfoCollection.Next(creditInfo);
            creditInfo.Credit = credit;

            credit += _random.Next(5, 10) * 1000;

            creditInfo        = account.CreditInfoCollection.Next(creditInfo);
            creditInfo.Credit = credit;

            creditInfo        = account.CreditInfoCollection.Next(creditInfo);
            creditInfo.Credit = credit;

            creditInfo        = account.CreditInfoCollection.Next(creditInfo);
            creditInfo.Credit = credit;

            creditInfo        = account.CreditInfoCollection.Next(creditInfo);
            creditInfo.Credit = 0M;

            IAccount result = await sut.UpdateAccountAsync(account);

            Assert.That(result, Is.Not.Null);
        }
コード例 #22
0
        public async Task CalculateAsync_WhenStatusDateIsNewerThanCreditInfo_AssertCalculatePostingValueWasCalledOnPostingLineCollectionFromAccount()
        {
            DateTime statusDate = DateTime.Today;

            int year  = statusDate.AddMonths(-3).Year;
            int month = statusDate.AddMonths(-3).Month;

            Mock <IPostingLineCollection> postingLineCollectionMock = _fixture.BuildPostingLineCollectionMock();
            IAccount    account = _fixture.BuildAccountMock(postingLineCollection: postingLineCollectionMock.Object).Object;
            ICreditInfo sut     = CreateSut(account, (short)year, (short)month);

            await sut.CalculateAsync(statusDate);

            postingLineCollectionMock.Verify(m => m.CalculatePostingValue(
                                                 It.Is <DateTime>(value => value == DateTime.MinValue),
                                                 It.Is <DateTime>(value => value == new DateTime(year, month, DateTime.DaysInMonth(year, month))),
                                                 It.Is <int?>(value => value.HasValue == false)),
                                             Times.Once());
        }
コード例 #23
0
        public async Task CalculateAsync_WhenCreditInfoCollectionContainsCreditInfoForStatusDate_ReturnsCreditInfoCollectionWhereValuesAtStatusDateIsNotNull()
        {
            ICreditInfoCollection sut = CreateSut();

            DateTime    creditInfoOffset                   = DateTime.Today.AddDays(_random.Next(1, _random.Next(1, 365)) * -1);
            ICreditInfo creditInfoForStatusDate            = _fixture.BuildCreditInfoMock(creditInfoOffset, true).Object;
            IEnumerable <ICreditInfo> creditInfoCollection = new List <ICreditInfo>
            {
                creditInfoForStatusDate,
                _fixture.BuildCreditInfoMock(creditInfoOffset.AddMonths(-1)).Object,
                _fixture.BuildCreditInfoMock(creditInfoOffset.AddMonths(-2)).Object
            };

            sut.Add(creditInfoCollection);

            ICreditInfoCollection result = await sut.CalculateAsync(DateTime.Now.AddDays(_random.Next(1, 365) * -1));

            Assert.That(result.ValuesAtStatusDate, Is.Not.Null);
        }
コード例 #24
0
        public async Task CalculateAsync_WhenCreditInfoCollectionContainsCreditInfoForEndOfLastYearFromStatusDate_ReturnsCreditInfoCollectionWhereBalanceInValuesAtEndOfLastYearFromStatusDateIsEqualToBalanceInCreditInfoForEndOfLastYearFromStatusDate()
        {
            ICreditInfoCollection sut = CreateSut();

            DateTime    creditInfoOffset = DateTime.Today.AddDays(_random.Next(1, _random.Next(1, 365)) * -1);
            ICreditInfo creditInfoForEndOfLastYearFromStatusDate = _fixture.BuildCreditInfoMock(creditInfoOffset, isLastYearOfStatusDate: true).Object;
            IEnumerable <ICreditInfo> creditInfoCollection       = new List <ICreditInfo>
            {
                creditInfoForEndOfLastYearFromStatusDate,
                _fixture.BuildCreditInfoMock(creditInfoOffset.AddMonths(-1), isLastYearOfStatusDate: true).Object,
                _fixture.BuildCreditInfoMock(creditInfoOffset.AddMonths(-2), isLastYearOfStatusDate: true).Object
            };

            sut.Add(creditInfoCollection);

            ICreditInfoCollection result = await sut.CalculateAsync(DateTime.Now.AddDays(_random.Next(1, 365) * -1));

            Assert.That(result.ValuesAtEndOfLastYearFromStatusDate.Balance, Is.EqualTo(creditInfoForEndOfLastYearFromStatusDate.Balance));
        }
        internal static void Populate(this ICreditInfoCollection creditInfoCollection, IAccount account, ICreditInfo[] creditInfos, DateTime statusDate, DateTime statusDateForCreditInfos)
        {
            NullGuard.NotNull(creditInfoCollection, nameof(creditInfoCollection))
            .NotNull(account, nameof(account))
            .NotNull(creditInfos, nameof(creditInfos));

            DateTime fromDate = new DateTime(statusDate.AddYears(-1).Year, 1, 1);

            if (creditInfos.Length == 0)
            {
                creditInfoCollection.Add(BuildCreditInfo(account, (short)fromDate.Year, (short)fromDate.Month));
                creditInfoCollection.Add(BuildCreditInfo(account, (short)statusDateForCreditInfos.Year, (short)statusDateForCreditInfos.Month));

                creditInfoCollection.EnsurePopulation(account);

                return;
            }

            ICreditInfo creditInfoForFromDate = creditInfos.FindInfoForFromDate(fromDate,
                                                                                (year, month, creditInfoBeforeFromDate) => BuildCreditInfo(account, year, month, creditInfoBeforeFromDate),
                                                                                (year, month) => BuildCreditInfo(account, year, month));

            creditInfoCollection.Add(creditInfoForFromDate);

            creditInfoCollection.Add(creditInfos.Between(creditInfoForFromDate.ToDate.AddDays(1), statusDateForCreditInfos));

            ICreditInfo lastCreditInfo = creditInfoCollection.Last();

            if (lastCreditInfo == null || lastCreditInfo.Year > (short)statusDateForCreditInfos.Year || lastCreditInfo.Year == (short)statusDateForCreditInfos.Year && lastCreditInfo.Month >= (short)statusDateForCreditInfos.Month)
            {
                creditInfoCollection.EnsurePopulation(account);

                return;
            }

            creditInfoCollection.Add(BuildCreditInfo(account, (short)statusDateForCreditInfos.Year, (short)statusDateForCreditInfos.Month, lastCreditInfo));

            creditInfoCollection.EnsurePopulation(account);
        }
コード例 #26
0
        public Task <IPostingLine> ApplyCalculationAsync(IAccount calculatedAccount)
        {
            NullGuard.NotNull(calculatedAccount, nameof(calculatedAccount));

            return(Task.Run <IPostingLine>(() =>
            {
                lock (_syncRoot)
                {
                    Account = calculatedAccount;
                }

                if (_calculateAccountValuesAtPostingDate == false)
                {
                    return this;
                }

                ICreditInfo creditInfo = Account.CreditInfoCollection.Find(PostingDate);
                decimal balance = Account.PostingLineCollection.CalculatePostingValue(DateTime.MinValue, PostingDate, SortOrder);
                AccountValuesAtPostingDate = new CreditInfoValues(creditInfo?.Credit ?? 0M, balance);

                return this;
            }));
        }
コード例 #27
0
 private ICreditInfoCommand CreateCreditInfoCommand(ICreditInfo creditInfo = null)
 {
     return(CreateCreditInfoCommandMock(creditInfo).Object);
 }
        private static ICreditInfo BuildCreditInfo(IAccount account, short year, short month, ICreditInfo copyFromCreditInfo)
        {
            NullGuard.NotNull(account, nameof(account))
            .NotNull(copyFromCreditInfo, nameof(copyFromCreditInfo));

            ICreditInfo creditInfo = new CreditInfo(account, year, month, copyFromCreditInfo.Credit);

            creditInfo.AddAuditInformation(copyFromCreditInfo.CreatedDateTime.ToUniversalTime(), copyFromCreditInfo.CreatedByIdentifier, copyFromCreditInfo.ModifiedDateTime.ToUniversalTime(), copyFromCreditInfo.ModifiedByIdentifier);
            return(creditInfo);
        }