public void Convert(object input, Type targetType, object?parameter, string cultureString, object expectedOutput)
        {
            var converter = new DateTimeToStringConverter();
            var culture   = new CultureInfo(cultureString);
            var output    = converter.Convert(input, targetType, parameter, culture);

            Assert.Equal(expectedOutput, output);
        }
        public void DateTimeToStringConverter_Convert_HasDateTimeValue_StringWithSplitSeconds()
        {
            //------------Setup for test--------------------------
            var dateTimeToStringConverter = new DateTimeToStringConverter();
            var dateTimeToConvert         = new DateTime(2014, 01, 02, 10, 15, 52, 52);
            //------------Execute Test---------------------------
            var convertedValue = dateTimeToStringConverter.Convert(dateTimeToConvert, null, null, null);

            //------------Assert Results-------------------------
            Assert.AreEqual("2014/01/02 10:15:52.0520 AM", convertedValue);
        }
        public void DateTimeToStringConverter_Convert_ValueNotDateTime_NoStringReturned()
        {
            //------------Setup for test--------------------------
            var dateTimeToStringConverter = new DateTimeToStringConverter();

            //------------Execute Test---------------------------
            var convertedValue = dateTimeToStringConverter.Convert("some data", null, null, null);

            //------------Assert Results-------------------------
            Assert.IsNotInstanceOfType(convertedValue, typeof(string));
        }
        public void DateTimeToStringConverter_Convert_HasDateTimeValue_StringWithSplitSeconds()
        {
            //------------Setup for test--------------------------
            var dateTimeToStringConverter = new DateTimeToStringConverter();
            var dateTimeToConvert         = new DateTime(2014, 01, 02, 10, 15, 52, 52);
            //------------Execute Test---------------------------
            var convertedValue = dateTimeToStringConverter.Convert(dateTimeToConvert, null, null, null).ToString();

            //------------Assert Results-------------------------
            Assert.IsTrue("2014/01/02 10:15:52.0520 AM" == convertedValue || "02/01/2014 10:15:52.0520 AM" == convertedValue, $"{convertedValue} string does not contain split seconds.");
        }
        public void Convert_NotDateTime()
        {
            // Arrange
            var converter = new DateTimeToStringConverter();

            // Act
            var result = (string)converter.Convert(new object(), null, null, null);

            // Assert
            Assert.AreEqual(string.Empty, result);
        }
        public void DateTimeToStringConverter_Convert_HasFormat_StringUsingProvidedFormat()
        {
            //------------Setup for test--------------------------
            var dateTimeToStringConverter = new DateTimeToStringConverter();

            dateTimeToStringConverter.Format = "dd/MMM/yyyy";
            var dateTimeToConvert = new DateTime(2014, 01, 02, 10, 15, 52, 52);
            //------------Execute Test---------------------------
            var convertedValue = dateTimeToStringConverter.Convert(dateTimeToConvert, null, null, null);

            //------------Assert Results-------------------------
            Assert.AreEqual("02/Jan/2014", convertedValue);
        }
        public void Convert()
        {
            // Arrange
            var converter = new DateTimeToStringConverter();

            var date = DateTime.Now;

            // Act
            var result = (string)converter.Convert(date, null, null, null);

            // Assert
            Assert.AreEqual(date.ToString("d"), result);
        }
Ejemplo n.º 8
0
        public bool MakeReportByTime(string filename, IEnumerable <Transaction> items)
        {
            try
            {
                var       document = MakeReportHeader(filename, "Отчет за месяц");
                PdfPTable table    = new PdfPTable(5);
                table.HorizontalAlignment = Element.ALIGN_LEFT;
                table.WidthPercentage     = 100;
                table.SetWidths(new[] { 75f, 75f, 75f, 75f, 450f });
                table.AddCell(new PdfPCell(new Phrase("Дата", highlightFont))
                {
                    Colspan = 1
                });
                table.AddCell(new PdfPCell(new Phrase("Сумма", highlightFont))
                {
                    Colspan = 1
                });
                table.AddCell(new PdfPCell(new Phrase("Счет", highlightFont))
                {
                    Colspan = 1
                });
                table.AddCell(new PdfPCell(new Phrase("Тип", highlightFont))
                {
                    Colspan = 1
                });
                table.AddCell(new PdfPCell(new Phrase("Комментарий", highlightFont))
                {
                    Colspan = 1
                });
                var sortingEvents = items.OrderBy(ev => ev.DateTime);
                foreach (var transaction in sortingEvents)
                {
                    table.AddCell(new Phrase(DateTimeToStringConverter.Convert(transaction.DateTime), textFont));
                    table.AddCell(new Phrase(transaction.Amount.ToString(), textFont));
                    table.AddCell(new Phrase(transaction.MoneySource, textFont));
                    table.AddCell(new Phrase(transaction.Type.ToString("G"), textFont));
                    table.AddCell(new Phrase(transaction.Comment, textFont));
                }

                document.Add(table);
                document.Close();
                return(true);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(false);
            }
        }
Ejemplo n.º 9
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);
        }