Beispiel #1
0
        public async Task CalculateAsync_WhenCalledMultipleTimesWithSameStatusDate_AssertCalculateAsyncWasCalledOnEachPostingLineWhereStatusDateDoesNotMatchStatusDateFromArgument()
        {
            IPostingLineCollection sut = CreateSut();

            IEnumerable <Mock <IPostingLine> > postingLineMockCollection = new List <Mock <IPostingLine> >
            {
                _fixture.BuildPostingLineMock(statusDate: DateTime.MinValue),
                _fixture.BuildPostingLineMock(statusDate: DateTime.MinValue),
                _fixture.BuildPostingLineMock(statusDate: DateTime.MinValue),
                _fixture.BuildPostingLineMock(statusDate: DateTime.MinValue),
                _fixture.BuildPostingLineMock(statusDate: DateTime.MinValue),
                _fixture.BuildPostingLineMock(statusDate: DateTime.MinValue),
                _fixture.BuildPostingLineMock(statusDate: DateTime.MinValue)
            };

            sut.Add(postingLineMockCollection.Select(postingLineMock => postingLineMock.Object).ToArray());

            DateTime statusDate = DateTime.Now.AddDays(_random.Next(1, 365) * -1);

            await(await(await sut.CalculateAsync(statusDate)).CalculateAsync(statusDate)).CalculateAsync(statusDate);

            foreach (Mock <IPostingLine> postingLineMock in postingLineMockCollection)
            {
                postingLineMock.Verify(m => m.CalculateAsync(It.Is <DateTime>(value => value == statusDate.Date)), Times.Once);
            }
        }
Beispiel #2
0
        public async Task CalculateAsync_WhenCalled_AssertCalculateAsyncWasNotCalledOnAnyPostingLineWhereStatusDateMatchesStatusDateFromArgument()
        {
            IPostingLineCollection sut = CreateSut();

            DateTime statusDate = DateTime.Now.AddDays(_random.Next(1, 365) * -1);
            IEnumerable <Mock <IPostingLine> > postingLineMockCollection = new List <Mock <IPostingLine> >
            {
                _fixture.BuildPostingLineMock(statusDate: statusDate),
                _fixture.BuildPostingLineMock(statusDate: statusDate),
                _fixture.BuildPostingLineMock(statusDate: statusDate),
                _fixture.BuildPostingLineMock(statusDate: statusDate),
                _fixture.BuildPostingLineMock(statusDate: statusDate),
                _fixture.BuildPostingLineMock(statusDate: statusDate),
                _fixture.BuildPostingLineMock(statusDate: statusDate)
            };

            sut.Add(postingLineMockCollection.Select(postingLineMock => postingLineMock.Object).ToArray());

            await sut.CalculateAsync(statusDate);

            foreach (Mock <IPostingLine> postingLineMock in postingLineMockCollection)
            {
                postingLineMock.Verify(m => m.CalculateAsync(It.IsAny <DateTime>()), Times.Never);
            }
        }
Beispiel #3
0
        public async Task CalculateAsync_WhenCalled_AssertStatusDateWasCalledTreeTimesOnEachPostingLine()
        {
            IPostingLineCollection sut = CreateSut();

            IEnumerable <Mock <IPostingLine> > postingLineMockCollection = new List <Mock <IPostingLine> >
            {
                _fixture.BuildPostingLineMock(statusDate: DateTime.MinValue),
                _fixture.BuildPostingLineMock(statusDate: DateTime.MinValue),
                _fixture.BuildPostingLineMock(statusDate: DateTime.MinValue),
                _fixture.BuildPostingLineMock(statusDate: DateTime.MinValue),
                _fixture.BuildPostingLineMock(statusDate: DateTime.MinValue),
                _fixture.BuildPostingLineMock(statusDate: DateTime.MinValue),
                _fixture.BuildPostingLineMock(statusDate: DateTime.MinValue)
            };

            sut.Add(postingLineMockCollection.Select(postingLineMock => postingLineMock.Object).ToArray());

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

            foreach (Mock <IPostingLine> postingLineMock in postingLineMockCollection)
            {
                postingLineMock.Verify(m => m.StatusDate, Times.Exactly(3));
            }
        }
Beispiel #4
0
        public void Add_WhenPostingLineCollectionIsNotNullAndOnePostingLineDoesExistWithinCollection_ThrowsIntranetSystemException()
        {
            IPostingLineCollection sut = CreateSut();

            IList <IPostingLine> postingLineCollection = new List <IPostingLine>
            {
                _fixture.BuildPostingLineMock().Object,
                                 _fixture.BuildPostingLineMock().Object,
                                 _fixture.BuildPostingLineMock().Object,
                                 _fixture.BuildPostingLineMock().Object,
                                 _fixture.BuildPostingLineMock().Object,
                                 _fixture.BuildPostingLineMock().Object,
                                 _fixture.BuildPostingLineMock().Object
            };

            IPostingLine existingPostingLine = postingLineCollection[_random.Next(0, postingLineCollection.Count - 1)];

            sut.Add(existingPostingLine);

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

            // ReSharper disable PossibleNullReferenceException
            Assert.That(result.Message.Contains(existingPostingLine.GetType().Name), Is.True);
            // ReSharper restore PossibleNullReferenceException
            Assert.That(result.ErrorCode, Is.EqualTo(ErrorCode.ObjectAlreadyExists));
            Assert.That(result.InnerException, Is.Null);
        }
        public async Task ApplyCalculationAsync_WhenCalled_AssertApplyCalculationAsyncWasNotCalledOnAnyPostingLineNotMatchingCalculatedAccount()
        {
            IPostingLineCollection sut = CreateSut();

            int         accountingNumber = _fixture.Create <int>();
            string      accountNumber    = _fixture.Create <string>();
            IAccounting accounting       = _fixture.BuildAccountingMock(accountingNumber).Object;
            IEnumerable <Mock <IPostingLine> > postingLineMockCollection = new List <Mock <IPostingLine> >
            {
                _fixture.BuildPostingLineMock(account: _fixture.BuildAccountMock(accounting).Object),
                _fixture.BuildPostingLineMock(account: _fixture.BuildAccountMock(accounting).Object),
                _fixture.BuildPostingLineMock(account: _fixture.BuildAccountMock(accounting).Object),
                _fixture.BuildPostingLineMock(account: _fixture.BuildAccountMock(accounting).Object),
                _fixture.BuildPostingLineMock(account: _fixture.BuildAccountMock(accounting).Object),
                _fixture.BuildPostingLineMock(account: _fixture.BuildAccountMock(accounting).Object),
                _fixture.BuildPostingLineMock(account: _fixture.BuildAccountMock(accounting).Object)
            };

            sut.Add(postingLineMockCollection.Select(postingLineMock => postingLineMock.Object).ToArray());

            IAccount calculatedAccount = _fixture.BuildAccountMock(accounting, accountNumber).Object;
            await sut.ApplyCalculationAsync(calculatedAccount);

            foreach (Mock <IPostingLine> postingLineMock in postingLineMockCollection)
            {
                postingLineMock.Verify(m => m.ApplyCalculationAsync(It.IsAny <IAccount>()), Times.Never);
            }
        }
Beispiel #6
0
        public async Task ApplyCalculationAsync_WhenCalled_AssertApplyCalculationAsyncWasCalledOnEachPostingLineMatchingCalculatedContactAccount()
        {
            IPostingLineCollection sut = CreateSut();

            int             accountingNumber = _fixture.Create <int>();
            string          accountNumber    = _fixture.Create <string>();
            IAccounting     accounting       = _fixture.BuildAccountingMock(accountingNumber).Object;
            IContactAccount contactAccount   = _fixture.BuildContactAccountMock(accounting, accountNumber).Object;
            IEnumerable <Mock <IPostingLine> > postingLineMockCollection = new List <Mock <IPostingLine> >
            {
                _fixture.BuildPostingLineMock(account: _fixture.BuildAccountMock(accounting).Object, contactAccount: contactAccount),
                _fixture.BuildPostingLineMock(account: _fixture.BuildAccountMock(accounting).Object, contactAccount: contactAccount),
                _fixture.BuildPostingLineMock(account: _fixture.BuildAccountMock(accounting).Object, contactAccount: contactAccount),
                _fixture.BuildPostingLineMock(account: _fixture.BuildAccountMock(accounting).Object, contactAccount: contactAccount),
                _fixture.BuildPostingLineMock(account: _fixture.BuildAccountMock(accounting).Object, contactAccount: contactAccount),
                _fixture.BuildPostingLineMock(account: _fixture.BuildAccountMock(accounting).Object, contactAccount: contactAccount),
                _fixture.BuildPostingLineMock(account: _fixture.BuildAccountMock(accounting).Object, contactAccount: contactAccount)
            };

            sut.Add(postingLineMockCollection.Select(postingLineMock => postingLineMock.Object).ToArray());

            IContactAccount calculatedContactAccount = _fixture.BuildContactAccountMock(accounting, accountNumber).Object;
            await sut.ApplyCalculationAsync(calculatedContactAccount);

            foreach (Mock <IPostingLine> postingLineMock in postingLineMockCollection)
            {
                postingLineMock.Verify(m => m.ApplyCalculationAsync(It.Is <IContactAccount>(value => value != null && value == calculatedContactAccount)), Times.Once);
            }
        }
Beispiel #7
0
        public async Task ApplyCalculationAsync_WhenCalled_AssertAccountingWasCalledOnEachPostingLine()
        {
            IPostingLineCollection sut = CreateSut();

            int            accountingNumber = _fixture.Create <int>();
            string         accountNumber    = _fixture.Create <string>();
            IAccounting    accounting       = _fixture.BuildAccountingMock(accountingNumber).Object;
            IBudgetAccount budgetAccount    = _fixture.BuildBudgetAccountMock(accounting, accountNumber).Object;
            IEnumerable <Mock <IPostingLine> > postingLineMockCollection = new List <Mock <IPostingLine> >
            {
                _fixture.BuildPostingLineMock(account: _fixture.BuildAccountMock(accounting).Object, budgetAccount: budgetAccount),
                _fixture.BuildPostingLineMock(account: _fixture.BuildAccountMock(accounting).Object, budgetAccount: budgetAccount),
                _fixture.BuildPostingLineMock(account: _fixture.BuildAccountMock(accounting).Object, budgetAccount: budgetAccount),
                _fixture.BuildPostingLineMock(account: _fixture.BuildAccountMock(accounting).Object, budgetAccount: budgetAccount),
                _fixture.BuildPostingLineMock(account: _fixture.BuildAccountMock(accounting).Object, budgetAccount: budgetAccount),
                _fixture.BuildPostingLineMock(account: _fixture.BuildAccountMock(accounting).Object, budgetAccount: budgetAccount),
                _fixture.BuildPostingLineMock(account: _fixture.BuildAccountMock(accounting).Object, budgetAccount: budgetAccount)
            };

            sut.Add(postingLineMockCollection.Select(postingLineMock => postingLineMock.Object).ToArray());

            IBudgetAccount calculatedBudgetAccount = _fixture.BuildBudgetAccountMock(accounting, accountNumber).Object;
            await sut.ApplyCalculationAsync(calculatedBudgetAccount);

            foreach (Mock <IPostingLine> postingLineMock in postingLineMockCollection)
            {
                postingLineMock.Verify(m => m.Accounting, Times.Once);
            }
        }
Beispiel #8
0
        public void Add_WhenPostingLineIsNotNullAndDoesNotExistWithinCollection_AddsPostingLineToCollection()
        {
            IPostingLineCollection sut = CreateSut();

            IPostingLine postingLine = _fixture.BuildPostingLineMock().Object;

            sut.Add(postingLine);

            Assert.That(sut.Contains(postingLine), Is.True);
        }
        public void Ordered_WhenCalled_ReturnsNotNull()
        {
            IPostingLineCollection sut = CreateSut();

            sut.Add(_fixture.CreateMany <IPostingLine>(_random.Next(10, 25)).ToArray());

            IPostingLineCollection result = sut.Ordered();

            Assert.That(result, Is.Not.Null);
        }
        public void Ordered_WhenCalled_ReturnsPostingLineCollection()
        {
            IPostingLineCollection sut = CreateSut();

            sut.Add(_fixture.CreateMany <IPostingLine>(_random.Next(10, 25)).ToArray());

            IPostingLineCollection result = sut.Ordered();

            Assert.That(result, Is.TypeOf <Domain.Accounting.PostingLineCollection>());
        }
        public void Ordered_WhenPostingLineCollectionHasPostingLines_ReturnsPostingLineCollectionWithSameAmountOfPostingLines()
        {
            IPostingLineCollection sut = CreateSut();

            IPostingLine[] postingLines = _fixture.CreateMany <IPostingLine>(_random.Next(10, 25)).ToArray();
            sut.Add(postingLines);

            IPostingLineCollection result = sut.Ordered();

            Assert.That(result.Count(), Is.EqualTo(postingLines.Length));
        }
        public void Top_WhenPostingLineCollectionContainsPostingLinesMoreThanNumberOfPostingLines_ReturnsPostingLineCollectionWithNumberOfPostingLines()
        {
            IPostingLineCollection sut = CreateSut();

            int numberOfPostingLines = _random.Next(10, 25);

            sut.Add(_fixture.CreateMany <IPostingLine>(numberOfPostingLines + _random.Next(1, 10)));

            IPostingLineCollection result = sut.Top(numberOfPostingLines);

            Assert.That(result.Count(), Is.EqualTo(numberOfPostingLines));
        }
        public void Top_WhenPostingLineCollectionContainsPostingLinesEqualToNumberOfPostingLines_ReturnsPostingLineCollectionWithSameAmountOfPostingLines()
        {
            IPostingLineCollection sut = CreateSut();

            int numberOfPostingLines = _random.Next(10, 25);

            IPostingLine[] postingLines = _fixture.CreateMany <IPostingLine>(numberOfPostingLines).ToArray();
            sut.Add(postingLines);

            IPostingLineCollection result = sut.Top(numberOfPostingLines);

            Assert.That(result.Count(), Is.EqualTo(postingLines.Length));
        }
        public void Ordered_WhenPostingLineCollectionHasPostingLines_ReturnsPostingLineCollectionWithSamePostingLines()
        {
            IPostingLineCollection sut = CreateSut();

            IPostingLine[] postingLines = _fixture.CreateMany <IPostingLine>(_random.Next(10, 25)).ToArray();
            sut.Add(postingLines);

            IPostingLineCollection result = sut.Ordered();

            foreach (IPostingLine postingLine in postingLines)
            {
                Assert.That(result.Contains(postingLine), Is.True);
            }
        }
        public void Top_WhenPostingLineCollectionContainsPostingLinesMoreThanNumberOfPostingLines_ReturnsPostingLineCollectionWithPostingLinesFromPostingLinesCollection()
        {
            IPostingLineCollection sut = CreateSut();

            int numberOfPostingLines = _random.Next(10, 25);

            sut.Add(_fixture.CreateMany <IPostingLine>(numberOfPostingLines + _random.Next(1, 10)));

            IPostingLineCollection result = sut.Top(numberOfPostingLines);

            foreach (IPostingLine postingLine in result)
            {
                Assert.That(sut.Contains(postingLine), Is.True);
            }
        }
Beispiel #16
0
        public void Add_WhenPostingLineIsNotNullAndDoesExistWithinCollection_ThrowsIntranetSystemException()
        {
            IPostingLineCollection sut = CreateSut();

            IPostingLine postingLine = _fixture.BuildPostingLineMock().Object;

            sut.Add(postingLine);

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

            // ReSharper disable PossibleNullReferenceException
            Assert.That(result.Message.Contains(postingLine.GetType().Name), Is.True);
            // ReSharper restore PossibleNullReferenceException
            Assert.That(result.ErrorCode, Is.EqualTo(ErrorCode.ObjectAlreadyExists));
            Assert.That(result.InnerException, Is.Null);
        }
        public void Top_WhenPostingLineCollectionContainsPostingLinesEqualToNumberOfPostingLines_ReturnsPostingLineCollectionWithSamePostingLines()
        {
            IPostingLineCollection sut = CreateSut();

            int numberOfPostingLines = _random.Next(10, 25);

            IPostingLine[] postingLines = _fixture.CreateMany <IPostingLine>(numberOfPostingLines).ToArray();
            sut.Add(postingLines);

            IPostingLineCollection result = sut.Top(numberOfPostingLines);

            foreach (IPostingLine postingLine in postingLines)
            {
                Assert.That(result.Contains(postingLine), Is.True);
            }
        }
Beispiel #18
0
        public void Add_WhenPostingLineCollectionIsNotNullAndEachPostingLineDoesNotExistWithinCollection_AddsEachPostingLineToCollection()
        {
            IPostingLineCollection sut = CreateSut();

            IEnumerable <IPostingLine> postingLineCollection = new List <IPostingLine>
            {
                _fixture.BuildPostingLineMock().Object,
                                       _fixture.BuildPostingLineMock().Object,
                                       _fixture.BuildPostingLineMock().Object,
                                       _fixture.BuildPostingLineMock().Object,
                                       _fixture.BuildPostingLineMock().Object,
                                       _fixture.BuildPostingLineMock().Object,
                                       _fixture.BuildPostingLineMock().Object
            };

            sut.Add(postingLineCollection);

            Assert.That(postingLineCollection.All(account => sut.Contains(account)), Is.True);
        }
        public void Ordered_WhenPostingLineCollectionHasPostingLines_ReturnsPostingLineCollectionWithOrderedPostingLines()
        {
            IPostingLineCollection sut = CreateSut();

            sut.Add(_fixture.CreateMany <IPostingLine>(_random.Next(10, 25)));

            IPostingLineCollection result = sut.Ordered();

            IPostingLine[] postingLines = result.ToArray();
            for (int i = 1; i < postingLines.Length; i++)
            {
                Assert.That(postingLines[i].PostingDate, Is.LessThanOrEqualTo(postingLines[i - 1].PostingDate));
                if (postingLines[i].PostingDate.Date != postingLines[i - 1].PostingDate.Date)
                {
                    continue;
                }

                Assert.That(postingLines[i].SortOrder, Is.LessThanOrEqualTo(postingLines[i - 1].SortOrder));
            }
        }
        public void Top_WhenPostingLineCollectionContainsPostingLinesMoreThanOfPostingLines_ReturnsPostingLineCollectionWithOrderedPostingLines()
        {
            IPostingLineCollection sut = CreateSut();

            int numberOfPostingLines = _random.Next(10, 25);

            sut.Add(_fixture.CreateMany <IPostingLine>(numberOfPostingLines + _random.Next(1, 10)));

            IPostingLineCollection result = sut.Top(numberOfPostingLines);

            IPostingLine[] postingLines = result.ToArray();
            for (int i = 1; i < postingLines.Length; i++)
            {
                Assert.That(postingLines[i].PostingDate, Is.LessThanOrEqualTo(postingLines[i - 1].PostingDate));

                if (postingLines[i].PostingDate.Date == postingLines[i - 1].PostingDate.Date)
                {
                    Assert.That(postingLines[i].SortOrder, Is.LessThanOrEqualTo(postingLines[i - 1].SortOrder));
                }
            }
        }
        public void Top_WhenPostingLineCollectionContainsPostingLinesMoreThanOfPostingLines_ReturnsPostingLineCollectionWithTopPostingLinesFromPostingLineCollection()
        {
            IPostingLineCollection sut = CreateSut();

            DateTime     maxDate = DateTime.Today.AddDays(_random.Next(1, 7) * -1);
            IPostingLine postingLineNotWithinTop1   = _fixture.BuildPostingLineMock(postingDate: maxDate.AddDays(_random.Next(7, 30) * -1)).Object;
            IPostingLine postingLineNotWithinTop2   = _fixture.BuildPostingLineMock(postingDate: maxDate.AddDays(_random.Next(7, 30) * -1)).Object;
            IPostingLine postingLineNotWithinTop3   = _fixture.BuildPostingLineMock(postingDate: maxDate.AddDays(_random.Next(7, 30) * -1)).Object;
            IPostingLine postingLineNotWithinTop4   = _fixture.BuildPostingLineMock(postingDate: maxDate.AddDays(_random.Next(7, 30) * -1)).Object;
            IPostingLine postingLineNotWithinTop5   = _fixture.BuildPostingLineMock(postingDate: maxDate.AddDays(_random.Next(7, 30) * -1)).Object;
            IPostingLine postingLineWithinTop1      = _fixture.BuildPostingLineMock(postingDate: maxDate.AddDays(_random.Next(0, 7) * -1)).Object;
            IPostingLine postingLineWithinTop2      = _fixture.BuildPostingLineMock(postingDate: maxDate.AddDays(_random.Next(0, 6) * -1)).Object;
            IPostingLine postingLineWithinTop3      = _fixture.BuildPostingLineMock(postingDate: maxDate.AddDays(_random.Next(0, 6) * -1)).Object;
            IEnumerable <IPostingLine> postingLines = new List <IPostingLine>
            {
                postingLineNotWithinTop1,
                postingLineNotWithinTop2,
                postingLineNotWithinTop3,
                postingLineNotWithinTop4,
                postingLineNotWithinTop5,
                postingLineWithinTop1,
                postingLineWithinTop2,
                postingLineWithinTop3
            };

            sut.Add(postingLines);

            IPostingLineCollection result = sut.Top(3);

            Assert.That(result.Contains(postingLineNotWithinTop1), Is.False);
            Assert.That(result.Contains(postingLineNotWithinTop2), Is.False);
            Assert.That(result.Contains(postingLineNotWithinTop3), Is.False);
            Assert.That(result.Contains(postingLineNotWithinTop4), Is.False);
            Assert.That(result.Contains(postingLineNotWithinTop5), Is.False);
            Assert.That(result.Contains(postingLineWithinTop1), Is.True);
            Assert.That(result.Contains(postingLineWithinTop2), Is.True);
            Assert.That(result.Contains(postingLineWithinTop3), Is.True);
        }
        public void Ordered_WhenCalled_AssertSortOrderWasCalledOnEachPostingLine()
        {
            IPostingLineCollection sut = CreateSut();

            IEnumerable <Mock <IPostingLine> > postingLineMockCollection = new List <Mock <IPostingLine> >
            {
                _fixture.BuildPostingLineMock(postingDate: DateTime.Today.AddDays(_random.Next(0, 30) * -1), sortOrder: _random.Next(100)),
                _fixture.BuildPostingLineMock(postingDate: DateTime.Today.AddDays(_random.Next(0, 30) * -1), sortOrder: _random.Next(100)),
                _fixture.BuildPostingLineMock(postingDate: DateTime.Today.AddDays(_random.Next(0, 30) * -1), sortOrder: _random.Next(100)),
                _fixture.BuildPostingLineMock(postingDate: DateTime.Today.AddDays(_random.Next(0, 30) * -1), sortOrder: _random.Next(100)),
                _fixture.BuildPostingLineMock(postingDate: DateTime.Today.AddDays(_random.Next(0, 30) * -1), sortOrder: _random.Next(100)),
                _fixture.BuildPostingLineMock(postingDate: DateTime.Today.AddDays(_random.Next(0, 30) * -1), sortOrder: _random.Next(100)),
                _fixture.BuildPostingLineMock(postingDate: DateTime.Today.AddDays(_random.Next(0, 30) * -1), sortOrder: _random.Next(100))
            };

            sut.Add(postingLineMockCollection.Select(postingLineMock => postingLineMock.Object));

            sut.Ordered();

            foreach (Mock <IPostingLine> postingLineMock in postingLineMockCollection)
            {
                postingLineMock.Verify(m => m.SortOrder, Times.Once);
            }
        }
Beispiel #23
0
        public void Add_WhenPostingLineCollectionIsNull_ThrowsArgumentNullException()
        {
            IPostingLineCollection sut = CreateSut();

            ArgumentNullException result = Assert.Throws <ArgumentNullException>(() => sut.Add((IEnumerable <IPostingLine>)null));

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