How to use TransformationProvider class of NBi.Core.Transformation package

Best NBi code snippet using NBi.Core.Transformation.TransformationProvider

TransformationProviderTest.cs

Source:TransformationProviderTest.cs Github

copy

Full Screen

...12using System.Threading.Tasks;13namespace NBi.Testing.Core.Transformation14{15 [TestFixture]16 public class TransformationProviderTest17 {18 [Test]19 public void Transform_SimpleTranformation_CorrectHandlingOfColumnNames()20 {21 var resultSet = new NBi.Core.ResultSet.ResultSet();22 resultSet.Load("aaaa;10");23 resultSet.Columns[0].ColumnName = "MyCol0";24 resultSet.Columns[1].ColumnName = "MyCol1";25 var transformation = Mock.Of<ITransformationInfo>26 (27 t => t.Language == LanguageType.CSharp28 && t.OriginalType == ColumnType.Text29 && t.Code == "value.Substring(0,1)"30 );31 var provider = new TransformationProvider(new ServiceLocator(), Context.None);32 provider.Add(new ColumnOrdinalIdentifier(0), transformation);33 provider.Transform(resultSet);34 Assert.That(resultSet.Columns[0].ColumnName, Is.EqualTo("MyCol0"));35 Assert.That(resultSet.Columns[1].ColumnName, Is.EqualTo("MyCol1"));36 Assert.That(resultSet.Columns.Count, Is.EqualTo(2));37 }38 [Test]39 public void Transform_SimpleTranformation_Correct()40 {41 var resultSet = new NBi.Core.ResultSet.ResultSet();42 resultSet.Load("aaaa;10");43 var transformation = Mock.Of<ITransformationInfo>44 (45 t => t.Language == LanguageType.CSharp46 && t.OriginalType == ColumnType.Text47 && t.Code == "value.Substring(0,1)"48 );49 var provider = new TransformationProvider(new ServiceLocator(), Context.None);50 provider.Add(new ColumnOrdinalIdentifier(0), transformation);51 provider.Transform(resultSet);52 Assert.That(resultSet.Rows[0][0], Is.EqualTo("a"));53 }54 [Test]55 public void Transform_NativeTranformationTrim_Correct()56 {57 var resultSet = new NBi.Core.ResultSet.ResultSet();58 resultSet.Load(" aaaa ;10");59 var transformation = Mock.Of<ITransformationInfo>60 (61 t => t.Language == LanguageType.Native62 && t.OriginalType == ColumnType.Text63 && t.Code == "text-to-trim"64 );65 var provider = new TransformationProvider(new ServiceLocator(), Context.None);66 provider.Add(new ColumnOrdinalIdentifier(0), transformation);67 provider.Transform(resultSet);68 Assert.That(resultSet.Rows[0][0], Is.EqualTo("aaaa"));69 }70 [Test]71 public void Transform_NativeTranformationFirstCharWithContext_Correct()72 {73 var resultSet = new NBi.Core.ResultSet.ResultSet();74 resultSet.Load(new[] { new object[] { "123456789", 6 }, new object[] { "abcdefgh", 2 } });75 var transformation = Mock.Of<ITransformationInfo>76 (77 t => t.Language == LanguageType.Native78 && t.OriginalType == ColumnType.Text79 && t.Code == "text-to-first-chars(#1)"80 );81 var provider = new TransformationProvider(new ServiceLocator(), Context.None);82 provider.Add(new ColumnOrdinalIdentifier(0), transformation);83 provider.Transform(resultSet);84 Assert.That(resultSet.Rows[0][0], Is.EqualTo("123456"));85 Assert.That(resultSet.Rows[1][0], Is.EqualTo("ab"));86 }87 [Test]88 public void Transform_NativeTranformationBlankToNull_Correct()89 {90 var resultSet = new NBi.Core.ResultSet.ResultSet();91 resultSet.Load("\t;10");92 var transformation = Mock.Of<ITransformationInfo>93 (94 t => t.Language == LanguageType.Native95 && t.OriginalType == ColumnType.Text96 && t.Code == "blank-to-null"97 );98 var provider = new TransformationProvider(new ServiceLocator(), Context.None);99 provider.Add(new ColumnOrdinalIdentifier(0), transformation);100 provider.Transform(resultSet);101 Assert.That(resultSet.Rows[0][0], Is.EqualTo("(null)"));102 }103 [Test]104 public void Transform_NativeTranformationUnknown_Exception()105 {106 var resultSet = new NBi.Core.ResultSet.ResultSet();107 resultSet.Load("\t;10");108 var transformation = Mock.Of<ITransformationInfo>109 (110 t => t.Language == LanguageType.Native111 && t.OriginalType == ColumnType.Text112 && t.Code == "unknown"113 );114 var provider = new TransformationProvider(new ServiceLocator(), null);115 Assert.Throws<NotImplementedTransformationException>(() => provider.Add(new ColumnOrdinalIdentifier(0), transformation));116 }117 [Test]118 public void Transform_TypeSwitch_Correct()119 {120 var resultSet = new NBi.Core.ResultSet.ResultSet();121 var obj = new object[] { new DateTime(2016,10,1) };122 resultSet.Load(Enumerable.Repeat(obj,1));123 var transformation = Mock.Of<ITransformationInfo>124 (125 t => t.Language == LanguageType.CSharp126 && t.OriginalType == ColumnType.DateTime127 && t.Code == "value.Month + (value.Year-2000)*12"128 );129 var provider = new TransformationProvider(new ServiceLocator(), Context.None);130 provider.Add(new ColumnOrdinalIdentifier(0), transformation);131 provider.Transform(resultSet);132 Assert.That(resultSet.Rows[0][0], Is.EqualTo(202));133 }134 }135}...

Full Screen

Full Screen

ResultSetEqualToBuilder.cs

Source:ResultSetEqualToBuilder.cs Github

copy

Full Screen

...33 protected NBiConstraint InstantiateConstraint()34 {35 BaseResultSetComparisonConstraint ctr = null;36 //Manage transformations37 var transformationProvider = new TransformationProvider(ServiceLocator, new Context(Variables));38 foreach (var columnDef in ConstraintXml.ColumnsDef)39 {40 if (columnDef.Transformation != null)41 transformationProvider.Add(columnDef.Identifier, columnDef.Transformation);42 }43 if (ConstraintXml.BaseItem is QueryXml)44 ctr = InstantiateConstraint(((QueryXml)(ConstraintXml.BaseItem)), ConstraintXml.Settings, transformationProvider);45 else if (ConstraintXml.ResultSetOld != null)46 ctr = InstantiateConstraint(ConstraintXml.ResultSetOld, ConstraintXml.Settings, transformationProvider);47 else if (ConstraintXml.ResultSet != null)48 ctr = InstantiateConstraint(ConstraintXml.ResultSet, ConstraintXml.Settings);49 else if (ConstraintXml.XmlSource != null)50 ctr = InstantiateConstraint(ConstraintXml.XmlSource, ConstraintXml.Settings, transformationProvider);51 if (ctr == null)52 throw new ArgumentException();53 //Manage settings for comparaison54 var builder = new SettingsEquivalerBuilder();55 if (ConstraintXml.Behavior == EqualToXml.ComparisonBehavior.SingleRow)56 {57 builder.Setup(false);58 builder.Setup(ConstraintXml.ValuesDefaultType, ConstraintXml.Tolerance);59 builder.Setup(ConstraintXml.ColumnsDef);60 }61 else62 {63 builder.Setup(ConstraintXml.KeysDef, ConstraintXml.ValuesDef);64 builder.Setup(65 ConstraintXml.KeyName?.Replace(" ", "").Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Distinct(),66 ConstraintXml.ValueName?.Replace(" ", "").Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Distinct());67 builder.Setup(ConstraintXml.ValuesDefaultType, ConstraintXml.Tolerance);68 builder.Setup(ConstraintXml.ColumnsDef);69 }70 builder.Build();71 var settings = builder.GetSettings();72 var factory = new EquivalerFactory();73 var comparer = factory.Instantiate(settings, EquivalenceKind);74 ctr = ctr.Using(comparer);75 ctr = ctr.Using(settings);76 //Manage parallelism77 if (ConstraintXml.ParallelizeQueries)78 ctr = ctr.Parallel();79 else80 ctr = ctr.Sequential();81 return ctr;82 }83 protected virtual BaseResultSetComparisonConstraint InstantiateConstraint(ResultSetSystemXml xml, SettingsXml settings)84 {85 xml.Settings = settings;86 var builder = new ResultSetServiceBuilder();87 var helper = new ResultSetSystemHelper(ServiceLocator, SettingsXml.DefaultScope.Assert, Variables);88 builder.Setup(helper.InstantiateResolver(xml));89 builder.Setup(helper.InstantiateAlterations(xml));90 var service = builder.GetService();91 return InstantiateConstraint(service);92 }93 protected virtual BaseResultSetComparisonConstraint InstantiateConstraint(object obj, SettingsXml settings, TransformationProvider transformation)94 {95 var argsBuilder = new ResultSetResolverArgsBuilder(ServiceLocator);96 argsBuilder.Setup(obj, settings, SettingsXml.DefaultScope.Assert, Variables);97 argsBuilder.Build();98 var factory = ServiceLocator.GetResultSetResolverFactory();99 var resolver = factory.Instantiate(argsBuilder.GetArgs());100 var serviceBuilder = new ResultSetServiceBuilder();101 serviceBuilder.Setup(resolver);102 if (transformation != null)103 serviceBuilder.Setup(transformation.Transform);104 var service = serviceBuilder.GetService();105 return InstantiateConstraint(service);106 }107 protected virtual BaseResultSetComparisonConstraint InstantiateConstraint(IResultSetService service)...

Full Screen

Full Screen

TransformationProvider.cs

Source:TransformationProvider.cs Github

copy

Full Screen

...10using System.Text;11using System.Threading.Tasks;12namespace NBi.Core.Transformation13{14 public class TransformationProvider15 {16 private IDictionary<IColumnIdentifier, ITransformer> cacheTransformers;17 private readonly TransformerFactory factory;18 private Context Context { get; }19 public TransformationProvider(ServiceLocator serviceLocator, Context context)20 {21 cacheTransformers = new Dictionary<IColumnIdentifier, ITransformer>();22 factory = new TransformerFactory(serviceLocator, context);23 Context = context;24 }25 public void Add(IColumnIdentifier indentifier, ITransformationInfo transfo)26 {27 var transformer = factory.Instantiate(transfo);28 transformer.Initialize(transfo.Code);29 if (cacheTransformers.ContainsKey(indentifier))30 throw new NBiException($"You can't define two transformers for the same column. The column {indentifier.Label} has already another transformer specified.");31 cacheTransformers.Add(indentifier, transformer);32 }33 public virtual IResultSet Transform(IResultSet resultSet)...

Full Screen

Full Screen

TransformationProvider

Using AI Code Generation

copy

Full Screen

1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using NBi.Core.Transformation;7using NBi.Core.Transformation.Transformer.Native;8{9 {10 public string Apply(string input, string transformation)11 {12 var provider = new NativeTransformationProvider();13 var transformationArgs = new TransformationArgs(transformation, string.Empty);14 var result = provider.Execute(input, transformationArgs);15 return result;16 }17 }18}19using System;20using System.Collections.Generic;21using System.Linq;22using System.Text;23using System.Threading.Tasks;24using NBi.Core.Transformation;25using NBi.Core.Transformation.Transformer.Native;26{27 {28 public string Apply(string input, string transformation)29 {30 var factory = new NativeTransformationFactory();31 var transformationArgs = new TransformationArgs(transformation, string.Empty);32 var result = factory.Instantiate(transformationArgs).Execute(input, transformationArgs);33 return result;34 }35 }36}37using System;38using System.Collections.Generic;39using System.Linq;40using System.Text;41using System.Threading.Tasks;42using NBi.Core.Transformation;43using NBi.Core.Transformation.Transformer.Native;44{45 {46 public string Apply(string input, string transformation)47 {48 var factory = new NativeTransformationFactory();49 var transformationArgs = new TransformationArgs(transformation, string.Empty);50 var result = factory.Instantiate(transformationArgs).Execute(input, transformationArgs);51 return result;52 }53 }54}55using System;56using System.Collections.Generic;57using System.Linq;58using System.Text;59using System.Threading.Tasks;60using NBi.Core.Transformation;61using NBi.Core.Transformation.Transformer.Native;62{63 {64 public string Apply(string input, string transformation)65 {66 var factory = new NativeTransformationFactory();67 var transformationArgs = new TransformationArgs(transformation

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run NBi automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used methods in TransformationProvider

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful