Beispiel #1
0
        /// <summary>
        /// method That returns all the data with SchedulesDto  as Json format
        /// </summary>
        /// <param name="userNo"></param>
        /// <returns></returns>
        public async Task <string> GetScheduleDataAsJsonAsync(int userNo)
        {
            var scheduleList = await this._scheduleDal.GetSchedulesByUserNoAsync(userNo);

            if (scheduleList.Count == 0)
            {
                return("");
            }

            var timeBlockList = await this._timeBlockDal.GetTimeBlocksByUserNoAsync(userNo);

            timeBlockList.Sort((x, y) => x.ScheduleNo.CompareTo(y.ScheduleNo));


            SchedulesDto schedulesDto = new SchedulesDto()
            {
                Schedules = scheduleList, Timeblocks = timeBlockList
            };


            return(JsonConvert.SerializeObject(schedulesDto));
        }
Beispiel #2
0
        /// <summary>
        /// method That returns all the data with SchedulesDto as  SchedulesDto object
        /// </summary>
        /// <param name="userNo"></param>
        /// <returns>if fail returns null else schedulesDto</returns>
        public async Task <SchedulesDto> GetScheduleDataAsync(int userNo)
        {
            var scheduleList = await this._scheduleDal.GetSchedulesByUserNoAsync(userNo);

            if (scheduleList.Count == 0)
            {
                return(null);
            }

            var timeBlockList = await this._timeBlockDal.GetTimeBlocksByUserNoAsync(userNo);

            timeBlockList.Sort((x, y) => x.ScheduleNo.CompareTo(y.ScheduleNo));


            SchedulesDto schedulesDto = new SchedulesDto()
            {
                Schedules = scheduleList, Timeblocks = timeBlockList
            };


            return(schedulesDto);
        }
Beispiel #3
0
        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);
        }