public void Ordered_WhenPostingWarningCollectionHasPostingWarnings_ReturnsPostingWarningCollectionWithOrderedPostingWarnings()
        {
            IPostingWarningCollection sut = CreateSut();

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

            IPostingWarningCollection result = sut.Ordered();

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

                Assert.That(postingWarnings[i].PostingLine.SortOrder, Is.LessThanOrEqualTo(postingWarnings[i - 1].PostingLine.SortOrder));
                if (postingWarnings[i].PostingLine.SortOrder != postingWarnings[i - 1].PostingLine.SortOrder)
                {
                    continue;
                }

                Assert.That((int)postingWarnings[i].Reason, Is.GreaterThanOrEqualTo((int)postingWarnings[i - 1].Reason));
            }
        }
        public void Ordered_WhenPostingWarningCollectionIsEmpty_ReturnsEmptyPostingWarningCollection()
        {
            IPostingWarningCollection sut = CreateSut();

            IPostingWarningCollection result = sut.Ordered();

            Assert.That(result, Is.Empty);
        }
        public void PostingWarningCollection_WhenCalculateAsyncHasNotBeenCalledOnPostingJournalResult_ReturnsEmptyPostingWarningCollection()
        {
            IPostingJournalResult sut = CreateSut();

            IPostingWarningCollection result = sut.PostingWarningCollection;

            Assert.That(result, Is.Empty);
        }
        public void PostingWarningCollection_WhenCalculateAsyncHasNotBeenCalledOnPostingJournalResult_ReturnsPostingWarningCollection()
        {
            IPostingJournalResult sut = CreateSut();

            IPostingWarningCollection result = sut.PostingWarningCollection;

            Assert.That(result, Is.TypeOf <Domain.Accounting.PostingWarningCollection>());
        }
        public void Ordered_WhenCalled_ReturnsPostingWarningCollection()
        {
            IPostingWarningCollection sut = CreateSut();

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

            IPostingWarningCollection result = sut.Ordered();

            Assert.That(result, Is.TypeOf <Domain.Accounting.PostingWarningCollection>());
        }
        public void Ordered_WhenCalled_ReturnsNotNull()
        {
            IPostingWarningCollection sut = CreateSut();

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

            IPostingWarningCollection result = sut.Ordered();

            Assert.That(result, Is.Not.Null);
        }
Ejemplo n.º 7
0
        public void Add_WhenPostingWarningCollectionIsNull_ThrowsArgumentNullException()
        {
            IPostingWarningCollection sut = CreateSut();

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

            // ReSharper disable PossibleNullReferenceException
            Assert.That(result.ParamName, Is.EqualTo("postingWarningCollection"));
            // ReSharper restore PossibleNullReferenceException
        }
Ejemplo n.º 8
0
        public void Add_WhenPostingWarningIsNotNull_AddsPostingWarningToCollection()
        {
            IPostingWarningCollection sut = CreateSut();

            IPostingWarning postingWarning = _fixture.BuildPostingWarningMock().Object;

            sut.Add(postingWarning);

            Assert.That(sut.Contains(postingWarning), Is.True);
        }
        public async Task CalculateAsync_WhenCalled_ReturnsSamePostingJournalResultWherePostingWarningCollectionIsEqualToPostingWarningCollectionFromPostingWarningCalculator()
        {
            IPostingWarningCollection postingWarningCollection = _fixture.BuildPostingWarningCollectionMock().Object;
            IPostingWarningCalculator postingWarningCalculator = _fixture.BuildPostingWarningCalculatorMock(postingWarningCollection).Object;
            IPostingJournalResult     sut = CreateSut(postingWarningCalculator: postingWarningCalculator);

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

            Assert.That(result.PostingWarningCollection, Is.SameAs(postingWarningCollection));
        }
        public async Task ExecuteAsync_WhenNoPostingJournalResultWasReturnedFromAccountingRepository_ReturnsPostingJournalResultWherePostingWarningCollectionEqualToPostingWarningCollectionFromPostingWarningCalculator()
        {
            IPostingWarningCollection postingWarningCollection = _fixture.BuildPostingWarningCollectionMock(isEmpty: true).Object;
            CommandHandler            sut = CreateSut(false, postingWarningCollection: postingWarningCollection);

            IApplyPostingJournalCommand applyPostingJournalCommand = CreateApplyPostingJournalCommand();
            IPostingJournalResult       result = await sut.ExecuteAsync(applyPostingJournalCommand);

            Assert.That(result.PostingWarningCollection, Is.EqualTo(postingWarningCollection));
        }
        public void Ordered_WhenPostingWarningCollectionHasPostingWarnings_ReturnsPostingWarningCollectionWithSameAmountOfPostingWarnings()
        {
            IPostingWarningCollection sut = CreateSut();

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

            IPostingWarningCollection result = sut.Ordered();

            Assert.That(result.Count(), Is.EqualTo(postingWarnings.Length));
        }
Ejemplo n.º 12
0
        public async Task ApplyPostingJournalAsync_WhenPublishAsyncForApplyPostingJournalCommandReturnsPostingJournalResult_ReturnsOkObjectResultWhereValueIsApplyPostingJournalResultModelWherePostingWarningsContainsMappedPostingWarningsFromPostingJournalResult()
        {
            IPostingWarning[]         postingWarnings          = _fixture.CreateMany <IPostingWarning>(_random.Next(10, 25)).ToArray();
            IPostingWarningCollection postingWarningCollection = _fixture.BuildPostingWarningCollectionMock(postingWarnings).Object;
            IPostingJournalResult     postingJournalResult     = _fixture.BuildPostingJournalResultMock(postingWarningCollection: postingWarningCollection).Object;
            Controller sut = CreateSut(postingJournalResult: postingJournalResult);

            OkObjectResult result = (OkObjectResult)(await sut.ApplyPostingJournalAsync(CreateApplyPostingJournalModel())).Result;

            ApplyPostingJournalResultModel applyPostingJournalResultModel = (ApplyPostingJournalResultModel)result.Value;

            Assert.That(applyPostingJournalResultModel.PostingWarnings.All(postingWarningModel => postingWarnings.Any(postingWarning => IsMatch(postingWarningModel, postingWarning))), Is.True);
        }
Ejemplo n.º 13
0
        public async Task ApplyPostingJournalAsync_WhenPublishAsyncForApplyPostingJournalCommandReturnsPostingJournalResult_ReturnsOkObjectResultWhereValueIsApplyPostingJournalResultModelWithSameAmountOfPostingWarningsAsPostingWarningsInPostingJournalResult()
        {
            IPostingWarning[]         postingWarnings          = _fixture.CreateMany <IPostingWarning>(_random.Next(10, 25)).ToArray();
            IPostingWarningCollection postingWarningCollection = _fixture.BuildPostingWarningCollectionMock(postingWarnings).Object;
            IPostingJournalResult     postingJournalResult     = _fixture.BuildPostingJournalResultMock(postingWarningCollection: postingWarningCollection).Object;
            Controller sut = CreateSut(postingJournalResult: postingJournalResult);

            OkObjectResult result = (OkObjectResult)(await sut.ApplyPostingJournalAsync(CreateApplyPostingJournalModel())).Result;

            ApplyPostingJournalResultModel applyPostingJournalResultModel = (ApplyPostingJournalResultModel)result.Value;

            Assert.That(applyPostingJournalResultModel.PostingWarnings.Count, Is.EqualTo(postingWarnings.Length));
        }
        public void Ordered_WhenPostingWarningCollectionHasPostingWarnings_ReturnsPostingWarningCollectionWithSamePostingWarnings()
        {
            IPostingWarningCollection sut = CreateSut();

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

            IPostingWarningCollection result = sut.Ordered();

            foreach (IPostingWarning postingWarning in postingWarnings)
            {
                Assert.That(result.Contains(postingWarning), Is.True);
            }
        }
Ejemplo n.º 15
0
        public void Add_WhenPostingWarningIsNotNull_AddsEachPostingWarningToCollection()
        {
            IPostingWarningCollection sut = CreateSut();

            IEnumerable <IPostingWarning> postingWarningCollection = new List <IPostingWarning>
            {
                _fixture.BuildPostingWarningMock().Object,
                                          _fixture.BuildPostingWarningMock().Object,
                                          _fixture.BuildPostingWarningMock().Object,
                                          _fixture.BuildPostingWarningMock().Object,
                                          _fixture.BuildPostingWarningMock().Object,
                                          _fixture.BuildPostingWarningMock().Object,
                                          _fixture.BuildPostingWarningMock().Object
            };

            sut.Add(postingWarningCollection);

            Assert.That(postingWarningCollection.All(account => sut.Contains(account)), Is.True);
        }
        public void Ordered_WhenCalled_AssertSortOrderWasCalledOnPostingLineForEachPostingWarning()
        {
            IPostingWarningCollection 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 => _fixture.BuildPostingWarningMock(postingLine: postingLineMock.Object).Object));

            sut.Ordered();

            foreach (Mock <IPostingLine> postingLineMock in postingLineMockCollection)
            {
                postingLineMock.Verify(m => m.SortOrder, Times.Once);
            }
        }
        public void Ordered_WhenCalled_AssertPostingLineWasCalledTwiceOnEachPostingWarning()
        {
            IPostingWarningCollection sut = CreateSut();

            IEnumerable <Mock <IPostingWarning> > postingWarningMockCollection = new List <Mock <IPostingWarning> >
            {
                _fixture.BuildPostingWarningMock(),
                                                  _fixture.BuildPostingWarningMock(),
                                                  _fixture.BuildPostingWarningMock(),
                                                  _fixture.BuildPostingWarningMock(),
                                                  _fixture.BuildPostingWarningMock(),
                                                  _fixture.BuildPostingWarningMock(),
                                                  _fixture.BuildPostingWarningMock()
            };

            sut.Add(postingWarningMockCollection.Select(postingWarningMock => postingWarningMock.Object));

            sut.Ordered();

            foreach (Mock <IPostingWarning> postingWarningMock in postingWarningMockCollection)
            {
                postingWarningMock.Verify(m => m.PostingLine, Times.Exactly(2));
            }
        }
        private CommandHandler CreateSut(bool hasPostingJournalResult = true, IPostingJournalResult postingJournalResult = null, IPostingWarningCollection postingWarningCollection = null)
        {
            _accountingRepositoryMock.Setup(m => m.ApplyPostingJournalAsync(It.IsAny <IPostingJournal>(), It.IsAny <IPostingWarningCalculator>()))
            .Returns(Task.FromResult(hasPostingJournalResult ? postingJournalResult ?? _fixture.BuildPostingJournalResultMock().Object : null));

            _postingWarningCalculatorMock.Setup(m => m.CalculateAsync(It.IsAny <IPostingLineCollection>()))
            .Returns(Task.FromResult(postingWarningCollection ?? _fixture.BuildPostingWarningCollectionMock(isEmpty: true).Object));

            return(new CommandHandler(_validatorMock.Object, _accountingRepositoryMock.Object, _commonRepositoryMock.Object, _postingWarningCalculatorMock.Object));
        }