public void It_should_have_the_Expected_Value_By_Default()
            {
                var target = new InterlockedDateTime();

                target.Equals(new DateTime(0, DateTimeKind.Utc)).Should().BeTrue();
                target.Equals(new InterlockedDateTime(0)).Should().BeTrue();
                target.GetHashCode().Should().Be(new DateTime(0, DateTimeKind.Utc).GetHashCode());
            }
            public void It_should_Implement_IComparable_of_T()
            {
                var now    = DateTime.UtcNow;
                var target = new InterlockedDateTime(now);

                target.CompareTo(now).Should().Be(0);
                target.CompareTo(new InterlockedDateTime(now)).Should().Be(0);
            }
Esempio n. 3
0
 public Runner(ProjectorBase projector, TimeSpan?runForDuration = null)
 {
     Projector      = projector;
     RunForDuration = runForDuration ?? TimeSpan.FromMinutes(1);
     _startedAt     = new InterlockedDateTime(DateTime.MaxValue);
     _timeoutCalc   = new TimeoutCalculator(TimeSpan.Zero);
     _runnerTimer   = CreateTimer(_timeoutCalc);
 }
            public void It_should_Accept_The_Value_Set()
            {
                var expected = DateTime.UtcNow;
                var target   = new InterlockedDateTime();

                target.Equals(expected).Should().BeFalse();
                target.SetValue(expected);
                target.Equals(expected).Should().BeTrue();
            }
            public void It_should_Be_Accept_A_Starting_Tick_Count()
            {
                var original = DateTime.UtcNow;
                var target   = new InterlockedDateTime(original.Ticks);

                target.GetValue().Should().Be(original);
                target.Equals(original).Should().BeTrue();
                target.Equals(new InterlockedDateTime(original)).Should().BeTrue();
            }
Esempio n. 6
0
        public Runner(IContractsRegistry contractsRegistry, ILogger logger, IPollerStateRepository stateRepository, SubscriptionPoller poller, IUpConverterFactory upConverterFactory)
        {
            if (poller == null)
            {
                throw new ArgumentNullException(nameof(poller));
            }
            Poller = poller;

            _pollerContext = new PollerContext(contractsRegistry, logger, stateRepository, upConverterFactory);
            _startedAt     = new InterlockedDateTime(DateTime.MaxValue);
            _timeoutCalc   = new PollerTimeoutCalculator(Poller.GetFetchTimeout());
            _runnerTimer   = CreateTimer(_timeoutCalc);
        }
Esempio n. 7
0
 public Linearizer(string connectionString, ILogger logger, TimeSpan timeout, TimeSpan durationWork, int batchSize)
 {
     _logger           = logger;
     _connectionString = PrepareConnectionString(connectionString);
     _timer            = new System.Timers.Timer(timeout.TotalMilliseconds)
     {
         AutoReset = false, SynchronizingObject = null, Site = null
     };
     _timer.Elapsed += OnTimerElapsed;
     _durationWork   = durationWork;
     _batchSize      = batchSize;
     _startedAt      = new InterlockedDateTime(DateTime.MaxValue);
 }
            public void It_should_Evaluate_Equality_With_Value_Semantics()
            {
                var now    = DateTime.UtcNow;
                var target = new InterlockedDateTime(now);

                target.Equals(null).Should().BeFalse();
                target.Equals((object)new InterlockedDateTime(now)).Should().BeTrue();

                // ReSharper disable once SuspiciousTypeConversion.Global
                target.Equals((object)now).Should().BeTrue();

                target.Equals(new object()).Should().BeFalse();
            }
Esempio n. 9
0
 protected Linearizer(ILogger logger, TimeSpan timeout, TimeSpan workDuration)
 {
     Logger = logger ?? throw new ArgumentNullException(nameof(logger));
     if (timeout != TimeSpan.Zero)
     {
         _timer = new System.Timers.Timer(timeout.TotalMilliseconds)
         {
             AutoReset = false, SynchronizingObject = null, Site = null
         };
         _timer.Elapsed += (s, e) => ExecuteOnIntervalElapsed().SwallowException();
     }
     WorkDuration = workDuration;
     Timeout      = timeout;
     _startedAt   = new InterlockedDateTime(DateTime.MaxValue);
 }
            public void It_should_Be_Comparable_To_Earlier_And_Later_Values()
            {
                var now    = DateTime.UtcNow;
                var before = now.AddDays(-1);
                var after  = now.AddDays(1);

                var target = new InterlockedDateTime(now);

                target.GetValue().Should().Be(now);
                target.Should().Be(new InterlockedDateTime(now));
                (target >= before).Should().BeTrue();
                (before <= target).Should().BeTrue();
                (target >= new InterlockedDateTime(before)).Should().BeTrue();
                (new InterlockedDateTime(before) <= target).Should().BeTrue();
                (target > before).Should().BeTrue();
                (before < target).Should().BeTrue();
                (target > new InterlockedDateTime(before)).Should().BeTrue();
                (new InterlockedDateTime(before) < target).Should().BeTrue();
                (target == now).Should().BeTrue();
                (now == target).Should().BeTrue();
                (target == new InterlockedDateTime(now)).Should().BeTrue();
                (new InterlockedDateTime(now) == target).Should().BeTrue();
                (target != after).Should().BeTrue();
                (after != target).Should().BeTrue();
                (target != new InterlockedDateTime(after)).Should().BeTrue();
                (new InterlockedDateTime(after) != target).Should().BeTrue();
                (target <= before).Should().BeFalse();
                (before >= target).Should().BeFalse();
                (target <= new InterlockedDateTime(before)).Should().BeFalse();
                (new InterlockedDateTime(before) >= target).Should().BeFalse();
                (target < before).Should().BeFalse();
                (before > target).Should().BeFalse();
                (target < new InterlockedDateTime(before)).Should().BeFalse();
                (new InterlockedDateTime(before) > target).Should().BeFalse();
                target.As <IComparable <DateTime> >().Should().BeGreaterThan(before);
                target.As <IComparable <DateTime> >().Should().BeLessThan(after);
                target.As <IComparable <InterlockedDateTime> >().Should().BeGreaterThan(new InterlockedDateTime(before));
                target.CompareTo(before).Should().BeGreaterThan(0);
            }