public void Can_short_circuit_string_with_no_escape_chars() { var model = new ModelWithIdAndName { Id = 1, Name = @"Simple string" }; SerializeAndCompare(model); }
/// <summary>Assert is equal.</summary> /// <param name="actual"> The actual.</param> /// <param name="expected">The expected.</param> public static void AssertIsEqual(ModelWithIdAndName actual, ModelWithIdAndName expected) { if (actual == null || expected == null) { Assert.That(actual == expected, Is.True); return; } Assert.That(actual.Id, Is.EqualTo(expected.Id)); Assert.That(actual.Name, Is.EqualTo(expected.Name)); }
public void Can_deserialize_text_with_escaped_chars() { var model = new ModelWithIdAndName { Id = 1, Name = @"1 \ 2 \r 3 \n 4 \b 5 \f 6 """ }; SerializeAndCompare(model); }
public void Can_deserialize_json_with_whitespace() { var model = new ModelWithIdAndName { Id = 1, Name = @"Simple string" }; const string json = "\t { \t \"Id\" \t : 1 , \t \"Name\" \t : \t \"Simple string\" \t } \t "; var fromJson = JsonSerializer.DeserializeFromString<ModelWithIdAndName>(json); Assert.That(fromJson, Is.EqualTo(model)); }
/// <summary> /// Determines whether the specified <see cref="T:System.Object" /> is equal to the current /// <see cref="T:System.Object" />. /// </summary> /// <param name="other">The model with identifier and name to compare to this object.</param> /// <returns> /// true if the specified <see cref="T:System.Object" /> is equal to the current /// <see cref="T:System.Object" />; otherwise, false. /// </returns> public bool Equals(ModelWithIdAndName other) { if (object.ReferenceEquals(null, other)) { return(false); } if (object.ReferenceEquals(this, other)) { return(true); } if (other.Id == this.Id) { return(object.Equals(other.Name, this.Name)); } return(false); }
/// <summary> /// Determines whether the specified <see cref="T:System.Object" /> is equal to the current /// <see cref="T:System.Object" />. /// </summary> /// <param name="other">The model with identifier and name to compare to this object.</param> /// <returns> /// true if the specified <see cref="T:System.Object" /> is equal to the current /// <see cref="T:System.Object" />; otherwise, false. /// </returns> public bool Equals(ModelWithIdAndName other) { if (object.ReferenceEquals(null, other)) { return false; } if (object.ReferenceEquals(this, other)) { return true; } if (other.Id == this.Id) { return object.Equals(other.Name, this.Name); } return false; }
public void Can_PrettyFormat_object() { object model = new ModelWithIdAndName { Id = 1, Name = "Name" }; var modelStr = model.Dump(); Assert.That(modelStr, Is.EqualTo( "{" + Environment.NewLine + "\tId: 1," + Environment.NewLine + "\tName: Name" + Environment.NewLine + "}" )); }
public void Can_access_ModelWithIdAndName() { var idAccessor = new PropertyAccessor<ModelWithIdAndName>("Id"); var nameAccessor = new PropertyAccessor<ModelWithIdAndName>("Name"); var obj = new ModelWithIdAndName { Id = 1, Name = "A" }; Assert.That(idAccessor.GetPropertyFn()(obj), Is.EqualTo(1)); Assert.That(nameAccessor.GetPropertyFn()(obj), Is.EqualTo("A")); idAccessor.SetPropertyFn()(obj, 2); nameAccessor.SetPropertyFn()(obj, "B"); Assert.That(obj.Id, Is.EqualTo(2)); Assert.That(obj.Name, Is.EqualTo("B")); }
/// <summary> /// Determines whether the specified <see cref="T:System.Object" /> is equal to the current /// <see cref="T:System.Object" />. /// </summary> /// <param name="other">The model with identifier and name to compare to this object.</param> /// <returns> /// true if the specified <see cref="T:System.Object" /> is equal to the current /// <see cref="T:System.Object" />; otherwise, false. /// </returns> public bool Equals(ModelWithIdAndName other) { if (ReferenceEquals(null, other)) return false; if (ReferenceEquals(this, other)) return true; return other.Id == Id && Equals(other.Name, Name); }
public void Can_Select_In_for_string_value() { const int n = 5; using (var db = new OrmLiteConnectionFactory(ConnectionString, FirebirdDialect.Provider).Open()) { db.CreateTable<ModelWithIdAndName>(true); db.DeleteAll<ModelWithIdAndName>(); for(int i=1; i<=n; i++){ ModelWithIdAndName m = new ModelWithIdAndName(){ Name= "Name"+i.ToString() }; db.Insert(m); } var selectInNames = new[] {"Name1", "Name2"}; var rows = db.Select<ModelWithIdAndName>("Name IN ({0})", selectInNames.SqlInValues()); Assert.That(rows.Count, Is.EqualTo(selectInNames.Length)); } }
public void Can_deserialize_basic_latin_unicode() { const string json = "{\"Id\":1,\"Name\":\"\\u0041 \\u0042 \\u0043 | \\u0031 \\u0032 \\u0033\"}"; var model = new ModelWithIdAndName { Id = 1, Name = "A B C | 1 2 3" }; var fromJson = JsonSerializer.DeserializeFromString<ModelWithIdAndName>(json); Assert.That(fromJson, Is.EqualTo(model)); }