Exemplo n.º 1
0
        public void GetTrendRanges_ReturnsProperCollectionOfTrendRanges()
        {
            //Arrange
            Mock <ITrendlineRepository> mockedRepository = new Mock <ITrendlineRepository>();
            List <TrendRangeDto>        dtos             = new List <TrendRangeDto>();
            TrendRange    range1 = getDefaultTrendRange();
            TrendRange    range2 = getDefaultTrendRange();
            TrendRange    range3 = getDefaultTrendRange();
            TrendRangeDto dto1   = range1.ToDto();
            TrendRangeDto dto2   = range2.ToDto();
            TrendRangeDto dto3   = range3.ToDto();

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

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

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

            //Assert
            IEnumerable <TrendRange> expectedTrendranges = new TrendRange[] { range1, range2, range3 };
            bool areEqual = expectedTrendranges.HasEqualItems(actualSimultations);

            Assert.IsTrue(areEqual);
        }
Exemplo n.º 2
0
        public void ToDto_returnProperDto()
        {
            //Act
            var trendRange = new TrendRange(DEFAULT_TRENDLINE_ID, DEFAULT_START_INDEX)
            {
                Guid              = DEFAULT_GUID,
                Id                = DEFAULT_ID,
                EndIndex          = DEFAULT_END_INDEX,
                QuotationsCounter = DEFAULT_QUOTATIONS_COUNTER,
                TotalDistance     = DEFAULT_TOTAL_DISTANCE,
                PreviousBreakGuid = DEFAULT_PREVIOUS_BREAK_GUID,
                PreviousHitGuid   = DEFAULT_PREVIOUS_HIT_GUID,
                NextBreakGuid     = DEFAULT_NEXT_BREAK_GUID,
                NextHitGuid       = DEFAULT_NEXT_HIT_GUID,
                Value             = DEFAULT_VALUE
            };
            var guid          = trendRange.Guid;
            var trendRangeDto = trendRange.ToDto();

            //Assert.
            Assert.AreEqual(DEFAULT_ID, trendRange.Id);
            Assert.AreEqual(DEFAULT_GUID, trendRange.Guid);
            Assert.AreEqual(DEFAULT_TRENDLINE_ID, trendRange.TrendlineId);
            Assert.AreEqual(DEFAULT_START_INDEX, trendRange.StartIndex);
            Assert.IsTrue(trendRange.EndIndex.IsEqual(DEFAULT_END_INDEX));
            Assert.AreEqual(DEFAULT_VALUE, trendRange.Value);
            Assert.AreEqual(DEFAULT_QUOTATIONS_COUNTER, trendRange.QuotationsCounter);
            Assert.AreEqual(DEFAULT_TOTAL_DISTANCE, trendRange.TotalDistance);
            Assert.IsTrue(trendRange.PreviousBreakGuid.Compare(DEFAULT_PREVIOUS_BREAK_GUID));
            Assert.IsTrue(trendRange.PreviousHitGuid.Compare(DEFAULT_PREVIOUS_HIT_GUID));
            Assert.IsTrue(trendRange.NextBreakGuid.Compare(DEFAULT_NEXT_BREAK_GUID));
            Assert.IsTrue(trendRange.NextHitGuid.Compare(DEFAULT_NEXT_HIT_GUID));
        }
Exemplo n.º 3
0
        public void GetTrendRangeById_ReturnsProperItem_IfItemExists()
        {
            //Arrange
            Mock <ITrendlineRepository> mockedRepository = new Mock <ITrendlineRepository>();
            TrendRange    range = getDefaultTrendRange();
            TrendRangeDto dto   = range.ToDto();

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

            //Act
            TrendlineService service = new TrendlineService(mockedRepository.Object);
            var actualTrendRange     = service.GetTrendRangeById(1);

            //Assert
            bool areEqual = range.Equals(actualTrendRange);

            Assert.IsTrue(areEqual);
        }
Exemplo n.º 4
0
        public void GetTrendRangeById_ReturnsAlwaysTheSameInstance()
        {
            //Arrange
            Mock <ITrendlineRepository> mockedRepository = new Mock <ITrendlineRepository>();
            List <TrendRangeDto>        dtos             = new List <TrendRangeDto>();
            TrendRange    range = getDefaultTrendRange();
            TrendRangeDto dto   = range.ToDto();

            dtos.AddRange(new TrendRangeDto[] { dto });
            mockedRepository.Setup(r => r.GetTrendRanges(1)).Returns(dtos);
            mockedRepository.Setup(r => r.GetTrendRangeById(1)).Returns(dto);

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

            //Assert
            TrendRange baseTrendRange     = service.GetTrendRangeById(1);
            TrendRange comparedTrendRange = service.GetTrendRangeById(1);

            bool areTheSame = (baseTrendRange == comparedTrendRange);

            Assert.IsTrue(areTheSame);
        }
Exemplo n.º 5
0
        public void UpdateTrendRanges_AllItemsPassedToMethodArePassedToRepository()
        {
            //Arrange
            List <TrendRangeDto>        trendRangeDtos   = new List <TrendRangeDto>();
            TrendRange                  trendRange       = getDefaultTrendRange();
            TrendRange                  trendRange2      = getDefaultTrendRange();
            Mock <ITrendlineRepository> mockedRepository = new Mock <ITrendlineRepository>();

            mockedRepository.
            Setup(r => r.UpdateTrendRanges(It.IsAny <IEnumerable <TrendRangeDto> >())).
            Callback <IEnumerable <TrendRangeDto> >((col) => trendRangeDtos.AddRange(col)).Verifiable();

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

            service.UpdateTrendRange(trendRange);
            service.UpdateTrendRange(trendRange2);

            //Assert
            IEnumerable <TrendRangeDto> expectedTrendRangeDtos = new TrendRangeDto[] { trendRange.ToDto(), trendRange2.ToDto() };

            mockedRepository.Verify(r => r.UpdateTrendRanges(It.IsAny <IEnumerable <TrendRangeDto> >()), Times.Exactly(2));
            Assert.IsTrue(trendRangeDtos.HasEqualItems(expectedTrendRangeDtos));
        }