Best NBi code snippet using NBi.Core.Transformation.Transformer.Native.NumericToClip.NumericToClip
NativeTransformationFactoryTest.cs
Source:NativeTransformationFactoryTest.cs
...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)")]...
NumericTransformations.cs
Source:NumericTransformations.cs
...56 public NumericToRound(IScalarResolver<int> digits)57 => Digits = digits;58 protected override decimal EvaluateNumeric(decimal numeric) => Math.Round(numeric, Digits.Execute());59 }60 class NumericToClip : AbstractNumericTransformation61 {62 public IScalarResolver<decimal> Min { get; }63 public IScalarResolver<decimal> Max { get; }64 public NumericToClip(IScalarResolver<decimal> min, IScalarResolver<decimal> max)65 => (Min, Max) = (min, max);66 protected override decimal EvaluateNumeric(decimal numeric) => (numeric < Min.Execute()) ? Min.Execute() : (numeric > Max.Execute()) ? Max.Execute() : numeric;67 }68 abstract class AbstractNumericArithmetic : AbstractNumericTransformation69 {70 public IScalarResolver<decimal> Value { get; }71 public AbstractNumericArithmetic(IScalarResolver<decimal> value)72 => Value = value;73 }74 class NumericToAdd : AbstractNumericArithmetic75 {76 public IScalarResolver<int> Times { get; }77 public NumericToAdd(IScalarResolver<decimal> value, IScalarResolver<int> times)78 : base(value) => Times = times;...
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!!