public void Will_Choose_Highest_Priority_Source_For_Two_Overlapping_Plan_Items()
        {
            // Create plan
            var group  = Guid.NewGuid();
            var plan1  = RecordingDefinition.Create(false, "test", Guid.NewGuid(), null, SourceMock.Create("s1", group), DateTime.UtcNow.AddHours(1), TimeSpan.FromMinutes(20));
            var times1 = plan1.GetTimes(DateTime.UtcNow).Select(s => s.Planned).Single();
            var plan2  = RecordingDefinition.Create(false, "test", Guid.NewGuid(), null, SourceMock.Create("s1", group), times1.End - TimeSpan.FromMinutes(10), TimeSpan.FromMinutes(20));
            var times2 = plan2.GetTimes(DateTime.UtcNow).Select(s => s.Planned).Single();
            var best   = ResourceMock.Create("r3", SourceMock.Create("s1", group)).SetPriority(6);

            // Create component under test
            var componentUnderTest =
                new RecordingScheduler(StringComparer.InvariantCultureIgnoreCase)
            {
                { ResourceMock.Create("r1", SourceMock.Create("s1", group)).SetPriority(1) },
                { best },
                { ResourceMock.Create("r2", SourceMock.Create("s1", group)).SetPriority(-1) },
                { plan2 },
                { plan1 },
            };

            // Load
            var schedules = componentUnderTest.GetSchedules(DateTime.UtcNow).ToArray();

            // Validate
            Assert.AreEqual(2, schedules.Length, "Schedules");
            Assert.AreSame(best, schedules[0].Resource, "Resource 0");
            Assert.AreSame(best, schedules[1].Resource, "Resource 1");
            Assert.AreSame(plan1, schedules[0].Definition, "Plan 0");
            Assert.AreSame(plan2, schedules[1].Definition, "Plan 1");
            Assert.AreEqual(times1, schedules[0].Time, "Time 0");
            Assert.AreEqual(times2, schedules[1].Time, "Time 1");
            Assert.IsFalse(schedules[0].StartsLate, "Late 0");
            Assert.IsFalse(schedules[1].StartsLate, "Late 1");
        }
        public void Will_Use_Resource_With_Highest_Priority_When_Explicit_Binding_Is_Used()
        {
            // Create plan
            var source1 = SourceMock.Create("s1");
            var source2 = SourceMock.Create("s2");
            var res1    = ResourceMock.Create("r1", source1, source2).SetPriority(5);
            var res2    = ResourceMock.Create("r2", source1, source2).SetPriority(6);
            var res3    = ResourceMock.Create("r3", source1, source2).SetPriority(0);
            var refTime = DateTime.UtcNow;
            var plan1   = RecordingDefinition.Create(false, "A1", Guid.NewGuid(), new[] { res1 }, source1, refTime.AddMinutes(100), TimeSpan.FromMinutes(20));
            var plan2   = RecordingDefinition.Create(false, "A2", Guid.NewGuid(), new[] { res1 }, source1, refTime.AddMinutes(110), TimeSpan.FromMinutes(20));
            var plan3   = RecordingDefinition.Create(false, "A3", Guid.NewGuid(), null, source2, refTime.AddMinutes(130), TimeSpan.FromMinutes(20));

            // Create component under test
            var componentUnderTest =
                new RecordingScheduler(StringComparer.InvariantCultureIgnoreCase)
            {
                { res1 },
                { res2 },
                { res3 },
                { plan1 },
                { plan2 },
                { plan3 },
            };

            // Load
            var schedules = componentUnderTest.GetSchedules(refTime).ToArray();

            // Validate
            Assert.AreEqual(3, schedules.Length, "#schedule");
            Assert.AreSame(res1, schedules[0].Resource, "resource 0");
            Assert.AreSame(res1, schedules[1].Resource, "resource 1");
            Assert.AreSame(res2, schedules[2].Resource, "resource 2");
        }
        public void Will_Enforce_Start_Order()
        {
            // Create plan
            var source1 = SourceMock.Create("s1");
            var source2 = SourceMock.Create("s2");
            var res1    = ResourceMock.Create("r1", source1, source2).SetPriority(1);
            var res2    = ResourceMock.Create("r2", source1, source2).SetPriority(2);
            var refTime = DateTime.UtcNow.Date.AddDays(10);
            var plan1   = RecordingDefinition.Create(false, "A1", Guid.NewGuid(), null, source1, refTime.AddHours(18), TimeSpan.FromHours(2));
            var plan2   = RecordingDefinition.Create(false, "A2", Guid.NewGuid(), null, source2, refTime.AddHours(19), TimeSpan.FromHours(2));

            // Create component under test
            var componentUnderTest =
                new RecordingScheduler(StringComparer.InvariantCultureIgnoreCase, Properties.Files.EnforceResourceStartOrder)
            {
                { res1 },
                { res2 },
                { plan1 },
                { plan2 },
            };

            // Load
            var schedules = componentUnderTest.GetSchedules(refTime).ToArray();

            // Validate
            Assert.AreEqual(2, schedules.Length, "#schedules");
            Assert.AreSame(plan1, schedules[0].Definition, "plan 1");
            Assert.AreSame(plan2, schedules[1].Definition, "plan 2");
            Assert.AreSame(res1, schedules[0].Resource, "resource 1");
            Assert.AreSame(res2, schedules[1].Resource, "resource 2");
        }
Example #4
0
        public void Recording_Has_Priority_Over_Task()
        {
            // Create the recording
            var plan1 = RecordingDefinition.Create(false, "test", Guid.NewGuid(), null, SourceMock.Source1Group1Free, TimeBias.AddMinutes(15), TimeSpan.FromMinutes(80));
            var plan2 = RecordingDefinition.Create(false, "test", Guid.NewGuid(), null, SourceMock.Source1Group1Free, TimeBias.AddHours(3), TimeSpan.FromMinutes(100));

            // Create the component under test
            var cut = new RecordingScheduler(StringComparer.InvariantCultureIgnoreCase)
            {
                TaskDevice, plan1, plan2
            };

            // Load some
            var schedules = cut.GetSchedules(TimeBias, Task).Take(5).ToArray();

            // Validate
            Assert.AreEqual(5, schedules.Length, "Schedules");
            Assert.AreSame(plan1, schedules[0].Definition, "Definition 1");
            Assert.IsFalse(schedules[0].StartsLate, "Late 1");
            Assert.AreSame(Task, schedules[1].Definition, "Definition 2");
            Assert.IsTrue(schedules[1].StartsLate, "Late 2");
            Assert.AreSame(Task, schedules[2].Definition, "Definition 3");
            Assert.IsFalse(schedules[2].StartsLate, "Late 3");
            Assert.AreEqual(TimeBias.ToLocalTime().Date.AddHours(20).ToUniversalTime(), schedules[2].Time.Start, "Start 3");
            Assert.AreSame(plan2, schedules[3].Definition, "Definition 4");
            Assert.IsFalse(schedules[3].StartsLate, "Late 4");
            Assert.AreSame(Task, schedules[4].Definition, "Definition 5");
            Assert.IsFalse(schedules[4].StartsLate, "Late 5");
            Assert.AreEqual(TimeBias.ToLocalTime().Date.AddDays(1).AddHours(10).ToUniversalTime(), schedules[4].Time.Start, "Start 5");
        }
Example #5
0
        public void Encrypted_Source_Of_A_Plan_Item_Is_Supported_By_Resource()
        {
            // Create component under test
            var componentUnderTest = new RecordingScheduler(StringComparer.InvariantCultureIgnoreCase);

            // Add
            componentUnderTest.Add(ResourceMock.Create("r1", SourceMock.Create("s1")).SetEncryptionLimit(1));
            componentUnderTest.Add(RecordingDefinition.Create(false, "test", Guid.NewGuid(), null, SourceMock.Create("s1", true), DateTime.UtcNow, TimeSpan.FromMinutes(12)));
        }
Example #6
0
        public void Exceptions_Must_Be_Defined_On_A_Full_Date()
        {
            // Create bad exception
            var exception = new PlanException {
                ExceptionDate = DateTime.Now.Date.AddMinutes(12)
            };

            // Create component under test
            var componentUnderTest = new RecordingScheduler(StringComparer.InvariantCultureIgnoreCase);

            // Add
            componentUnderTest.Add(ResourceMock.Create("r1", SourceMock.Create("s1")));
            componentUnderTest.Add(RecordingDefinition.Create(false, "test", Guid.NewGuid(), null, SourceMock.Create("s1"), DateTime.UtcNow, TimeSpan.FromMinutes(12)), exception);
        }
Example #7
0
        public void There_Can_Be_Only_One_Exception_Per_Date()
        {
            // Create bad exception
            var exception1 = new PlanException {
                ExceptionDate = DateTime.Now.Date
            };
            var exception2 = new PlanException {
                ExceptionDate = exception1.ExceptionDate
            };

            // Create component under test
            var componentUnderTest = new RecordingScheduler(StringComparer.InvariantCultureIgnoreCase);

            // Add
            componentUnderTest.Add(ResourceMock.Create("r1", SourceMock.Create("s1")));
            componentUnderTest.Add(RecordingDefinition.Create(false, "test", Guid.NewGuid(), null, SourceMock.Create("s1"), DateTime.UtcNow, TimeSpan.FromMinutes(12)), exception1, exception2);
        }
        public void Will_Minimize_Sources_Per_Resource()
        {
            // Create plan
            var source1 = SourceMock.Create("s1");
            var source2 = SourceMock.Create("s2");
            var source3 = SourceMock.Create("s3");
            var res1    = ResourceMock.Create("r1", source1, source2, source3).SetPriority(1);
            var res2    = ResourceMock.Create("r2", source1, source2, source3).SetPriority(1);
            var res3    = ResourceMock.Create("r3", source1, source2, source3).SetPriority(0);
            var refTime = DateTime.UtcNow.Date.AddDays(10);
            var plan1   = RecordingDefinition.Create(false, "A1", Guid.NewGuid(), null, source1, refTime.AddHours(19), TimeSpan.FromHours(2));
            var plan2   = RecordingDefinition.Create(false, "A2", Guid.NewGuid(), null, source2, refTime.AddHours(20), TimeSpan.FromHours(3));
            var plan3   = RecordingDefinition.Create(false, "A3", Guid.NewGuid(), null, source3, refTime.AddHours(20), TimeSpan.FromHours(2));
            var plan4   = RecordingDefinition.Create(false, "A4", Guid.NewGuid(), null, source2, refTime.AddHours(22), TimeSpan.FromHours(2));

            // Create component under test
            var componentUnderTest =
                new RecordingScheduler(StringComparer.InvariantCultureIgnoreCase, Properties.Files.MinimizeSourcesPerResource)
            {
                { res1 },
                { res2 },
                { res3 },
                { plan1 },
                { plan2 },
                { plan3 },
                { plan4 },
            };

            // Load
            var schedules = componentUnderTest.GetSchedules(refTime).ToArray();

            // Validate
            Assert.AreEqual(4, schedules.Length, "#schedule");
            var exec1 = schedules.Single(s => s.Definition.UniqueIdentifier == plan1.UniqueIdentifier);
            var exec2 = schedules.Single(s => s.Definition.UniqueIdentifier == plan2.UniqueIdentifier);
            var exec3 = schedules.Single(s => s.Definition.UniqueIdentifier == plan3.UniqueIdentifier);
            var exec4 = schedules.Single(s => s.Definition.UniqueIdentifier == plan4.UniqueIdentifier);

            Assert.AreSame(res1, exec1.Resource, "A1");
            Assert.AreSame(res2, exec2.Resource, "A2");
            Assert.AreSame(res3, exec3.Resource, "A3");
            Assert.AreSame(res2, exec4.Resource, "A4");
        }