How to use Instantiate method of NBi.Core.Transformation.Transformer.NativeTransformationFactory class

Best NBi code snippet using NBi.Core.Transformation.Transformer.NativeTransformationFactory.Instantiate

NativeTransformationFactoryTest.cs

Source:NativeTransformationFactoryTest.cs Github

copy

Full Screen

...15{16 public class NativeTransformationFactoryTest17 {18 [Test]19 public void Instantiate_ExistingWithoutParameter_CorrectType()20 {21 var factory = new NativeTransformationFactory(new ServiceLocator(), null);;22 var result = factory.Instantiate("dateTime-to-date");23 24 Assert.That(result, Is.AssignableTo<INativeTransformation>());25 Assert.That(result, Is.TypeOf<DateTimeToDate>());26 }27 [Test]28 public void Instantiate_ExistingWithoutParameterAndWhitespaces_CorrectType()29 {30 var factory = new NativeTransformationFactory(new ServiceLocator(), null);;31 var result = factory.Instantiate("\t\tdateTime-to-date\r\n");32 Assert.That(result, Is.AssignableTo<INativeTransformation>());33 Assert.That(result, Is.TypeOf<DateTimeToDate>());34 }35 [Test]36 public void Instantiate_ExistingWithParameter2_CorrectType()37 {38 var factory = new NativeTransformationFactory(new ServiceLocator(), null);;39 var result = factory.Instantiate("text-to-pad-right(6, *)");40 Assert.That(result, Is.AssignableTo<INativeTransformation>());41 Assert.That(result, Is.TypeOf<TextToPadRight>());42 Assert.That((result as TextToPadRight).Length.Execute(), Is.EqualTo(6));43 Assert.That((result as TextToPadRight).Character.Execute(), Is.EqualTo('*'));44 }45 [Test]46 public void Instantiate_ExistingWithParameter_CorrectType()47 {48 var factory = new NativeTransformationFactory(new ServiceLocator(), null);;49 var result = factory.Instantiate("utc-to-local(Brussels)");50 Assert.That(result, Is.AssignableTo<INativeTransformation>());51 Assert.That(result, Is.TypeOf<UtcToLocal>());52 Assert.That((result as UtcToLocal).TimeZoneLabel, Is.AssignableTo<IScalarResolver>());53 Assert.That((result as UtcToLocal).TimeZoneLabel, Is.AssignableTo<IScalarResolver<string>>());54 Assert.That((result as UtcToLocal).TimeZoneLabel, Is.TypeOf<LiteralScalarResolver<string>>());55 Assert.That((result as UtcToLocal).TimeZoneLabel.Execute(), Is.EqualTo("Brussels"));56 }57 [Test]58 public void Instantiate_ExistingWithParameterIncludingSpaces_CorrectType()59 {60 var factory = new NativeTransformationFactory(new ServiceLocator(), null);;61 var result = factory.Instantiate("utc-to-local( Romance Standard Time )");62 Assert.That(result, Is.AssignableTo<INativeTransformation>());63 Assert.That(result, Is.TypeOf<UtcToLocal>());64 Assert.That((result as UtcToLocal).TimeZoneLabel.Execute(), Is.EqualTo("Romance Standard Time"));65 }66 [Test]67 public void Instantiate_ExistingWithParameterAndWhitespaces_CorrectType()68 {69 var factory = new NativeTransformationFactory(new ServiceLocator(), null);;70 var result = factory.Instantiate("\r\n\t\t\tutc-to-local(Brussels) \t\r\n");71 Assert.That(result, Is.AssignableTo<INativeTransformation>());72 Assert.That(result, Is.TypeOf<UtcToLocal>());73 Assert.That((result as UtcToLocal).TimeZoneLabel.Execute(), Is.EqualTo("Brussels"));74 }75 [Test]76 public void Instantiate_ExistingWithParameters_CorrectType()77 {78 var factory = new NativeTransformationFactory(new ServiceLocator(), null);;79 var result = factory.Instantiate("numeric-to-clip(10, 2000)");80 Assert.That(result, Is.AssignableTo<INativeTransformation>());81 Assert.That(result, Is.TypeOf<NumericToClip>());82 Assert.That((result as NumericToClip).Min.Execute(), Is.EqualTo(10));83 Assert.That((result as NumericToClip).Max.Execute(), Is.EqualTo(2000));84 }85 [Test]86 public void Instantiate_ExistingWithParametersAndWhitespaces_CorrectType()87 {88 var factory = new NativeTransformationFactory(new ServiceLocator(), null);;89 var result = factory.Instantiate("\r\n\t\t\tnumeric-to-clip( 10, 2000 )\t\t\t\r\n");90 Assert.That(result, Is.AssignableTo<INativeTransformation>());91 Assert.That(result, Is.TypeOf<NumericToClip>());92 Assert.That((result as NumericToClip).Min.Execute(), Is.EqualTo(10));93 Assert.That((result as NumericToClip).Max.Execute(), Is.EqualTo(2000));94 }95 [Test]96 public void Instantiate_ExistingWithParametersAndSpaces_CorrectType()97 {98 var factory = new NativeTransformationFactory(new ServiceLocator(), null);;99 var result = factory.Instantiate("numeric-to-clip (10, 2000)");100 Assert.That(result, Is.AssignableTo<INativeTransformation>());101 Assert.That(result, Is.TypeOf<NumericToClip>());102 Assert.That((result as NumericToClip).Min.Execute(), Is.EqualTo(10));103 Assert.That((result as NumericToClip).Max.Execute(), Is.EqualTo(2000));104 }105 [Test]106 public void Instantiate_ExistingWithParametersAndVariables_CorrectType()107 {108 var variables = new Dictionary<string, IVariable>()109 {110 { "avg", new GlobalVariable(new LiteralScalarResolver<decimal>(50)) },111 { "min", new GlobalVariable(new LiteralScalarResolver<decimal>(10)) },112 { "max", new GlobalVariable(new LiteralScalarResolver<decimal>(2000)) },113 };114 var factory = new NativeTransformationFactory(new ServiceLocator(), new Context(variables));115 var result = factory.Instantiate("numeric-to-clip(@min, @max)");116 Assert.That(result, Is.AssignableTo<INativeTransformation>());117 Assert.That(result, Is.TypeOf<NumericToClip>());118 Assert.That((result as NumericToClip).Min.Execute(), Is.EqualTo(10));119 Assert.That((result as NumericToClip).Max.Execute(), Is.EqualTo(2000));120 }121 [Test]122 [TestCase("blank-to-empty")]123 [TestCase("blank-to-null")]124 [TestCase("empty-to-null")]125 [TestCase("null-to-empty")]126 [TestCase("null-to-value")]127 [TestCase("null-to-zero")]128 [TestCase("value-to-value")]129 [TestCase("any-to-any")]130 [TestCase("text-to-trim")]131 [TestCase("text-to-upper")]132 [TestCase("text-to-lower")]133 [TestCase("text-to-suffix(abc)")]134 [TestCase("text-to-prefix(abc)")]135 [TestCase("text-to-length")]136 [TestCase("text-to-first-chars(3)")]137 [TestCase("text-to-last-chars(3)")]138 [TestCase("text-to-skip-first-chars(3)")]139 [TestCase("text-to-skip-last-chars(3)")]140 [TestCase("text-to-pad-right(3, *)")]141 [TestCase("text-to-pad-left(3, *)")]142 [TestCase("text-to-html")]143 [TestCase("text-to-without-diacritics")]144 [TestCase("text-to-token-count")]145 [TestCase("text-to-token-count(;)")]146 [TestCase("text-to-token(2)")]147 [TestCase("text-to-token(2,;)")]148 [TestCase("text-to-without-whitespaces")]149 [TestCase("text-to-remove-chars(*)")]150 [TestCase("text-to-dateTime(yyyy.mm.dd hh:mm)")]151 [TestCase("text-to-dateTime(dddd dd mm yyyy hh:mm, fr-fr)")]152 [TestCase("text-to-mask(BE-***.***.**)")]153 [TestCase("mask-to-text(BE-***.***.**)")]154 [TestCase("html-to-text")]155 [TestCase("date-to-age")]156 [TestCase("utc-to-local(Brussels)")]157 [TestCase("local-to-utc(Brussels)")]158 [TestCase("dateTime-to-date")]159 [TestCase("null-to-date(2010-05-01)")]160 [TestCase("dateTime-to-first-of-month")]161 [TestCase("dateTime-to-last-of-month")]162 [TestCase("dateTime-to-first-of-year")]163 [TestCase("dateTime-to-last-of-year")]164 [TestCase("dateTime-to-next-day")]165 [TestCase("dateTime-to-previous-day")]166 [TestCase("dateTime-to-next-month")]167 [TestCase("dateTime-to-previous-month")]168 [TestCase("dateTime-to-next-year")]169 [TestCase("dateTime-to-previous-year")]170 [TestCase("dateTime-to-floor-hour")]171 [TestCase("dateTime-to-ceiling-hour")]172 [TestCase("dateTime-to-floor-minute")]173 [TestCase("dateTime-to-ceiling-minute")]174 [TestCase("dateTime-to-clip(2019-01-01, 2019-12-31)")]175 [TestCase("dateTime-to-set-time(07:00:00)")]176 [TestCase("dateTime-to-add(00:15:00)")]177 [TestCase("dateTime-to-add(00:15:00, 3)")]178 [TestCase("dateTime-to-subtract(00:15:00)")]179 [TestCase("dateTime-to-subtract(00:15:00, 3)")]180 [TestCase("numeric-to-round(5)")]181 [TestCase("numeric-to-floor")]182 [TestCase("numeric-to-ceiling")]183 [TestCase("numeric-to-integer")]184 [TestCase("numeric-to-increment")]185 [TestCase("numeric-to-decrement")]186 [TestCase("numeric-to-clip(10, 20)")]187 [TestCase("numeric-to-add(10)")]188 [TestCase("numeric-to-add(10, 3)")]189 [TestCase("numeric-to-subtract(10)")]190 [TestCase("numeric-to-subtract(10, 3)")]191 [TestCase("numeric-to-multiply(10)")]192 [TestCase("numeric-to-divide(12)")]193 [TestCase("numeric-to-invert")]194 [TestCase("path-to-filename")]195 [TestCase("path-to-filename-without-extension")]196 [TestCase("path-to-extension")]197 [TestCase("path-to-root")]198 [TestCase("path-to-directory")]199 [TestCase("file-to-size")]200 [TestCase("file-to-creation-dateTime")]201 [TestCase("file-to-creation-dateTime-utc")]202 [TestCase("file-to-update-dateTime")]203 [TestCase("file-to-update-dateTime-utc")]204 public void Instantiate_ExistingNativeTransformation_CorrectlyBuilt(string value)205 {206 var factory = new NativeTransformationFactory(new ServiceLocator(), null);;207 var result = factory.Instantiate(value);208 Assert.That(result, Is.AssignableTo<INativeTransformation>());209 }210 }211}...

Full Screen

Full Screen

ScalarResolverArgsFactory.cs

Source:ScalarResolverArgsFactory.cs Github

copy

Full Screen

...16 private ServiceLocator ServiceLocator { get; }17 private Context Context { get; }18 public ScalarResolverArgsFactory(ServiceLocator serviceLocator, Context context)19 => (ServiceLocator, Context) = (serviceLocator, context);20 public IScalarResolverArgs Instantiate(string value)21 {22 switch (value)23 {24 case string obj when obj.TrimStart().StartsWith("`") && obj.TrimEnd().EndsWith("`"):25 return new LiteralScalarResolverArgs(obj.Trim().Substring(1, obj.Trim().Length - 2));26 case string obj when string.IsNullOrEmpty(value): return new LiteralScalarResolverArgs(string.Empty);27 case null: return new LiteralScalarResolverArgs(string.Empty);28 default:29 var tokens = Regex.Matches(value, @"(?:(?:\{(?>[^{}]+|\{(?<subpart>)|\}(?<-subpart>))*(?(subpart)(?!))\})|[^|])+").Cast<Match>().Select(x => x.Value.Trim());30 var firstToken = tokens.First().Trim();31 var prefix = tokens.First().Trim().ToCharArray()[0];32 var suffix = tokens.Last().Trim().ToCharArray().Last();33 var functions = tokens.Skip(1);34 var factory = ServiceLocator.GetScalarResolverFactory();35 IScalarResolverArgs args = null;36 var columnIdentifierFactory = new ColumnIdentifierFactory();37 switch (prefix)38 {39 case '@':40 args = new GlobalVariableScalarResolverArgs(firstToken.Substring(1), Context?.Variables);41 break;42 case '~':43 args = new FormatScalarResolverArgs(firstToken.Substring(1), Context?.Variables);44 break;45 case '[' when firstToken.ToCharArray().Last() == ']' && !firstToken.Contains(';') && MatchExternalBrakets(firstToken).Count==1:46 case '#':47 args = new ContextScalarResolverArgs(Context, columnIdentifierFactory.Instantiate(firstToken));48 break;49 default:50 args = new LiteralScalarResolverArgs(firstToken);51 break;52 }53 if (functions.Count() > 0)54 {55 var transformations = new List<INativeTransformation>();56 var nativeTransformationFactory = new NativeTransformationFactory(ServiceLocator, Context);57 foreach (var function in functions)58 transformations.Add(nativeTransformationFactory.Instantiate(function));59 return new FunctionScalarResolverArgs(factory.Instantiate(args), transformations);60 }61 else62 return args;63 }64 }65 private MatchCollection MatchExternalBrakets(string value)66 {67 var regex = new Regex(@"68 \[ # Match [69 (70 [^[\]]+ # all chars except []71 | (?<Level>\[) # or if [ then Level += 172 | (?<-Level>\]) # or if ] then Level -= 173 )+ # Repeat (to go from inside to outside)...

Full Screen

Full Screen

NativeTransformationfactory.cs

Source:NativeTransformationfactory.cs Github

copy

Full Screen

...17 protected ServiceLocator ServiceLocator { get; }18 protected Context Context { get; }19 public NativeTransformationFactory(ServiceLocator serviceLocator, Context context)20 => (ServiceLocator, Context) = (serviceLocator, context);21 public INativeTransformation Instantiate(string code)22 {23 var textInfo = CultureInfo.InvariantCulture.TextInfo;24 var functionParameters = code.Replace("(", ",")25 .Replace(")", ",").Trim()26 .Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries)27 .ToList().Skip(1).Select(x => x.Trim()).ToList();28 var classToken = code.Contains("(") ? code.Substring(0, code.IndexOf('(')).Replace(" ", "") : code;29 var className = textInfo.ToTitleCase(classToken.Trim().Replace("-", " ")).Replace(" ", "").Replace("Datetime", "DateTime").Replace("Timespan", "TimeSpan");30 var type = typeof(INativeTransformation).Assembly.GetTypes()31 .Where(32 t => t.IsClass33 && t.IsAbstract == false34 && t.Name == className35 && t.GetInterface(typeof(INativeTransformation).Name) != null)36 .SingleOrDefault();37 if (type == null)38 throw new NotImplementedTransformationException(className);39 if (typeof(IBasePathTransformation).IsAssignableFrom(type))40 functionParameters.Insert(0, ServiceLocator.BasePath);41 var ctor = type.GetConstructors().SingleOrDefault(x => x.GetParameters().Count() == functionParameters.Count());42 if (ctor == null)43 throw new MissingOrUnexpectedParametersTransformationException(className, functionParameters.Count());44 var zip = ctor.GetParameters().Zip(functionParameters, (x, y) => new { x.ParameterType, Value = y });45 var typedFunctionParameters = new List<object>();46 var argsFactory = new ScalarResolverArgsFactory(ServiceLocator, Context);47 var factory = ServiceLocator.GetScalarResolverFactory();48 foreach (var param in zip)49 {50 if (typeof(IScalarResolver).IsAssignableFrom(param.ParameterType))51 {52 53 var scalarType = param.ParameterType.GenericTypeArguments[0];54 var args = argsFactory.Instantiate(param.Value);55 var resolver = factory.Instantiate(args, scalarType);56 typedFunctionParameters.Add(resolver);57 }58 else59 typedFunctionParameters.Add(param.Value);60 }61 return (INativeTransformation)ctor.Invoke(typedFunctionParameters.ToArray());62 }63 }64}...

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 method in NativeTransformationFactory

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful