Exemplo n.º 1
0
		public void ShouldFailMapValueForInsert()
		{
			// db config
			var conn = new MockDb()
				.NewNonQuery()
				.NewNonQuery();

			using (conn)
			using (var db = new DbManager(conn))
			{
				// fluent config
				new FluentMap<MapValueMemberDbo>()
					.MapField(_ => _.Field1)
						.MapValue("result true", true)
						.MapValue("result false", false)
					.MapField(_ => _.Field2)
						.MapValue("value true", true)
						.MapValue("value false", false)
					.MapTo(db);

				var table = db.GetTable<MapValueMemberDbo>();

				// when
				table.Insert(() => new MapValueMemberDbo { Field1 = "result true", Field2 = "value false" }); // linq
				db.Insert(new MapValueMemberDbo { Field1 = "result true", Field2 = "value false" }); // other?

				// then
				var i1 = conn.Commands[0].CommandText.IndexOf("result true", StringComparison.Ordinal);
				Assert.IsTrue(-1 == i1, "Not map to value1 for linq");

				var i2 = conn.Commands[0].CommandText.IndexOf("value false", StringComparison.Ordinal);
				Assert.IsTrue(-1 == i2, "Not map to value2 for linq");

				Assert.AreEqual(true, conn.Commands[1].Parameters[0].Value, "Not map to value1");
				Assert.AreEqual(false, conn.Commands[1].Parameters[1].Value, "Not map to value2");
			}
		}