public void TimeSpanToStringConverter_PerElements()
        {
            var con = new TimeSpanToStringConverter();

            con.Mode = TimeSpanToStringMode.PerElements;

            var res = con.Convert(TimeSpan.Parse("1.18:53:58.1234567"), CultureInfo.CurrentCulture);

            Assert.Contains($"1 {Strings.day}", res);
            Assert.Contains($"18 {Strings.hours}", res);
            Assert.Contains($"53 {Strings.minutes}", res);
            Assert.Contains($"58 {Strings.seconds}", res);
            Assert.Contains($"123 {Strings.milliseconds}", res);

            con.NumberOfElements = 3;

            res = con.Convert(TimeSpan.Parse("1.18:53:58.1234567"), CultureInfo.CurrentCulture);
            Assert.Contains($"1 {Strings.day}", res);
            Assert.Contains($"18 {Strings.hours}", res);
            Assert.Contains($"53 {Strings.minutes}", res);
            Assert.DoesNotContain($"58 {Strings.seconds}", res);
            Assert.DoesNotContain($"123 {Strings.milliseconds}", res);

            res = con.Convert(TimeSpan.Parse("0.18:53:58.1234567"), CultureInfo.CurrentCulture);
            Assert.DoesNotContain($"0 {Strings.day}", res);
            Assert.Contains($"18 {Strings.hours}", res);
            Assert.Contains($"53 {Strings.minutes}", res);
            Assert.Contains($"58 {Strings.seconds}", res);
            Assert.DoesNotContain($"123 {Strings.milliseconds}", res);
        }
        public void TimeSpanToStringConverter_First()
        {
            var con = new TimeSpanToStringConverter();

            con.Mode = TimeSpanToStringMode.PerElements;
            //con.NumberOfElements = 3;
            output.WriteLine($"1.18:53:58.1234567 => {con.Convert(TimeSpan.Parse("1.18:53:58.1234567"), null, CultureInfo.CurrentCulture)}");
            output.WriteLine($"0.18:53:58.1234567 => {con.Convert(TimeSpan.Parse("0.18:53:58.1234567"), null, CultureInfo.CurrentCulture)}");
            output.WriteLine($"0.00:53:58.1234567 => {con.Convert(TimeSpan.Parse("0.00:53:58.1234567"), null, CultureInfo.CurrentCulture)}");
        }
Exemplo n.º 3
0
        public void WhenTimeSpanIsLessThanAMinute_ShouldOnlyShowSeconds()
        {
            var timeSpan  = new TimeSpan(0, 0, 0, 10);
            var converted = _converter.Convert(timeSpan, null, null, null);

            Assert.AreEqual("10 seconds", converted);
        }
        public void TestConvertToString(TimeSpan value, string expected)
        {
            var converter = new TimeSpanToStringConverter();
            var result    = (string)converter.Convert(value, typeof(string), null, CultureInfo.InvariantCulture);

            Assert.Equal(result, expected);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Filters the specified content.
        /// </summary>
        /// <param name="content">The content.</param>
        /// <param name="filterText"></param>
        public bool Filter(object content, string filterText)
        {
            if (filterText == null)
            {
                return(false);
            }

            filterText = filterText.ToLower();
            IDebugState debugState = content as IDebugState;

            if (debugState != null)
            {
                string convertedActivityType = Convert.ToString(_enumToStringConverter.Convert(debugState.ActivityType, null, null, null));
                if (convertedActivityType.ToLower().Contains(filterText))
                {
                    return(true);
                }

                if (debugState.ActivityType.ToString().ToLower().Contains(filterText))
                {
                    return(true);
                }
                if (debugState.DisplayName != null && debugState.DisplayName.ToLower().Contains(filterText))
                {
                    return(true);
                }
                if (debugState.ActivityType == ActivityType.Step && debugState.Name != null && debugState.Name.ToLower().Contains(filterText))
                {
                    return(true);
                }
                if (debugState.ActivityType == ActivityType.Workflow && debugState.Server != null && debugState.Server.ToLower().Contains(filterText))
                {
                    return(true);
                }
                if (debugState.Version != null && debugState.Version.ToLower().Contains(filterText))
                {
                    return(true);
                }

                if (debugState.ActivityType == ActivityType.Step)
                {
                    string convertedDuration = Convert.ToString(_timeSpanToStringConverter.Convert(debugState.Duration, null, null, null));
                    if (convertedDuration.ToLower().Contains(filterText))
                    {
                        return(true);
                    }
                }

                if (debugState.ActivityType == ActivityType.Workflow)
                {
                    string convertedStartTime = Convert.ToString(_dateTimeToStringConverter.Convert(debugState.StartTime, null, null, null));
                    if (debugState.StateType == StateType.Before && convertedStartTime.ToLower().Contains(filterText))
                    {
                        return(true);
                    }

                    string convertedEndTime = Convert.ToString(_dateTimeToStringConverter.Convert(debugState.EndTime, null, null, null));
                    if (debugState.StateType == StateType.After && convertedEndTime.ToLower().Contains(filterText))
                    {
                        return(true);
                    }
                }

                if (debugState.Inputs != null && debugState.Inputs.Any(o => o.Contains(filterText)))
                {
                    return(true);
                }
                if (debugState.Outputs != null && debugState.Outputs.Any(o => o.Contains(filterText)))
                {
                    return(true);
                }
            }
            else if (content is string && content.ToString().ToLower().Contains(filterText))
            {
                return(true);
            }

            return(false);
        }