public TimeDataController(ScheduleDataBll scheduleDataBll) { this._scheduleDataBll = scheduleDataBll; }
public async Task GetScheduleDataAsJsonAsync_ShouldReturnCorrectJson() { //1. Arrange var mockTimeBlockDalClass = new Mock <ITimeBlockDal>(); var testTimeBlockList = new List <TimeBlock> { new TimeBlock() { No = 1, IntialUTCTime = 5954484981710000, BlockSize = 10000, RepeatPeriod = 10000, ScheduleNo = 1 }, new TimeBlock() { No = 2, IntialUTCTime = 5954484981720000, BlockSize = 20000, RepeatPeriod = 20000, ScheduleNo = 1 }, new TimeBlock() { No = 3, IntialUTCTime = 5954484981730000, BlockSize = 30000, RepeatPeriod = 30000, ScheduleNo = 1 }, new TimeBlock() { No = 4, IntialUTCTime = 5954484981740000, BlockSize = 40000, RepeatPeriod = 40000, ScheduleNo = 1 }, new TimeBlock() { No = 5, IntialUTCTime = 5954484981750000, BlockSize = 50000, RepeatPeriod = 50000, ScheduleNo = 2 }, new TimeBlock() { No = 6, IntialUTCTime = 5954484981760000, BlockSize = 60000, RepeatPeriod = 60000, ScheduleNo = 2 }, new TimeBlock() { No = 7, IntialUTCTime = 5954484981770000, BlockSize = 70000, RepeatPeriod = 70000, ScheduleNo = 2 } }; var testScheduleList = new List <Schedule> { new Schedule() { No = 1, Title = "This is Test Schedule Class 1", Description = "This is Test 1", IsScheduleEnd = false, UserNo = 1, Type = ScheduleType.NORMAL, }, new Schedule() { No = 2, Title = "This is Test Schedule Class 2", Description = "This is Test 2", IsScheduleEnd = true, UserNo = 1, Type = ScheduleType.NORMAL, } }; mockTimeBlockDalClass.Setup(x => x.GetTimeBlocksByUserNoAsync(It.IsAny <int>())) .ReturnsAsync(new List <TimeBlock> { new TimeBlock() { No = 1, IntialUTCTime = 5954484981710000, BlockSize = 10000, RepeatPeriod = 10000, ScheduleNo = 1 }, new TimeBlock() { No = 2, IntialUTCTime = 5954484981720000, BlockSize = 20000, RepeatPeriod = 20000, ScheduleNo = 1 }, new TimeBlock() { No = 3, IntialUTCTime = 5954484981730000, BlockSize = 30000, RepeatPeriod = 30000, ScheduleNo = 1 }, new TimeBlock() { No = 4, IntialUTCTime = 5954484981740000, BlockSize = 40000, RepeatPeriod = 40000, ScheduleNo = 1 }, new TimeBlock() { No = 5, IntialUTCTime = 5954484981750000, BlockSize = 50000, RepeatPeriod = 50000, ScheduleNo = 2 }, new TimeBlock() { No = 6, IntialUTCTime = 5954484981760000, BlockSize = 60000, RepeatPeriod = 60000, ScheduleNo = 2 }, new TimeBlock() { No = 7, IntialUTCTime = 5954484981770000, BlockSize = 70000, RepeatPeriod = 70000, ScheduleNo = 2 } }); var mockScheduleDalClass = new Mock <IScheduleDal>(); mockScheduleDalClass.Setup(x => x.GetSchedulesByUserNoAsync(It.IsAny <int>())) .ReturnsAsync(new List <Schedule> { new Schedule() { No = 1, Title = "This is Test Schedule Class 1", Description = "This is Test 1", IsScheduleEnd = false, UserNo = 1, Type = ScheduleType.NORMAL, }, new Schedule() { No = 2, Title = "This is Test Schedule Class 2", Description = "This is Test 2", IsScheduleEnd = true, UserNo = 1, Type = ScheduleType.NORMAL, } }); var scheduleDataBll = new ScheduleDataBll(mockTimeBlockDalClass.Object, mockScheduleDalClass.Object); SchedulesDto testScheduleDtoList = new SchedulesDto() { Schedules = testScheduleList, Timeblocks = testTimeBlockList }; //2.Act var jsonDataActual = await scheduleDataBll.GetScheduleDataAsJsonAsync(1); var jsonDataExpect = JsonConvert.SerializeObject(testScheduleDtoList); //3.Assert Assert.Equal(jsonDataExpect, jsonDataActual); }