public void GetUtcNowAccuracyIsMilliseconds()
        {
            SystemClockMillisecondsAccuracy.GetUtcNow();

            var nowActual   = SystemClockMillisecondsAccuracy.GetUtcNow();
            var nowExpected = DateTimeOffset.UtcNow;

            var diff = nowExpected - nowActual;
            var ms   = Math.Abs(diff.TotalMilliseconds);

            Assert.True(ms < 1.0);
        }
Exemplo n.º 2
0
        public MakerDbContext CreateDbContext(string[] args)
        {
            var assemblyName   = Assembly.GetExecutingAssembly().GetName().Name;
            var optionsBuilder = new DbContextOptionsBuilder <MakerDbContext>();

            optionsBuilder.UseSqlServer("Server=(localdb)\\mssqllocaldb;Database=Maker.Identity;Trusted_Connection=True;MultipleActiveResultSets=True", b => b.MigrationsAssembly(assemblyName));

            var idGenerator = new IdGenerator(0);
            var systemClock = new SystemClockMillisecondsAccuracy();

            return(new MakerDbContext(optionsBuilder.Options, idGenerator, systemClock));
        }
        public void GetUtcNowHasNonZeroMilliseconds()
        {
            var sw = Stopwatch.StartNew();

            var startTime = SystemClockMillisecondsAccuracy.GetUtcNow();

            SpinWait.SpinUntil(() => sw.ElapsedMilliseconds > 1, 2);

            var endTime = SystemClockMillisecondsAccuracy.GetUtcNow();

            Assert.True(sw.ElapsedMilliseconds > 0);

            var duration = endTime - startTime;

            Assert.NotEqual(0.0, duration.TotalMilliseconds);
        }