Best NBi code snippet using NBi.Core.Transformation.TransformationProvider.TransformationProvider
TransformationProviderTest.cs
Source:TransformationProviderTest.cs
...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}...
ResultSetEqualToBuilder.cs
Source:ResultSetEqualToBuilder.cs
...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)...
TransformationProvider.cs
Source:TransformationProvider.cs
...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)...
TransformationProvider
Using AI Code Generation
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 static void Main(string[] args)11 {12 TransformationProvider provider = new TransformationProvider();13 provider.Transform = new NativeTransformation();14 provider.Transformation = "md5";15 provider.Arguments = new string[] { "test" };16 string output = provider.Execute();17 Console.WriteLine(output);18 Console.ReadLine();19 }20 }21}22using System;23using System.Collections.Generic;24using System.Linq;25using System.Text;26using System.Threading.Tasks;27using NBi.Core.Transformation;28using NBi.Core.Transformation.Transformer.Native;29{30 {31 static void Main(string[] args)32 {33 TransformationProvider provider = new TransformationProvider();34 provider.Transform = new NativeTransformation();35 provider.Transformation = "md5";36 provider.Arguments = new string[] { "test" };37 string output = provider.Execute();38 Console.WriteLine(output);39 Console.ReadLine();40 }41 }42}43using System;44using System.Collections.Generic;45using System.Linq;46using System.Text;47using System.Threading.Tasks;48using NBi.Core.Transformation;49using NBi.Core.Transformation.Transformer.Native;50{
TransformationProvider
Using AI Code Generation
1var path = @"C:\Users\user\Documents\NBi\NBi.Testing\NBi.Testing.Integration\Transformation\1.cs";2var transformationProvider = new TransformationProvider(path);3var result = transformationProvider.Execute("Hello World");4var path = @"C:\Users\user\Documents\NBi\NBi.Testing\NBi.Testing.Integration\Transformation\2.cs";5var transformationProvider = new TransformationProvider(path);6var result = transformationProvider.Execute("Hello World");7var path = @"C:\Users\user\Documents\NBi\NBi.Testing\NBi.Testing.Integration\Transformation\3.cs";8var transformationProvider = new TransformationProvider(path);9var result = transformationProvider.Execute("Hello World");10var path = @"C:\Users\user\Documents\NBi\NBi.Testing\NBi.Testing.Integration\Transformation\4.cs";11var transformationProvider = new TransformationProvider(path);12var result = transformationProvider.Execute("Hello World");13var path = @"C:\Users\user\Documents\NBi\NBi.Testing\NBi.Testing.Integration\Transformation\5.cs";14var transformationProvider = new TransformationProvider(path);15var result = transformationProvider.Execute("Hello World");16var path = @"C:\Users\user\Documents\NBi\NBi.Testing\NBi.Testing.Integration\Transformation\6.cs";17var transformationProvider = new TransformationProvider(path);18var result = transformationProvider.Execute("Hello World");19var path = @"C:\Users\user\Documents\NBi\NBi.Testing\NBi.Testing.Integration\Transformation\7.cs";20var transformationProvider = new TransformationProvider(path);
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!