public static void AreEqual(IDataItem expected, IDataItem actual) { var expectedNames = expected.GetFieldNames(); Assert.IsNotNull(expectedNames, Resources.NullExpectedFieldNames); var actualNames = actual.GetFieldNames(); Assert.IsNotNull(actualNames, Resources.NullActualFieldNames); CollectionAssert.AreEquivalent(expectedNames.ToArray(), actualNames.ToArray(), Resources.InvalidFieldNames); foreach (var fieldName in expectedNames) { var expectedValue = expected.GetValue(fieldName); var actualValue = actual.GetValue(fieldName); if (expectedValue is IDataItem) { Assert.IsTrue(actualValue is IDataItem, Resources.InvalidDataItemFieldValue); AreEqual((IDataItem)expectedValue, (IDataItem)actualValue); } else { if (expectedValue != null && expectedValue.GetType().IsValueType) { // Try change type to expected for value types to workaround DocumentDB deserialization issue (Int32 are becoming Int64) try { actualValue = Convert.ChangeType(actualValue, expectedValue.GetType(), CultureInfo.InvariantCulture); } catch { } } Assert.AreEqual(expectedValue, actualValue, Resources.InvalidFieldValue); } } }
public void KeepsOnlyIntersectionIncludingRightNumberOfDuplicatesAndExcludesBadItems() { DataBinding[] bindings = new DataBinding[] { new DataBinding(0, null) }; IDataProvider[] providers = new IDataProvider[] { Mocks.StrictMock <IDataProvider>(), Mocks.StrictMock <IDataProvider>(), Mocks.StrictMock <IDataProvider>() }; using (Mocks.Record()) { IDataItem badItem = Mocks.StrictMock <IDataItem>(); Expect.Call(badItem.GetValue(bindings[0])).Throw(new InvalidOperationException("Test exception")); Expect.Call(providers[0].GetItems(bindings, true)).Return(new IDataItem[] { new ScalarDataItem <int>(1, null, false), new ScalarDataItem <int>(2, null, true), new ScalarDataItem <int>(1, null, false), new ScalarDataItem <int>(3, null, false), new ScalarDataItem <int>(6, null, false), }); Expect.Call(providers[1].GetItems(bindings, true)).Return(new IDataItem[] { new ScalarDataItem <int>(1, null, false), new ScalarDataItem <int>(1, null, false), badItem, new ScalarDataItem <int>(2, null, true), new ScalarDataItem <int>(6, null, false), new ScalarDataItem <int>(1, null, false), new ScalarDataItem <int>(4, null, false), }); Expect.Call(providers[2].GetItems(bindings, true)).Return(new IDataItem[] { new ScalarDataItem <int>(1, null, false), new ScalarDataItem <int>(1, null, false), new ScalarDataItem <int>(5, null, false), new ScalarDataItem <int>(3, null, false), new ScalarDataItem <int>(2, null, true) }); } using (Mocks.Playback()) { List <IDataItem> items = new List <IDataItem>(IntersectionMergeStrategy.Instance.Merge(providers, bindings, true)); Assert.Count(3, items); Assert.AreEqual(1, items[0].GetValue(bindings[0])); Assert.IsFalse(items[0].IsDynamic); Assert.AreEqual(1, items[1].GetValue(bindings[0])); Assert.IsFalse(items[1].IsDynamic); Assert.AreEqual(2, items[2].GetValue(bindings[0])); Assert.IsTrue(items[2].IsDynamic); } }
protected override object GetValueImpl(DataBinding binding) { if (binding == null) { throw new ArgumentNullException("binding"); } return(item.GetValue(source.TranslateBinding(binding))); }
protected static void VerifyDataItem(IReadOnlyDictionary<string, object> expected, IDataItem actual) { var actualColumns = actual.GetFieldNames().ToList(); foreach (var key in expected.Keys) { Assert.IsTrue(actualColumns.Contains(key), TestResources.PropertyMissingFormat, key); Assert.AreEqual(expected[key], actual.GetValue(key), TestResources.InvalidPropertyValueFormat, key); } }
protected static void VerifyDataItem(IReadOnlyDictionary <string, object> expected, IDataItem actual) { var actualColumns = actual.GetFieldNames().ToList(); foreach (var key in expected.Keys) { Assert.IsTrue(actualColumns.Contains(key), TestResources.PropertyMissingFormat, key); Assert.AreEqual(expected[key], actual.GetValue(key), TestResources.InvalidPropertyValueFormat, key); } }
private static object[] GetValues(IDataItem item, ICollection <DataBinding> bindings) { try { return(GenericCollectionUtils.ConvertAllToArray <DataBinding, object>(bindings, delegate(DataBinding binding) { return item.GetValue(binding); })); } catch { return(null); } }
public void GetValueCallsRowsGetValueWithTheBinding() { IDataItem item = Mocks.StrictMock <IDataItem>(); DataBinding binding = new DataBinding(0, null); using (Mocks.Record()) { Expect.Call(item.GetValue(binding)).Return(42); } using (Mocks.Playback()) { BoundDataAccessor accessor = new BoundDataAccessor(binding); Assert.AreEqual(42, accessor.GetValue(item)); } }
public void EliminatesDuplicatesAndIncludesBadItems() { DataBinding[] bindings = new DataBinding[] { new DataBinding(0, null) }; IDataProvider[] providers = new IDataProvider[] { Mocks.StrictMock <IDataProvider>(), Mocks.StrictMock <IDataProvider>(), Mocks.StrictMock <IDataProvider>() }; using (Mocks.Record()) { IDataItem badItem = Mocks.StrictMock <IDataItem>(); Expect.Call(badItem.GetValue(bindings[0])).Repeat.Twice().Throw(new InvalidOperationException("Test exception")); Expect.Call(providers[0].GetItems(bindings, true)).Return(new IDataItem[] { new ScalarDataItem <int>(1, null, true), new ScalarDataItem <int>(1, null, true), new ScalarDataItem <int>(2, null, false), }); Expect.Call(providers[1].GetItems(bindings, true)).Return(EmptyArray <IDataItem> .Instance); Expect.Call(providers[2].GetItems(bindings, true)).Return(new IDataItem[] { badItem, new ScalarDataItem <int>(3, null, true), new ScalarDataItem <int>(2, null, true) }); } using (Mocks.Playback()) { List <IDataItem> items = new List <IDataItem>(UnionMergeStrategy.Instance.Merge(providers, bindings, true)); Assert.Count(4, items); Assert.AreEqual(1, items[0].GetValue(bindings[0])); Assert.IsTrue(items[0].IsDynamic); Assert.AreEqual(2, items[1].GetValue(bindings[0])); Assert.IsFalse(items[1].IsDynamic); Assert.Throws <InvalidOperationException>(delegate { items[2].GetValue(bindings[0]); }); Assert.AreEqual(3, items[3].GetValue(bindings[0])); Assert.IsTrue(items[3].IsDynamic); } }
private static int GetDataItemHash(IDataItem dataItem) { var result = 0; foreach (var fieldName in dataItem.GetFieldNames()) { var value = dataItem.GetValue(fieldName); if (value == null) continue; result ^= fieldName.GetHashCode() ^ ( value is IDataItem ? GetDataItemHash((IDataItem)value) : GetValueHashCode(value)); } return result; }
private static object Bind(IDataAccessor accessor, IDataItem bindingItem, IFormatter formatter) { try { return(accessor.GetValue(bindingItem)); } catch (DataBindingException ex) { using (TestLog.Failures.BeginSection("Data binding failure")) { if (!string.IsNullOrEmpty(ex.Message)) { TestLog.Failures.WriteLine(ex.Message); } bool first = true; foreach (DataBinding binding in bindingItem.GetBindingsForInformalDescription()) { if (first) { TestLog.Failures.Write("\nAvailable data bindings for this item:\n\n"); first = false; } using (TestLog.Failures.BeginMarker(Marker.Label)) { TestLog.Failures.Write(binding); TestLog.Failures.Write(": "); } TestLog.Failures.WriteLine(bindingItem.GetValue(binding)); } if (first) { TestLog.Failures.Write("\nThis item does not appear to provide any data bindings.\n"); } } throw new SilentTestException(TestOutcome.Error); } }
public static void AreEqual(IDataItem expected, IDataItem actual) { var expectedNames = expected.GetFieldNames(); Assert.IsNotNull(expectedNames, Resources.NullExpectedFieldNames); var actualNames = actual.GetFieldNames(); Assert.IsNotNull(actualNames, Resources.NullActualFieldNames); CollectionAssert.AreEquivalent(expectedNames.ToArray(), actualNames.ToArray(), Resources.InvalidFieldNames); foreach (var fieldName in expectedNames) { var expectedValue = expected.GetValue(fieldName); var actualValue = actual.GetValue(fieldName); CheckItem(expectedValue, actualValue); } }
private static int GetDataItemHash(IDataItem dataItem) { var result = 0; foreach (var fieldName in dataItem.GetFieldNames()) { var value = dataItem.GetValue(fieldName); if (value == null) { continue; } result ^= fieldName.GetHashCode() ^ ( value is IDataItem ? GetDataItemHash((IDataItem)value) : GetValueHashCode(value)); } return(result); }
/// <inheritdoc /> protected override object GetValueImpl(IDataItem item) { object value = item.GetValue(binding); return value; }
/// <inheritdoc /> protected override object GetValueImpl(IDataItem item) { object value = item.GetValue(binding); return(value); }
public object GetValue(string fieldName) { return(dataItem.GetValue(fieldName)); }
public virtual object GetValue(string fieldName) { Guard.NotNull("fieldName", fieldName); return(dataItem.GetValue(fieldName)); }
private static object Bind(IDataAccessor accessor, IDataItem bindingItem, IFormatter formatter) { try { return accessor.GetValue(bindingItem); } catch (DataBindingException ex) { using (TestLog.Failures.BeginSection("Data binding failure")) { if (!string.IsNullOrEmpty(ex.Message)) TestLog.Failures.WriteLine(ex.Message); bool first = true; foreach (DataBinding binding in bindingItem.GetBindingsForInformalDescription()) { if (first) { TestLog.Failures.Write("\nAvailable data bindings for this item:\n\n"); first = false; } using (TestLog.Failures.BeginMarker(Marker.Label)) { TestLog.Failures.Write(binding); TestLog.Failures.Write(": "); } TestLog.Failures.WriteLine(bindingItem.GetValue(binding)); } if (first) TestLog.Failures.Write("\nThis item does not appear to provide any data bindings.\n"); } throw new SilentTestException(TestOutcome.Error); } }
private static object[] GetValues(IDataItem item, ICollection<DataBinding> bindings) { try { return GenericCollectionUtils.ConvertAllToArray<DataBinding, object>(bindings, delegate(DataBinding binding) { return item.GetValue(binding); }); } catch { return null; } }