public void SetUp()
        {
            fixture = new Fixture();
            FixtureUtils.ConfigureFixtureForCreateSchedule(fixture);
            freshDays = new List <ISchedule>();
            for (int i = 0; i < 4; i++)
            {
                freshDays.Add(FixtureUtils.CreateFixtureDaySchedule(3, 1, fixture));
            }
            groups = new List <IScheduleGroup>();
            freshDays.ForEach(d => groups.Add(d.ScheduleGroups.First()));
            storedDays = new List <ISchedule>();
            for (int i = 0; i < 3; i++)
            {
                storedDays.Add(FixtureUtils.CreateFixtureDaySchedule(3, 1, fixture));
            }
            storedDays.Select((d, i) => d.ScheduleGroups = new[] { groups[i] }).ToList();
            infoProviderFake = A.Fake <IScheduleInfoProvider>();
            A.CallTo(() => infoProviderFake.GetSchedules(null, default(DayOfWeek))).WithAnyArguments()
            .Returns(freshDays);
            storageFake = A.Fake <ISchedulesStorage>();
            A.CallTo(() => storageFake.GetSchedules(null, default(DayOfWeek))).WithAnyArguments().Returns(storedDays);
            monitorFake = A.Fake <IGroupsMonitor>();
            A.CallTo(() => monitorFake.AvailableGroups).Returns(groups);

            service = new ScheduleService(storageFake, monitorFake, infoProviderFake, new DefaultEventArgsFactory(),
                                          new SchElemsMerger(new DefaultSchElemsFactory()));
        }
Example #2
0
        public ScheduleService(ISchedulesStorage storage, IGroupsMonitor groupsMonitor,
                               IScheduleInfoProvider freshInfoProvider, IScheduleEventArgsFactory eventArgsFactory, SchElemsMerger branchMerger,
                               ILogger <ScheduleService> logger = null)
        {
            this.storage             = storage;
            this.freshInfoProvider   = freshInfoProvider;
            this.eventArgsFactory    = eventArgsFactory;
            this.logger              = logger;
            this.scheduleConstructor = new ScheduleConstructor(new DefaultSchElemsFactory(), branchMerger);
            this.GroupsMonitor       = groupsMonitor;

            try
            {
                for (int i = 1; i <= 6; i++)
                {
                    UpdateSchedulesAsync(groupsMonitor.AvailableGroups.ToList(), (DayOfWeek)i).Wait();
                }
            }
            catch (Exception e)
            {
                if (logger == null)
                {
                    Console.WriteLine(e);
                    Console.WriteLine("UPDATE INTERRUPTED");
                }
                else
                {
                    logger.LogError("First time schedules update interrupted", e);
                }
            }

            if (logger == null)
            {
                Console.WriteLine("UPDATED");
            }
            else
            {
                logger.LogInformation("First time schedules updates");
            }
        }