Exemplo n.º 1
0
        public async Task CalculateAsync_WhenCalled_AssertCalculateAsyncWasCalledOnEachInfo()
        {
            IInfoCollection <ICreditInfo, Sut> sut = CreateSut();

            IEnumerable <Mock <ICreditInfo> > infoMockCollection = new List <Mock <ICreditInfo> >
            {
                _fixture.BuildCreditInfoMock(),
                                              _fixture.BuildCreditInfoMock(),
                                              _fixture.BuildCreditInfoMock(),
                                              _fixture.BuildCreditInfoMock(),
                                              _fixture.BuildCreditInfoMock(),
                                              _fixture.BuildCreditInfoMock(),
                                              _fixture.BuildCreditInfoMock()
            };

            sut.Add(infoMockCollection.Select(infoMock => infoMock.Object).ToArray());

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

            foreach (Mock <ICreditInfo> infoMock in infoMockCollection)
            {
                infoMock.Verify(m => m.CalculateAsync(It.Is <DateTime>(value => value == statusDate.Date)), Times.Once);
            }
        }
Exemplo n.º 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
        }
Exemplo n.º 3
0
        public async Task CalculateAsync_WhenCalled_ReturnsSameInfoCollectionBase()
        {
            IInfoCollection <ICreditInfo, Sut> sut = CreateSut();

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

            Assert.That(result, Is.SameAs(sut));
        }
        public void Find_WhenInfoCollectionIsEmpty_ReturnsNull()
        {
            IInfoCollection <ICreditInfo, Sut> sut = CreateSut();

            IInfo <ICreditInfo> result = sut.Find(DateTime.Today);

            Assert.That(result, Is.Null);
        }
        public void Last_WhenInfoCollectionIsEmpty_ReturnsNull()
        {
            IInfoCollection <ICreditInfo, Sut> sut = CreateSut();

            IInfo <ICreditInfo> result = sut.Last();

            Assert.That(result, Is.Null);
        }
        public void Next_WhenInfoCollectionIsEmpty_ReturnsNull()
        {
            IInfoCollection <ICreditInfo, Sut> sut = CreateSut();

            IInfo <ICreditInfo> result = sut.Next(_fixture.BuildCreditInfoMock().Object);

            Assert.That(result, Is.Null);
        }
Exemplo n.º 7
0
        public async Task CalculateAsync_WhenCalled_AssertCalculateWasCalledOnSut()
        {
            IInfoCollection <ICreditInfo, Sut> sut = CreateSut();

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

            Assert.That(result.CalculateWasCalled, Is.True);
        }
Exemplo n.º 8
0
        public async Task CalculateAsync_WhenCalled_AssertCalculateWasCalledWithSameStatusDate()
        {
            IInfoCollection <ICreditInfo, Sut> sut = CreateSut();

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

            Assert.That(result.CalculateCalledWithStatusDate, Is.EqualTo(statusDate.Date));
        }
Exemplo n.º 9
0
        public async Task CalculateAsync_WhenCalledMultipleTimesWithSameStatusDate_ReturnsSameInfoCollectionBase()
        {
            IInfoCollection <ICreditInfo, Sut> sut = CreateSut();

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

            Assert.That(result, Is.SameAs(sut));
        }
Exemplo n.º 10
0
        public async Task CalculateAsync_WhenCalledMultipleTimesWithSameStatusDate_AssertAlreadyCalculatedWasCalledTwiceOnSut()
        {
            IInfoCollection <ICreditInfo, Sut> sut = CreateSut();

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

            Assert.That(result.AlreadyCalculatedWasCalledTimes, Is.EqualTo(2));
        }
Exemplo n.º 11
0
        public async Task CalculateAsync_WhenCalled_ReturnsSameInfoCollectionBaseWhereStatusDateEqualDateFromCall()
        {
            IInfoCollection <ICreditInfo, Sut> sut = CreateSut();

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

            Assert.That(result.StatusDate, Is.EqualTo(statusDate.Date));
        }
Exemplo n.º 12
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);
        }
        public void Next_WhenInfoIsNull_ThrowsArgumentNullException()
        {
            IInfoCollection <ICreditInfo, Sut> sut = CreateSut();

            ArgumentNullException result = Assert.Throws <ArgumentNullException>(() => sut.Next(null));

            // ReSharper disable PossibleNullReferenceException
            Assert.That(result.ParamName, Is.EqualTo("info"));
            // ReSharper restore PossibleNullReferenceException
        }
        public void Last_WhenInfoCollectionContainsOneInfoElement_ReturnsNewestInfoElement()
        {
            IInfoCollection <ICreditInfo, Sut> sut = CreateSut();

            DateTime infoOffset = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1);

            sut.Add(_fixture.BuildCreditInfoMock(infoOffset).Object);

            IInfo <ICreditInfo> result = sut.Last();

            Assert.That(result.Year == infoOffset.Year && result.Month == infoOffset.Month, Is.True);
        }
        public void Find_WhenInfoCollectionContainsInfoElementForMatchingDate_ReturnsMatchingInfoElement()
        {
            IInfoCollection <ICreditInfo, Sut> sut = CreateSut();

            DateTime infoOffset = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1);

            sut.Add(_fixture.BuildCreditInfoMock(infoOffset).Object);
            sut.Add(_fixture.BuildCreditInfoMock(infoOffset.AddMonths(-1)).Object);
            sut.Add(_fixture.BuildCreditInfoMock(infoOffset.AddMonths(-2)).Object);

            IInfo <ICreditInfo> result = sut.Find(infoOffset);

            Assert.That(result.Year == infoOffset.Year && result.Month == infoOffset.Month, Is.True);
        }
        public void Next_WhenInfoCollectionDoesNotContainNextInfoElement_ReturnsNull()
        {
            IInfoCollection <ICreditInfo, Sut> sut = CreateSut();

            DateTime infoOffset = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1);

            sut.Add(_fixture.BuildCreditInfoMock(infoOffset).Object);
            sut.Add(_fixture.BuildCreditInfoMock(infoOffset.AddMonths(-1)).Object);
            sut.Add(_fixture.BuildCreditInfoMock(infoOffset.AddMonths(-2)).Object);

            IInfo <ICreditInfo> result = sut.Next(sut.Last());

            Assert.That(result, Is.Null);
        }
Exemplo n.º 17
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
        }
Exemplo n.º 18
0
        public void Add_WhenInfoCollectionIsNotNullAndEachInfoDoesNotExistWithinCollection_AddsEachInfoToCollection()
        {
            IInfoCollection <ICreditInfo, Sut> sut = CreateSut();

            IEnumerable <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
            };

            sut.Add(infoCollection);

            Assert.That(infoCollection.All(info => sut.Contains(info)), Is.True);
        }
Exemplo n.º 19
0
        public async Task CalculateAsync_WhenCalled_AssertCalculateWasCalledWithCalculatedInfoCollection()
        {
            IInfoCollection <ICreditInfo, Sut> sut = CreateSut();

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

            sut.Add(calculatedInfoCollection.Select(calculatedInfo => _fixture.BuildCreditInfoMock(calculatedCreditInfo: calculatedInfo).Object).ToArray());

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

            Assert.That(result.CalculateCalledWithCalculatedInfoCollection.All(calculatedInfo => calculatedInfoCollection.Contains(calculatedInfo)), Is.True);
        }