public void GetConstraint_BuildWithQuery_ConstraintBuilt() { var sutXml = new MembersXml(); sutXml.ChildrenOf = "memberCaption"; var item = new LevelXml(); sutXml.Item = item; item.ConnectionString = "connectionString"; item.Perspective = "perspective"; item.Dimension = "dimension"; item.Hierarchy = "hierarchy"; item.Caption = "level"; var ctrXml = new OrderedXml(); var query = new QueryXml(); query.InlineQuery = "select label from myTable order by sortOrder"; ctrXml.Query = query; var builder = new MembersOrderedBuilder(); builder.Setup(sutXml, ctrXml); builder.Build(); var ctr = builder.GetConstraint(); Assert.That(ctr, Is.InstanceOf <OrderedConstraint>()); }
public void Execute_ExistingDefaultOnEveryWhereWithAlsoAssert_AssertValueReturned() { var xml = new QueryXml() { Settings = new SettingsXml() { Defaults = new List <DefaultXml>() { new DefaultXml() { ApplyTo = SettingsXml.DefaultScope.Everywhere, ConnectionString = new ConnectionStringXml() { Inline = CONNECTION_STRING } }, new DefaultXml() { ApplyTo = SettingsXml.DefaultScope.Assert, ConnectionString = new ConnectionStringXml() { Inline = CONNECTION_STRING_2 } } } }, ConnectionString = string.Empty }; var helper = new ConnectionStringHelper(); var actual = helper.Execute(xml, SettingsXml.DefaultScope.Assert); Assert.That(actual, Is.EqualTo(CONNECTION_STRING_2)); }
public static void ExportCulture(string directoryName, CultureInfo ci) { bool?replace = null; bool?delete = null; SyncFolder(ref replace, ref delete, Path.Combine(directoryName, ci.Name, AppendicesDirectory), Database.Query <AppendixHelpEntity>().Where(ah => ah.Culture.Name == ci.Name).ToList(), ah => "{0}.{1}.help".FormatWith(RemoveInvalid(ah.UniqueName), ah.Culture.Name), ah => AppendixXml.ToXDocument(ah)); SyncFolder(ref replace, ref delete, Path.Combine(directoryName, ci.Name, NamespacesDirectory), Database.Query <NamespaceHelpEntity>().Where(nh => nh.Culture.Name == ci.Name).ToList(), nh => "{0}.{1}.help".FormatWith(RemoveInvalid(nh.Name), nh.Culture.Name), nh => NamespaceXml.ToXDocument(nh)); SyncFolder(ref replace, ref delete, Path.Combine(directoryName, ci.Name, TypesDirectory), Database.Query <TypeHelpEntity>().Where(th => th.Culture.Name == ci.Name).ToList(), th => "{0}.{1}.help".FormatWith(RemoveInvalid(th.Type.CleanName), th.Culture.Name), th => EntityXml.ToXDocument(th)); SyncFolder(ref replace, ref delete, Path.Combine(directoryName, ci.Name, QueriesDirectory), Database.Query <QueryHelpEntity>().Where(qh => qh.Culture.Name == ci.Name).ToList(), qh => "{0}.{1}.help".FormatWith(RemoveInvalid(qh.Query.Key), qh.Culture.Name), qh => QueryXml.ToXDocument(qh)); }
public void Execute_NonExistingReference_ReferenceValueReturned() { var xml = new QueryXml() { Settings = new SettingsXml() { References = new List <ReferenceXml>() { new ReferenceXml() { Name = "Ref1", ConnectionString = new ConnectionStringXml() { Inline = CONNECTION_STRING_2 } } } }, ConnectionString = "@Ref2" }; var helper = new ConnectionStringHelper(); var actual = helper.Execute(xml, SettingsXml.DefaultScope.Assert); Assert.That(actual, Is.Null.Or.Empty); }
public void Serialize_InlineQuery_UseCData() { // Create an instance of the XmlSerializer specifying type and namespace. var ctrXml = new EqualToXml(); var queryXml = new QueryXml { ConnectionString = "my connection-string", InlineQuery = "select * from table" }; ctrXml.Query = queryXml; var overrides = new WriteOnlyAttributes(); overrides.Build(); var serializer = new XmlSerializer(typeof(EqualToXml), overrides); var stream = new MemoryStream(); var writer = new StreamWriter(stream, Encoding.UTF8); serializer.Serialize(writer, ctrXml); var content = Encoding.UTF8.GetString(stream.ToArray()); writer.Close(); stream.Close(); Debug.WriteLine(content); Assert.That(content, Is.StringContaining("<![CDATA[")); Assert.That(content, Is.StringContaining("select * from table")); Assert.That(content, Is.StringContaining("my connection-string")); Assert.That(content.Split(new[] { ' ' }), Has.Exactly(1).EqualTo("*")); }
public void Execute_ExistingReferenceAndDefaultConnectionStringDefinedWithReference_ReferenceValueReturned() { var xml = new QueryXml() { Settings = new SettingsXml() { References = new List <ReferenceXml>() { new ReferenceXml() { Name = "Ref1", ConnectionString = new ConnectionStringXml() { Inline = CONNECTION_STRING_2 } } }, Defaults = new List <DefaultXml>() { new DefaultXml() { ApplyTo = SettingsXml.DefaultScope.Assert, ConnectionString = new ConnectionStringXml() { Inline = CONNECTION_STRING } } } }, ConnectionString = "@Ref1" }; var helper = new ConnectionStringHelper(); var actual = helper.Execute(xml, SettingsXml.DefaultScope.Assert); Assert.That(actual, Is.EqualTo(CONNECTION_STRING_2)); }
public static void ImportAll(string directoryName) { var namespaces = HelpLogic.AllTypes().Select(a => a.Namespace !).Distinct().ToDictionary(a => a); var types = HelpLogic.AllTypes().ToDictionary(a => a.FullName !); foreach (var path in Directory.GetFiles(directoryName, "*.help", SearchOption.AllDirectories)) { try { XDocument doc = XDocument.Load(path); ImportAction action = doc.Root !.Name == AppendixXml._Appendix ? AppendixXml.Load(doc): doc.Root !.Name == NamespaceXml._Namespace ? NamespaceXml.Load(doc, namespaces): doc.Root !.Name == EntityXml._Entity ? EntityXml.Load(doc, types): doc.Root !.Name == QueryXml._Query ? QueryXml.Load(doc) : throw new InvalidOperationException("Unknown Xml root: " + doc.Root.Name); ConsoleColor color = action == ImportAction.Inserted ? ConsoleColor.Green : action == ImportAction.Updated ? ConsoleColor.DarkGreen : action == ImportAction.Skipped ? ConsoleColor.Yellow : action == ImportAction.NoChanges ? ConsoleColor.DarkGray : throw new InvalidOperationException("Unexpected action"); SafeConsole.WriteLineColor(color, " {0} {1}".FormatWith(action, path)); } catch (Exception e) { SafeConsole.WriteLineColor(ConsoleColor.Red, " Error {0}:\r\n\t".FormatWith(path) + e.Message); } } }
public void Setup(QueryXml queryXml, SettingsXml settingsXml, SettingsXml.DefaultScope scope, IDictionary <string, ITestVariable> variables) { obj = queryXml; Settings = settingsXml ?? SettingsXml.Empty; Scope = scope; Variables = variables; isSetup = true; }
public static void ExportAll(string directoryName = "../../Help") { bool?replace = null; foreach (var ah in Database.Query <AppendixHelpEntity>()) { string path = Path.Combine(directoryName, ah.Culture.Name, AppendicesDirectory, "{0}.{1}.help".FormatWith(RemoveInvalid(ah.UniqueName), ah.Culture.Name)); FileTools.CreateParentDirectory(path); if (!File.Exists(path) || SafeConsole.Ask(ref replace, "Overwrite {0}?".FormatWith(path))) { AppendixXml.ToXDocument(ah).Save(path); } } foreach (var nh in Database.Query <NamespaceHelpEntity>()) { string path = Path.Combine(directoryName, nh.Culture.Name, NamespacesDirectory, "{0}.{1}.help".FormatWith(RemoveInvalid(nh.Name), nh.Culture.Name)); FileTools.CreateParentDirectory(path); if (!File.Exists(path) || SafeConsole.Ask(ref replace, "Overwrite {0}?".FormatWith(path))) { NamespaceXml.ToXDocument(nh).Save(path); } } foreach (var eh in Database.Query <EntityHelpEntity>()) { string path = Path.Combine(directoryName, eh.Culture.Name, EntitiesDirectory, "{0}.{1}.help".FormatWith(RemoveInvalid(eh.Type.CleanName), eh.Culture.Name)); FileTools.CreateParentDirectory(path); if (!File.Exists(path) || SafeConsole.Ask(ref replace, "Overwrite {0}?".FormatWith(path))) { EntityXml.ToXDocument(eh).Save(path); } } foreach (var qh in Database.Query <QueryHelpEntity>()) { string path = Path.Combine(directoryName, qh.Culture.Name, QueriesDirectory, "{0}.{1}.help".FormatWith(RemoveInvalid(qh.Query.Key), qh.Culture.Name)); FileTools.CreateParentDirectory(path); if (!File.Exists(path) || SafeConsole.Ask(ref replace, "Overwrite {0}?".FormatWith(path))) { QueryXml.ToXDocument(qh).Save(path); } } }
private ResultSetResolverArgs BuildQueryResolverArgs(QueryXml queryXml) { Trace.WriteLineIf(Extensibility.NBiTraceSwitch.TraceVerbose, "ResultSet defined through a query."); var argsBuilder = new Helper.QueryResolverArgsBuilder(serviceLocator); argsBuilder.Setup(queryXml); argsBuilder.Setup(settings); argsBuilder.Setup(globalVariables); argsBuilder.Build(); var argsQuery = argsBuilder.GetArgs(); return(new QueryResultSetResolverArgs(argsQuery)); }
public void Execute_OnlyInlineConnectionStringWithCrLfTab_InlineConnectionStringReturned() { var xml = new QueryXml() { Settings = SettingsXml.Empty, ConnectionString = $"\r\n\t\t{CONNECTION_STRING}\r\n" }; var helper = new ConnectionStringHelper(); var actual = helper.Execute(xml, SettingsXml.DefaultScope.Assert); Assert.That(actual, Is.EqualTo(CONNECTION_STRING)); }
public void Execute_NoRoleAdded_NoRoleIncludedInConnectionStringReturned() { var xml = new QueryXml() { Settings = SettingsXml.Empty, ConnectionString = CONNECTION_STRING }; var helper = new ConnectionStringHelper(); var actual = helper.Execute(xml, SettingsXml.DefaultScope.Assert); Assert.That(actual, Does.Contain(CONNECTION_STRING)); Assert.That(actual, Is.Not.StringContaining("Roles=")); }
public void Execute_TwoRolesAdded_TwoRolesIncludedInConnectionStringReturned() { var xml = new QueryXml() { Settings = SettingsXml.Empty, ConnectionString = CONNECTION_STRING, Roles = "PowerUser;LimitedAccess" }; var helper = new ConnectionStringHelper(); var actual = helper.Execute(xml, SettingsXml.DefaultScope.Assert); Assert.That(actual, Does.Contain(CONNECTION_STRING)); Assert.That(actual, Does.Match(".*Roles.*=.*\"PowerUser;LimitedAccess\".*")); }
public void Execute_OneInitialRoleAndOneAdditionalRoleProvided_OneRoleAtTheEnd() { var xml = new QueryXml() { Settings = SettingsXml.Empty, ConnectionString = CONNECTION_STRING + ";Roles=\"Admin\"", Roles = "PowerUser" }; var helper = new ConnectionStringHelper(); var actual = helper.Execute(xml, SettingsXml.DefaultScope.Assert); Assert.That(actual, Does.Match(".*Roles.*=.*\"PowerUser\".*")); Assert.That(actual, Is.Not.StringMatching("Admin")); }
public void Execute_OneInitialRoleWithSpaceAndTwoAdditionalRolesProvided_TwoRolesAtTheEnd() { var xml = new QueryXml() { Settings = SettingsXml.Empty, ConnectionString = CONNECTION_STRING + "Roles = \"Admin Maximum\"", Roles = "Power User;Limited Access" }; var helper = new ConnectionStringHelper(); var actual = helper.Execute(xml, SettingsXml.DefaultScope.Assert); Assert.That(actual, Does.Match(".*Roles.*=.*\"Power User;Limited Access\".*")); Assert.That(actual, Is.Not.StringMatching("Admin")); Assert.That(actual, Is.Not.StringMatching("Maximum")); }
protected void Build(QueryXml queryXml) { queryXml.Settings = Settings; var connectionString = new ConnectionStringHelper().Execute(queryXml, Scope); var parameters = BuildParameters(queryXml.GetParameters()); var templateVariables = queryXml.GetTemplateVariables(); var timeout = Convert.ToInt32(Math.Ceiling(queryXml.Timeout / 1000m)); //Timeout is expressed in milliseconds if (!string.IsNullOrEmpty(queryXml.InlineQuery)) { args = new EmbeddedQueryResolverArgs(queryXml.InlineQuery , connectionString, parameters, templateVariables, new TimeSpan(0, 0, timeout)); } else if (!string.IsNullOrEmpty(queryXml.File)) { var file = GetFullPath(Settings?.BasePath, queryXml.File); args = new ExternalFileQueryResolverArgs(file , connectionString, parameters, templateVariables, new TimeSpan(0, 0, timeout)); } else if (queryXml.Assembly != null) { args = Build(queryXml.Assembly, connectionString, parameters, templateVariables, new TimeSpan(0, 0, timeout)); } else if (queryXml.Report != null) { args = Build(queryXml.Report, connectionString, parameters, templateVariables, new TimeSpan(0, 0, timeout)); } else if (queryXml.SharedDataset != null) { args = Build(queryXml.SharedDataset, connectionString, parameters, templateVariables, new TimeSpan(0, 0, timeout)); } if (args == null) { throw new ArgumentException(); } }
private IQuery BuildQuery(QueryXml queryXml) { var connectionString = new ConnectionStringHelper().Execute(queryXml, Xml.Settings.SettingsXml.DefaultScope.SystemUnderTest); return(new NBi.Core.Query.Query(queryXml.InlineQuery, connectionString, new TimeSpan(0, 0, 0))); }
public void Setup(QueryXml queryXml) { this.queryXml = queryXml; isSetup = true; }
private IQuery BuildQuery(QueryXml queryXml) { return(new NBi.Core.Query.Query(queryXml.GetQuery(), queryXml.GetConnectionString(), new TimeSpan(0, 0, 0))); }