コード例 #1
0
        public void Last_WhenInfoCollectionContainsMultipleInfoElements_ReturnsNewestInfoElement()
        {
            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.Last();

            Assert.That(result.Year == infoOffset.Year && result.Month == infoOffset.Month, Is.True);
        }
コード例 #2
0
        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);
        }
コード例 #3
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);
            }
        }
コード例 #4
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
        }
コード例 #5
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);
        }
コード例 #6
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
        }
コード例 #7
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);
        }
コード例 #8
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);
        }
コード例 #9
0
        public void Add_WhenInfoCollectionIsNull_ThrowsArgumentNullException()
        {
            IInfoCollection <ICreditInfo, Sut> sut = CreateSut();

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

            // ReSharper disable PossibleNullReferenceException
            Assert.That(result.ParamName, Is.EqualTo("infoCollection"));
            // ReSharper restore PossibleNullReferenceException
        }
コード例 #10
0
 /// <summary>
 /// Adds an item to the collection.
 /// </summary>
 /// <param name="information">The item to add</param>
 public void AddItem(IUserInformation information)
 {
     _infoCollection.Add(information);
 }