예제 #1
0
        public void WithinInterval_Expired(int secondsElapsed)
        {
            // Use NSubstitute to provide an implementation of IDateTimeServices.
            var dateTimeServices = Substitute.For <System.Abstractions.IDateTimeServices>();

            dateTimeServices.UtcNow.Returns(new DateTime(2020, 1, 1));


            // Our timer that we want to test
            var simpleTimer = new MyLib.SimpleTimer(
                dateTimeServices: dateTimeServices,
                interval: timerInterval);


            // Update the mocked date time services so that a simulated interval
            // of time has elapsed, less than the
            dateTimeServices.UtcNow.Returns(
                dateTimeServices.UtcNow +
                TimeSpan.FromSeconds(secondsElapsed));


            // FluentAssertions method of checking the Expired property
            simpleTimer.Expired.Should().BeFalse();


            // Standard XUnit test for comparison
            Assert.False(simpleTimer.Expired);
        }
예제 #2
0
        public void AfterInterval_Expired(int secondsElapsed)
        {
            var dateTimeServices = Substitute.For <System.Abstractions.IDateTimeServices>();

            dateTimeServices.UtcNow.Returns(new DateTime(2020, 1, 1));


            var simpleTimer = new MyLib.SimpleTimer(
                dateTimeServices: dateTimeServices,
                interval: timerInterval);


            dateTimeServices.UtcNow.Returns(
                dateTimeServices.UtcNow +
                TimeSpan.FromSeconds(secondsElapsed));


            simpleTimer.Expired.Should().BeTrue();
        }