public void Today_WithCustomScope_ShouldReturnExpectedResult()
        {
            using var scope = new ClockScope(() => new DateTime(2000, 01, 01, 12, 00, 00, DateTimeKind.Local));

            var result = ClockScope.Current.Today;

            Assert.Equal(new DateTime(2000, 01, 01, 00, 00, 00, DateTimeKind.Local), result);
        }
        public void Current_WithCustomScope_ShouldReturnExpectedResult()
        {
            using var scope = new ClockScope(() => DateTime.UnixEpoch);

            var result = ClockScope.Current;

            Assert.Equal(scope, result);
        }
        public void Current_WithNestedCustomScopes_ShouldReturnExpectedResult()
        {
            using var outerScope = new ClockScope(() => DateTime.UnixEpoch);
            using var innerScope = new ClockScope(() => DateTime.UnixEpoch);

            var result = ClockScope.Current;

            Assert.Equal(innerScope, result);
        }
        public void Now_WithCustomScope_ShouldReturnExpectedResult()
        {
            var expectedResult = new DateTime(2000, 01, 01, 12, 00, 00, DateTimeKind.Local);

            using var scope = new ClockScope(() => expectedResult);

            var result = ClockScope.Current.Now;

            Assert.Equal(expectedResult, result);
        }
        public void Today_WithCustomScope_ShouldMatchNow()
        {
            var expectedResult = new DateTime(2000, 01, 01, 12, 00, 00, DateTimeKind.Local).ToUniversalTime();

            using var scope = new ClockScope(() => new DateTime(2000, 01, 01, 12, 00, 00, DateTimeKind.Local));

            var now   = ClockScope.Current.Now;
            var today = ClockScope.Current.Today;

            Assert.Equal(now.Date, today);
        }
            public async Task GetsAfterLiveEvent()
            {
                // next day
                ClockScope.OverrideNow(new DateTime(2014, 12, 15, 3, 5, 0));
                ClockScope.OverrideNowOffset(new DateTime(2014, 12, 15, 3, 5, 0));

                // verify current
                var nameCurrent1 = await System.TryGetCurrentServerAsync(characterNameTestguy);

                Expect(nameCurrent1, EqualTo(new ServerName("Exodus")));

                // add live event
                var path = Path.Combine(
                    ClientMock.InstallDirectory.FullPath,
                    "players",
                    "Testguy",
                    "logs",
                    "_Event.2014-12.txt");
                var logwriter = new LogWriter(path, new DateTime(2014, 12, 1), true);

                //Trace.WriteLine("----- before write");
                //Trace.Write(File.ReadAllText(path));
                //Trace.WriteLine("-----");
                logwriter.WriteSection(
                    new Collection <LogEntry>()
                {
                    new LogEntry(new DateTime(2014, 12, 15, 3, 4, 0), String.Empty,
                                 "42 other players are online. You are on Abuzabi (765 totally in Wurm).")
                }, true);
                //Trace.WriteLine("----- after write");
                //Trace.Write(File.ReadAllText(path));
                //Trace.WriteLine("-----");

                ClockScope.AdvanceTime(1);

                Thread.Sleep(2000);

                ClockScope.AdvanceTime(1);

                var nameBefore = await System.TryGetServerAsync(characterNameTestguy, new DateTime(2014, 12, 15, 3, 3, 0));

                Expect(nameBefore, EqualTo(new ServerName("Exodus")));
                var nameAfter = await System.TryGetServerAsync(characterNameTestguy, new DateTime(2014, 12, 15, 3, 5, 0));

                Expect(nameAfter, EqualTo(new ServerName("Abuzabi")));
                var nameCurrent2 = await System.TryGetCurrentServerAsync(characterNameTestguy);

                Expect(nameCurrent2, EqualTo(new ServerName("Abuzabi")));
            }
        public void UtcNow_WithCustomScope_ShouldMatchNow()
        {
            var localDateTime  = new DateTime(2000, 01, 01, 12, 00, 00, DateTimeKind.Local);
            var utcOffset      = TimeZoneInfo.Local.GetUtcOffset(localDateTime);
            var expectedResult = localDateTime.ToUniversalTime();

            using var scope = new ClockScope(() => localDateTime);

            var now    = ClockScope.Current.Now;
            var utcNow = ClockScope.Current.UtcNow;

            var offset = utcNow.Add(utcOffset) - now;

            Assert.Equal(TimeSpan.Zero, offset);
        }
        public void Construct_Regularly_ShouldReturnExpectedResult()
        {
            using var idScope    = new IdGeneratorScope(new CustomIdGenerator(id: 1));
            using var clockScope = new ClockScope(() => DateTime.UnixEpoch);

            var orderBuilder = new OrderBuilder()
                               .WithDescription("Description");

            var order = orderBuilder.Build();

            Assert.Equal(1, order.Id);
            Assert.Equal(DateTime.UnixEpoch, order.CreationDateTime);
            Assert.Equal(order.CreationDateTime, order.ShippingStatus.DateTime);
            Assert.Equal(ShippingResult.Unshipped, order.ShippingStatus.Result);
            Assert.Equal("Description", order.Description);
        }