public void Filter_ReturnsNull() { // Arrange var allRewrite = new[] { GetValueProvider(rewritesKeys: true), GetValueProvider(rewritesKeys: true) }; var provider = new CompositeValueProvider(allRewrite); // Act var result = provider.Filter(); // Assert Assert.Null(result); }
public void Filter_ReturnsProvider(CompositeValueProvider provider) { // Arrange var originalProviders = provider.ToArray(); // Act var result = provider.Filter(); // Assert (does not change inner providers) var newProvider = Assert.IsType <CompositeValueProvider>(result); Assert.Equal(originalProviders, newProvider, ReferenceEqualityComparer.Instance); }
public void FilterReturnsItself_ForAnyClassRegisteredAsGenericParam(IBindingSourceMetadata metadata) { // Arrange var values = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase); var valueProvider1 = GetMockValueProvider("Test"); var valueProvider2 = GetMockValueProvider("Unrelated"); var provider = new CompositeValueProvider() { valueProvider1.Object, valueProvider2.Object }; // Act var result = provider.Filter(metadata.BindingSource); // Assert var valueProvider = Assert.IsType<CompositeValueProvider>(result); var filteredProvider = Assert.Single(valueProvider); // should not be unrelated metadata. Assert.Same(valueProvider1.Object, filteredProvider); }
public void FilterReturnsItself_ForAnyClassRegisteredAsGenericParam(IValueProviderMetadata metadata) { // Arrange var values = new Dictionary <string, object>(StringComparer.OrdinalIgnoreCase); var unrelatedMetadata = new UnrelatedValueBinderMetadata(); var valueProvider1 = GetMockValueProvider(metadata); var valueProvider2 = GetMockValueProvider(unrelatedMetadata); var provider = new CompositeValueProvider(new List <IValueProvider>() { valueProvider1.Object, valueProvider2.Object }); // Act var result = provider.Filter(metadata); // Assert var valueProvider = Assert.IsType <CompositeValueProvider>(result); var filteredProvider = Assert.Single(valueProvider); // should not be unrelated metadata. Assert.Same(valueProvider1.Object, filteredProvider); }
public void Filter_RemovesThoseThatRewrite() { // Arrange var doesNotRewrite1 = GetValueProvider(rewritesKeys: false); var doesNotRewrite2 = GetValueProvider(rewritesKeys: false); var doesNotImplement1 = GetMockValueProvider("One").Object; var doesNotImplement2 = GetMockValueProvider("Two").Object; var rewrites1 = GetValueProvider(rewritesKeys: true); var rewrites2 = GetValueProvider(rewritesKeys: true); var providers = new IValueProvider[] { doesNotRewrite1, doesNotImplement1, rewrites1, doesNotRewrite2, doesNotImplement2, rewrites2, }; var expectedProviders = new IValueProvider[] { doesNotRewrite1, doesNotImplement1, doesNotRewrite2, doesNotImplement2, }; var provider = new CompositeValueProvider(providers); // Act var result = provider.Filter(); // Assert Assert.NotSame(provider, result); var newProvider = Assert.IsType <CompositeValueProvider>(result); Assert.Equal(expectedProviders, newProvider, ReferenceEqualityComparer.Instance); }