private static DateTimeOffset GetDateTimeOffset(ScheduleResponse s)
        {
            var dateTime  = s.StartDate.ConvertLongIntoDateTime();
            var alertTime = dateTime.AddMinutes(MyConstants.DefaultBroadcastOverhead);

            return(alertTime);
        }
        public async Task DeleteAsyncWhenInvalidIdReturnsSheduleNotFoundResponse()
        {
            // Arrange
            var mockUnitOfWork        = GetDefaultUnitOfWorkRepositoryInstance();
            var mockSheduleRepository = GetDefaultSheduleRepositoryInstance();
            var SheduleId             = 1;
            var Shedule = new Schedule()
            {
                Id       = 1,
                StarDate = DateTime.MinValue,
                EndDate  = DateTime.MinValue,
                TutorId  = 1
            };

            mockSheduleRepository.Setup(r => r.FindById(SheduleId)).Returns(Task.FromResult <Schedule>(null));
            mockSheduleRepository.Setup(r => r.Remove(Shedule));
            var service = new ScheduleService(mockSheduleRepository.Object, mockUnitOfWork.Object);

            // Act
            ScheduleResponse result = await service.DeleteAsync(SheduleId);

            var message = result.Message;

            // Assert
            message.Should().Be("Schedule not found");
        }
Ejemplo n.º 3
0
 public void Check(ScheduleResponse response)
 {
     foreach (var checker in _checkers)
     {
         checker.Check(response);
     }
 }
        public async Task UpdateAsyncWhenIdIsCorrectReturnsSheduleInstance()
        {
            // Arrange
            var mockUnitOfWork        = GetDefaultUnitOfWorkRepositoryInstance();
            var mockSheduleRepository = GetDefaultSheduleRepositoryInstance();
            var SheduleId             = 1;
            var Shedule = new Schedule()
            {
                Id       = 1,
                StarDate = DateTime.MinValue,
                EndDate  = DateTime.MinValue,
                TutorId  = 1
            };

            mockSheduleRepository.Setup(r => r.FindById(SheduleId)).Returns(Task.FromResult(Shedule));
            mockSheduleRepository.Setup(r => r.Update(Shedule));
            var service = new ScheduleService(mockSheduleRepository.Object, mockUnitOfWork.Object);

            // Act
            ScheduleResponse result = await service.UpdateAsync(SheduleId, Shedule);

            var resource = result.Resource;

            // Assert
            resource.Should().Equals(Shedule);
        }
        public void GetAll_ValidArguments_ShouldReturnRoutingRules()
        {
            //Arrange
            var mockFacilityKey = Utility.ParseStringToGuid(_executionContextAccessor.Current.Facility.FacilityKey);
            var mockGuid        = Guid.Parse("E767B738-3944-4896-93A0-6F074BA16890");
            var fakeSchedule    = new ScheduleResponse
            {
                Key = mockGuid
            };
            var scheduleList = new List <ScheduleResponse>();

            scheduleList.Add(fakeSchedule);
            _mockScheduleBusiness.Setup(x => x.GetSchedules(It.IsAny <Guid>())).ReturnsAsync(scheduleList);

            var mockRoutingRuleGuid = new Guid();
            var fakeRoutingRule     = new RoutingRule
            {
                FacilityKey     = mockFacilityKey,
                RoutingRuleKey  = mockRoutingRuleGuid,
                RoutingRuleName = "test",
            };
            var routingList = new List <RoutingRule>();

            routingList.Add(fakeRoutingRule);
            routingList.AsEnumerable();
            _mockRoutingRuleRepository.Setup(x => x.GetRoutingRules(mockFacilityKey, 0, 0, "")).ReturnsAsync(routingList);
            //Act
            var response = _routingRuleManager.GetAllRoutingRule();

            //Assert
            Assert.Equal(mockRoutingRuleGuid, response.First().RoutingRuleKey);
        }
        public ScheduleResponse Any(ScheduleRequest request)
        {
            ScheduleResponse resp = new ScheduleResponse();

            TaskExecuter(request.Task).GetAwaiter().GetResult();
            return(resp);
        }
        /// <summary>
        /// Mock Schedule request
        /// </summary>
        /// <returns></returns>
        private IEnumerable <ScheduleResponse> FakeData()
        {
            ScheduleResponse s = new ScheduleResponse();

            s.Key          = Guid.Parse("BEC05D78-2F6C-4034-8FB9-ACE3417F83E8");
            s.EndTime      = new TimeSpan();
            s.StartTime    = new TimeSpan();
            s.Name         = "Test";
            s.ScheduleDays = new List <string>()
            {
                "Monday", "Tuesday"
            };

            ScheduleResponse s1 = new ScheduleResponse();

            s.Key          = Guid.Parse("BEC05D78-2F6C-4034-8FB9-ACE3417F83E9");
            s.EndTime      = new TimeSpan();
            s.StartTime    = new TimeSpan();
            s.Name         = "Test1";
            s.ScheduleDays = new List <string>()
            {
                "Monday", "Tuesday"
            };

            List <ScheduleResponse> sc = new List <ScheduleResponse>();

            sc.Add(s);
            sc.Add(s1);
            return(sc.AsEnumerable());
        }
 public ScheduleResponse GetSchedule()
 {
     if (_schedule == null)
     {
         _schedule = GenerateSchedule();
     }
     return(_schedule);
 }
        private static Message BuildBroadcastMessage(TeamIds t, ScheduleResponse s, Settings settings)
        {
            var message = new Message($"{settings.BroadcastMessageIdPrefix}{s.Id.ToString()}")
            {
                To      = GetListFromTeamId(t, settings),
                Content = GetMessageFromScheduledEvent(s, t, settings)
            };

            return(message);
        }
Ejemplo n.º 10
0
        public static ScheduleEntity ScheduleResponseToEntity(ScheduleResponse scheduleResponse)
        {
            ScheduleEntity scheduleEntity = new ScheduleEntity()
            {
                HallId    = scheduleResponse.HallId,
                Day       = scheduleResponse.Day,
                StartTime = scheduleResponse.StartTime,
                EndTime   = scheduleResponse.EndTime
            };

            return(scheduleEntity);
        }
Ejemplo n.º 11
0
        public static ScheduleResponse ScheduleEntityToResponse(ScheduleEntity scheduleEntity)
        {
            ScheduleResponse scheduleResponse = new ScheduleResponse()
            {
                HallId    = scheduleEntity.HallId,
                Day       = scheduleEntity.Day,
                StartTime = scheduleEntity.StartTime,
                EndTime   = scheduleEntity.EndTime
            };

            return(scheduleResponse);
        }
Ejemplo n.º 12
0
 public void Check(ScheduleResponse response)
 {
     foreach (var driver in response.Drivers)
     {
         for (int i = 0; i < driver.Assignments.Count - 1; i++)
         {
             if (driver.Assignments[i + 1].Range.ExactFrom < driver.Assignments[i].Range.ExactTo)
             {
                 throw new ValidationException();
             }
         }
     }
 }
Ejemplo n.º 13
0
        public static async Task DemoGetStage()
        {
            // create provider
            OWLAsyncApiDataProvider asyncProvider = new OWLAsyncApiDataProvider();

            // get schedule object
            ScheduleResponse schedule = await asyncProvider.FetchSchedule();

            // get next stage
            Stage stage = schedule.GetNextStage();

            Console.Out.WriteLine($"The next stage of the current OWL season is: {stage.Name}");
        }
Ejemplo n.º 14
0
        public static ScheduleResponse ToDto(this Schedule schedule)
        {
            var scheduleResponse = new ScheduleResponse
            {
                TimePeriod = schedule.TimePeriod.ToDto(),
                NextRun    = schedule.NextRun,
                Amount     = schedule.Amount
            };

            scheduleResponse.AddLink(Rels.Self,
                                     $"/account/{schedule.AccountId}/schedule/{schedule.ScheduleId}");
            return(scheduleResponse);
        }
        static string EncryptResponse(string strClass)
        {
            string encResp = string.Empty;

            switch (strClass)
            {
            case "SampleScheduleResponseLC":
                ScheduleResponse resp = new ScheduleResponse();
                resp = PVSLibrary.Common.SampleScheduleResponseLC();
                string strObj = JsonConvert.SerializeObject(resp, Formatting.None);
                encResp = Encrypt(strObj, "k6KUvMXYy2I6J5y5hTTgsqG8E2VDL64JhFtPjBB//sU=", true);
                break;
            }
            return(encResp);
        }
Ejemplo n.º 16
0
 public void Check(ScheduleResponse response)
 {
     foreach (var driver in response.Drivers)
     {
         for (int i = 0; i < driver.Assignments.Count - 2; i++)
         {
             var range1 = driver.Assignments[i + 0].Range;
             var range2 = driver.Assignments[i + 1].Range;
             var range3 = driver.Assignments[i + 2].Range;
             if (range1.IsNightShift && range2.IsNightShift && range3.IsNightShift)
             {
                 throw new ValidationException("You dun goofed");
             }
         }
     }
 }
Ejemplo n.º 17
0
        public static async Task DemoGetMatch()
        {
            // create provider
            OWLAsyncApiDataProvider asyncProvider = new OWLAsyncApiDataProvider();

            // get schedule object
            ScheduleResponse schedule = await asyncProvider.FetchSchedule();

            // get the stage using the name, index/id can also be used
            Stage stage = schedule.GetStage("Stage 1");

            // get the next match in this stage
            StageMatch nextMatch = stage.GetNextMatch();

            Console.Out.WriteLine($"Next match is: {nextMatch.Team1.Name} vs {nextMatch.Team2.Name} at {nextMatch.StartDateTimeOffset()}");
        }
        public ScheduleResponse SaveSchedule(ScheduleEntity scheduleEntity)
        {
            db.Schedules.Add(scheduleEntity);

            try
            {
                db.SaveChanges();
            }
            catch (DbEntityValidationException)
            {
                return(null);
            }

            ScheduleResponse scheduleResponse = Converter.ScheduleEntityToResponse(scheduleEntity);

            return(scheduleResponse);
        }
Ejemplo n.º 19
0
        public void Check(ScheduleResponse response)
        {
            foreach (var driver in response.Drivers)
            {
                foreach (var assignment in driver.Assignments)
                {
                    var totalWork = driver.Assignments
                                    .Where(a => a.Range.Day == assignment.Range.Day)
                                    .Aggregate(Duration.Zero, (a, b) => a + b.Range.Duration);

                    if (totalWork > Duration.FromHours(12))
                    {
                        throw new ValidationException();
                    }
                }
            }
        }
        public async Task GetByIdAsyncWhenInvalidIdReturnsSheduleNotFoundResponse()
        {
            // Arrange
            var mockUnitOfWork        = GetDefaultUnitOfWorkRepositoryInstance();
            var mockSheduleRepository = GetDefaultSheduleRepositoryInstance();
            var SheduleId             = 1;

            mockSheduleRepository.Setup(r => r.FindById(SheduleId)).Returns(Task.FromResult <Schedule>(null));
            var service = new ScheduleService(mockSheduleRepository.Object, mockUnitOfWork.Object);

            // Act
            ScheduleResponse result = await service.GetByIdAsync(SheduleId);

            var message = result.Message;

            // Assert
            message.Should().Be("Schedule not found");
        }
Ejemplo n.º 21
0
        public ActionResult <ScheduleResponse> PostSchedule(ScheduleEntity scheduleEntity, int hallId)
        {
            if (!ModelState.IsValid || hallServices.GetHall(hallId) == null)
            {
                return(BadRequest());
            }

            scheduleEntity.HallId = hallId;

            ScheduleResponse scheduleResponse = scheduleService.SaveSchedule(scheduleEntity);

            if (scheduleResponse == null)
            {
                return(BadRequest());
            }

            return(CreatedAtAction("GetSchedule", new { id = scheduleEntity.Id }, scheduleResponse));
        }
Ejemplo n.º 22
0
 public void Check(ScheduleResponse response)
 {
     foreach (var driver in response.Drivers)
     {
         foreach (var assignment in driver.Assignments)
         {
             var total = driver.Assignments
                         .Where(a => a.Range.Day >= assignment.Range.Day)
                         .Where(a => a.Range.Day < assignment.Range.Day.PlusDays(7))
                         .Select(a => 1)
                         .Sum();
             if (total > 6)
             {
                 throw new ValidationException();
             }
         }
     }
 }
Ejemplo n.º 23
0
 public void Check(ScheduleResponse response)
 {
     foreach (var driver in response.Drivers)
     {
         foreach (var assignment in driver.Assignments)
         {
             var total = driver.Assignments
                         .Where(a => a.Range.Day >= assignment.Range.Day)
                         .Where(a => a.Range.Day < assignment.Range.Day.PlusDays(7))
                         .Select(a => a.Range.Duration)
                         .Aggregate(Duration.Zero, (a, b) => a + b);
             if (total > Duration.FromHours(48))
             {
                 throw new ValidationException();
             }
         }
     }
 }
        public void Check(ScheduleResponse response)
        {
            foreach (var driver in response.Drivers)
            {
                for (int i = 0; i < driver.Assignments.Count - 1; i++)
                {
                    if (driver.Assignments[i].Range.Day == driver.Assignments[i + 1].Range.Day)
                    {
                        continue;
                    }

                    var duration = driver.Assignments[i + 1].Range.ExactFrom - driver.Assignments[i].Range.ExactTo;
                    if (duration.ToDuration() < Duration.FromHours(12))
                    {
                        throw new ValidationException("You dun goofed");
                    }
                }
            }
        }
Ejemplo n.º 25
0
        /// <summary>
        /// Generate schedule
        /// </summary>
        /// <param name="disbursement"></param>
        /// <returns>List of schedules</returns>
        public async Task <IList <ScheduleResponse> > GenerateSchechule(DisbursementRequest disbursement)
        {
            var schedules = new List <ScheduleResponse>();

            if (disbursement == null)
            {
                return(schedules);
            }

            var Cust_Code = await _disbursementRepository.GetCustomerCodeAsync();

            for (var i = 1; i <= disbursement.Months; i++)
            {
                var schedule = new ScheduleResponse();
                //compute SL_NO
                var sNo            = Cust_Code + i;
                var currentBalance = 0F;

                schedule.Cust_Code = Cust_Code;
                schedule.EMI_Date  = disbursement.EMS_St_Date;

                schedule.Total_Amount = schedules.Count == 0 ? disbursement.Disb_Amount : schedules.Sum(x => x.Total_Amount);

                if (schedules.Count > 0)
                {
                    currentBalance = (float)PrincipalAmount(schedules, sNo).Item2;
                }

                schedule.Balance    = currentBalance == 0 ? disbursement.Disb_Amount : currentBalance;
                schedule.Prn_Amount = currentBalance == 0 ? disbursement.Disb_Amount : (float)PrincipalAmount(schedules, sNo).Item1;
                schedule.Int_Amount = i == 1 ? (float)InsterestCalculator(disbursement)
                                    : (float)SecondMonthInterestCalculator(disbursement, currentBalance);
                schedule.EMS_St_Date = DateTime.Now;
                schedule.SL_NO       = sNo;


                schedules.Add(schedule);
            }

            return(schedules);
        }
Ejemplo n.º 26
0
        private static Document GetMessageFromScheduledEvent(ScheduleResponse s, TeamIds t, Settings settings)
        {
            var carousel = new DocumentCollection()
            {
                ItemType = DocumentSelect.MediaType,
                Items    = new DocumentSelect[]
                {
                    new DocumentSelect
                    {
                        Header = new DocumentContainer
                        {
                            Value = new MediaLink
                            {
                                AspectRatio = MyConstants.FacebookCarouselAspectRatio,
                                Uri         = new Uri(settings.OWLLogo),
                                Title       = s.Competitors[0].Name + " X " + s.Competitors[1].Name,
                                Text        = $"{s.StartDate.ConvertLongIntoDateTime().ToShortDateString()} - {s.StartDate.ConvertLongIntoDateTime().ToShortTimeString()} (GMT)"
                            }
                        },
                        Options = new DocumentSelectOption[]
                        {
                            new DocumentSelectOption
                            {
                                Label = new DocumentContainer
                                {
                                    Value = new WebLink
                                    {
                                        Uri   = new Uri(settings.OWLTwitch),
                                        Title = "💻Watch!"
                                    }
                                }
                            }
                        }
                    }
                }
            };

            return(carousel);
        }
Ejemplo n.º 27
0
        public ScheduleResponse GetSchedule(int tenantId)
        {
            var schedule = BackupRepository.GetBackupSchedule(tenantId);

            if (schedule != null)
            {
                var tmp = new ScheduleResponse
                {
                    StorageType           = schedule.StorageType,
                    StorageBasePath       = schedule.StorageBasePath,
                    BackupMail            = schedule.BackupMail,
                    NumberOfBackupsStored = schedule.BackupsStored,
                    Cron           = schedule.Cron,
                    LastBackupTime = schedule.LastBackupTime,
                    StorageParams  = JsonConvert.DeserializeObject <Dictionary <string, string> >(schedule.StorageParams)
                };
                return(tmp);
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 28
0
 public void Check(ScheduleResponse response)
 {
     foreach (var driver in response.Drivers)
     {
         foreach (var assignment in driver.Assignments)
         {
             var weekAssignments = driver.Assignments
                                   .Where(a => a.Range.Day >= assignment.Range.Day)
                                   .Where(a => a.Range.Day < assignment.Range.Day.PlusDays(7))
                                   .Select(a => a.Range)
                                   .ToList();
             bool ok = false;
             if (weekAssignments.Count > 0)
             {
                 var restAtStart = (weekAssignments[0].ExactFrom - assignment.Range.ExactTo).ToDuration();
                 var restAtEnd   = (assignment.Range.ExactFrom.PlusDays(7) - weekAssignments.Last().ExactTo).ToDuration();
                 if (restAtStart >= Duration.FromHours(35) || restAtEnd >= Duration.FromHours(35))
                 {
                     ok = true;
                 }
             }
             for (int i = 0; i < weekAssignments.Count - 1; i++)
             {
                 var rest = (weekAssignments[i + 1].ExactFrom - weekAssignments[i].ExactTo).ToDuration();
                 if (rest >= Duration.FromHours(35))
                 {
                     ok = true;
                 }
             }
             if (!ok)
             {
                 throw new ValidationException();
             }
         }
     }
 }
Ejemplo n.º 29
0
        public double Evaluate(ScheduleResponse response)
        {
            double totalTime      = response.Drivers.Aggregate(Duration.Zero, (a, b) => a + b.TotalWorkTime).TotalHours;
            double totalNightTime = response.Drivers.Aggregate(Duration.Zero, (a, b) => a + b.TimeInNightShift).TotalHours;

            double scale = 1;

            if (totalTime != 0)
            {
                scale = totalNightTime / totalTime;
            }

            var workTimeDeviation =
                response.Drivers
                .Select(d => d.TotalWorkTime.TotalHours)
                .StandardDeviation();

            var nightTimeDeviation = response.Drivers
                                     .Select(d => d.TimeInNightShift.TotalHours)
                                     .Select(t => t / scale)
                                     .StandardDeviation();

            return(workTimeDeviation + nightTimeDeviation);
        }
Ejemplo n.º 30
0
 public ScheduleViewModel(ScheduleResponse schedule)
 {
     this.apiService = new ApiService();
     this.Schedule   = schedule;
     this.LoadAppointments();
 }