public void Produce_same_output_when_get_time_difference_datetime(DateTimeKind kind)
        {
            var dateTime = new DateTime(2017, 1, 25, 0, 0, 0, kind);
            var timeSpan = TimeSpan.FromHours(7);
            var result   = TodayDateValueProvider.GetDifference(dateTime, timeSpan);
            var expected = new DateTime(2017, 1, 24, 17, 0, 0, kind);

            Assert.Equal(expected, result);
        }
        public void Produce_same_output_when_get_time_difference_timespan(DateTimeKind leftTimeKind,
                                                                          DateTimeKind rightTimeKind)
        {
            var leftTime       = new DateTime(2017, 1, 25, 16, 45, 0, leftTimeKind);
            var rightTime      = new DateTime(2017, 1, 25, 9, 45, 0, rightTimeKind);
            var timeDifference = TodayDateValueProvider.GetDifference(leftTime, rightTime);

            Assert.Equal(TimeSpan.FromHours(7), timeDifference);
        }
        public void Can_get_user_today_date()
        {
            var test    = new TestHelper();
            var context = Substitute.For <ITransactionContextBase>();

            context.Service.Returns(test.Service);

            var userId           = Guid.NewGuid();
            var initiatingUserId = Guid.NewGuid();

            context.PluginExecutionContext.InitiatingUserId.Returns(initiatingUserId);

            var userSettings = new UserSettings
            {
                Id = Guid.NewGuid()
            };

            userSettings.Set(e => e.SystemUserId, userId);
            userSettings.Set(e => e.TimeZoneCode, 1234);
            context.Service.RetrieveMultiple(Arg.Any <QueryBase>())
            .Returns(new EntityCollection(new List <Entity> {
                userSettings
            }));

            var utcTime   = new DateTime(2017, 1, 25, 9, 45, 0, DateTimeKind.Utc);
            var localTime = new DateTime(2017, 1, 25, 16, 45, 0, DateTimeKind.Unspecified);

            context.Service.Execute(Arg.Any <LocalTimeFromUtcTimeRequest>())
            .Returns(ci =>
            {
                var request = ci.ArgAt <LocalTimeFromUtcTimeRequest>(0);
                Assert.Equal(1234, request.TimeZoneCode);
                Assert.Equal(utcTime, request.UtcTime);
                var response = new LocalTimeFromUtcTimeResponse
                {
                    ["LocalTime"] = localTime
                };
                return(response);
            });

            var expectedTodayDate      = new DateTime(2017, 1, 24, 17, 0, 0, DateTimeKind.Utc);
            var todayDateValueProvider = new TodayDateValueProvider(context);

            Assert.Equal(initiatingUserId, todayDateValueProvider.UserId);
            todayDateValueProvider.UserId = userId;
            var todayDate = todayDateValueProvider.GetTodayDate(utcTime);

            Assert.Equal(expectedTodayDate, todayDate);
        }