public async Task ImportDataReturned()
        {
            var mockRepository = new MockRepository(MockBehavior.Strict);

            var year = DateTime.Now.Year;

            var cancellationToken = new CancellationToken();
            var nonTradingDays    = new NonTradingDay[]
            {
                new NonTradingDay(new Common.Date(year, 01, 01), "New Year's Day"),
                new NonTradingDay(new Common.Date(year, 12, 25), "Christmas Day")
            };
            var dataService = mockRepository.Create <ITradingDayService>();

            dataService.Setup(x => x.GetNonTradingDays(year, cancellationToken)).Returns(Task <IEnumerable <NonTradingDay> > .FromResult(nonTradingDays.AsEnumerable()));

            var tradingCalendarService = mockRepository.Create <ITradingCalendarService>();

            tradingCalendarService.Setup(x => x.SetNonTradingDays(year, nonTradingDays));

            var logger = mockRepository.Create <ILogger <TradingDayImporter> >(MockBehavior.Loose);

            var importer = new TradingDayImporter(tradingCalendarService.Object, dataService.Object, logger.Object);

            await importer.Import(cancellationToken);

            mockRepository.Verify();
        }
Ejemplo n.º 2
0
        public void AddNonTradingDay(Date date, string description)
        {
            var nonTradingDay = new NonTradingDay()
            {
                Date        = date,
                Description = description
            };

            NonTradingDays.Add(nonTradingDay);
        }
        public void SetNewTradingDaysForInvalidYear()
        {
            var tradingCalendar = new TradingCalendar(Guid.NewGuid());

            var nonTradingDays = new NonTradingDay[] {
                new NonTradingDay(new Date(2019, 01, 01), "New Years Day"),
                new NonTradingDay(new Date(2020, 12, 25), "Christmas Day")
            };

            Action a = () => tradingCalendar.SetNonTradingDays(2019, nonTradingDays);

            a.Should().Throw <ArgumentException>();
        }
        public void RetriveNonTradingDaysForYearWithNoData()
        {
            var tradingCalendar = new TradingCalendar(Guid.NewGuid());

            var nonTradingDays = new NonTradingDay[] {
                new NonTradingDay(new Date(2019, 01, 01), "New Years Day"),
                new NonTradingDay(new Date(2019, 12, 25), "Christmas Day")
            };

            tradingCalendar.SetNonTradingDays(2019, nonTradingDays);

            tradingCalendar.NonTradingDays(2020).Should().BeEmpty();
        }
        public void RetriveNonTradingDaysForYear()
        {
            var tradingCalendar = new TradingCalendar(Guid.NewGuid());

            var nonTradingDays = new NonTradingDay[] {
                new NonTradingDay(new Date(2019, 01, 01), "New Years Day"),
                new NonTradingDay(new Date(2019, 12, 25), "Christmas Day")
            };

            tradingCalendar.SetNonTradingDays(2019, nonTradingDays);

            tradingCalendar.NonTradingDays(2019).Should().HaveCount(2);
        }
        public void PreviousTradingDayForWeekEnd()
        {
            var tradingCalendar = new TradingCalendar(Guid.NewGuid());

            var nonTradingDays = new NonTradingDay[] {
                new NonTradingDay(new Date(2019, 01, 01), "New Years Day"),
                new NonTradingDay(new Date(2019, 12, 25), "Christmas Day")
            };
            var @event = new NonTradingDaysSetEvent(tradingCalendar.Id, 0, 2019, nonTradingDays);

            tradingCalendar.ApplyEvents(new Event[] { @event });

            tradingCalendar.PreviousTradingDay(new Date(2019, 11, 10)).Should().Be(new Date(2019, 11, 08));
        }
        public void CheckIfDateIsAtradingDayReturnFalse()
        {
            var tradingCalendar = new TradingCalendar(Guid.NewGuid());

            var nonTradingDays = new NonTradingDay[] {
                new NonTradingDay(new Date(2019, 01, 01), "New Years Day"),
                new NonTradingDay(new Date(2019, 12, 25), "Christmas Day")
            };
            var @event = new NonTradingDaysSetEvent(tradingCalendar.Id, 0, 2019, nonTradingDays);

            tradingCalendar.ApplyEvents(new Event[] { @event });

            tradingCalendar.IsTradingDay(new Date(2019, 01, 01)).Should().BeFalse();
        }
        public void EnumerateTradingDays()
        {
            var tradingCalendar = new TradingCalendar(Guid.NewGuid());

            var nonTradingDays = new NonTradingDay[] {
                new NonTradingDay(new Date(2019, 01, 01), "New Years Day"),
                new NonTradingDay(new Date(2019, 12, 25), "Christmas Day")
            };

            tradingCalendar.SetNonTradingDays(2019, nonTradingDays);

            var tradingDays = tradingCalendar.TradingDays(new DateRange(new Date(2019, 01, 01), new Date(2019, 01, 10))).ToList();

            tradingDays.Should().HaveCount(7).And.BeInAscendingOrder().And.OnlyHaveUniqueItems();
        }
        public void ApplyNonTradingDaysSetEvent()
        {
            var tradingCalendar = new TradingCalendar(Guid.NewGuid());

            var nonTradingDays = new NonTradingDay[] {
                new NonTradingDay(new Date(2019, 01, 01), "New Years Day"),
                new NonTradingDay(new Date(2019, 12, 25), "Christmas Day")
            };
            var @event = new NonTradingDaysSetEvent(tradingCalendar.Id, 0, 2019, nonTradingDays);

            tradingCalendar.ApplyEvents(new Event[] { @event });

            using (new AssertionScope())
            {
                tradingCalendar.IsTradingDay(new Date(2019, 01, 01)).Should().BeFalse();
                tradingCalendar.IsTradingDay(new Date(2019, 12, 25)).Should().BeFalse();
                tradingCalendar.IsTradingDay(new Date(2019, 01, 02)).Should().BeTrue();
            }
        }
        public void SetNewTradingDays()
        {
            var tradingCalendar = new TradingCalendar(Guid.NewGuid());

            var nonTradingDays = new NonTradingDay[] {
                new NonTradingDay(new Date(2019, 01, 01), "New Years Day"),
                new NonTradingDay(new Date(2019, 12, 25), "Christmas Day")
            };

            tradingCalendar.SetNonTradingDays(2019, nonTradingDays);

            var events = tradingCalendar.FetchEvents().ToList();

            events.Should().SatisfyRespectively(

                first => first.Should().BeOfType <NonTradingDaysSetEvent>().Which.NonTradingDays.Should().SatisfyRespectively(
                    day1 => day1.Should().BeEquivalentTo(new { Date = new Date(2019, 01, 01), Description = "New Years Day" }),
                    day2 => day2.Should().BeEquivalentTo(new { Date = new Date(2019, 12, 25), Description = "Christmas Day" })
                    )
                );
        }