Beispiel #1
0
		public void CreateParametersSqlTest()
		{
			using (DbManager db = new DbManager())
			{
				DataTypeSqlTest dt = new DataTypeSqlTest();
				
				dt.ID        = 12345;
				dt.Binary_   = new SqlBinary(new byte[2] {1, 2});
				dt.Boolean_  = new SqlBoolean(1);
				dt.Byte_     = new SqlByte(250);
				dt.DateTime_ = new SqlDateTime(DateTime.Now);
				dt.Decimal_  = new SqlDecimal(9876543210.0m);
				dt.Double_   = new SqlDouble(12345.67890);
				dt.Guid_     = new SqlGuid(Guid.Empty);
				dt.Int16_    = new SqlInt16(12345);
				dt.Int32_    = new SqlInt32(1234567890);
				dt.Int64_    = new SqlInt64(1234567890123456789);
				dt.Money_    = new SqlMoney(99876543210.0m);
				dt.Single_   = new SqlSingle(1234.0f);
				dt.String_   = new SqlString("Crazy Frog");

#if !SQLCE
				dt.Bytes_    = new SqlBytes(new byte[2] {2, 1});
				dt.Chars_    = new SqlChars(new char[2] {'B', 'L'});
				dt.Xml_      = new SqlXml(new XmlTextReader(new StringReader("<xml/>")));
#endif

				var parameters = db.CreateParameters(dt);

				Assert.IsNotNull(parameters);
				Assert.AreEqual(ObjectMapper<DataTypeSqlTest>.Instance.Count, parameters.Length);

				foreach (MemberMapper mm in ObjectMapper<DataTypeSqlTest>.Instance)
				{
					var pName = (string)db.DataProvider.Convert(mm.Name, db.GetConvertTypeToParameter());
					var p     = Array.Find(parameters, obj => obj.ParameterName == pName);

					Assert.IsNotNull(p);
					Assert.AreEqual(mm.GetValue(dt), p.Value);
				}
			}
		}
Beispiel #2
0
		public void NonUpdatableTest()
		{
			var da = new SqlQuery();

			using (var db = new DbManager())
			{
				var update = da.GetSqlQueryInfo<TestCategory>(db, "Update");
				var insert = da.GetSqlQueryInfo<TestCategory>(db, "Insert");

				Assert.That(update.QueryText, Is.Not.Contains(
					"\t" + db.DataProvider.Convert("Id", ConvertType.NameToQueryField) + " = " + db.DataProvider.Convert("Id", db.GetConvertTypeToParameter()) + "\n"),
					"Update");
				Assert.That(insert.QueryText, Is.Not.Contains("Id"), "Insert");
			}
		}
Beispiel #3
0
		public void CreateParametersTest()
		{
			using (var db = new DbManager())
			{
				var dt = new DataTypeTest
				{
					ID        = 12345,
					Binary_   = new byte[2] {1, 2},
#if !ORACLE
					Boolean_  = true,
					Guid_     = Guid.Empty,
#endif
					Byte_     = 250,
					Bytes_    = new byte[] { 2, 1 },
					DateTime_ = DateTime.Now,
					Decimal_  = 9876543210.0m,
					Double_   = 12345.67890,
					Int16_    = 12345,
					Int32_    = 1234567890,
					Int64_    = 1234567890123456789,
					Money_    = 99876543210.0m,
					Single_   = 1234.0f,
					String_   = "Crazy Frog",

					Char_     = 'F',
					SByte_    = 123,
					//UInt16_   = 65432,
					//UInt32_   = 4000000000,
					//UInt64_   = 12345678901234567890,
#if !SQLCE
					Stream_   = new MemoryStream(5),
					Xml_      = new XmlTextReader(new StringReader("<xml/>")),
#endif
				};

				var parameters = db.CreateParameters(dt);

				Assert.IsNotNull(parameters);
				Assert.AreEqual(ObjectMapper<DataTypeTest>.Instance.Count, parameters.Length);

				foreach (MemberMapper mm in ObjectMapper<DataTypeTest>.Instance)
				{
					var paramName = (string)db.DataProvider.Convert(mm.Name, db.GetConvertTypeToParameter());
					var p         = parameters.First(obj => obj.ParameterName == paramName);

					Assert.IsNotNull(p);
					Assert.AreEqual(mm.GetValue(dt), p.Value, mm.MemberName);
				}
			}
		}
Beispiel #4
0
		public void CreateParametersTest()
		{
			using (DbManager db = new DbManager())
			{
				DataTypeTest dt = new DataTypeTest();
				
				dt.ID        = 12345;
				dt.Binary_   = new byte[2] {1, 2};
#if !ORACLE
				dt.Boolean_  = true;
				dt.Guid_     = Guid.Empty;
#endif
				dt.Byte_     = 250;
				dt.Bytes_    = new byte[2] {2, 1};
				dt.DateTime_ = DateTime.Now;
				dt.Decimal_  = 9876543210.0m;
				dt.Double_   = 12345.67890;
				dt.Int16_    = 12345;
				dt.Int32_    = 1234567890;
				dt.Int64_    = 1234567890123456789;
				dt.Money_    = 99876543210.0m;
				dt.Single_   = 1234.0f;
				dt.String_   = "Crazy Frog";

				dt.Char_     = 'F';
				dt.SByte_    = 123;
				dt.UInt16_   = 65432;
				dt.UInt32_   = 4000000000;
				dt.UInt64_   = 12345678901234567890;
#if !SQLCE
				dt.Stream_   = new MemoryStream(5);
				dt.Xml_      = new XmlTextReader(new StringReader("<xml/>"));
				dt.XmlDoc_   = new XmlDocument(); dt.XmlDoc_.LoadXml("<xmldoc/>");
#endif

				IDbDataParameter[] parameters = db.CreateParameters(dt);

				Assert.IsNotNull(parameters);
				Assert.AreEqual(ObjectMapper<DataTypeTest>.Instance.Count, parameters.Length);

				foreach (MemberMapper mm in ObjectMapper<DataTypeTest>.Instance)
				{
					string paramName = (string)db.DataProvider.Convert(mm.Name, db.GetConvertTypeToParameter());
					IDbDataParameter p = Array.Find(parameters,
						delegate(IDbDataParameter obj) { return obj.ParameterName == paramName; });

					Assert.IsNotNull(p);
					Assert.AreEqual(mm.GetValue(dt), p.Value);
				}
			}
		}