public void StringToValueSuccess(object expected, string value, Type type) { var converted = converter.Convert(value, type); Assert.IsType(type, converted); Assert.Equal(expected, converted); }
public void TestStringConverter() { StringConverter stringConverter = new StringConverter(); Assert.True(stringConverter.CanConvertTo(typeof(string))); Assert.True(stringConverter.CanConvertTo(typeof(StringBuilder))); Assert.False(stringConverter.CanConvertTo(typeof(float))); Assert.False(stringConverter.CanConvertTo(typeof(double))); Assert.False(stringConverter.CanConvertTo(typeof(decimal))); Assert.False(stringConverter.CanConvertTo(typeof(Enum))); Assert.True(stringConverter.CanConvertFrom(" 123 ")); Assert.True(stringConverter.CanConvertFrom("1.0")); Assert.True(stringConverter.CanConvertFrom(" Dog")); Assert.True(stringConverter.CanConvertFrom(" True ")); Assert.True(stringConverter.CanConvertFrom(" abc")); Assert.True(stringConverter.CanConvertFrom("1.2E3")); Assert.True(stringConverter.CanConvertFrom(" 0xFF")); Assert.True(stringConverter.CanConvertFrom("Hello, World!")); Assert.True(stringConverter.CanConvertFrom("The quick brown fox jumps over the lazy dog.")); Assert.Equal("Hello, World!", stringConverter.Convert(typeof(string), "Hello, World!")); Assert.Equal("The quick brown fox jumps over the lazy dog.", stringConverter.Convert(typeof(object), "The quick brown fox jumps over the lazy dog.")); StringBuilder stringBuilder = new StringBuilder("Hello, World!"); Assert.True(stringBuilder.Equals(stringConverter.Convert(typeof(StringBuilder), "Hello, World!") as StringBuilder)); stringBuilder = new StringBuilder("The quick brown fox"); stringBuilder.Append(" jumps over the lazy dog."); Assert.True(stringBuilder.Equals(stringConverter.Convert(typeof(StringBuilder), "The quick brown fox jumps over the lazy dog.") as StringBuilder)); }
public void NullValueException() { var ex = Assert.Throws <ArgumentNullException>(() => { converter.Convert(null, typeof(int)); }); Assert.Equal("source", ex.ParamName); }
static void Main(string[] args) { string path = ConfigurationManager.AppSettings["path"]; var fileGenerator = new RandomCharsFileGenerator(path); StringConverter sc = new StringConverter(); Stopwatch sw = new Stopwatch(); for (int i = 1, power = 1; i <= 5; i++) { var contentLength = 10 * power; fileGenerator.GenerateFiles(1, contentLength); power *= 10; string source = File.ReadAllText(path); sw.Start(); sc.Convert(source, Int32.MaxValue); sw.Stop(); Console.WriteLine($"Content length {contentLength}. Time in milliseconds {sw.ElapsedMilliseconds}."); sw.Reset(); } Console.ReadKey(); }
public void Convert_User() { string received = StringConverter.Convert(User.InstantiateUser("Pete Bondourant")); string expected = "Id=<0>,Login=<Pete Bondourant>"; Assert.AreEqual(expected, received); }
public void Convert_OrphanedMedia() { string received = StringConverter.Convert(Media.InstantiateOrphanedMedia(MediaType.Book, "LA Confidential", "Crime Fiction")); string expected = "Description=<Crime Fiction>,Id=<0>,Library=<null>,Name=<LA Confidential>,Type=<Book>"; Assert.AreEqual(expected, received); }
public void Default(object input, string output, string locale = null) { var converter = new StringConverter(locale != null ? new CultureInfo(locale) : null); var result = converter.Convert(input); Assert.AreEqual(output, result); }
public void Convert_ThrowsWhenNotRecognizedType() { var teststr = new DateTime(); var conv = new StringConverter(); Assert.Throws <FormatException>(() => conv.Convert(new AttributeValueList(teststr))); }
public void Convert_ReturnString_WhenUnicodeString() { var py = Python.Instance(); var pyStr = py.Eval("u\"unicode string\""); var converter = new StringConverter(); Assert.AreEqual("unicode string", converter.Convert(pyStr)); }
public void Convert_ThrowsException_WhenNotUnicodeOrString() { var py = Python.Instance(); var pyInt = py.Eval("55"); var converter = new StringConverter(); Assert.Throws<ConversionException>(() => converter.Convert(pyInt)); }
public void Convert_CanConvertSimpleString() { var teststr = "some thing"; var conv = new StringConverter(); var converted = conv.Convert(new AttributeValueList(teststr)); Assert.Equal(teststr, converted); }
public void Convert_Library() { Library library = Library.InstantiateLibrary(); string received = StringConverter.Convert(library); string expected = "Id=<" + library.Id.ToString() + ">"; Assert.AreEqual(expected, received); }
public void Convert_WrongTestNnull_NUnit() { StringConverter stringConverter = new StringConverter(); string s = "Привет Епам!"; Assert.Throws <ArgumentOutOfRangeException>(() => stringConverter.Convert(s, 0)); }
public void Convert_Media() { Library library = Library.InstantiateLibrary(); Media media = library.Create(Media.InstantiateOrphanedMedia(MediaType.Book, "Refactoring", "Programming")); string received = StringConverter.Convert(media); string expected = "Description=<Programming>,Id=<0>,Library=<Id=<" + library.Id.ToString() + ">>,Name=<Refactoring>,Type=<Book>"; Assert.AreEqual(expected, received); }
public void Convert_CanConvertUtf8Bytes() { var teststr = "some thing"; var strBytes = Encoding.UTF8.GetBytes(teststr); var conv = new StringConverter(); var converted = conv.Convert(new AttributeValueList(new[] { strBytes })); Assert.Equal(teststr, converted); }
/// <summary> /// Resolve object from context. /// </summary> /// <param name="context"></param> /// <returns></returns> public object Resolve(IBuilderContext context) { object value; StepSynchronizationManager.GetContext().GetStepExecutionContext().TryGetValue(_propertyName, out value); if (value == null) { throw new InvalidOperationException(string.Format("Failed to get property {0} in step context.", _propertyName)); } return(value is T ? (T)value : StringConverter.Convert <T>(value.ToString())); }
public void TrimStartEnd(string input, string expected, bool?option = null) { var converter = new StringConverter(new CultureInfo("hu-HU")); if (option != null) { converter.TrimStartEnd = option.Value; } var result = converter.Convert(input); Assert.AreEqual(expected, result); }
public void RemoveLineBreaks(string input, string expected, bool?option = null) { var converter = new StringConverter(new CultureInfo("hu-HU")); if (option != null) { converter.RemoveLineBreaks = option.Value; } var result = converter.Convert(input); Assert.AreEqual(expected, result); }
public void Conversion() { // Arrange IConverter converter = new StringConverter(); var expectedValue = "value"; // Act var actualValue = converter.Convert(expectedValue, converter.TargetType); // Assert Assert.NotNull(actualValue); Assert.IsType <string>(actualValue); Assert.Equal(expectedValue, (string)actualValue); }
public void test_string_converter_always_pick_a_random_matched_rule() { var converter = new StringConverter(_rules); converter.RuleSelector = (rules) => { var random = new Random((int)DateTime.Now.Ticks); return(rules[random.Next(rules.Count)]); }; var result = converter.Convert("CBABC"); Assert.AreEqual(result, "CAC"); }
public void test_string_converter_always_pick_the_first_matched_rule() { var converter = new StringConverter(_rules); converter.RuleSelector = (rules) => { rules = rules.OrderBy(x => x.Key).ToList(); foreach (var r in rules) { Console.Write("{0}:{1},", r.Key, r.Value); } Console.WriteLine(); return(rules[0]); }; var result = converter.Convert("CBABC"); Assert.AreEqual(result, "CAC"); }
public void ShouldReturnByteArray() { var converter = new StringConverter(); const string data = "test"; var bytes = converter.Convert(data).ToArray(); const int dataLengthBytes = 2; const int unicode = 2; bytes.Should().HaveCount(dataLengthBytes + data.Length * unicode); bytes[0].Should().Be(0x08); bytes[1].Should().Be(0x00); bytes[2].Should().Be(0x74); bytes[3].Should().Be(0x00); bytes[4].Should().Be(0x65); bytes[5].Should().Be(0x00); bytes[6].Should().Be(0x73); bytes[7].Should().Be(0x00); bytes[8].Should().Be(0x74); bytes[9].Should().Be(0x00); }
public string ConvertTests(string source, int cout) => StringConverter.Convert(source, cout);
public string Convert_InputCorrect2_Nunit(string s, int n) { StringConverter stringConverter = new StringConverter(); return(stringConverter.Convert(s, n)); }
public void Convert_WrongTestEmptyString_NUnit() { StringConverter stringConverter = new StringConverter(); Assert.Throws <ArgumentNullException>(() => stringConverter.Convert(string.Empty, 1)); }
public void Convert_WrongTest_NUnit() { StringConverter stringConverter = new StringConverter(); Assert.Throws <ArgumentNullException>(() => stringConverter.Convert(null, 2)); }
public void TestConvertStringUInt() { Assert.AreEqual(4294967295, StringConverter.Convert <uint>("4294967295")); }
public void TestConvertStringUShort() { Assert.AreEqual((ushort)65535, StringConverter.Convert <ushort>("65535")); }
public void TestConvertStringFloat() { Assert.AreEqual(5.3f, StringConverter.Convert <float>("5.3")); }
public void TestConvertStringSByte() { Assert.AreEqual((sbyte)-128, StringConverter.Convert <sbyte>("-128")); }
public void Convert_SourceIsInvalid_ThrowArgumentException() { Assert.Throws <ArgumentException>(() => StringConverter.Convert(null, 9)); Assert.Throws <ArgumentException>(() => StringConverter.Convert(string.Empty, 9)); Assert.Throws <ArgumentException>(() => StringConverter.Convert(" ", 9)); }
public void Convert_CountIsInvalid_ThrowArgumentException() { Assert.Throws <ArgumentException>(() => StringConverter.Convert("hello", -9)); }
public void Convert_ReturnString_WhenAnsiString() { var py = Python.Instance(); var pyStr = py.Eval("\"ansi string\""); var converter = new StringConverter(); Assert.AreEqual("ansi string", converter.Convert(pyStr)); }