public void Test_Issue4() { var strings = new [] { "hello", "there" }; var hron = HRONSerializer.ObjectAsString(strings); List <string> resultsStrings; HRONObjectParseError[] errors; var result = HRONSerializer.TryParseObject( 100, hron.ReadLines(), out resultsStrings, out errors ); TestFor.Equality(true, result, "TryParseObject should succeed"); if (TestFor.Equality(strings.Length, resultsStrings.Count, "The length of expected and result sets should be the same")) { for (var iter = 0; iter < strings.Length; ++iter) { TestFor.Equality(strings[iter], resultsStrings[iter], "The result set should have the same value as the expected set: {0}".FormatWith(iter)); } } }
static void TestSkipListContent(int[] set, SkipList <int, string> skipList) { var result = skipList.ToArray(); if (TestFor.Equality(set.Length, result.Length, "SkipList Count must match")) { for (var index = 0; index < set.Length; index++) { var expected = set[index]; var found = result[index]; TestFor.Equality(expected, found.Key, "The key must be in the right position in skiplist"); } } for (var index = 0; index < set.Length; index++) { var expected = set[index]; var found = skipList.Find(expected); if (TestFor.Equality(true, found != null, "The key must in the skiplist".FormatWith(expected))) { TestFor.Equality(expected, found.Key, "The found node must have the right key"); TestFor.Equality(expected.ToString(CultureInfo.InvariantCulture), found.Value, "The found node must have the right value"); } } }
public void Test_EnumParsing() { { var canParseTestEnum = typeof(TestEnum).CanParseEnumValue(); if (TestFor.Equality(true, canParseTestEnum, "TestEnum must be parsable")) { object parsedValue; var parseResult = "X".TryParseEnumValue(typeof(TestEnum), out parsedValue); if ( TestFor.Equality(true, parseResult, "X must be parsable") && TestFor.Equality(true, parsedValue != null, "Parsed value must not be null") && TestFor.Equality(true, parsedValue.GetType() == typeof(TestEnum), "Parsed value must be TestEnum") ) { TestFor.Equality((int)TestEnum.X, (int)(TestEnum)parsedValue, "X must be parsable"); } var noParseResult = "None".TryParseEnumValue(typeof(TestEnum), out parsedValue); TestFor.Equality(false, noParseResult, "None must fail to parse"); TestFor.Equality(false, parsedValue != null, "None must fail to parse"); } var x = "X".ParseEnumValue(TestEnum.X); TestFor.Equality((int)TestEnum.X, (int)x, "X must be parsable"); var multiCharacter = "MultiCharacter".ParseEnumValue(TestEnum.X); TestFor.Equality((int)TestEnum.MultiCharacter, (int)multiCharacter, "MultiCharacter must be parsable"); var canParseTestNullableEnum = typeof(TestEnum?).CanParseEnumValue(); if (TestFor.Equality(true, canParseTestNullableEnum, "TestEnum? must be parsable")) { object parsedValue; var parseResult = "X".TryParseEnumValue(typeof(TestEnum?), out parsedValue); if ( TestFor.Equality(true, parseResult, "X must be parsable") && TestFor.Equality(true, parsedValue != null, "Parsed value must not be null") && TestFor.Equality(true, parsedValue.GetType() == typeof(TestEnum), "Parsed value must be TestEnum?") ) { TestFor.Equality((int)TestEnum.X, (int)((TestEnum?)parsedValue).Value, "X must be parsable"); } var noParseResult = "None".TryParseEnumValue(typeof(TestEnum?), out parsedValue); TestFor.Equality(false, noParseResult, "None must fail to parse"); TestFor.Equality(false, parsedValue != null, "None must fail to parse"); } var nx = "X".ParseEnumValue <TestEnum>(); if (TestFor.Equality(true, nx.HasValue, "X must be parsable")) { TestFor.Equality((int)TestEnum.X, (int)nx.Value, "X must be parsable"); } var nmultiCharacter = "MultiCharacter".ParseEnumValue <TestEnum>(); if (TestFor.Equality(true, nmultiCharacter.HasValue, "MultiCharacter must be parsable")) { TestFor.Equality((int)TestEnum.MultiCharacter, (int)nmultiCharacter.Value, "MultiCharacter must be parsable"); } } }
public void Test_ObjectAsString() { var dic = new Dictionary <string, object> { { "A", "AA" }, { "B", "BB" }, { "C", new Dictionary <string, object> { { "AAA", "AAAA" }, { "BBB", "BBBB" }, } }, }; var value = HRONSerializer.ObjectAsString(dic); const string testCase = @"=A AA =B BB @C =AAA AAAA =BBB BBBB" ; TestFor.Equality(testCase, value, "Serialized dictionary should have the expected value"); }
public void Disabled_Test_TaskScheduler_Basic() { var sequentialTaskScheduler = new SequentialTaskScheduler( "TestScheduler" ); var taskFactory = new TaskFactory(sequentialTaskScheduler); var usageCount = 0; var stopwatch = new Stopwatch(); stopwatch.Start(); var firstTask = taskFactory.StartNew(() => { Thread.Sleep(500); ++usageCount; }); var secondTask = taskFactory.StartNew(() => { Thread.Sleep(500); ++usageCount; }); firstTask.Wait(); secondTask.Wait(); stopwatch.Stop(); TestFor.Equality(2, usageCount, "Both tasks are expected to be executed"); TestFor.Equality(true, Math.Abs(stopwatch.ElapsedMilliseconds - 1000) < 100, "Elapsed time is expected to be around 1 sec"); sequentialTaskScheduler.DisposeNoThrow(); }
public void Test_Basic() { foreach (var testCase in TestCases) { var type = testCase.Type; var typeName = type.Name; var classDescriptor = ClassDescriptor.GetClassDescriptor(type); TestFor.Equality( testCase.IsNullable, classDescriptor.IsNullable, "{0} should {1}be nullable".FormatWith(typeName, GetNegation(testCase.IsNullable)) ); TestFor.Equality( testCase.IsListLike, classDescriptor.IsListLike, "{0} should {1}be list like".FormatWith(typeName, GetNegation(testCase.IsListLike)) ); TestFor.Equality( testCase.IsDictionaryLike, classDescriptor.IsDictionaryLike, "{0} should not {1}dictionary like".FormatWith(typeName, GetNegation(testCase.IsDictionaryLike)) ); } }
public void Test_Basic() { var test = Enumerable.Range(0, EnumerableCount); var producer = new EnumerableProducer <int> (Task.Factory, test); var queue = new ConcurrentQueue <int> (); var l = new object(); using (producer.Subscribe( queue.Enqueue, () => { lock (l) { Monitor.Pulse(l); } } )) { lock (l) { producer.Start(); Monitor.Wait(l); } } TestFor.Equality(EnumerableCount, queue.Count, "Queue must have expected count"); TestFor.Equality(true, test.SequenceEqual(queue), "Queue must be equal to test sequence"); }
public void Test_Clear() { var sortedSet = Enumerable.Range(0, TestSetSize).ToArray(); var skipList = GenerateFromSet(sortedSet); TestFor.Equality(TestSetSize, skipList.Count, "SkipList Count must be correct"); skipList.Clear(); TestFor.Equality(0, skipList.Count, "SkipList Count must be zero"); }
public void Test_ReadLines() { const string testCase = "A\r\nB\rC\nD\n\rE\n\nF\r\rG\r\r\nH\n\r\nI\r\n\rJ\n\n\rK\r\n"; using (var stringReader = new StringReader(testCase)) { var expected = stringReader.ReadLines().ToArray(); var found = testCase.ReadLines().Select(ss => ss.ToString()).ToArray(); TestFor.Equality(expected.Length + 1, found.Length, "ReadLines in the presence of ending linebreak should read one line extra compared to StringReader"); TestFor.SequenceEquality(expected, found.Take(expected.Length), "ReadLines should otherwise match StringReader behavior"); } }
public void Test_TestControl() { var testControl = new TestControl { IsValid = true }; const string testPropertyValue = "TEST"; TestControl.SetAdditional(testControl, testPropertyValue); TestFor.Equality(1, testControl.IsValidCalledCount, "IsValidCalledCount must be 1"); TestFor.Equality(testPropertyValue, TestControl.GetAdditional(testControl), "Additional property must be {0}".FormatWith(testPropertyValue)); }
public void Test_CompareWithSortedDictionary() { var sortedSet = Enumerable.Range(0, TestSetSize).ToArray(); var skipList = GenerateFromSet(sortedSet); var sortedDictionary = new SortedDictionary <int, string> (); foreach (var v in sortedSet) { sortedDictionary.Add(v, v.ToString(CultureInfo.InvariantCulture)); } var random = new Random(19740531); TestSkipListContent(sortedDictionary, skipList); for (var iter = 0; iter < TestSetSize / 10; ++iter) { var action = random.Next(0, 2); var v = random.Next(0, TestSetSize * 2); var value = v.ToString(CultureInfo.InvariantCulture); switch (action) { case 0: { var slResult = skipList.TryAdd(v, value); var sdResult = TryAdd(sortedDictionary, v, value); TestFor.Equality(sdResult, slResult, "SkipList and SortedDictionary add result must be equal"); } break; case 1: { var slResult = skipList.TryRemove(v); var sdResult = sortedDictionary.Remove(v); TestFor.Equality(sdResult, slResult, "SkipList and SortedDictionary remove result must be equal"); } break; default: break; } TestSkipListContent(sortedDictionary, skipList); } }
static SkipList <int, string> GenerateFromSet(int[] set) { set = set ?? new int[0]; var skipList = new SkipList <int, string> (); foreach (var v in set) { var addResult = skipList.TryAdd(v, v.ToString(CultureInfo.InvariantCulture)); TestFor.Equality(true, addResult, "SkipList.TryAdd ({0},'{0}') must succeed".FormatWith(v)); } return(skipList); }
static void TestSkipListContent(SortedDictionary <int, string> sortedDictionary, SkipList <int, string> skipList) { if (TestFor.Equality(sortedDictionary.Count, skipList.Count, "SkipList and SortedDictionary count must be equal")) { var firstMismatch = sortedDictionary .Zip(skipList, (l, r) => new { Left = l, Right = r }) .FirstOrDefault(uo => uo.Left.Key != uo.Right.Key) ; var leftValue = firstMismatch != null ? firstMismatch.Left.Key : 0; var rightValue = firstMismatch != null ? firstMismatch.Right.Key : 0; TestFor.Equality(true, firstMismatch == null, "SkipList and SortedDictionary content must be equal, first mismatch: {0} != {1}".FormatWith(leftValue, rightValue)); } }
public void Test_Operator() { const string left = "APA"; const string right = "APA BEPA"; var ssleft = left.ToSubString(); var ssright = right.ToSubString(); TestFor.Equality(left == right, ssleft == ssright, "Operator == must work as expected"); TestFor.Equality(left != right, ssleft != ssright, "Operator != must work as expected"); TestFor.Equality(left == left, ssleft == ssleft, "Operator == must work as expected"); TestFor.Equality(left != left, ssleft != ssleft, "Operator != must work as expected"); TestFor.Equality(right == right, ssright == ssright, "Operator == must work as expected"); TestFor.Equality(right != right, ssright != ssright, "Operator != must work as expected"); }
public void Test_Parse() { var visitor = new HRONWriterVisitor(); var lines = s_test_hron.ReadLines().ToArray(); HRONSerializer.Parse( int.MaxValue, lines, visitor ); TestFor.Equality( s_test_hron, visitor.Value, "HRON after deserialize/serialize should be identical to test case" ); }
public void Test_TryParseObject() { var lines = s_test2_hron.ReadLines().ToArray(); Config config; HRONObjectParseError[] errors; var result = HRONSerializer.TryParseObject(int.MaxValue, lines, out config, out errors); if (TestFor.Equality(true, result, "HRON should be parsed successfully")) { var value = HRONSerializer.ObjectAsString(config); TestFor.Equality( s_test2_hron, value, "HRON after deserialize/serialize to object should be identical to test case" ); } }
public void Test_Basic() { var expected = GetExpected(TestCase); var result = TestCase .TextToObjects <Customer>() .ToArray() ; if (TestFor.Equality(expected.Length, result.Length + 1, "Expected length and result length must match")) { for (var index = 0; index < result.Length; index++) { var customer = result[index]; var line = expected[index + 1]; TestFor.Equality(line[0], customer.ID, "ID must match for line: {0}".FormatWith(index)); TestFor.Equality(line[1], customer.FirstName, "FirstName must match for line: {0}".FormatWith(index)); TestFor.Equality(line[2], customer.LastName, "LastName must match for line: {0}".FormatWith(index)); } } }
public void Test_BasicTuple() { var one = new Session { Id = 101, ClientIp = "192.168.0.1", }; var two = new Session { Id = 101, ClientIp = "192.168.0.1", }; var three = new Session { Id = 201, ClientIp = "192.168.0.2", }; var asString = one.ToString(); TestFor.Equality(BasicTupleAsString, asString, "Tuple.ToString must match"); TestFor.Equality(true, one.Equals(one), "Identical tuples must match"); TestFor.Equality(false, one.Equals(two), "Structural identical tuples must not match"); TestFor.Equality(false, two.Equals(one), "Structural identical tuples must not match"); TestFor.Equality(false, one.Equals(three), "Structural non-identical tuples must not match"); TestFor.Equality(false, three.Equals(one), "Structural non-identical tuples must not match"); TestFor.Equality(true, one.GetHashCode() == one.GetHashCode(), "Identical tuples must have same hash code"); TestFor.Equality(false, one.GetHashCode() == two.GetHashCode(), "Structural identical tuples must not have same hash code"); TestFor.Equality(false, two.GetHashCode() == one.GetHashCode(), "Structural identical tuples must not have same hash code"); TestFor.Equality(false, one.GetHashCode() == three.GetHashCode(), "Structural non-identical tuples must not have same hash code"); TestFor.Equality(false, three.GetHashCode() == one.GetHashCode(), "Structural non-identical tuples must not have same hash code"); }
public void Test_Trim() { { const string testCase = "\t\t\t APA \r\n BEPA \r\n "; var ss = testCase.ToSubString(); TestFor.Equality(testCase.TrimStart(), ss.TrimStart().Value, "TrimStart must work as expected"); TestFor.Equality(testCase.TrimEnd(), ss.TrimEnd().Value, "TrimEnd must work as expected"); TestFor.Equality(testCase.Trim(), ss.Trim().Value, "Trim must work as expected"); } { const string testCase = "ABCBA"; var ss = testCase.ToSubString(); var trimChars = new [] { 'A', 'B' }; TestFor.Equality(testCase.TrimStart(trimChars), ss.TrimStart(trimChars).Value, "TrimStart must work as expected"); TestFor.Equality(testCase.TrimEnd(trimChars), ss.TrimEnd(trimChars).Value, "TrimEnd must work as expected"); TestFor.Equality(testCase.Trim(trimChars), ss.Trim(trimChars).Value, "Trim must work as expected"); } }
public void Test_TaskScheduler_ShutDown() { var sequentialTaskScheduler = new SequentialTaskScheduler( "TestScheduler" ); var taskFactory = new TaskFactory(sequentialTaskScheduler); var usageCount = 0; var firstTask = taskFactory.StartNew(() => { Thread.Sleep(500); ++usageCount; }); var secondTask = taskFactory.StartNew(() => { Thread.Sleep(500); ++usageCount; }); var stopwatch = new Stopwatch(); stopwatch.Start(); var remainingTime = new RemainingTime(TimeSpan.FromMilliseconds(4000)); sequentialTaskScheduler.ShutDown(remainingTime); stopwatch.Stop(); TestFor.Equality(true, stopwatch.ElapsedMilliseconds < 750, "Shutdwn time is expected to be less than 0.75 sec"); }
public void Test_StructuralTuple() { var one = new Customer { Id = 10L, FirstName = "A.", LastName = "Tester", Aliases = new [] { "Another", "Any" }, InvoiceAddress = new Address { Id = 100L, Address1 = "My street", Zip = "000HOME", City = "My hometown", Country = "The Motherland" }, DeliveryAddress = new Address { Id = 101L, CareOf = "My mom", Address1 = "My mom's street", Zip = "001HOME", City = "My mom's hometown", Country = "The Motherland" } }; var two = new Customer { Id = 10L, FirstName = "A.", LastName = "Tester", Aliases = new [] { "Another", "Any" }, InvoiceAddress = new Address { Id = 100L, Address1 = "My street", Zip = "000HOME", City = "My hometown", Country = "The Motherland" }, DeliveryAddress = new Address { Id = 101L, CareOf = "My mom", Address1 = "My mom's street", Zip = "001HOME", City = "My mom's hometown", Country = "The Motherland" } }; var three = new Customer { Id = 10L, FirstName = "A.", LastName = "Tester", Aliases = new [] { "Another", "Any" }, InvoiceAddress = new Address { Id = 200L, Address1 = "My street", Zip = "000HOME", City = "My hometown", Country = "The Motherland" }, DeliveryAddress = new Address { Id = 201L, CareOf = "My mom", Address1 = "My mom's street", Zip = "001HOME", City = "My mom's hometown", Country = "The Motherland" } }; var four = new Customer { Id = 20L, FirstName = "A.", LastName = "Tester", Aliases = new [] { "Another", "Any" }, InvoiceAddress = new Address { Id = 200L, Address1 = "My street", Zip = "000HOME", City = "My hometown", Country = "The Motherland" }, DeliveryAddress = new Address { Id = 201L, CareOf = "My mom", Address1 = "My mom's street", Zip = "001HOME", City = "My mom's hometown", Country = "The Motherland" } }; var asString = one.ToString(); TestFor.Equality(StructuralTupleAsString, asString, "Tuple.ToString must match"); TestFor.Equality(true, one.Equals(one), "Identical tuples must match"); TestFor.Equality(true, one.Equals(two), "Structural identical tuples must match"); TestFor.Equality(true, two.Equals(one), "Structural identical tuples must match"); TestFor.Equality(false, one.Equals(three), "Structural non-identical tuples must not match"); TestFor.Equality(false, three.Equals(one), "Structural non-identical tuples must not match"); TestFor.Equality(false, one.Equals(four), "Structural non-identical tuples must not match"); TestFor.Equality(false, four.Equals(one), "Structural non-identical tuples must not match"); TestFor.Equality(true, one.GetHashCode() == one.GetHashCode(), "Identical tuples must have same hash code"); TestFor.Equality(true, one.GetHashCode() == two.GetHashCode(), "Structural identical tuples must have same hash code"); TestFor.Equality(true, two.GetHashCode() == one.GetHashCode(), "Structural identical tuples must have same hash code"); TestFor.Equality(false, one.GetHashCode() == three.GetHashCode(), "Structural non-identical tuples must not have same hash code"); TestFor.Equality(false, three.GetHashCode() == one.GetHashCode(), "Structural non-identical tuples must not have same hash code"); TestFor.Equality(false, one.GetHashCode() == four.GetHashCode(), "Structural non-identical tuples must not have same hash code"); TestFor.Equality(false, four.GetHashCode() == one.GetHashCode(), "Structural non-identical tuples must not have same hash code"); }
public void Test_Basic() { using (var sqlConnection = new SqlConnection(@"Data Source=.\SQLEXPRESS;Initial Catalog=tempdb;Integrated Security=True")) { sqlConnection.Open(); try { ExecuteScript(sqlConnection, SetupText); var schema = new Schema(sqlConnection); using (var cmd = sqlConnection.CreateCommand()) { cmd.CommandType = CommandType.Text; cmd.CommandText = GetTypesText; var typeCount = 0; using (var reader = cmd.ExecuteReader()) { while (reader.Read()) { ++typeCount; var fullName = reader.Get("schema", "") + "." + reader.Get("name", ""); var typeDefinition = schema.FindTypeDefinition(fullName); if (TestFor.Equality(true, typeDefinition != null, "{0} must exist".FormatWith(fullName))) { TestFor.Equality(reader.Get("name", ""), typeDefinition.Name, "Name must match"); TestFor.Equality(reader.Get("system_type_id", (byte)0), typeDefinition.SystemTypeId, "SystemTypeId must match"); TestFor.Equality(reader.Get("user_type_id", 0), typeDefinition.UserTypeId, "UserTypeId must match"); TestFor.Equality(reader.Get("max_length", 0), typeDefinition.MaxLength, "MaxLength must match"); TestFor.Equality(reader.Get("precision", 0), typeDefinition.Precision, "Precision must match"); TestFor.Equality(reader.Get("scale", 0), typeDefinition.Scale, "Scale must match"); TestFor.Equality(reader.Get("is_nullable", false), typeDefinition.IsNullable, "IsNullable must match"); } } } TestFor.Equality(typeCount, schema.TypeDefinitions.Count(), "Schema type count must match"); } using (var cmd = sqlConnection.CreateCommand()) { cmd.CommandType = CommandType.Text; cmd.CommandText = GetObjectsText; var objectCount = 0; using (var reader = cmd.ExecuteReader()) { while (reader.Read()) { ++objectCount; var fullName = reader.Get("schema", "") + "." + reader.Get("name", ""); var schemaObject = schema.FindSchemaObject(fullName); if (TestFor.Equality(true, schemaObject != null, "{0} must exist".FormatWith(fullName))) { TestFor.Equality(reader.Get("object_id", 0), schemaObject.Id, "Id must match"); TestFor.Equality(reader.Get("schema", ""), schemaObject.Schema, "Schema must match"); TestFor.Equality(reader.Get("name", ""), schemaObject.Name, "Name must match"); TestFor.Equality(reader.Get("type", "").Trim(), TypeToString(schemaObject.Type), "Type must match"); TestFor.Equality(reader.Get("create_date", DateTime.MinValue), schemaObject.CreateDate, "CreateDate must match"); TestFor.Equality(reader.Get("modify_date", DateTime.MinValue), schemaObject.ModifyDate, "ModifyDate must match"); } } } TestFor.Equality(objectCount, schema.SchemaObjects.Count(), "Object count must match"); } using (var cmd = sqlConnection.CreateCommand()) { cmd.CommandType = CommandType.Text; cmd.CommandText = GetColumnsText; var columnCount = 0; using (var reader = cmd.ExecuteReader()) { while (reader.Read()) { ++columnCount; var fullName = reader.Get("object_schema", "") + "." + reader.Get("object_name", ""); var columnId = reader.Get("column_id", 0); var schemaObject = schema.FindSchemaObject(fullName); if (TestFor.Equality(true, schemaObject != null, "{0} must exist".FormatWith(fullName))) { var columnSubObject = schemaObject.Columns.FirstOrDefault(c => c.Id == columnId); if (TestFor.Equality(true, columnSubObject != null, "Column {0} must exist".FormatWith(columnId))) { TestFor.Equality(columnId, columnSubObject.Id, "Id must match"); TestFor.Equality(reader.Get("column_name", ""), columnSubObject.Name, "Name must match"); TestFor.Equality(reader.Get("type_schema", ""), columnSubObject.Type.Schema, "Type.Schema must match"); TestFor.Equality(reader.Get("type_name", ""), columnSubObject.Type.Name, "Type.Name must match"); TestFor.Equality(reader.Get("max_length", (short)0), columnSubObject.MaxLength, "MaxLength must match"); TestFor.Equality(reader.Get("precision", (short)0), columnSubObject.Precision, "Precision must match"); TestFor.Equality(reader.Get("scale", (short)0), columnSubObject.Scale, "Scale must match"); TestFor.Equality(reader.Get("collation_name", ""), columnSubObject.Collation, "Collation must match"); TestFor.Equality(reader.Get("is_nullable", false), columnSubObject.IsNullable, "IsNullable must match"); TestFor.Equality(reader.Get("is_identity", false), columnSubObject.IsIdentity, "IsIdentity must match"); TestFor.Equality(reader.Get("is_computed", false), columnSubObject.IsComputed, "IsComputed must match"); } } } } TestFor.Equality(columnCount, schema.SchemaObjects.SelectMany(o => o.Columns).Count(), "Column count must match"); } using (var cmd = sqlConnection.CreateCommand()) { cmd.CommandType = CommandType.Text; cmd.CommandText = GetParametersText; var parameterCount = 0; using (var reader = cmd.ExecuteReader()) { while (reader.Read()) { ++parameterCount; var fullName = reader.Get("object_schema", "") + "." + reader.Get("object_name", ""); var parameterId = reader.Get("parameter_id", 0); var schemaObject = schema.FindSchemaObject(fullName); if (TestFor.Equality(true, schemaObject != null, "{0} must exist".FormatWith(fullName))) { var parameterSubObject = schemaObject.Parameters.FirstOrDefault(c => c.Id == parameterId); if (TestFor.Equality(true, parameterSubObject != null, "Column {0} must exist".FormatWith(parameterId))) { TestFor.Equality(parameterId, parameterSubObject.Id, "Id must match"); TestFor.Equality(reader.Get("parameter_name", ""), parameterSubObject.Name, "Name must match"); TestFor.Equality(reader.Get("type_schema", ""), parameterSubObject.Type.Schema, "Type.Schema must match"); TestFor.Equality(reader.Get("type_name", ""), parameterSubObject.Type.Name, "Type.Name must match"); TestFor.Equality(reader.Get("max_length", (short)0), parameterSubObject.MaxLength, "MaxLength must match"); TestFor.Equality(reader.Get("precision", (short)0), parameterSubObject.Precision, "Precision must match"); TestFor.Equality(reader.Get("scale", (short)0), parameterSubObject.Scale, "Scale must match"); TestFor.Equality(reader.Get("is_output", false), parameterSubObject.IsOutput, "IsOutput must match"); } } } } TestFor.Equality(parameterCount, schema.SchemaObjects.SelectMany(o => o.Parameters).Count(), "Parameter count must match"); } } finally { ExecuteScript(sqlConnection, TearDownText); } } }
public void Test_TryParseDynamic() { var lines = s_test2_hron.ReadLines().ToArray(); dynamic dyn; HRONDynamicParseError[] errors; var result = HRONSerializer.TryParseDynamic(int.MaxValue, lines, out dyn, out errors); if (TestFor.Equality(true, result, "HRON should be parsed successfully")) { MyFlag myFlag = dyn.Common.MyFlag; MyFlag myMissingFlag = dyn.Common.MyMissingFlag; TestFor.Equality((int)MyFlag.MyFlagValue, (int)myFlag, "Expects MyFlagValue"); TestFor.Equality((int)MyFlag.MyDefaultValue, (int)myMissingFlag, "Expects the default MyFlag"); dynamic connections = dyn.DataBaseConnection; if (TestFor.Equality(2, connections.GetCount(), "Expects two database connections")) { { var connection = connections[0]; string name = connection.Name; string connectionString = connection.ConnectionString; string timeOut = connection.TimeOut; int parsedTimeOut = connection.TimeOut; int? optParsedTimeOut = connection.TimeOut; int[] arrParsedTimeOut = connection.TimeOut; TestFor.Equality( "CustomerDB", name, "Expects CustomerDB name" ); TestFor.Equality( @"Data Source=.\SQLEXPRESS;Initial Catalog=Customers", connectionString, "Expects CustomerDB connection" ); TestFor.Equality( @"10", timeOut, "Expects CustomerDB timeout" ); TestFor.Equality( 10, parsedTimeOut, "Expects parsed CustomerDB timeout" ); if (TestFor.Equality( true, optParsedTimeOut.HasValue, "Expects parsed CustomerDB timeout" )) { TestFor.Equality( 10, optParsedTimeOut.Value, "Expects parsed CustomerDB timeout" ); } if (TestFor.Equality( 1, arrParsedTimeOut.Length, "Expects parsed CustomerDB timeout" )) { TestFor.Equality( 10, arrParsedTimeOut[0], "Expects parsed CustomerDB timeout" ); } } { var connection = connections[1]; string name = connection.Name; string connectionString = connection.ConnectionString; string timeOut = connection.TimeOut; int parsedTimeOut = connection.TimeOut; int? optParsedTimeOut = connection.TimeOut; int[] arrParsedTimeOut = connection.TimeOut; TestFor.Equality( "PartnerDB", name, "Expects PartnerDB name" ); TestFor.Equality( @"Data Source=.\SQLEXPRESS;Initial Catalog=Partners", connectionString, "Expects PartnerDB connection" ); TestFor.Equality( "", timeOut, "Expects no PartnerDB timeout" ); TestFor.Equality( 0, parsedTimeOut, "Expects no parsed CustomerDB timeout" ); TestFor.Equality( false, optParsedTimeOut.HasValue, "Expects no parsed CustomerDB timeout" ); TestFor.Equality( 0, arrParsedTimeOut.Length, "Expects no parsed CustomerDB timeout" ); } } var value = HRONSerializer.DynamicAsString(dyn); TestFor.Equality( s_test2_hron, value, "HRON after deserialize/serialize to object should be identical to test case" ); } }