public void WhenStartTimeGreaterThanEnd_ThenThrowException()
            {
                var start = new SubRipTimeSpan("00:01:20,001");
                var end   = new SubRipTimeSpan("00:01:20,000");

                Assert.Throws <ArgumentException>(() => _ = new SubRipDuration(start, end));
            }
            public void WhenAfterSubtractSameAmountTime_ThenReturnZero()
            {
                var sut = new SubRipTimeSpan("01:23:45,600");

                var result = sut.Subtract(new SubRipTimeSpan(1, 23, 45, 600));

                Assert.That(result.TotalMilliseconds, Is.EqualTo(0));
            }
            public void WhenMsZero_ThenReturnsString(string value)
            {
                var sut = new SubRipTimeSpan(value);

                var result = sut.ToString();

                Assert.That(result, Is.EqualTo(value));
            }
            public void WhenMultipleEntries_ThenSetDurationOnAll()
            {
                var ts = new SubRipTimeSpan(0, 0, 2, 100);

                _sut.SetAbsoluteDuration(ts);

                Assert.That(_sut.Entries.First().Duration.ToString(), Is.EqualTo("01:40:55,758 --> 01:40:57,858"));
                Assert.That(_sut.Entries.Second().Duration.ToString(), Is.EqualTo("01:40:58,677 --> 01:41:00,777"));
            }
            public void WhenCalled_ThenReturnsMin()
            {
                var sut = SubRipTimeSpan.MinValue();

                Assert.That(sut.Hours, Is.EqualTo(0));
                Assert.That(sut.Minutes, Is.EqualTo(0));
                Assert.That(sut.Seconds, Is.EqualTo(0));
                Assert.That(sut.Milliseconds, Is.EqualTo(0));
            }
            public void WhenTwoAreEqual_ThenReturnTrue()
            {
                var sut1 = SubRipTimeSpan.MaxValue();
                var sut2 = SubRipTimeSpan.MaxValue();

                var result = sut1 == sut2;

                Assert.That(result, Is.True);
            }
            public void WhenOneIsGreaterThanOther_ThenReturnFalse()
            {
                var max = SubRipTimeSpan.MaxValue();
                var min = SubRipTimeSpan.MinValue();

                var result = max <= min;

                Assert.That(result, Is.False);
            }
            public void WhenOneIsEqualOther_ThenReturnTrue()
            {
                var max1 = SubRipTimeSpan.MaxValue();
                var max2 = SubRipTimeSpan.MaxValue();

                var result = max2 <= max1;

                Assert.That(result, Is.True);
            }
            public void WhenIsValid_ThenSetProperties(string timeSpan, int expectedHours, int expectedMins, int expectedSecs, int expectedMs)
            {
                var sut = new SubRipTimeSpan(timeSpan);

                Assert.That(sut.Hours, Is.EqualTo(expectedHours));
                Assert.That(sut.Minutes, Is.EqualTo(expectedMins));
                Assert.That(sut.Seconds, Is.EqualTo(expectedSecs));
                Assert.That(sut.Milliseconds, Is.EqualTo(expectedMs));
            }
            public void WhenArgsValid_ThenSetProperties()
            {
                var sut = new SubRipTimeSpan(1, 59, 59, 999);

                Assert.That(sut.Hours, Is.EqualTo(1));
                Assert.That(sut.Minutes, Is.EqualTo(59));
                Assert.That(sut.Seconds, Is.EqualTo(59));
                Assert.That(sut.Milliseconds, Is.EqualTo(999));
            }
            public void WhenTwoAreNotEqual_ThenReturnFalse()
            {
                var sut1 = SubRipTimeSpan.MaxValue();
                var sut2 = SubRipTimeSpan.MinValue();

                var result = sut1 == sut2;

                Assert.That(result, Is.False);
            }
            public void WhenOneIsLessThanOther_ThenReturnTrue()
            {
                var max = SubRipTimeSpan.MaxValue();
                var min = SubRipTimeSpan.MinValue();

                var result = min <= max;

                Assert.That(result, Is.True);
            }
            public void WhenSubRipTimeSpanIsValid_ThenSubtract()
            {
                var sut = new SubRipTimeSpan("01:23:45,600");

                var result = sut.Subtract(new SubRipTimeSpan(0, 10, 10, 0));

                Assert.That(result.Hours, Is.EqualTo(1));
                Assert.That(result.Minutes, Is.EqualTo(13));
                Assert.That(result.Seconds, Is.EqualTo(35));
                Assert.That(result.Milliseconds, Is.EqualTo(600));
            }
            public void WhenValid_ThenSetProperties()
            {
                var start = new SubRipTimeSpan("00:01:20,000");
                var end   = new SubRipTimeSpan("00:01:23,000");

                var sut = new SubRipDuration(start, end);

                Assert.That(sut.Start.ToString(), Is.EqualTo("00:01:20,000"));
                Assert.That(sut.End.ToString(), Is.EqualTo("00:01:23,000"));
                Assert.That(sut.TotalActiveTime.ToString(), Is.EqualTo("00:00:03,000"));
            }
            public void WhenEntryOverMax_ThenSetDurationToMax()
            {
                var ts = new SubRipTimeSpan(0, 0, 2, 500);

                var sut = new SubRipFile(FileName, new List <SubRipEntry> {
                    _entry1
                });

                sut.SetMaxDuration(ts);

                Assert.That(sut.Entries.Single().Duration.ToString(), Is.EqualTo("01:40:55,758 --> 01:40:58,258"));
            }
            public void WhenEntryLessThanMax_ThenDoNothing()
            {
                var ts = new SubRipTimeSpan(0, 0, 2, 700);

                var sut = new SubRipFile(FileName, new List <SubRipEntry> {
                    _entry1
                });

                sut.SetMaxDuration(ts);

                Assert.That(sut.Entries.Single().Duration.ToString(), Is.EqualTo("01:40:55,758 --> 01:40:58,426"));
            }
            public void WhenOverlapsWithNextEntry_ThenSetToStartOfNext()
            {
                _sut.Entries.First().Duration  = new SubRipDuration("01:40:00,000 --> 01:40:02,500");
                _sut.Entries.Second().Duration = new SubRipDuration("01:40:03,000 --> 01:40:05,000");

                var ts = new SubRipTimeSpan(0, 0, 4, 0);

                _sut.SetAbsoluteDuration(ts, true);

                Assert.That(_sut.Entries.First().Duration.ToString(), Is.EqualTo("01:40:00,000 --> 01:40:02,999"));
                Assert.That(_sut.Entries.Second().Duration.ToString(), Is.EqualTo("01:40:03,000 --> 01:40:07,000"));
            }
            public void WhenAfterSubtractLessThanZeroTime_ThenReturnZero()
            {
                var sut = new SubRipTimeSpan("01:23:45,600");

                var result = sut.Subtract(new SubRipTimeSpan(1, 23, 46, 600));

                Assert.That(result.TotalMilliseconds, Is.EqualTo(0));

                Assert.That(result.Hours, Is.EqualTo(0));
                Assert.That(result.Minutes, Is.EqualTo(0));
                Assert.That(result.Seconds, Is.EqualTo(0));
                Assert.That(result.Milliseconds, Is.EqualTo(0));
            }
            public void WhenEntriesMix_ThenSetDuration()
            {
                var ts = new SubRipTimeSpan(0, 0, 2, 800);

                var sut = new SubRipFile(FileName, new List <SubRipEntry> {
                    _entry1, _entry2
                });

                sut.SetMaxDuration(ts);

                // Hasn't changed
                Assert.That(sut.Entries.First().Duration.ToString(), Is.EqualTo("01:40:55,758 --> 01:40:58,426"));

                // Has set to new ts
                Assert.That(sut.Entries.Second().Duration.ToString(), Is.EqualTo("01:40:58,677 --> 01:41:01,477"));
            }
 public void WhenInvalidMilliseconds_ThenThrowException(int ms)
 {
     Assert.Throws <ArgumentOutOfRangeException>(() => _ = new SubRipTimeSpan(1, 1, 1, ms));
 }
 public void WhenInvalidMinutes_ThenThrowException(int minutes)
 {
     Assert.Throws <ArgumentOutOfRangeException>(() => _ = new SubRipTimeSpan(1, minutes, 1, 1));
 }
 public void WhenInvalidHours_ThenThrowException(int hours)
 {
     Assert.Throws <ArgumentOutOfRangeException>(() => _ = new SubRipTimeSpan(hours, 1, 1, 1));
 }
 public void WhenIsInvalidFormat_ThenThrowException(string value)
 {
     Assert.Throws <ArgumentException>(() => _ = new SubRipTimeSpan(value));
 }