예제 #1
0
		/// <summary>
		/// Initializes a new instance of the TemplatingContext class.
		/// </summary>
		/// <param name="xpe"> The XML persist engine in-effect. </param>
		/// <param name="tokenizer"> The tokenizer in-efect. </param>
		/// <param name="input"> The input mechanism in-effect. </param>
		/// <param name="output"> The output mechanism in-effect. </param>
		/// <param name="properties"> The properties in-effect. </param>
		public TemplatingContext(IXmlPersistEngine xpe, Tokenizer tokenizer, IInputMechanism input, IOutputMechanism output, IDictionary<string, IList<string>> properties)
		{
			if ((object)xpe == null)
				throw new ArgumentNullException(nameof(xpe));

			if ((object)tokenizer == null)
				throw new ArgumentNullException(nameof(tokenizer));

			if ((object)input == null)
				throw new ArgumentNullException(nameof(input));

			if ((object)output == null)
				throw new ArgumentNullException(nameof(output));

			if ((object)properties == null)
				throw new ArgumentNullException(nameof(properties));

			this.xpe = xpe;
			this.tokenizer = tokenizer;
			this.input = input;
			this.output = output;
			this.properties = properties;
		}
예제 #2
0
		public void ShouldCreateTest()
		{
			Tokenizer tokenizer;
			MockFactory mockFactory;
			IDictionary<string, ITokenReplacementStrategy> mockTokenReplacementStrategies;

			mockFactory = new MockFactory();
			mockTokenReplacementStrategies = mockFactory.CreateInstance<IDictionary<string, ITokenReplacementStrategy>>();

			tokenizer = new Tokenizer(true);

			Assert.IsNotNull(tokenizer);
			Assert.IsNotNull(tokenizer.TokenReplacementStrategies);
			Assert.IsTrue(tokenizer.StrictMatching);

			tokenizer = new Tokenizer(mockTokenReplacementStrategies, true);

			Assert.IsNotNull(tokenizer);
			Assert.IsNotNull(tokenizer.TokenReplacementStrategies);
			Assert.IsTrue(tokenizer.StrictMatching);

			mockFactory.VerifyAllExpectationsHaveBeenMet();
		}
예제 #3
0
		private static void WriteSqlQuery(IEnumerable<SqlQuery> sqlQueries, IAssociativeXmlObject parentAssociativeXmlObject, Type connectionType, string connectionString, bool getSchemaOnly)
		{
			ArrayConstruct arrayConstruct;
			ObjectConstruct objectConstruct;
			PropertyConstruct propertyConstructA, propertyConstructB;
			Tokenizer tokenizer;

			IEnumerable<IDictionary<string, object>> records;
			string commandText;
			int count = 0;

			if ((object)sqlQueries == null)
				throw new ArgumentNullException(nameof(sqlQueries));

			if ((object)parentAssociativeXmlObject == null)
				throw new ArgumentNullException(nameof(parentAssociativeXmlObject));

			if ((object)connectionType == null)
				throw new ArgumentNullException(nameof(connectionType));

			if ((object)connectionString == null)
				throw new ArgumentNullException(nameof(connectionString));

			if (SolderLegacyInstanceAccessor.DataTypeFascadeLegacyInstance.IsWhiteSpace(connectionString))
				throw new ArgumentOutOfRangeException(nameof(connectionString));

			tokenizer = new Tokenizer(true);

			foreach (SqlQuery sqlQuery in sqlQueries.OrderBy(c => c.Key).ThenBy(c => c.Order))
			{
				arrayConstruct = new ArrayConstruct();
				arrayConstruct.Name = sqlQuery.Key;
				parentAssociativeXmlObject.Items.Add(arrayConstruct);

				commandText = tokenizer.ExpandTokens(sqlQuery.Text, new DynamicWildcardTokenReplacementStrategy(new object[] { parentAssociativeXmlObject }));

				records = DatazoidLegacyInstanceAccessor.AdoNetBufferingLegacyInstance.ExecuteRecords(getSchemaOnly, connectionType, connectionString, false, IsolationLevel.Unspecified, sqlQuery.Type, commandText, null);

				propertyConstructA = new PropertyConstruct();
				propertyConstructA.Name = "RowCount";
				arrayConstruct.Items.Add(propertyConstructA);

				if ((object)records != null)
				{
					foreach (IDictionary<string, object> record in records)
					{
						objectConstruct = new ObjectConstruct();
						arrayConstruct.Items.Add(objectConstruct);

						if ((object)record != null)
						{
							foreach (KeyValuePair<string, object> keyValuePair in record)
							{
								propertyConstructB = new PropertyConstruct();
								propertyConstructB.Name = keyValuePair.Key;
								propertyConstructB.RawValue = keyValuePair.Value;

								objectConstruct.Items.Add(propertyConstructB);
							}
						}

						// correlated
						WriteSqlQuery(sqlQuery.SubQueries, objectConstruct, connectionType, connectionString, getSchemaOnly);

						count++;
					}

					propertyConstructA.RawValue = count;
				}
			}
		}
예제 #4
0
		public void ShouldExpandTokensLooseMatchingTest()
		{
			Tokenizer tokenizer;
			MockFactory mockFactory;
			IDictionary<string, ITokenReplacementStrategy> mockTokenReplacementStrategies;
			ITokenReplacementStrategy mockTokenReplacementStrategy;

			ITokenReplacementStrategy _unusedTokenReplacementStrategy = null;
			string _unusedString = null;
			string[] _unusedStrings = null;

			string tokenizedValue;
			string expandedValue;
			string expectedValue;

			mockFactory = new MockFactory();
			mockTokenReplacementStrategies = mockFactory.CreateInstance<IDictionary<string, ITokenReplacementStrategy>>();
			mockTokenReplacementStrategy = mockFactory.CreateInstance<ITokenReplacementStrategy>();

			Expect.On(mockTokenReplacementStrategies).One.Method(x => x.TryGetValue(_unusedString, out _unusedTokenReplacementStrategy)).With(new EqualMatcher("myValueSemanticToken"), new AndMatcher(new ArgumentsMatcher.OutMatcher(), new AlwaysMatcher(true, string.Empty))).Will(new SetNamedParameterAction("value", mockTokenReplacementStrategy), Return.Value(true));
			Expect.On(mockTokenReplacementStrategy).One.Method(x => x.Evaluate(_unusedStrings)).With(new EqualMatcher(null)).WillReturn("testValue");

			Expect.On(mockTokenReplacementStrategies).One.Method(x => x.TryGetValue(_unusedString, out _unusedTokenReplacementStrategy)).With(new EqualMatcher("myFunctionSemanticToken0"), new AndMatcher(new ArgumentsMatcher.OutMatcher(), new AlwaysMatcher(true, string.Empty))).Will(new SetNamedParameterAction("value", mockTokenReplacementStrategy), Return.Value(true));
			Expect.On(mockTokenReplacementStrategy).One.Method(x => x.Evaluate(_unusedStrings)).With(new EqualMatcher(new string[] { })).WillReturn("testValue");

			Expect.On(mockTokenReplacementStrategies).One.Method(x => x.TryGetValue(_unusedString, out _unusedTokenReplacementStrategy)).With(new EqualMatcher("myFunctionSemanticToken1"), new AndMatcher(new ArgumentsMatcher.OutMatcher(), new AlwaysMatcher(true, string.Empty))).Will(new SetNamedParameterAction("value", mockTokenReplacementStrategy), Return.Value(true));
			Expect.On(mockTokenReplacementStrategy).One.Method(x => x.Evaluate(_unusedStrings)).With(new EqualMatcher(new string[] { "a", })).WillReturn("testValue");

			Expect.On(mockTokenReplacementStrategies).One.Method(x => x.TryGetValue(_unusedString, out _unusedTokenReplacementStrategy)).With(new EqualMatcher("myFunctionSemanticToken2"), new AndMatcher(new ArgumentsMatcher.OutMatcher(), new AlwaysMatcher(true, string.Empty))).Will(new SetNamedParameterAction("value", mockTokenReplacementStrategy), Return.Value(true));
			Expect.On(mockTokenReplacementStrategy).One.Method(x => x.Evaluate(_unusedStrings)).With(new EqualMatcher(new string[] { "a", "b" })).WillReturn("testValue");

			Expect.On(mockTokenReplacementStrategies).One.Method(x => x.TryGetValue(_unusedString, out _unusedTokenReplacementStrategy)).With(new EqualMatcher("myUnkSemanticToken"), new AndMatcher(new ArgumentsMatcher.OutMatcher(), new AlwaysMatcher(true, string.Empty))).Will(new SetNamedParameterAction("value", null), Return.Value(false));

			Expect.On(mockTokenReplacementStrategies).One.Method(x => x.TryGetValue(_unusedString, out _unusedTokenReplacementStrategy)).With(new EqualMatcher("myErrSemanticToken"), new AndMatcher(new ArgumentsMatcher.OutMatcher(), new AlwaysMatcher(true, string.Empty))).Will(new SetNamedParameterAction("value", mockTokenReplacementStrategy), Return.Value(true));
			Expect.On(mockTokenReplacementStrategy).One.Method(x => x.Evaluate(_unusedStrings)).With(new EqualMatcher(null)).Will(Throw.Exception(new Exception()));

			Expect.On(mockTokenReplacementStrategies).One.Method(x => x.TryGetValue(_unusedString, out _unusedTokenReplacementStrategy)).With(new EqualMatcher("a"), new AndMatcher(new ArgumentsMatcher.OutMatcher(), new AlwaysMatcher(true, string.Empty))).Will(new SetNamedParameterAction("value", mockTokenReplacementStrategy), Return.Value(true));
			Expect.On(mockTokenReplacementStrategy).One.Method(x => x.Evaluate(_unusedStrings)).With(new EqualMatcher(null)).WillReturn(string.Empty);

			Expect.On(mockTokenReplacementStrategies).One.Method(x => x.TryGetValue(_unusedString, out _unusedTokenReplacementStrategy)).With(new EqualMatcher("b"), new AndMatcher(new ArgumentsMatcher.OutMatcher(), new AlwaysMatcher(true, string.Empty))).Will(new SetNamedParameterAction("value", mockTokenReplacementStrategy), Return.Value(true));
			Expect.On(mockTokenReplacementStrategy).One.Method(x => x.Evaluate(_unusedStrings)).With(new EqualMatcher(null)).WillReturn(string.Empty);

			Expect.On(mockTokenReplacementStrategies).One.Method(x => x.TryGetValue(_unusedString, out _unusedTokenReplacementStrategy)).With(new EqualMatcher("c"), new AndMatcher(new ArgumentsMatcher.OutMatcher(), new AlwaysMatcher(true, string.Empty))).Will(new SetNamedParameterAction("value", mockTokenReplacementStrategy), Return.Value(true));
			Expect.On(mockTokenReplacementStrategy).One.Method(x => x.Evaluate(_unusedStrings)).With(new EqualMatcher(null)).WillReturn(string.Empty);

			Expect.On(mockTokenReplacementStrategies).One.Method(x => x.TryGetValue(_unusedString, out _unusedTokenReplacementStrategy)).With(new EqualMatcher("d"), new AndMatcher(new ArgumentsMatcher.OutMatcher(), new AlwaysMatcher(true, string.Empty))).Will(new SetNamedParameterAction("value", mockTokenReplacementStrategy), Return.Value(true));
			Expect.On(mockTokenReplacementStrategy).One.Method(x => x.Evaluate(_unusedStrings)).With(new EqualMatcher(null)).Will(Throw.Exception(new Exception()));

			tokenizer = new Tokenizer(mockTokenReplacementStrategies, false);

			tokenizedValue = string.Empty;
			expandedValue = tokenizer.ExpandTokens(tokenizedValue);
			expectedValue = string.Empty;
			Assert.AreEqual(expectedValue, expandedValue);

			tokenizedValue = "...{myNoSemanticToken}...";
			expandedValue = tokenizer.ExpandTokens(tokenizedValue);
			expectedValue = "...{myNoSemanticToken}...";
			Assert.AreEqual(expectedValue, expandedValue);

			tokenizedValue = "...${myValueSemanticToken}...";
			expandedValue = tokenizer.ExpandTokens(tokenizedValue);
			expectedValue = "...testValue...";
			Assert.AreEqual(expectedValue, expandedValue);

			tokenizedValue = "...${myFunctionSemanticToken0()}...";
			expandedValue = tokenizer.ExpandTokens(tokenizedValue);
			expectedValue = "...testValue...";
			Assert.AreEqual(expectedValue, expandedValue);

			tokenizedValue = "...${myFunctionSemanticToken1(`a`)}...";
			expandedValue = tokenizer.ExpandTokens(tokenizedValue);
			expectedValue = "...testValue...";
			Assert.AreEqual(expectedValue, expandedValue);

			tokenizedValue = "...${myFunctionSemanticToken2(`a`,  `b`)}...";
			expandedValue = tokenizer.ExpandTokens(tokenizedValue);
			expectedValue = "...testValue...";
			Assert.AreEqual(expectedValue, expandedValue);

			tokenizedValue = "...${myUnkSemanticToken}...";
			expandedValue = tokenizer.ExpandTokens(tokenizedValue);
			expectedValue = "...${myUnkSemanticToken}...";
			Assert.AreEqual(expectedValue, expandedValue);

			tokenizedValue = "...${myErrSemanticToken}...";
			expandedValue = tokenizer.ExpandTokens(tokenizedValue);
			expectedValue = "...${myErrSemanticToken}...";
			Assert.AreEqual(expectedValue, expandedValue);

			tokenizedValue = "...${a}...${c}...${b}...${d}...";
			expandedValue = tokenizer.ExpandTokens(tokenizedValue);
			expectedValue = "............${d}...";
			Assert.AreEqual(expectedValue, expandedValue);

			Assert.IsNotNull(tokenizer.OrderedPreviousExpansionTokens);
			Assert.AreEqual("a,b,c,d", string.Join(",", tokenizer.OrderedPreviousExpansionTokens));

			mockFactory.VerifyAllExpectationsHaveBeenMet();
		}
예제 #5
0
		public void ShouldFailOnNullTokenReplStratsCreateTest()
		{
			Tokenizer tokenizer;
			MockFactory mockFactory;
			IDictionary<string, ITokenReplacementStrategy> mockTokenReplacementStrategies;

			mockFactory = new MockFactory();
			mockTokenReplacementStrategies = null;

			tokenizer = new Tokenizer(mockTokenReplacementStrategies, true);

			mockFactory.VerifyAllExpectationsHaveBeenMet();
		}