Exemple #1
0
        public void GetYearExists()
        {
            var mockRepository = new MockRepository(MockBehavior.Strict);

            var tradingCalendar = new TradingCalendar(Guid.NewGuid());

            tradingCalendar.SetNonTradingDays(2000, new[] { new NonTradingDay(new Date(2000, 01, 01), "New Year's Day") });
            var repository = mockRepository.Create <IRepository <TradingCalendar> >();

            repository.Setup(x => x.Get(tradingCalendar.Id)).Returns(tradingCalendar);

            var service = new TradingCalendarService(repository.Object, tradingCalendar.Id);

            var result   = service.Get(2000);
            var response = result.Result;

            response.Should().BeEquivalentTo(new
            {
                Year           = 2000,
                NonTradingDays = new []
                {
                    new RestApi.TradingCalendars.TradingCalendar.NonTradingDay()
                    {
                        Date = new Date(2000, 01, 01), Description = "New Year's Day"
                    }
                },
            });
        }
Exemple #2
0
        public void SetNonTradingDays()
        {
            var mockRepository = new MockRepository(MockBehavior.Strict);

            var tradingCalendar = new TradingCalendar(Guid.NewGuid());

            tradingCalendar.SetNonTradingDays(2001, new[] { new NonTradingDay(new Date(2001, 01, 01), "New Year's Day") });
            var repository = mockRepository.Create <IRepository <TradingCalendar> >();

            repository.Setup(x => x.Get(tradingCalendar.Id)).Returns(tradingCalendar);
            repository.Setup(x => x.Update(tradingCalendar));

            var service = new TradingCalendarService(repository.Object, tradingCalendar.Id);

            var calendarReference = service.TradingCalendar;

            using (new AssertionScope())
            {
                calendarReference.IsTradingDay(new Date(2001, 01, 01)).Should().BeFalse();
                calendarReference.IsTradingDay(new Date(2001, 12, 25)).Should().BeTrue();
            }

            service.SetNonTradingDays(2001, new[] { new NonTradingDay(new Date(2001, 12, 25), "Christmas Day") });

            using (new AssertionScope())
            {
                calendarReference.IsTradingDay(new Date(2001, 01, 01)).Should().BeTrue();
                calendarReference.IsTradingDay(new Date(2001, 12, 25)).Should().BeFalse();
            }

            mockRepository.Verify();
        }
        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 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();
        }
Exemple #7
0
        public void CreateServiceForExistingCalendar()
        {
            var mockRepository = new MockRepository(MockBehavior.Strict);

            var tradingCalendar = new TradingCalendar(Guid.NewGuid());

            tradingCalendar.SetNonTradingDays(2000, new[] { new NonTradingDay(new Date(2000, 01, 01), "New Year's Day") });
            var repository = mockRepository.Create <IRepository <TradingCalendar> >();

            repository.Setup(x => x.Get(tradingCalendar.Id)).Returns(tradingCalendar);

            var service = new TradingCalendarService(repository.Object, tradingCalendar.Id);

            service.TradingCalendar.Should().Be(tradingCalendar);

            mockRepository.Verify();
        }
Exemple #8
0
        public void Update()
        {
            var mockRepository = new MockRepository(MockBehavior.Strict);

            var tradingCalendar = new TradingCalendar(Guid.NewGuid());

            tradingCalendar.SetNonTradingDays(2001, new[] { new NonTradingDay(new Date(2001, 01, 01), "New Year's Day") });
            var repository = mockRepository.Create <IRepository <TradingCalendar> >();

            repository.Setup(x => x.Get(tradingCalendar.Id)).Returns(tradingCalendar);
            repository.Setup(x => x.Update(tradingCalendar));

            var service = new TradingCalendarService(repository.Object, tradingCalendar.Id);

            var calendarReference = service.TradingCalendar;

            using (new AssertionScope())
            {
                calendarReference.IsTradingDay(new Date(2001, 01, 01)).Should().BeFalse();
                calendarReference.IsTradingDay(new Date(2001, 12, 25)).Should().BeTrue();
            }

            var updatedTradingCalendar = new RestApi.TradingCalendars.TradingCalendar();

            updatedTradingCalendar.Year = 2001;
            updatedTradingCalendar.NonTradingDays.Add(new RestApi.TradingCalendars.TradingCalendar.NonTradingDay()
            {
                Date = new Date(2001, 12, 25), Description = "Christmas Day"
            });

            var result = service.Update(updatedTradingCalendar);

            using (new AssertionScope())
            {
                result.Should().HaveOkStatus();

                calendarReference.IsTradingDay(new Date(2001, 01, 01)).Should().BeTrue();
                calendarReference.IsTradingDay(new Date(2001, 12, 25)).Should().BeFalse();
            }

            mockRepository.Verify();
        }
        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" })
                    )
                );
        }
 public void SetNonTradingDays(int year, IEnumerable <NonTradingDay> nonTradingDays)
 {
     _TradingCalendar.SetNonTradingDays(year, nonTradingDays);
     _Repository.Update(_TradingCalendar);
 }