public ServiceResult Update(RestApi.TradingCalendars.TradingCalendar tradingCalendar) { var nonTradingDays = tradingCalendar.NonTradingDays.Select(x => new NonTradingDay(x.Date, x.Description)); SetNonTradingDays(tradingCalendar.Year, nonTradingDays); return(ServiceResult.Ok()); }
public ServiceResult <RestApi.TradingCalendars.TradingCalendar> Get(int year) { var result = new RestApi.TradingCalendars.TradingCalendar(); result.Year = year; foreach (var nonTradingDay in _TradingCalendar.NonTradingDays(year)) { result.AddNonTradingDay(nonTradingDay.Date, nonTradingDay.Desciption); } return(ServiceResult <RestApi.TradingCalendars.TradingCalendar> .Ok(result)); }
public void Update() { var mockRepository = new MockRepository(MockBehavior.Strict); var tradingCalendar = new RestApi.TradingCalendars.TradingCalendar(); var service = mockRepository.Create <ITradingCalendarService>(); service.Setup(x => x.Update(tradingCalendar)).Returns(ServiceResult.Ok()).Verifiable(); var controller = new TradingCalendarController(service.Object); var result = controller.Update(2010, tradingCalendar); result.Should().BeOkResult(); mockRepository.VerifyAll(); }
public void UpdateValidationError() { var mockRepository = new MockRepository(MockBehavior.Strict); var tradingCalendar = new RestApi.TradingCalendars.TradingCalendar(); var service = mockRepository.Create <ITradingCalendarService>(); service.Setup(x => x.Update(tradingCalendar)).Returns(ServiceResult.Error("Error message")).Verifiable(); var controller = new TradingCalendarController(service.Object); var result = controller.Update(2010, tradingCalendar); result.Should().BeBadRequestObjectResult().Error.Should().BeEquivalentTo(new [] { "Error message" }); mockRepository.VerifyAll(); }
public void GetYear() { var mockRepository = new MockRepository(MockBehavior.Strict); var response = new RestApi.TradingCalendars.TradingCalendar(); var service = mockRepository.Create <ITradingCalendarService>(); service.Setup(x => x.Get(2010)).Returns(ServiceResult <RestApi.TradingCalendars.TradingCalendar> .Ok(response)).Verifiable(); var controller = new TradingCalendarController(service.Object); var result = controller.Get(2010); result.Result.Should().BeOkObjectResult().Value.Should().Be(response); mockRepository.VerifyAll(); }
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(); }