Esempio n. 1
0
        public void GetTrendBreaks_ReturnsProperCollectionOfTrendBreaks()
        {
            //Arrange
            Mock <ITrendlineRepository> mockedRepository = new Mock <ITrendlineRepository>();
            List <TrendBreakDto>        dtos             = new List <TrendBreakDto>();
            TrendBreak    break1 = getDefaultTrendBreak();
            TrendBreak    break2 = getDefaultTrendBreak();
            TrendBreak    break3 = getDefaultTrendBreak();
            TrendBreakDto dto1   = break1.ToDto();
            TrendBreakDto dto2   = break2.ToDto();
            TrendBreakDto dto3   = break3.ToDto();

            dtos.AddRange(new TrendBreakDto[] { dto1, dto2, dto3 });

            mockedRepository.Setup(r => r.GetTrendBreaks(1)).Returns(dtos);

            //Act
            TrendlineService service = new TrendlineService(mockedRepository.Object);
            var actualSimultations   = service.GetTrendBreaks(1);

            //Assert
            IEnumerable <TrendBreak> expectedTrendBreaks = new TrendBreak[] { break1, break2, break3 };
            bool areEqual = expectedTrendBreaks.HasEqualItems(actualSimultations);

            Assert.IsTrue(areEqual);
        }
Esempio n. 2
0
        public void GetTrendBreakById_ReturnsProperItem_IfItemExists()
        {
            //Arrange
            Mock <ITrendlineRepository> mockedRepository = new Mock <ITrendlineRepository>();
            TrendBreak    trendBreak = getDefaultTrendBreak();
            TrendBreakDto dto        = trendBreak.ToDto();

            mockedRepository.Setup(r => r.GetTrendBreakById(1)).Returns(dto);

            //Act
            TrendlineService service = new TrendlineService(mockedRepository.Object);
            var actualTrendBreak     = service.GetTrendBreakById(1);

            //Assert
            bool areEqual = trendBreak.Equals(actualTrendBreak);

            Assert.IsTrue(areEqual);
        }
Esempio n. 3
0
        public void ToDto_returnProperDto()
        {
            //Act
            var TrendBreak = new TrendBreak(DEFAULT_TRENDLINE_ID, DEFAULT_INDEX_NUMBER)
            {
                Id = DEFAULT_ID,
                PreviousRangeGuid = DEFAULT_PREVIOUS_RANGE_GUID,
                NextRangeGuid     = null
            };
            var guid          = TrendBreak.Guid;
            var TrendBreakDto = TrendBreak.ToDto();

            //Assert.
            Assert.AreEqual(DEFAULT_ID, TrendBreakDto.Id);
            Assert.AreEqual(guid, TrendBreakDto.Guid);
            Assert.AreEqual(DEFAULT_TRENDLINE_ID, TrendBreakDto.TrendlineId);
            Assert.AreEqual(DEFAULT_INDEX_NUMBER, TrendBreakDto.IndexNumber);
            Assert.AreEqual(DEFAULT_PREVIOUS_RANGE_GUID, TrendBreakDto.PreviousRangeGuid);
            Assert.IsNull(TrendBreakDto.NextRangeGuid);
        }
Esempio n. 4
0
        public void GetTrendBreakById_ReturnsAlwaysTheSameInstance()
        {
            //Arrange
            Mock <ITrendlineRepository> mockedRepository = new Mock <ITrendlineRepository>();
            List <TrendBreakDto>        dtos             = new List <TrendBreakDto>();
            TrendBreak    trendBreak = getDefaultTrendBreak();
            TrendBreakDto dto        = trendBreak.ToDto();

            dtos.AddRange(new TrendBreakDto[] { dto });
            mockedRepository.Setup(r => r.GetTrendBreaks(1)).Returns(dtos);
            mockedRepository.Setup(r => r.GetTrendBreakById(1)).Returns(dto);

            //Act
            TrendlineService service = new TrendlineService(mockedRepository.Object);

            //Assert
            TrendBreak baseTrendBreak     = service.GetTrendBreakById(1);
            TrendBreak comparedTrendBreak = service.GetTrendBreakById(1);

            bool areTheSame = (baseTrendBreak == comparedTrendBreak);

            Assert.IsTrue(areTheSame);
        }
Esempio n. 5
0
        public void UpdateTrendBreaks_AllItemsPassedToMethodArePassedToRepository()
        {
            //Arrange
            List <TrendBreakDto>        trendBreakDtos   = new List <TrendBreakDto>();
            TrendBreak                  trendBreak       = getDefaultTrendBreak();
            TrendBreak                  trendBreak2      = getDefaultTrendBreak();
            Mock <ITrendlineRepository> mockedRepository = new Mock <ITrendlineRepository>();

            mockedRepository.
            Setup(r => r.UpdateTrendBreaks(It.IsAny <IEnumerable <TrendBreakDto> >())).
            Callback <IEnumerable <TrendBreakDto> >((col) => trendBreakDtos.AddRange(col)).Verifiable();

            //Act
            TrendlineService service = new TrendlineService(mockedRepository.Object);

            service.UpdateTrendBreak(trendBreak);
            service.UpdateTrendBreak(trendBreak2);

            //Assert
            IEnumerable <TrendBreakDto> expectedTrendBreakDtos = new TrendBreakDto[] { trendBreak.ToDto(), trendBreak2.ToDto() };

            mockedRepository.Verify(r => r.UpdateTrendBreaks(It.IsAny <IEnumerable <TrendBreakDto> >()), Times.Exactly(2));
            Assert.IsTrue(trendBreakDtos.HasEqualItems(expectedTrendBreakDtos));
        }