示例#1
0
        public void CoreCommand_Provider()
        {
            var engine = new Concrete.DataEngine();
            var link   = new FakeLink(engine, NestableTransactionMode.Database);

            var other = new FakeCommandProvider(link);

            other.TheCommand.From(x => x.Employees);

            var provider = new FakeCommandProvider(link);

            provider.TheCommand.From(x => x(other).As(x.Emp));
            provider.TheCommand.Select(x => x.Number.As(x.Id));
            provider.TheCommand.Where(x => x.Name == "James Bond");

            var parser = new Concrete.Parser(engine);
            var pars   = engine.CreateParameterCollection();

            var result = parser.Parse(provider, pars);

            Assert.AreEqual(
                "SELECT Number AS Id FROM (SELECT * FROM Employees) AS Emp WHERE (Name = #0)"
                , result);
            Assert.AreEqual(1, pars.Count);
            Assert.AreEqual("James Bond", pars[0].Value);
        }
示例#2
0
		public void NullValues()
		{
			var engine = new Concrete.DataEngine();
			var parser = new Concrete.Parser(engine);
			var pars = engine.CreateParameterCollection();

			var result = parser.Parse(null, pars);
			Assert.AreEqual("NULL", result);
			Assert.AreEqual(0, pars.Count);
		}
示例#3
0
		public void ShortTag()
		{
			var engine = new Concrete.DataEngine();
			var parser = new Concrete.Parser(engine);
			var pars = engine.CreateParameterCollection();

			var result = parser.Parse((Func<dynamic, object>)(x => x.Name), pars);
			Assert.AreEqual("Name", result);
			Assert.AreEqual(0, pars.Count);
		}
示例#4
0
		public void GetMember()
		{
			var engine = new Concrete.DataEngine();
			var parser = new Concrete.Parser(engine);
			var pars = engine.CreateParameterCollection();

			var result = parser.Parse((Func<dynamic, object>)(x => x.Alpha.Beta), pars);
			Assert.AreEqual("Alpha.Beta", result);
			Assert.AreEqual(0, pars.Count);
		}
示例#5
0
        public void GetMember()
        {
            var engine = new Concrete.DataEngine();
            var parser = new Concrete.Parser(engine);
            var pars   = engine.CreateParameterCollection();

            var result = parser.Parse((Func <dynamic, object>)(x => x.Alpha.Beta), pars);

            Assert.AreEqual("Alpha.Beta", result);
            Assert.AreEqual(0, pars.Count);
        }
示例#6
0
        public void NullValues()
        {
            var engine = new Concrete.DataEngine();
            var parser = new Concrete.Parser(engine);
            var pars   = engine.CreateParameterCollection();

            var result = parser.Parse(null, pars);

            Assert.AreEqual("NULL", result);
            Assert.AreEqual(0, pars.Count);
        }
示例#7
0
		public void Dispose_Twice()
		{
			var engine = new Concrete.DataEngine();
			var parser = new Concrete.Parser(engine);

			parser.Dispose();
			parser.Dispose();

			Assert.IsTrue(parser.IsDisposed);
			Assert.IsNull(parser.Engine);
		}
示例#8
0
        public void Method_Distinct()
        {
            var engine = new Concrete.DataEngine();
            var parser = new Concrete.Parser(engine);
            var pars   = engine.CreateParameterCollection();

            var result = parser.Parse((Func <dynamic, object>)(x => x.Distinct(x.Alpha)), pars);

            Assert.AreEqual("DISTINCT Alpha", result);
            Assert.AreEqual(0, pars.Count);
        }
示例#9
0
        public void Is_NotNull()
        {
            var engine = new Concrete.DataEngine();
            var parser = new Concrete.Parser(engine);
            var pars   = engine.CreateParameterCollection();

            var result = parser.Parse((Func <dynamic, object>)(x => x.Name != null), pars);

            Assert.AreEqual("(Name IS NOT NULL)", result);
            Assert.AreEqual(0, pars.Count);
        }
示例#10
0
        public void Dispose_Twice()
        {
            var engine = new Concrete.DataEngine();
            var parser = new Concrete.Parser(engine);

            parser.Dispose();
            parser.Dispose();

            Assert.IsTrue(parser.IsDisposed);
            Assert.IsNull(parser.Engine);
        }
示例#11
0
        public void GetIndexed_RoundedSyntax()
        {
            var engine = new Concrete.DataEngine();
            var parser = new Concrete.Parser(engine);
            var pars   = engine.CreateParameterCollection();

            var result = parser.Parse((Func <dynamic, object>)(x => x("James", "Bond")), pars);

            Assert.AreEqual("JamesBond", result);
            Assert.AreEqual(0, pars.Count);
        }
示例#12
0
		public void LongTag()
		{
			var engine = new Concrete.DataEngine();
			var parser = new Concrete.Parser(engine);
			var pars = engine.CreateParameterCollection();

			Parser.ComplexTags = true;
			var result = parser.Parse((Func<dynamic, object>)(emp => emp.Name), pars);
			Assert.AreEqual("emp.Name", result);
			Assert.AreEqual(0, pars.Count);
		}
示例#13
0
        public void ShortTag()
        {
            var engine = new Concrete.DataEngine();
            var parser = new Concrete.Parser(engine);
            var pars   = engine.CreateParameterCollection();

            var result = parser.Parse((Func <dynamic, object>)(x => x.Name), pars);

            Assert.AreEqual("Name", result);
            Assert.AreEqual(0, pars.Count);
        }
示例#14
0
        public void Binary_WithNegate()
        {
            var engine = new Concrete.DataEngine();
            var parser = new Concrete.Parser(engine);
            var pars   = engine.CreateParameterCollection();

            var result = parser.Parse((Func <dynamic, object>)(x => - x.Name + 5), pars);

            Assert.AreEqual("(-Name + #0)", result);
            Assert.AreEqual(1, pars.Count);
            Assert.AreEqual(5, pars[0].Value);
        }
示例#15
0
        public void LongTag()
        {
            var engine = new Concrete.DataEngine();
            var parser = new Concrete.Parser(engine);
            var pars   = engine.CreateParameterCollection();

            Parser.ComplexTags = true;
            var result = parser.Parse((Func <dynamic, object>)(emp => emp.Name), pars);

            Assert.AreEqual("emp.Name", result);
            Assert.AreEqual(0, pars.Count);
        }
示例#16
0
		public void Validate_Standard_Transformers()
		{
			var obj = new Concrete.DataEngine();
			Assert.IsTrue(obj.IsTransformerRegistered<CalendarDate>());
			Assert.IsTrue(obj.IsTransformerRegistered<ClockTime>());

			var rd = obj.TryTransform(new CalendarDate(2000, 1, 1));
			Assert.AreEqual(new DateTime(2000, 1, 1), (DateTime)rd);

			var rc = obj.TryTransform(new ClockTime(1, 1, 1));
			Assert.AreEqual("1:1:1", (string)rc);
		}
示例#17
0
        public void Method_NotIn()
        {
            var engine = new Concrete.DataEngine();
            var parser = new Concrete.Parser(engine);
            var pars   = engine.CreateParameterCollection();

            var result = parser.Parse((Func <dynamic, object>)(x => x.Alpha.NotIn(x.Beta, "37", "40")), pars);

            Assert.AreEqual("NOT Alpha IN (Beta, #0, #1)", result);
            Assert.AreEqual(2, pars.Count);
            Assert.AreEqual("37", pars[0].Value);
            Assert.AreEqual("40", pars[1].Value);
        }
示例#18
0
		public void SetMember()
		{
			var engine = new Concrete.DataEngine();
			var parser = new Concrete.Parser(engine);
			var pars = engine.CreateParameterCollection();

			var result = parser.Parse((Func<dynamic, object>)(x => x.Alpha.Beta = null), pars);
			Assert.AreEqual("Alpha.Beta = (NULL)", result);
			Assert.AreEqual(0, pars.Count);

			result = parser.Parse((Func<dynamic, object>)(x => x.Alpha.Beta = "Bond"), pars);
			Assert.AreEqual("Alpha.Beta = (#0)", result);
			Assert.AreEqual(1, pars.Count);
			Assert.AreEqual("Bond", pars[0].Value);
		}
示例#19
0
        public void Validate_Standard_Transformers()
        {
            var obj = new Concrete.DataEngine();

            Assert.IsTrue(obj.IsTransformerRegistered <CalendarDate>());
            Assert.IsTrue(obj.IsTransformerRegistered <ClockTime>());

            var rd = obj.TryTransform(new CalendarDate(2000, 1, 1));

            Assert.AreEqual(new DateTime(2000, 1, 1), (DateTime)rd);

            var rc = obj.TryTransform(new ClockTime(1, 1, 1));

            Assert.AreEqual("1:1:1", (string)rc);
        }
示例#20
0
        public void SetMember()
        {
            var engine = new Concrete.DataEngine();
            var parser = new Concrete.Parser(engine);
            var pars   = engine.CreateParameterCollection();

            var result = parser.Parse((Func <dynamic, object>)(x => x.Alpha.Beta = null), pars);

            Assert.AreEqual("Alpha.Beta = (NULL)", result);
            Assert.AreEqual(0, pars.Count);

            result = parser.Parse((Func <dynamic, object>)(x => x.Alpha.Beta = "Bond"), pars);
            Assert.AreEqual("Alpha.Beta = (#0)", result);
            Assert.AreEqual(1, pars.Count);
            Assert.AreEqual("Bond", pars[0].Value);
        }
示例#21
0
        public void Disposing()
        {
            DataEngine.ClearEngines();
            var template = new Concrete.DataEngine();
            var cloned   = template.Clone(new Dictionary <string, object>()
            {
                { "InvariantName", "WhateverName" },
                { "ServerVersion", "8" }
            });

            DataEngine.RegisterEngine(cloned);
            Assert.AreEqual(1, DataEngine.Engines.Count());
            Assert.AreEqual(cloned, DataEngine.Engines.First());

            cloned.Dispose();
            Assert.AreEqual(0, DataEngine.Engines.Count());
        }
示例#22
0
		public void Disposing()
		{
			DataEngine.ClearEngines();
			var template = new Concrete.DataEngine();
			var cloned = template.Clone(new Dictionary<string, object>()
			{
				{ "InvariantName", "WhateverName"},
				{ "ServerVersion", "8"}
			});

			DataEngine.RegisterEngine(cloned);
			Assert.AreEqual(1, DataEngine.Engines.Count());
			Assert.AreEqual(cloned, DataEngine.Engines.First());

			cloned.Dispose();
			Assert.AreEqual(0, DataEngine.Engines.Count());
		}
示例#23
0
        public void Embedded_Commands()
        {
            var engine = new Concrete.DataEngine();
            var link   = new FakeLink(engine, NestableTransactionMode.Database);
            var inner  = link.Raw("SELECT * From WhoKnows WHERE Name == {0}", "James Bond");

            var parser = new Concrete.Parser(engine);
            var pars   = engine.CreateParameterCollection();

            pars.AddCreate("PlaceHolderForPositionCero");
            Assert.AreEqual(1, pars.Count);

            var result = parser.Parse(inner, pars);

            Assert.AreEqual("SELECT * From WhoKnows WHERE Name == #1", result);
            Assert.AreEqual(2, pars.Count);
            Assert.AreEqual("James Bond", pars[1].Value);
        }
示例#24
0
		public void Locate_With_MinVersion()
		{
			DataEngine.ClearEngines();
			var template = new Concrete.DataEngine();
			DataEngine.RegisterEngine(template.Clone(new Dictionary<string, object>()
			{
				{ "InvariantName", "WhateverName"},
				{ "ServerVersion", "8"}
			}));
			DataEngine.RegisterEngine(template.Clone(new Dictionary<string, object>()
			{
				{ "InvariantName", "WhateverName"},
				{ "ServerVersion", "10"}
			}));

			var engine = DataEngine.Locate("WhateverName", minVersion: "9");
			Assert.IsNotNull(engine);
			Assert.AreEqual("10", engine.ServerVersion);
		}
示例#25
0
        public void Locate_With_MaxVersion()
        {
            DataEngine.ClearEngines();
            var template = new Concrete.DataEngine();

            DataEngine.RegisterEngine(template.Clone(new Dictionary <string, object>()
            {
                { "InvariantName", "WhateverName" },
                { "ServerVersion", "8" }
            }));
            DataEngine.RegisterEngine(template.Clone(new Dictionary <string, object>()
            {
                { "InvariantName", "WhateverName" },
                { "ServerVersion", "10" }
            }));

            var engine = DataEngine.Locate("WhateverName", maxVersion: "9");

            Assert.IsNotNull(engine);
            Assert.AreEqual("8", engine.ServerVersion);
        }
示例#26
0
		public void GetIndexed_SquareSyntax()
		{
			var engine = new Concrete.DataEngine();
			var parser = new Concrete.Parser(engine);
			var pars = engine.CreateParameterCollection();

			var result = parser.Parse((Func<dynamic, object>)(x => x.Name["James", "Bond"]), pars);
			Assert.AreEqual("NameJamesBond", result);
			Assert.AreEqual(0, pars.Count);
		}
示例#27
0
		public void CoreCommand_Provider()
		{
			var engine = new Concrete.DataEngine();
			var link = new FakeLink(engine, NestableTransactionMode.Database);

			var other = new FakeCommandProvider(link);
			other.TheCommand.From(x => x.Employees);

			var provider = new FakeCommandProvider(link);
			provider.TheCommand.From(x => x(other).As(x.Emp));
			provider.TheCommand.Select(x => x.Number.As(x.Id));
			provider.TheCommand.Where(x => x.Name == "James Bond");

			var parser = new Concrete.Parser(engine);
			var pars = engine.CreateParameterCollection();

			var result = parser.Parse(provider, pars);
			Assert.AreEqual(
				"SELECT Number AS Id FROM (SELECT * FROM Employees) AS Emp WHERE (Name = #0)"
				, result);
			Assert.AreEqual(1, pars.Count);
			Assert.AreEqual("James Bond", pars[0].Value);
		}
示例#28
0
		public void Embedded_Commands()
		{
			var engine = new Concrete.DataEngine();
			var link = new FakeLink(engine, NestableTransactionMode.Database);
			var inner = link.Raw("SELECT * From WhoKnows WHERE Name == {0}", "James Bond");

			var parser = new Concrete.Parser(engine);
			var pars = engine.CreateParameterCollection();
			pars.AddCreate("PlaceHolderForPositionCero");
			Assert.AreEqual(1, pars.Count);

			var result = parser.Parse(inner, pars);
			Assert.AreEqual("SELECT * From WhoKnows WHERE Name == #1", result);
			Assert.AreEqual(2, pars.Count);
			Assert.AreEqual("James Bond", pars[1].Value);
		}
示例#29
0
		public void Method_NotIn()
		{
			var engine = new Concrete.DataEngine();
			var parser = new Concrete.Parser(engine);
			var pars = engine.CreateParameterCollection();

			var result = parser.Parse((Func<dynamic, object>)(x => x.Alpha.NotIn(x.Beta, "37", "40")), pars);
			Assert.AreEqual("NOT Alpha IN (Beta, #0, #1)", result);
			Assert.AreEqual(2, pars.Count);
			Assert.AreEqual("37", pars[0].Value);
			Assert.AreEqual("40", pars[1].Value);
		}
示例#30
0
		public void Method_Distinct()
		{
			var engine = new Concrete.DataEngine();
			var parser = new Concrete.Parser(engine);
			var pars = engine.CreateParameterCollection();

			var result = parser.Parse((Func<dynamic, object>)(x => x.Distinct(x.Alpha)), pars);
			Assert.AreEqual("DISTINCT Alpha", result);
			Assert.AreEqual(0, pars.Count);
		}
示例#31
0
		public void Binary_WithNegate()
		{
			var engine = new Concrete.DataEngine();
			var parser = new Concrete.Parser(engine);
			var pars = engine.CreateParameterCollection();

			var result = parser.Parse((Func<dynamic, object>)(x => -x.Name + 5), pars);
			Assert.AreEqual("(-Name + #0)", result);
			Assert.AreEqual(1, pars.Count);
			Assert.AreEqual(5, pars[0].Value);
		}
示例#32
0
		public void Is_NotNull()
		{
			var engine = new Concrete.DataEngine();
			var parser = new Concrete.Parser(engine);
			var pars = engine.CreateParameterCollection();

			var result = parser.Parse((Func<dynamic, object>)(x => x.Name != null), pars);
			Assert.AreEqual("(Name IS NOT NULL)", result);
			Assert.AreEqual(0, pars.Count);
		}