Пример #1
0
        /// <summary>
        /// Process the specified input template and verify the output against an expected DateTime result.
        /// </summary>
        /// <param name="expectedDateTime"></param>
        /// <param name="inputTemplate"></param>
        /// <param name="maximumDelta"></param>
        public void AssertTemplateOutputDate(ILavaEngine engine, DateTime?expectedDateTime, string inputTemplate, TimeSpan?maximumDelta = null)
        {
            AssertDateIsUtc(expectedDateTime);

            var outputString = GetTemplateOutput(engine, inputTemplate);

            var outputDateUtc = LavaDateTime.ParseToUtc(outputString, null);

            WriteOutputToDebug(engine, outputString);

            Assert.That.IsNotNull(outputDateUtc, $"Template Output does not represent a valid DateTime. [Output=\"{ outputString }\"]");

            if (maximumDelta != null)
            {
                DateTimeAssert.AreEqual(expectedDateTime, outputDateUtc, maximumDelta.Value);
            }
            else
            {
                DateTimeAssert.AreEqual(expectedDateTime, outputDateUtc);
            }
        }
Пример #2
0
        /// <summary>
        /// Process the specified input template and verify the output against an expected DateTime result.
        /// </summary>
        /// <param name="expectedDateTime"></param>
        /// <param name="inputTemplate"></param>
        /// <param name="maximumDelta"></param>
        public void AssertTemplateOutputDate(ILavaEngine engine, DateTimeOffset?expectedDateTime, string inputTemplate, TimeSpan?maximumDelta = null)
        {
            var outputString = GetTemplateOutput(engine, inputTemplate);

            var outputDateUtc = LavaDateTime.ParseToOffset(outputString, null);

            WriteOutputToDebug(engine, outputString);

            Assert.That.IsNotNull(outputDateUtc, $"Template Output does not represent a valid DateTime. [Output=\"{ outputString }\"]");

            try
            {
                if (maximumDelta != null)
                {
                    DateTimeAssert.AreEqual(expectedDateTime, outputDateUtc, maximumDelta.Value);
                }
                else
                {
                    DateTimeAssert.AreEqual(expectedDateTime, outputDateUtc);
                }
            }
            catch (Exception ex)
            {
                var info = $@"
Test Environment:
LavaEngine = { engine.EngineName },
LocalDateTime = {DateTimeOffset.Now},
LocalTimeZoneName = {TimeZoneInfo.Local.DisplayName},
LocalTimeZoneOffset = { TimeZoneInfo.Local.BaseUtcOffset }
RockDateTime = { LavaDateTime.NowOffset },
RockTimeZoneName = { RockDateTime.OrgTimeZoneInfo.DisplayName },
RockTimeZoneOffset = { RockDateTime.OrgTimeZoneInfo.BaseUtcOffset }
";
                throw new Exception($"Lava Date/Time test failed.\n{ info }", ex);
            }
        }