public void Can_PrettyFormat_generic_type()
		{
			var model = new ModelWithIdAndName { Id = 1, Name = "Name" };
			var modelStr = model.Dump();

			Assert.That(modelStr, Is.EqualTo("{\r\n\tId: 1,\r\n\tName: Name\r\n}"));
		}
 public void OnBeforeEachTest()
 {
     cacheClient = new MemoryCacheClient();
     //cacheClient = new RedisCacheClient(TestConfig.SingleHost);
     cacheClient.FlushAll();
     model = ModelWithIdAndName.Create(1);
     xmlModel = DataContractSerializer.Instance.Parse(model);
 }
		public void Can_PrettyFormat_object()
		{
			object model = new ModelWithIdAndName { Id = 1, Name = "Name" };
			var modelStr = model.Dump();

			Console.WriteLine(modelStr);

			Assert.That(modelStr, Is.EqualTo("{\r\n\tId: 1,\r\n\tName: Name\r\n}"));
		}
		public void Can_short_circuit_string_with_no_escape_chars()
		{
			var model = new ModelWithIdAndName
			{
				Id = 1,
				Name = @"Simple string"
			};

			SerializeAndCompare(model);
		}
        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));
        }
		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 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_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));
		}
		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;
		}
Ejemplo n.º 10
0
 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);
 }
Ejemplo n.º 11
0
		public void Can_PrettyFormat_generic_type()
		{
			var 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"));
		}
Ejemplo n.º 13
0
		public void Can_PrettyFormat_object()
		{
			object model = new ModelWithIdAndName { Id = 1, Name = "Name" };
			var modelStr = model.Dump();

			Console.WriteLine(modelStr);

			Assert.That(modelStr, 
			            Is.EqualTo(
							"{"
							+ Environment.NewLine
			           		+ "\tId: 1,"
							+ Environment.NewLine
							+"\tName: Name"
							+ Environment.NewLine
							+ "}"
						));
		}
		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_deserialize_with_new_line()
        {
            var model = new ModelWithIdAndName
            {
                Id = 1,
                Name = "Hi I'm\r\nnew line :)"
            };

            const string json = "{\"Id\":1,\"Name\":\"Hi I'm\\r\\nnew line :)\"}";

            var fromJson = JsonSerializer.DeserializeFromString<ModelWithIdAndName>(json);

            Assert.That(fromJson, Is.EqualTo(model));
        }
        public void Can_serialize_object_with_escaped_chars()
        {
            const string expected = "{\"Id\":1,\"Name\":\"Hi I'm\\r\\nnew line :)\"}";
            var model = new ModelWithIdAndName
            {
                Id = 1,
                Name = "Hi I'm\r\nnew line :)"
            };

            var result = JsonSerializer.SerializeToString(model);

            Assert.AreEqual(expected, result);
        }
		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.SelectFmt<ModelWithIdAndName>("Name IN ({0})", selectInNames.SqlInValues());

				Assert.That(rows.Count, Is.EqualTo(selectInNames.Length));
			}
		}
		public void Can_Select_In_for_string_value()
		{
			const int n = 5;

			using (var db = ConnectionString.OpenDbConnection())
			using (var dbCmd = db.CreateCommand())
			{
				dbCmd.CreateTable<ModelWithIdAndName>(true);
				dbCmd.DeleteAll<ModelWithIdAndName>();
				
				for(int i=1; i<=n; i++){
					ModelWithIdAndName m = new ModelWithIdAndName(){
						Name= 	"Name"+i.ToString()
					};
					dbCmd.Insert(m);
				}
				
				var selectInNames = new[] {"Name1", "Name2"};
				var rows = dbCmd.Select<ModelWithIdAndName>("Name IN ({0})", selectInNames.SqlInValues());

				Assert.That(rows.Count, Is.EqualTo(selectInNames.Length));
			}
		}
Ejemplo n.º 19
0
        public void Can_store_unicode_string()
        {
            using(var con = ConnectionString.OpenDbConnection())
            {
                OrmLiteConfig.DialectProvider.UseUnicode = true;
                ModelWithIdAndName model = new ModelWithIdAndName()
                {
                    Id = 1,
                    Name = "日本語 äÄöÖüÜß ıIiİüÜğĞşŞöÖçÇ åÅäÄöÖ"
                };

                con.CreateTable<ModelWithIdAndName>(true);
                con.Save(model);

                var result = con.GetById<ModelWithIdAndName>(1);
                con.DropTable<ModelWithIdAndName>();

                Console.WriteLine("Inserted: {0}, Retrieved: {1}", model.Name, result.Name);
                Assert.That(model.Name.Equals(result.Name));
            }
        }