public void CreatePriceHistoryReturnsIEnumerableForValidSearch()
        {
            int productId = 1, conditionId = 2;
            var mockRepository = CreateBasicMockRepository(productId, conditionId);

            var sut = new PriceHistoryService(mockRepository) as IPriceHistoryService;

            var results = sut.CreateBasicPriceHistory(productId, conditionId);

            A.CallTo(() => mockRepository.GetSearchResultsByProductID(productId, conditionId, A<bool>.Ignored)).MustHaveHappened();

            Assert.AreEqual(results.Count(), 16);
        }
        public void CalculateSimpleMovingAverageFromBasicPriceHistory()
        {
            int productId = 2, conditionId = 2;
            var mockRepository = CreateBasicMockRepository(productId, conditionId);

            var sut = new PriceHistoryService(mockRepository) as IPriceHistoryService;

            var results = sut.CreateBasicPriceHistory(productId, conditionId);

            sut.AddSimpleMovingAverage(results, 5);

            var smas = results.Select(ph => ph.SMA.HasValue ? Math.Round(ph.SMA.Value, 3) : ph.SMA);

            smas.AssertSequenceIsEqual(null, null, null, null, 12.694, 12.804, 12.894,
                12.812, 13.168, 13.12, 13.21, 13.63, 14.036, 14.48, 13.786, 13.588);
        }
        public void CalculateExponentialMovingAverageFromBasicPriceHistory()
        {
            int searchId = 2, conditionId = 2;
            var mockRepository = CreateBasicMockRepository(searchId, conditionId);

            var sut = new PriceHistoryService(mockRepository) as IPriceHistoryService;

            var results = sut.CreateBasicPriceHistory(searchId, conditionId);

            sut.AddExponentialMovingAverage(results, 5);

            var emas = results.Select(ph => ph.EMA.HasValue ? Math.Round(ph.EMA.Value, 8) : ph.EMA);

            // Test results
            emas.AssertSequenceIsEqual(null, null, null, null, 12.694, 12.976, 12.64733333, 12.60822222, 12.66548148,
                13.36365432, 13.57243621, 13.74495748, 14.01663832, 14.34442554, 13.3262837, 13.21752246);
        }
        public void CalculateSimpleMovingAverageWhenIntervalBiggerThanNumberOfPricesDoesntSetSMAs()
        {
            var mockRepository = A.Fake<ISoldOutRepository>();

            A.CallTo(() => mockRepository.GetSearchResultsByProductID(A<int>.Ignored, A<int>.Ignored, A<bool>.Ignored)).Returns(CreateListOfTwoSearchResults());

            var sut = new PriceHistoryService(mockRepository) as IPriceHistoryService;

            var results = sut.CreateBasicPriceHistory(1, 2);

            sut.AddSimpleMovingAverage(results, 5);

            Assert.AreEqual(results.Count, 2);

            foreach (var result in results)
                Assert.IsNull(result.SMA);
        }
示例#5
0
 public APIController()
 {
     _statsRepository = new StatsRepository();
     _repository = new SoldOutRepository();
     _priceHistoryService = new PriceHistoryService(_repository);
 }
        public void CalculateExponentialMovingAverageWhenIntervalEqualsNumberOfPrices()
        {
            var mockRepository = A.Fake<ISoldOutRepository>();

            A.CallTo(() => mockRepository.GetSearchResultsByProductID(A<int>.Ignored, A<int>.Ignored, A<bool>.Ignored)).Returns(CreateTestSearchResults().Take(5));

            var sut = new PriceHistoryService(mockRepository) as IPriceHistoryService;

            var results = sut.CreateBasicPriceHistory(1, 2);

            sut.AddExponentialMovingAverage(results, 5);

            Assert.AreEqual(Math.Round(results[4].EMA.Value, 3), 12.694);
        }