Best NBi code snippet using NBi.Core.Transformation.Transformer.Native.ValueToValue.Evaluate
TextTest.cs
Source:TextTest.cs
...26 [TestCase(0, "(empty)", "(null)")]27 public void Execute_TextToToken_DefaultSeparator(int index, string value, string expected)28 {29 var function = new TextToToken(new LiteralScalarResolver<int>(index));30 var result = function.Evaluate(value);31 Assert.That(result, Is.EqualTo(expected));32 }33 [Test]34 [TestCase(0, ';', "1;2017-07-06;CUST0001", "1")]35 [TestCase(1, ',', "1, 2017-07-06 ,CUST0001", " 2017-07-06 ")]36 [TestCase(2, '|', "1 | 2017-07-06 | CUST0001", " CUST0001")]37 [TestCase(0, '|', "(null)", "(null)")]38 [TestCase(0, '|', "(blank)", "(blank)")]39 [TestCase(0, ' ', "(blank)", "(null)")]40 [TestCase(0, '|', "(empty)", "(null)")]41 public void Execute_TextToToken_CustomSeparator(int index, char separator, string value, string expected)42 {43 var function = new TextToToken(new LiteralScalarResolver<int>(index), new LiteralScalarResolver<char>(separator));44 var result = function.Evaluate(value);45 Assert.That(result, Is.EqualTo(expected));46 }47 [Test]48 [TestCase("abc 123")]49 [TestCase("abc 123 ")]50 [TestCase(" abc 123")]51 [TestCase("abc 123")]52 [TestCase(" abc 123 ")]53 [TestCase(" abc , 123 ")]54 public void Execute_TextToTokenAndTextToTokenCount_Aligned(string value)55 {56 var tokenCount = (int)new TextToTokenCount().Evaluate(value);57 for (int i = 0; i < tokenCount; i++)58 {59 var nextTextToToken = new TextToToken(new LiteralScalarResolver<int>(i));60 Assert.That(nextTextToToken.Evaluate(value), Is.Not.EqualTo("(null)"));61 }62 var textToToken = new TextToToken(new LiteralScalarResolver<int>(tokenCount));63 Assert.That(textToToken.Evaluate(value), Is.EqualTo("(null)"));64 }65 [Test]66 [TestCase("")]67 [TestCase("(null)")]68 [TestCase("\t")]69 [TestCase(" \t")]70 [TestCase(" ")]71 [TestCase("\r\n")]72 public void Execute_BlankToNull_Null(string value)73 {74 var function = new BlankToNull();75 var result = function.Evaluate(value);76 Assert.That(result, Is.EqualTo("(null)"));77 }78 [Test]79 [TestCase("(null)")]80 [TestCase("alpha")]81 public void Execute_BlankToEmpty_NotEmpty(string value)82 {83 var function = new BlankToNull();84 var result = function.Evaluate(value);85 Assert.That(result, Is.Not.EqualTo("(empty)"));86 }87 [Test]88 [TestCase("alpha")]89 public void Execute_BlankToNull_NotNull(string value)90 {91 var function = new BlankToNull();92 var result = function.Evaluate(value);93 Assert.That(result, Is.Not.EqualTo("(null)"));94 }95 [Test]96 [TestCase("")]97 [TestCase("(null)")]98 [TestCase("(empty)")]99 public void Execute_EmptyToNull_Null(string value)100 {101 var function = new EmptyToNull();102 var result = function.Evaluate(value);103 Assert.That(result, Is.EqualTo("(null)"));104 }105 [Test]106 [TestCase("alpha")]107 [TestCase("\t")]108 [TestCase(" \t")]109 [TestCase(" ")]110 [TestCase("\r\n")]111 public void Execute_EmptyToNull_NotNull(string value)112 {113 var function = new EmptyToNull();114 var result = function.Evaluate(value);115 Assert.That(result, Is.Not.EqualTo("(null)"));116 }117 [Test]118 [TestCase("")]119 [TestCase("(any)")]120 [TestCase("(empty)")]121 [TestCase("(null)")]122 [TestCase(150)]123 public void Execute_AnyToAny_Any(object value)124 {125 var function = new AnyToAny();126 var result = function.Evaluate(value);127 Assert.That(result, Is.EqualTo("(any)"));128 }129 [Test]130 [TestCase("")]131 [TestCase("(any)")]132 [TestCase("(empty)")]133 [TestCase(150)]134 public void Execute_ValueToValue_Value(object value)135 {136 var function = new ValueToValue();137 var result = function.Evaluate(value);138 Assert.That(result, Is.EqualTo("(value)"));139 }140 [Test]141 [TestCase("(null)")]142 public void Execute_ValueToValue_NotValue(object value)143 {144 var function = new ValueToValue();145 var result = function.Evaluate(value);146 Assert.That(result, Is.Not.EqualTo("(value)"));147 }148 [Test]149 [TestCase("(null)")]150 public void Execute_NullToValue_Value(object value)151 {152 var function = new NullToValue();153 var result = function.Evaluate(value);154 Assert.That(result, Is.EqualTo("(value)"));155 }156 [Test]157 [TestCase("(empty)")]158 [TestCase("123")]159 public void Execute_NullToValue_NotValue(object value)160 {161 var function = new NullToValue();162 var result = function.Evaluate(value);163 Assert.That(result, Is.Not.EqualTo("(value)"));164 }165 [Test]166 [TestCase("ABC")]167 [TestCase(" ABC ")]168 public void Execute_Trim_ABC(object value)169 {170 var function = new TextToTrim();171 var result = function.Evaluate(value);172 Assert.That(result, Is.EqualTo("ABC"));173 }174 [Test]175 [TestCase("(null)")]176 [TestCase(" XYZ ")]177 public void Execute_Trim_NotABC(object value)178 {179 var function = new TextToTrim();180 var result = function.Evaluate(value);181 Assert.That(result, Is.Not.EqualTo("ABC"));182 }183 [Test]184 [TestCase("abC")]185 public void Execute_UpperCase_ABC(object value)186 {187 var function = new TextToUpper();188 var result = function.Evaluate(value);189 Assert.That(result, Is.EqualTo("ABC"));190 }191 [Test]192 [TestCase(" abC ")]193 public void Execute_LowerCase_abc(object value)194 {195 var function = new TextToLower();196 var result = function.Evaluate(value);197 Assert.That(result, Is.EqualTo(" abc "));198 }199 [Test]200 [TestCase(" abC ")]201 public void Execute_Length_5(object value)202 {203 var function = new TextToLength();204 var result = function.Evaluate(value);205 Assert.That(result, Is.EqualTo(5));206 }207 [Test]208 [TestCase("Cédric")]209 public void Execute_TextToHtml_Valid(object value)210 {211 var function = new TextToHtml();212 var result = function.Evaluate(value);213 Assert.That(result, Is.EqualTo("Cédric"));214 }215 [Test]216 [TestCase("Cédric")]217 [TestCase("Cédric")]218 public void Execute_HtmlToText_Valid(object value)219 {220 var function = new HtmlToText();221 var result = function.Evaluate(value);222 Assert.That(result, Is.EqualTo("Cédric"));223 }224 [Test]225 [TestCase("Cédric")]226 public void Execute_Diacritics_Valid(object value)227 {228 var function = new TextToWithoutDiacritics();229 var result = function.Evaluate(value);230 Assert.That(result, Is.EqualTo("Cedric"));231 }232 [Test]233 [TestCase("My taylor is rich", "Mytaylorisrich")]234 [TestCase(" My Lord ! ", "MyLord!")]235 [TestCase("My Lord !\r\nMy taylor is \t rich", "MyLord!Mytaylorisrich")]236 [TestCase("(null)", "(null)")]237 [TestCase(null, "(null)")]238 [TestCase("(empty)", "(empty)")]239 [TestCase("(blank)", "(empty)")]240 public void Execute_Whitespace_Valid(object value, string expected)241 {242 var function = new TextToWithoutWhitespaces();243 var result = function.Evaluate(value);244 Assert.That(result, Is.EqualTo(expected));245 }246 [Test]247 [TestCase("My taylor is rich", 4)]248 [TestCase(" My Lord ! ", 2)]249 [TestCase(" My Lord ! ", 2)]250 [TestCase(" My Lord ! C-L.", 3)]251 [TestCase("(null)", 0)]252 [TestCase(null, 0)]253 [TestCase("(empty)", 0)]254 [TestCase("(blank)", 0)]255 [TestCase("1 2017-07-06 CUST0001", 3)]256 [TestCase("1 2017-07-06 CUST0001", 3)]257 public void Execute_TokenCount_Valid(object value, int expected)258 {259 var function = new TextToTokenCount();260 var result = function.Evaluate(value);261 Assert.That(result, Is.EqualTo(expected));262 }263 [Test]264 [TestCase("123456789", "abc", "abc123456789")]265 [TestCase("(null)", "abc", "(null)")]266 [TestCase("(empty)", "abc", "abc")]267 [TestCase("(blank)", "abc", "abc")]268 public void Execute_TextToPrefix_Valid(string value, string prefix, string expected)269 {270 var function = new TextToPrefix(new LiteralScalarResolver<string>(prefix));271 var result = function.Evaluate(value);272 Assert.That(result, Is.EqualTo(expected));273 }274 [Test]275 [TestCase("123456789", "abc", "123456789abc")]276 [TestCase("(null)", "abc", "(null)")]277 [TestCase("(empty)", "abc", "abc")]278 [TestCase("(blank)", "abc", "abc")]279 public void Execute_TextToSuffix_Valid(string value, string suffix, string expected)280 {281 var function = new TextToSuffix(new LiteralScalarResolver<string>(suffix));282 var result = function.Evaluate(value);283 Assert.That(result, Is.EqualTo(expected));284 }285 [Test]286 [TestCase("123456789", 9, "123456789")]287 [TestCase("123456789", 10, "123456789")]288 [TestCase("123456789", 8, "12345678")]289 [TestCase("123456789", 0, "")]290 [TestCase("(null)", 3, "(null)")]291 [TestCase("(empty)", 3, "(empty)")]292 public void Execute_TextToFirstChars_Valid(string value, int length, string expected)293 {294 var function = new TextToFirstChars(new LiteralScalarResolver<int>(length));295 var result = function.Evaluate(value);296 Assert.That(result, Is.EqualTo(expected));297 }298 [Test]299 [TestCase("123456789", 9, "123456789")]300 [TestCase("123456789", 10, "123456789")]301 [TestCase("123456789", 8, "23456789")]302 [TestCase("123456789", 0, "")]303 [TestCase("(null)", 3, "(null)")]304 [TestCase("(empty)", 3, "(empty)")]305 public void Execute_TextToLastChars_Valid(string value, int length, string expected)306 {307 var function = new TextToLastChars(new LiteralScalarResolver<int>(length));308 var result = function.Evaluate(value);309 Assert.That(result, Is.EqualTo(expected));310 }311 [Test]312 [TestCase("123456789", 9, "(empty)")]313 [TestCase("123456789", 10, "(empty)")]314 [TestCase("123456789", 8, "9")]315 [TestCase("123456789", 5, "6789")]316 [TestCase("123456789", 0, "123456789")]317 [TestCase("(null)", 3, "(null)")]318 [TestCase("(empty)", 3, "(empty)")]319 public void Execute_TextToSkipFirstChars_Valid(string value, int length, string expected)320 {321 var function = new TextToSkipFirstChars(new LiteralScalarResolver<int>(length));322 var result = function.Evaluate(value);323 Assert.That(result, Is.EqualTo(expected));324 }325 [Test]326 [TestCase("123456789", 9, "(empty)")]327 [TestCase("123456789", 10, "(empty)")]328 [TestCase("123456789", 8, "1")]329 [TestCase("123456789", 5, "1234")]330 [TestCase("123456789", 0, "123456789")]331 [TestCase("(null)", 3, "(null)")]332 [TestCase("(empty)", 3, "(empty)")]333 public void Execute_TextToSkipLastChars_Valid(string value, int length, string expected)334 {335 var function = new TextToSkipLastChars(new LiteralScalarResolver<int>(length));336 var result = function.Evaluate(value);337 Assert.That(result, Is.EqualTo(expected));338 }339 [Test]340 public void Execute_TextToLastCharsWithVariable_Valid()341 {342 var args = new GlobalVariableScalarResolverArgs("length", new Dictionary<string, IVariable>() { { "length", new GlobalVariable(new LiteralScalarResolver<int>(6) )} });343 var function = new TextToLastChars(new GlobalVariableScalarResolver<int>(args));344 var result = function.Evaluate("123456789");345 Assert.That(result, Is.EqualTo("456789"));346 }347 [Test]348 [TestCase("1234", 9, '0', "123400000")]349 [TestCase("1234", 9, '*', "1234*****")]350 [TestCase("123456789", 3, '0', "123456789")]351 [TestCase("(null)", 3, '0', "000")]352 [TestCase("(empty)", 3, '0', "000")]353 public void Execute_TextToPadRight_Valid(string value, int length, char character, string expected)354 {355 var function = new TextToPadRight(new LiteralScalarResolver<int>(length), new LiteralScalarResolver<char>(character));356 var result = function.Evaluate(value);357 Assert.That(result, Is.EqualTo(expected));358 }359 [Test]360 [TestCase("1234", 9, '0', "000001234")]361 [TestCase("1234", 9, '*', "*****1234")]362 [TestCase("123456789", 3, '0', "123456789")]363 [TestCase("(null)", 3, '0', "000")]364 [TestCase("(empty)", 3, '0', "000")]365 public void Execute_TextToPadLeft_Valid(string value, int length, char character, string expected)366 {367 var function = new TextToPadLeft(new LiteralScalarResolver<int>(length), new LiteralScalarResolver<char>(character));368 var result = function.Evaluate(value);369 Assert.That(result, Is.EqualTo(expected));370 }371 [Test]372 [TestCase("20190317111223", "yyyyMMddhhmmss", "2019-03-17 11:12:23")]373 [TestCase("2019-03-17 11:12:23", "yyyy-MM-dd hh:mm:ss", "2019-03-17 11:12:23")]374 [TestCase("17-03-2019 11:12:23", "dd-MM-yyyy hh:mm:ss", "2019-03-17 11:12:23")]375 [TestCase("2019-03-17T11:12:23", "yyyy-MM-ddThh:mm:ss", "2019-03-17 11:12:23")]376 [TestCase("17/03/2019 11:12:23", "dd/MM/yyyy hh:mm:ss", "2019-03-17 11:12:23")]377 [TestCase("17.03.2019 11.12.23", "dd.MM.yyyy hh.mm.ss", "2019-03-17 11:12:23")]378 [TestCase("Wed, 25.09.19", "ddd, dd.MM.yy", "2019-09-25")]379 [TestCase("Wednesday 25-SEP-19", "dddd dd-MMM-yy", "2019-09-25")]380 [TestCase("2019-10-01T19:58Z", "yyyy-MM-ddTHH:mmZ", "2019-10-01 19:58:00")]381 public void Execute_TextToDateTime_Valid(string value, string format, DateTime expected)382 {383 var function = new TextToDateTime(new LiteralScalarResolver<string>(format));384 var result = function.Evaluate(value);385 Assert.That(result, Is.EqualTo(expected));386 Assert.That(((DateTime) result).Kind, Is.EqualTo(DateTimeKind.Unspecified));387 }388 [Test]389 [TestCase("2019-11-01T19:58Z", "yyyy-MM-ddTHH:mmZ", "Brussels", "2019-11-01 20:58:00")]390 [TestCase("2019-10-01T19:58Z", "yyyy-MM-ddTHH:mmZ", "Brussels", "2019-10-01 21:58:00")]391 [TestCase("2019-10-01T19:58Z", "yyyy-MM-ddTHH:mmZ", "Moscow", "2019-10-01 22:58:00")]392 [TestCase("2019-10-01T19:58Z", "yyyy-MM-ddTHH:mmZ", "Pacific Standard Time", "2019-10-01 12:58:00")]393 public void Execute_TextToDateTimeAndUtcToLocal_Valid(string value, string format, string timeZone, DateTime expected)394 {395 var textToDateTime = new TextToDateTime(new LiteralScalarResolver<string>(format));396 var utcToLocal = new UtcToLocal(new LiteralScalarResolver<string>(timeZone));397 var result = utcToLocal.Evaluate(textToDateTime.Evaluate(value));398 Assert.That(result, Is.EqualTo(expected));399 Assert.That(((DateTime)result).Kind, Is.EqualTo(DateTimeKind.Unspecified));400 }401 [Test]402 [TestCase("20190317111223", "yyyyMMddhhmmss", "fr-fr", "2019-03-17 11:12:23")]403 [TestCase("mercredi 25-sept.-19", "dddd dd-MMM-yy", "fr-fr", "2019-09-25")]404 public void Execute_TextToDateTimeWithCulture_Valid(string value, string format, string culture, DateTime expected)405 {406 var function = new TextToDateTime(new LiteralScalarResolver<string>(format), new LiteralScalarResolver<string>(culture));407 var result = function.Evaluate(value);408 Assert.That(result, Is.EqualTo(expected));409 }410 [Test]411 [TestCase("123*456*78", "*", "12345678")]412 [TestCase("***123***456*78****", "*", "12345678")]413 [TestCase("******", "*", "")]414 [TestCase("(null)", "*", "(null)")]415 [TestCase("(empty)", "*", "(empty)")]416 [TestCase("(blank)", "*", "(blank)")]417 [TestCase("(blank)", " ", "(empty)")]418 public void Execute_TextToRemoveChars_Valid(string value, char charToRemove, string expected)419 {420 var function = new TextToRemoveChars(new LiteralScalarResolver<char>(charToRemove));421 var result = function.Evaluate(value);422 Assert.That(result, Is.EqualTo(expected));423 }424 [Test]425 [TestCase("12345678", "BE-***.***.**", "BE-123.456.78")]426 [TestCase("1234567890", "BE-***.***.**", "BE-123.456.78")]427 [TestCase("12345", "BE-***.***.**", "BE-123.45*.**")]428 [TestCase("(null)", "BE-***.***.**", "(null)")]429 [TestCase("(empty)", "BE-***.***.**", "BE-***.***.**")]430 [TestCase("(blank)", "BE-***.***.**", "BE-***.***.**")]431 public void Execute_TextToMask_Valid(string value, string mask, string expected)432 {433 var function = new TextToMask(new LiteralScalarResolver<string>(mask));434 var result = function.Evaluate(value);435 Assert.That(result, Is.EqualTo(expected));436 }437 [Test]438 [TestCase("12345678", "BE-***.***.**", "BE-123.456.78")]439 [TestCase("12345", "BE-***.***.**", "BE-123.45*.**")]440 [TestCase("(null)", "BE-***.***.**", "(null)")]441 [TestCase("", "BE-***.***.**", "BE-***.***.**")]442 [TestCase("(null)", "BE-***.***.**", "(empty)")]443 [TestCase("(empty)", "********", "(empty)")]444 [TestCase("(null)", "BE-***.***.**", "(blank)")]445 [TestCase("(blank)", "********", "(blank)")]446 public void Execute_MaskToText_Valid(string expected, string mask, string value)447 {448 var function = new MaskToText(new LiteralScalarResolver<string>(mask));449 var result = function.Evaluate(value);450 Assert.That(result, Is.EqualTo(expected));451 }452 }453}...
ValueToValue.cs
Source:ValueToValue.cs
...6namespace NBi.Core.Transformation.Transformer.Native7{8 class ValueToValue : INativeTransformation9 {10 public object Evaluate(object value)11 {12 if (value == null || DBNull.Value.Equals(value) || (value is string && value as string == "(null)"))13 return "(null)";14 else15 return "(value)";16 }17 18 }19}...
Evaluate
Using AI Code Generation
1using NBi.Core.Transformation.Transformer.Native;2ValueToValue vtv = new ValueToValue();3vtv.Evaluate("1", "int", "int");4using NBi.Core.Transformation.Transformer.Native;5ValueToValue vtv = new ValueToValue();6vtv.Evaluate("1", "int", "int");7using NBi.Core.Transformation.Transformer.Native;8ValueToValue vtv = new ValueToValue();9vtv.Evaluate("1", "int", "int");10using NBi.Core.Transformation.Transformer.Native;11ValueToValue vtv = new ValueToValue();12vtv.Evaluate("1", "int", "int");13using NBi.Core.Transformation.Transformer.Native;14ValueToValue vtv = new ValueToValue();15vtv.Evaluate("1", "int", "int");16using NBi.Core.Transformation.Transformer.Native;17ValueToValue vtv = new ValueToValue();18vtv.Evaluate("1", "int", "int");19using NBi.Core.Transformation.Transformer.Native;20ValueToValue vtv = new ValueToValue();21vtv.Evaluate("1", "int", "int");22using NBi.Core.Transformation.Transformer.Native;23ValueToValue vtv = new ValueToValue();24vtv.Evaluate("1", "int", "int");
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!!