private void AssertSchedules(IDictionary <String, long> schedules, Object[][] expected) { ScopeTestHelper.AssertEquals(expected.Length, schedules.Count); ICollection <int> matchNumber = new HashSet <int>(); foreach (KeyValuePair <string, long> entry in schedules) { bool matchFound = false; for (int i = 0; i < expected.Length; i++) { if (matchNumber.Contains(i)) { continue; } if (expected[i][0].Equals(entry.Key)) { matchFound = true; matchNumber.Add(i); if (expected[i][1] == null && entry.Value == null) { continue; } if (!expected[i][1].Equals(entry.Value)) { ScopeTestHelper.Fail("Failed to match value for key '" + entry.Key + "' expected '" + expected[i][i] + "' received '" + entry.Value + "'"); } } } if (!matchFound) { ScopeTestHelper.Fail("Failed to find key '" + entry.Key + "'"); } } }
public static void AssertEventTypeProperties( object[][] expectedValuesArr, EventType eventType, params SupportEventTypeAssertionEnum[] assertions) { var propertyDescriptors = eventType.PropertyDescriptors .OrderBy(p => p.PropertyName) .ToList(); for (var propNum = 0; propNum < expectedValuesArr.Length; propNum++) { var message = "Failed assertion for property " + propNum; var prop = propertyDescriptors[propNum]; var expectedArr = expectedValuesArr[propNum]; for (var i = 0; i < assertions.Length; i++) { var assertion = assertions[i]; var expected = expectedArr[i]; var value = assertion.GetExtractor().Invoke(prop, eventType); if (expected == typeof(object[])) { var valueAsType = (Type) value; if ((valueAsType != null) && (valueAsType.IsArray) && !valueAsType.GetElementType().IsPrimitive) { continue; } } ScopeTestHelper.AssertEquals( message + " at assertion " + assertion, expected, value); } } }
public void Verify(ExpressionScriptProvided expressionScript) { #if true var script = new StringScriptSource(expressionScript.Expression); ScopeTestHelper.AssertNotNull(script); #else throw new UnsupportedOperationException("jurassic engine is not supported outside of x86 and x64 builds"); #endif }
private static void AssertConsistencyProperties(EventType eventType) { var propertyNames = new List<string>(); IList<EventPropertyDescriptor> properties = eventType.PropertyDescriptors; for (int i = 0; i < properties.Count; i++) { string propertyName = properties[i].PropertyName; propertyNames.Add(propertyName); string failedMessage = "failed assertion for property '" + propertyName + "' "; // assert presence of descriptor ScopeTestHelper.AssertSame(properties[i], eventType.GetPropertyDescriptor(propertyName)); // test properties that can simply be in a property expression if ((!properties[i].RequiresIndex) && (!properties[i].RequiresMapKey)) { ScopeTestHelper.AssertTrue(failedMessage, eventType.IsProperty(propertyName)); ScopeTestHelper.AssertSame( failedMessage, eventType.GetPropertyType(propertyName), properties[i].PropertyType); ScopeTestHelper.AssertNotNull(failedMessage, eventType.GetGetter(propertyName)); } // test indexed property if (properties[i].IsIndexed) { string propertyNameIndexed = propertyName + "[0]"; ScopeTestHelper.AssertTrue(failedMessage, eventType.IsProperty(propertyNameIndexed)); ScopeTestHelper.AssertNotNull(failedMessage, eventType.GetPropertyType(propertyNameIndexed)); ScopeTestHelper.AssertNotNull(failedMessage, eventType.GetGetter(propertyNameIndexed)); } // test mapped property if (properties[i].RequiresMapKey) { string propertyNameMapped = propertyName + "('a')"; ScopeTestHelper.AssertTrue(failedMessage, eventType.IsProperty(propertyNameMapped)); ScopeTestHelper.AssertNotNull(failedMessage, eventType.GetPropertyType(propertyNameMapped)); ScopeTestHelper.AssertNotNull(failedMessage, eventType.GetGetter(propertyNameMapped)); } // consistent flags ScopeTestHelper.AssertFalse(failedMessage, properties[i].IsIndexed && properties[i].IsMapped); if (properties[i].RequiresIndex) { ScopeTestHelper.AssertTrue(failedMessage, properties[i].IsIndexed); } if (properties[i].RequiresMapKey) { ScopeTestHelper.AssertTrue(failedMessage, properties[i].IsMapped); } } // assert same property names EPAssertionUtil.AssertEqualsAnyOrder(eventType.PropertyNames, propertyNames.ToArray()); }
private static void AssertFragmentArray(EventBean @event, bool isNative, string propertyExpression) { var fragmentBean = (EventBean[]) @event.GetFragment(propertyExpression); FragmentEventType fragmentType = @event.EventType.GetFragmentType(propertyExpression); ScopeTestHelper.AssertTrue("failed for " + propertyExpression, fragmentType.IsIndexed); ScopeTestHelper.AssertEquals("failed for " + propertyExpression, isNative, fragmentType.IsNative); ScopeTestHelper.AssertSame( "failed for " + propertyExpression, fragmentBean[0].EventType, fragmentType.FragmentType); AssertConsistency(fragmentBean[0]); }
public static void AssertEventTypeProperties( Object[][] expectedArr, EventType eventType, params SupportEventTypeAssertionEnum[] assertions) { for (int propNum = 0; propNum < expectedArr.Length; propNum++) { string message = "Failed assertion for property " + propNum; EventPropertyDescriptor prop = eventType.PropertyDescriptors[propNum]; for (int i = 0; i < assertions.Length; i++) { SupportEventTypeAssertionEnum assertion = assertions[i]; object expected = expectedArr[propNum][i]; object value = assertion.GetExtractor().Invoke(prop, eventType); ScopeTestHelper.AssertEquals(message + " at assertion " + assertion, expected, value); } } }
/// <summary>Asserts that exactly one remove stream event was received and no insert stream events, resets the listener clearing all state and returns the received event. </summary> /// <returns>single remove-stream event</returns> public object AssertOneGetOldAndReset() { ScopeTestHelper.AssertTrue("Listener invocation not received but expected", _isInvoked); ScopeTestHelper.AssertEquals("Mismatch in the number of invocations", 1, _newDataList.Count); ScopeTestHelper.AssertEquals("Mismatch in the number of invocations", 1, _oldDataList.Count); if (_lastOldData == null) { ScopeTestHelper.Fail("No old-data events received"); } ScopeTestHelper.AssertEquals("Mismatch in the number of old-data events", 1, _lastOldData.Length); ScopeTestHelper.AssertNull("Expected no new-data events", _lastNewData); object lastNew = _lastOldData[0]; Reset(); return(lastNew); }
private static void AssertConsistencyRecursive(EventType eventType, ISet<EventType> alreadySeenTypes) { if (alreadySeenTypes.Contains(eventType)) { return; } alreadySeenTypes.Add(eventType); AssertConsistencyProperties(eventType); // test fragments foreach (EventPropertyDescriptor descriptor in eventType.PropertyDescriptors) { string failedMessage = "failed assertion for property '" + descriptor.PropertyName + "' "; if (!descriptor.IsFragment) { ScopeTestHelper.AssertNull(failedMessage, eventType.GetFragmentType(descriptor.PropertyName)); continue; } FragmentEventType fragment = eventType.GetFragmentType(descriptor.PropertyName); if (!descriptor.RequiresIndex) { ScopeTestHelper.AssertNotNull(failedMessage, fragment); if (fragment.IsIndexed) { ScopeTestHelper.AssertTrue(descriptor.IsIndexed); } AssertConsistencyRecursive(fragment.FragmentType, alreadySeenTypes); } else { fragment = eventType.GetFragmentType(descriptor.PropertyName + "[0]"); ScopeTestHelper.AssertNotNull(failedMessage, fragment); ScopeTestHelper.AssertTrue(descriptor.IsIndexed); AssertConsistencyRecursive(fragment.FragmentType, alreadySeenTypes); } } }
private static void AssertConsistencyRecursive( EventBean eventBean, ISet<EventType> alreadySeenTypes) { AssertConsistencyRecursive(eventBean.EventType, alreadySeenTypes); var properties = eventBean.EventType.PropertyDescriptors; for (var i = 0; i < properties.Count; i++) { var failedMessage = "failed assertion for property '" + properties[i].PropertyName + "' "; var propertyName = properties[i].PropertyName; // assert getter if (!properties[i].IsRequiresIndex && !properties[i].IsRequiresMapKey) { var getter = eventBean.EventType.GetGetter(propertyName); var resultGetter = getter.Get(eventBean); var resultGet = eventBean.Get(propertyName); if (resultGetter == null && resultGet == null) { // fine } else if (resultGet is XmlNodeList) { ScopeTestHelper.AssertEquals( failedMessage, ((XmlNodeList) resultGet).Count, ((XmlNodeList) resultGetter).Count); } else if (resultGet.GetType().IsArray) { ScopeTestHelper.AssertEquals( failedMessage, ((Array) resultGet).Length, ((Array) resultGetter).Length); } else { ScopeTestHelper.AssertEquals(failedMessage, resultGet, resultGetter); } if (resultGet != null) { if (resultGet is EventBean[] || resultGet is EventBean) { ScopeTestHelper.AssertTrue(properties[i].IsFragment); } else { var resultType = resultGet.GetType(); var propertyType = properties[i].PropertyType.GetBoxedType(); if ((resultType != propertyType) && !TypeHelper.IsSubclassOrImplementsInterface(resultType, propertyType)) { ScopeTestHelper.Fail(failedMessage); } } } } // fragment if (!properties[i].IsFragment) { ScopeTestHelper.AssertNull(failedMessage, eventBean.GetFragment(propertyName)); continue; } var fragmentType = eventBean.EventType.GetFragmentType(propertyName); ScopeTestHelper.AssertNotNull(failedMessage, fragmentType); // fragment can be null var fragment = eventBean.GetFragment(propertyName); if (fragment == null) { return; } if (!fragmentType.IsIndexed) { ScopeTestHelper.AssertTrue(failedMessage, fragment is EventBean); var fragmentEvent = (EventBean) fragment; AssertConsistencyRecursive(fragmentEvent, alreadySeenTypes); } else { ScopeTestHelper.AssertTrue(failedMessage, fragment is EventBean[]); var events = (EventBean[]) fragment; ScopeTestHelper.AssertTrue(failedMessage, events.Length > 0); foreach (var theEvent in events) { AssertConsistencyRecursive(theEvent, alreadySeenTypes); } } } }
private static void AssertConsistencyRecusive(EventBean eventBean, ISet<EventType> alreadySeenTypes) { AssertConsistencyRecursive(eventBean.EventType, alreadySeenTypes); IList<EventPropertyDescriptor> properties = eventBean.EventType.PropertyDescriptors; for (int i = 0; i < properties.Count; i++) { string failedMessage = "failed assertion for property '" + properties[i].PropertyName + "' "; string propertyName = properties[i].PropertyName; // assert getter if ((!properties[i].RequiresIndex) && (!properties[i].RequiresMapKey)) { EventPropertyGetter getter = eventBean.EventType.GetGetter(propertyName); object resultGetter = getter.Get(eventBean); object resultGet = eventBean.Get(propertyName); if ((resultGetter == null) && (resultGet == null)) { // fine } else if (resultGet is XmlNodeList) { ScopeTestHelper.AssertEquals( failedMessage, ((XmlNodeList) resultGet).Count, ((XmlNodeList) resultGetter).Count); } else if (resultGet is Array) { ScopeTestHelper.AssertEquals( failedMessage, ((Array) resultGet).Length, ((Array) resultGetter).Length); } else { ScopeTestHelper.AssertEquals(failedMessage, resultGet, resultGetter); } if (resultGet != null) { if (resultGet is EventBean[] || resultGet is EventBean) { ScopeTestHelper.AssertTrue(properties[i].IsFragment); } else { ScopeTestHelper.AssertTrue( failedMessage, TypeHelper.IsSubclassOrImplementsInterface( resultGet.GetType(), properties[i].PropertyType.GetBoxedType())); } } } // fragment if (!properties[i].IsFragment) { ScopeTestHelper.AssertNull(failedMessage, eventBean.GetFragment(propertyName)); continue; } object fragment = eventBean.GetFragment(propertyName); ScopeTestHelper.AssertNotNull(failedMessage, fragment); FragmentEventType fragmentType = eventBean.EventType.GetFragmentType(propertyName); ScopeTestHelper.AssertNotNull(failedMessage, fragmentType); if (!fragmentType.IsIndexed) { ScopeTestHelper.AssertTrue(failedMessage, fragment is EventBean); var fragmentEvent = (EventBean) fragment; AssertConsistencyRecusive(fragmentEvent, alreadySeenTypes); } else { ScopeTestHelper.AssertTrue(failedMessage, fragment is EventBean[]); var events = (EventBean[]) fragment; ScopeTestHelper.AssertTrue(failedMessage, events.Length > 0); foreach (EventBean theEvent in events) { AssertConsistencyRecusive(theEvent, alreadySeenTypes); } } } }