public void ItShouldThrowExceptionWhenPlanNotExists() { var dataService = new Mock <IForecastDataAccessService>(); dataService.Setup(x => x.GetPlan(1)).Throws(new ForecastServiceException()); var service = new ForecastService <int>(dataService.Object); Assert.Throws(typeof(ForecastServiceException), () => service.LoadPlan(1)); }
public void ItShouldRunPlan() { var planId = 15; var service = new ForecastService <decimal>(new ForecastDataAccessService()); service.LoadPlan(planId); service.Run(); Thread.Sleep(30000); }
public void ItShouldLoadPlanWhenExists() { var forecastPlan = new ForecastPlan <int> { CreationDate = DateTime.Today }; var dataService = new Mock <IForecastDataAccessService>(); dataService.Setup(x => x.GetPlan(1)).Returns(forecastPlan); var service = new ForecastService <int>(dataService.Object); service.LoadPlan(1); Assert.AreEqual(forecastPlan, service.Plan); }
public void ItShouldChangeStatusToRunAfterRun() { var plan = new Mock <IForecastPlan>(); plan.Setup(x => x.SetStatus(It.IsAny <ForecastPlanStatus>())).Verifiable(); plan.Setup(x => x.CreationDate).Returns(DateTime.Today); var positions = new List <IPosition>(); var positionOpen = new Mock <IPosition>(); var positionActive1 = new Mock <IPosition>(); var positionActive2 = new Mock <IPosition>(); positionOpen.Setup(x => x.Status).Returns(HCPositionStatus.Open); positionOpen.Setup(x => x.HCType).Returns(new HCTypeDto { Code = "FTE" }); positionOpen.Setup(x => x.Company).Returns(new CompanyDto { Code = "4001" }); positionActive1.Setup(x => x.Status).Returns(HCPositionStatus.Active); positionActive1.Setup(x => x.HCType).Returns(new HCTypeDto { Code = "FTE" }); positionActive1.Setup(x => x.Company).Returns(new CompanyDto { Code = "4003" }); positionActive2.Setup(x => x.Status).Returns(HCPositionStatus.Active); positionActive2.Setup(x => x.HCType).Returns(new HCTypeDto { Code = "FTE" }); positionActive2.Setup(x => x.Company).Returns(new CompanyDto { Code = "4001" }); positions.Add(positionActive1.Object); positions.Add(positionActive2.Object); positions.Add(positionOpen.Object); plan.Setup(x => x.PositionLogs).Returns(positions); var dataService = new Mock <IForecastDataAccessService>(); dataService.Setup(x => x.GetPlan(1)).Returns(plan.Object); //dataService.Setup(x => x.GetPositions(DateTime.Today)).Returns(positions); var service = new ForecastService <int>(dataService.Object); service.LoadPlan(1); service.Run(); Thread.Sleep(5000); plan.Verify(x => x.SetStatus(ForecastPlanStatus.Run), Times.Once()); }
public void ItShouldSetExecutionDateAfterRun() { var plan = new ForecastPlan <int> { CreationDate = DateTime.Today }; var positions = new List <IPosition>(); var positionOpen = new Mock <IPosition>(); var positionActive1 = new Mock <IPosition>(); var positionActive2 = new Mock <IPosition>(); positionOpen.Setup(x => x.Status).Returns(HCPositionStatus.Open); positionOpen.Setup(x => x.HCType).Returns(new HCTypeDto { Code = "FTE" }); positionOpen.Setup(x => x.Company).Returns(new CompanyDto { Code = "4001" }); positionActive1.Setup(x => x.Status).Returns(HCPositionStatus.Active); positionActive1.Setup(x => x.HCType).Returns(new HCTypeDto { Code = "FTE" }); positionActive1.Setup(x => x.Company).Returns(new CompanyDto { Code = "4003" }); positionActive2.Setup(x => x.Status).Returns(HCPositionStatus.Active); positionActive2.Setup(x => x.HCType).Returns(new HCTypeDto { Code = "FTE" }); positionActive2.Setup(x => x.Company).Returns(new CompanyDto { Code = "4001" }); positions.Add(positionActive1.Object); positions.Add(positionActive2.Object); positions.Add(positionOpen.Object); plan.AddPositions(positions); var dataService = new Mock <IForecastDataAccessService>(); dataService.Setup(x => x.GetPlan(1)).Returns(plan); //dataService.Setup(x => x.GetPositions(It.IsAny<DateTime>())).Returns(positions); var service = new ForecastService <int>(dataService.Object); service.LoadPlan(1); service.Run(); Thread.Sleep(5000); Assert.AreEqual(DateTime.Today.Date, service.Plan.ExecutionDate.Value.Date); }
public void ItShouldDeleteResultsBeforeRun() { var plan = new ForecastPlan <int> { CreationDate = DateTime.Today, Id = 1 }; var dataService = new Mock <IForecastDataAccessService>(); dataService.Setup(x => x.DeleteResults(It.IsAny <int>())).Verifiable(); dataService.Setup(x => x.GetPlan(1)).Returns(plan); var positions = new List <IPosition>(); var positionOpen = new Mock <IPosition>(); var positionActive1 = new Mock <IPosition>(); var positionActive2 = new Mock <IPosition>(); positionOpen.Setup(x => x.Status).Returns(HCPositionStatus.Open); positionOpen.Setup(x => x.HCType).Returns(new HCTypeDto { Code = "FTE" }); positionOpen.Setup(x => x.Company).Returns(new CompanyDto { Code = "4001" }); positionActive1.Setup(x => x.Status).Returns(HCPositionStatus.Active); positionActive1.Setup(x => x.HCType).Returns(new HCTypeDto { Code = "FTE" }); positionActive1.Setup(x => x.Company).Returns(new CompanyDto { Code = "4003" }); positionActive2.Setup(x => x.Status).Returns(HCPositionStatus.Active); positionActive2.Setup(x => x.HCType).Returns(new HCTypeDto { Code = "FTE" }); positionActive2.Setup(x => x.Company).Returns(new CompanyDto { Code = "4001" }); positions.Add(positionActive1.Object); positions.Add(positionActive2.Object); positions.Add(positionOpen.Object); plan.PositionLogs = positions; var service = new ForecastService <int>(dataService.Object); service.LoadPlan(1); service.Run(); dataService.Verify(x => x.DeleteResults(1), Times.Once()); }
public void ItShouldDeleteResults() { var plan = new ForecastPlan <int> { CreationDate = DateTime.Today, Id = 1 }; var dataService = new Mock <IForecastDataAccessService>(); dataService.Setup(x => x.DeleteResults(It.IsAny <int>())).Verifiable(); dataService.Setup(x => x.GetPlan(1)).Returns(plan); var service = new ForecastService <int>(dataService.Object); service.LoadPlan(1); service.DeleteResults(); dataService.Verify(x => x.DeleteResults(1), Times.Once()); }