public void TestFormatInt32() { var formatter = new ObjectFormatter(); formatter.Format(42) .Should().Be("42"); }
public void DefaultFormat() { var formatter = new ObjectFormatter(); Assert.Equal("10", formatter.Format(10)); Assert.Equal("<null>", formatter.Format(null)); }
public void It_should_format_object_collection() { var items = new object[] { new ComplexType { StringField = "test!", Int = 5, Flag = true, Span = TimeSpan.FromDays(0.5), Dictionary = { { "abc", null } } }, new BaseType { StringField = "123" }, 3.14, false }; var actual = ObjectFormatter.DumpMany(items); Assert.That(actual.Replace("\r", ""), Is.EqualTo(@"ComplexType: { StringField=""test!"" Int=5 Flag=True ReadonlyFloat=3.14 Array=[ Local Unspecified Utc ] Dictionary=[ {...} ] Span=""12:00:00"" } BaseType: { StringField=""123"" } Double: 3.14 Boolean: False".Replace("\r", ""))); }
public void ApplyDoubleFormat() { var formatter = new ObjectFormatter(); formatter.AddFormatter((double d) => d.ToString("#####0.#")); Assert.Equal("10.5", formatter.Format(10.52345643)); }
private static string CreateHtml(string templateFile, PropertyLocation source, Operation operation) { StringBuilder sb = new StringBuilder(); IEnumerable <string> lines = File.ReadAllLines(templateFile).Where(_ => !string.IsNullOrWhiteSpace(_)); foreach (string item in lines) { string line = item; /* Replace some special lines we might expect... */ if (line.Contains("var var_awSource = null")) { line = string.Format("var var_awSource = {0};", Json.Serialize(source)); } else if (line.Contains("var var_awOperation = null")) { line = string.Format("var var_awOperation = {0};", Json.Serialize(operation)); } else { line = ObjectFormatter.ToString(operation, line); } sb.AppendLine(line); } return(sb.ToString()); }
public void Range() { var range = new Range <int>(0, 10, System.Linq.Enumerable.Range(0, 11)); var result = new ObjectFormatter().Format(range); Assert.AreEqual("0..10", result); }
public void TestPreviewInt32() { var formatter = new ObjectFormatter(); formatter.Preview(-42) .Should().Be("-42"); }
public void TestPreviewFloatEllipses() { var formatter = new ObjectFormatter(); formatter.Preview((float)Math.PI, 6) .Should().Be("3.1..."); }
protected void WriteItem(Point2D cellPos, ISpatial2DThing <T> item) { if (item.TopLeft.Equals(cellPos)) { WriteStartElement("g"); if (!string.IsNullOrEmpty(item.Id)) { XmlWriter.WriteAttributeString("id", item.Id); } var itemNode = ObjectFormatter.Invoke(item.Data); foreach (var pos in item.Positions) { WriteRect(pos, item.Colour, new Colour()); } if (itemNode != null) { var cent = item.RotationalCentre; WriteStartElement("text"); XmlWriter.WriteAttributeString("x", ((cent.X + 0.5) * _unitWidth).ToString()); XmlWriter.WriteAttributeString("y", ((cent.Y + 0.5) * _unitHeight).ToString()); itemNode.WriteTo(XmlWriter); XmlWriter.WriteEndElement(); } XmlWriter.WriteEndElement(); } }
public void TestPreviewDouble() { var formatter = new ObjectFormatter(); formatter.Preview(Math.E) .Should().Be("2.71828182845905"); }
public void TestFormatKeyValuePair() { var formatter = new ObjectFormatter(); formatter.Format(new KeyValuePair <int, int>(42, 1)) .Should().Be("{\r\n\tKey: 42,\r\n\tValue: 1\r\n}"); }
public void TestPreviewFloat() { var formatter = new ObjectFormatter(); formatter.Preview((float)Math.PI) .Should().Be("3.141593"); }
private static string FormatResult(object input) { try { var formatter = new ObjectFormatter(maxLineLength: 350); var result = formatter.FormatObject(input); if (string.IsNullOrEmpty(result)) { return("null"); } result = result.Replace(Environment.NewLine, " ").Replace("\n", " ").Replace("\r", " "); if (result.Length > 350) { result = result.Substring(0, 350); } return(result); } catch (Exception ex) { return(ex.ToString()); } }
public void TestPreviewUInt64() { var formatter = new ObjectFormatter(); formatter.Preview(UInt64.MaxValue) .Should().Be("18446744073709551615"); }
public void TestPreviewInt64() { var formatter = new ObjectFormatter(); formatter.Preview(-123456789) .Should().Be("-123456789"); }
public void TestFormatInt64() { var formatter = new ObjectFormatter(); formatter.Format(-123456789) .Should().Be("-123456789"); }
private ExecutionResult Execute(string className, string resultProperty) { var result = new ExecutionResult(); var type = typeof(ByteCodeLoader); var formatter = new ObjectFormatter(maxLineLength: 5120); var domain = AppDomain.CurrentDomain; try { var totalProcessorTime = domain.MonitoringTotalProcessorTime; var totalAllocatedMemorySize = domain.MonitoringTotalAllocatedMemorySize; var loader = (ByteCodeLoader)domain.CreateInstanceAndUnwrap(type.Assembly.FullName, type.FullName); var unformattedResult = loader.Run(className, resultProperty, _assemblyBytes); result.Result = formatter.FormatObject(unformattedResult.ReturnValue); result.ConsoleOutput = unformattedResult.ConsoleOutput; result.ProcessorTime = domain.MonitoringTotalProcessorTime - totalProcessorTime; result.TotalMemoryAllocated = domain.MonitoringTotalAllocatedMemorySize - totalAllocatedMemorySize; } catch (SerializationException ex) { result.Result = ex.Message; } catch (TargetInvocationException ex) { result.Result = ex.InnerException.ToString(); } return(result); }
public void TestPreviewKeyValuePair() { var formatter = new ObjectFormatter(); formatter.Preview(new KeyValuePair <int, int>(42, 1)) .Should().Be("{Key: 42, Value: 1}"); }
protected override void OnSaving() { if (!(Session is NestedUnitOfWork) && (Session.DataLayer != null) && Session.IsNewObject(this) && (Session.ObjectLayer is SimpleObjectLayer)) { if (Numero == 0) { this.Progressivo = Session.FindObject <Impostazioni>(CriteriaOperator.Parse($"[Chiave]='{this.ClassInfo.TableName}_Progressivo'"), false)?.Valore; Numero = DistributedIdGeneratorHelper.Generate(Session.DataLayer, this.GetType().FullName, this.Progressivo); } if (String.IsNullOrEmpty(Codice)) { var f = Session.FindObject <Impostazioni>(CriteriaOperator.Parse($"[Chiave]='{this.ClassInfo.TableName}_Formato'"), false)?.Valore; if (f == null) { f = String.Concat(this.ClassInfo.TableName.Substring(0, 4).ToUpper(), "{Numero:00000}/{Progressivo}"); } Codice = ObjectFormatter.Format(f, this, EmptyEntriesMode.RemoveDelimiterWhenEntryIsEmpty); } } base.OnSaving(); }
public void TestPreviewIntArray() { var formatter = new ObjectFormatter(); formatter.Preview(new [] { 1, 2, 3, 4 }) .Should().Be("{1, 2, 3, 4}"); }
public void TestPreviewSByte() { var formatter = new ObjectFormatter(); formatter.Preview((sbyte)-42) .Should().Be("-42"); }
public void TestPreviewUInt16() { var formatter = new ObjectFormatter(); formatter.Preview((ushort)42) .Should().Be("42"); }
public void TestPreviewString() { var formatter = new ObjectFormatter(); formatter.Preview("Hello, World!") .Should().Be("\"Hello, World!\""); }
public void TestPreviewDateTime() { var formatter = new ObjectFormatter(); formatter.Preview(new DateTime(2018, 11, 28, 19, 38, 31)).Should().Be("2018-11-28T19:38:31.0000000"); formatter.Preview(new DateTime(2018, 11, 28, 19, 38, 31, DateTimeKind.Utc)).Should().Be("2018-11-28T19:38:31.0000000Z"); }
public override string ToString() { var textBuilder = new StringBuilder(); using (var formatter = new ObjectFormatter(textBuilder, this)) { formatter.Append(Grade, nameof(Grade)); formatter.Append(Type, nameof(Type)); formatter.Append(InspectorName, nameof(InspectorName)); formatter.Append(RingName, nameof(RingName)); if (StandardCourseTime != null) { formatter.Append(StandardCourseTime.Value.TotalSeconds, nameof(StandardCourseTime)); } if (MaximumCourseTime != null) { formatter.Append(MaximumCourseTime.Value.TotalSeconds, nameof(MaximumCourseTime)); } formatter.Append(TrackLengthInMeters, nameof(TrackLengthInMeters)); } return(textBuilder.ToString()); }
public void TestPreviewUInt32() { var formatter = new ObjectFormatter(); formatter.Preview(UInt32.MaxValue) .Should().Be("4294967295"); }
public void TestPreviewIpAddress() { var formatter = new ObjectFormatter(); formatter.Preview(IPAddress.Loopback).Should().Be("127.0.0.1"); formatter.Preview(IPAddress.IPv6Loopback).Should().Be("::1"); formatter.Preview(IPAddress.IPv6Any).Should().Be("::"); }
public void TestPreviewVersion() { var formatter = new ObjectFormatter(); formatter.Preview(new Version(1, 0)).Should().Be("1.0"); formatter.Preview(new Version(1, 2, 3)).Should().Be("1.2.3"); formatter.Preview(new Version(1, 2, 3, 4)).Should().Be("1.2.3.4"); }
public void TestPreviewByteArray() { var formatter = new ObjectFormatter(); formatter.Preview(new byte[0]).Should().Be("{}"); formatter.Preview(new byte[] { 0 }).Should().Be("{0x00}"); formatter.Preview(new byte[] { 255 }).Should().Be("{0xFF}"); formatter.Preview(new byte[] { 1, 2, 3 }).Should().Be("{0x01, 0x02, 0x03}"); }
protected override void Write(BinaryWriter w, object o, WriterContext ctx) { w.Write(PrimaryId); ObjectFormatter.WriteObject(w, o.GetType(), ctx); string v = (string)converter.ConvertTo(null, Helpers.InvariantCulture, o, typeof(string)); base.Write(w, v, ctx); }
public override string ToString() { var textBuilder = new StringBuilder(); using (var formatter = new ObjectFormatter(textBuilder, this)) { formatter.Append(() => Grade, () => Grade); formatter.Append(() => Type, () => Type); formatter.Append(() => InspectorName, () => InspectorName); formatter.Append(() => RingName, () => RingName); if (StandardCourseTime != null) { formatter.Append(() => StandardCourseTime.Value.TotalSeconds, () => StandardCourseTime); } if (MaximumCourseTime != null) { formatter.Append(() => MaximumCourseTime.Value.TotalSeconds, () => MaximumCourseTime); } formatter.Append(() => TrackLengthInMeters, () => TrackLengthInMeters); } return textBuilder.ToString(); }