Exemplo n.º 1
0
        public void Should_Calculate_ThrowException_WhenResultIsNotAvailableOrNull()
        {
            // Given
            var trackBuilder = Substitute.For <ITrackBuilder>();

            trackBuilder.Build(Arg.Any <int>()).Returns(new List <Track>());

            var optionAccessor = Substitute.For <IOptions <SchedulingOptions> >();

            optionAccessor.Value.Returns(new SchedulingOptions {
                ConcurrentTracks = 1
            });

            var strategy = Substitute.For <ITrackSlotAllocationStrategy>();

            strategy.Allocate(Arg.Any <IReadOnlyList <TrackSlot> >(), Arg.Any <IReadOnlyList <SessionDefinition> >())
            .Returns((AllocationResult)null);

            var sut = new TrackSchedulingEngine(trackBuilder, strategy, optionAccessor);

            // When
            Action action = () => sut.Calculate(_fixture.SessionDefinitions);

            // Then
            action.ShouldThrow <AppException>().WithMessage("Error in allocating sessions. result is null");
        }
Exemplo n.º 2
0
        public void Should_Calculate_ReturnTheCorrectAllocation_WhenSlotsAreAllocatedCorrectly()
        {
            // Given
            var trackBuilder = Substitute.For <ITrackBuilder>();
            var tracks       = new List <Track> {
                _fixture.EqualSlotsTrack
            };

            trackBuilder.Build(Arg.Any <int>()).Returns(tracks);

            var optionAccessor = Substitute.For <IOptions <SchedulingOptions> >();

            optionAccessor.Value.Returns(new SchedulingOptions {
                ConcurrentTracks = 1
            });

            var strategy         = Substitute.For <ITrackSlotAllocationStrategy>();
            var allocationResult = new AllocationResult(new List <TrackSlot>(), new List <SessionDefinition>());

            strategy.Allocate(Arg.Any <IReadOnlyList <TrackSlot> >(), Arg.Any <IReadOnlyList <SessionDefinition> >())
            .Returns(allocationResult);

            var sut = new TrackSchedulingEngine(trackBuilder, strategy, optionAccessor);

            // When
            var result = sut.Calculate(_fixture.SessionDefinitions);

            // Then
            result.ShouldBeEquivalentTo(tracks);
        }
Exemplo n.º 3
0
        public void Should_Calculate_ThrowException_WhenSlotsAreSmallerThenSessions()
        {
            // Given
            var trackBuilder = Substitute.For <ITrackBuilder>();

            trackBuilder.Build(Arg.Any <int>()).Returns(new List <Track>());

            var optionAccessor = Substitute.For <IOptions <SchedulingOptions> >();

            optionAccessor.Value.Returns(new SchedulingOptions {
                ConcurrentTracks = 1
            });

            var strategy         = Substitute.For <ITrackSlotAllocationStrategy>();
            var allocationResult = new AllocationResult(new List <TrackSlot>(), new List <SessionDefinition> {
                new SessionDefinition("Session", 30)
            });

            strategy.Allocate(Arg.Any <IReadOnlyList <TrackSlot> >(), Arg.Any <IReadOnlyList <SessionDefinition> >())
            .Returns(allocationResult);

            var sut = new TrackSchedulingEngine(trackBuilder, strategy, optionAccessor);

            // When
            Action action = () => sut.Calculate(_fixture.SessionDefinitions);

            // Then
            action.ShouldThrow <UnallocatedSessionsException>();
        }
        public void Should_Calculate_ReturnTheCorrectAllocation_WhenSlotsAreEqual()
        {
            // Given
            var trackBuilder = Substitute.For <ITrackBuilder>();

            trackBuilder.Build(Arg.Any <int>()).Returns(new List <Track> {
                _fixture.EqualSlotsTrack
            });

            var optionAccessor = Substitute.For <IOptions <SchedulingOptions> >();

            optionAccessor.Value.Returns(new SchedulingOptions {
                ConcurrentTracks = 1
            });

            var strategy         = Substitute.For <ITrackSlotAllocationStrategy>();
            var allocationResult = new AllocationResult(new List <TrackSlot>(), new List <SessionDefinition>());

            strategy.Allocate(Arg.Any <IReadOnlyList <TrackSlot> >(), Arg.Any <IReadOnlyList <SessionDefinition> >())
            .Returns(allocationResult);

            var sut = new TrackSchedulingEngine(trackBuilder, strategy, optionAccessor);

            // When
            var result = sut.Calculate(_fixture.SessionDefinitions);

            // Then
            result[0].Slots[0].TrackSessions.Should()
            .HaveCount(2)
            .And.Contain(m => m.Title == "Session #2")
            .And.Contain(m => m.Title == "Session #3");

            result[0].Slots[1].TrackSessions.Should()
            .HaveCount(3)
            .And.Contain(m => m.Title == "Session #5")
            .And.Contain(m => m.Title == "Session #1")
            .And.Contain(m => m.Title == "Session #4");
        }