Skip to content

Commit

Permalink
Implements ImplementNotifyPropertyChanged for DictionaryPropertyAcces…
Browse files Browse the repository at this point in the history
…sor (part of issue #90)
  • Loading branch information
David-Desmaisons committed Nov 6, 2018
1 parent 163d698 commit ad60792
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public sealed class DictionaryPropertyAccessor<T> : IGenericPropertyAcessor
{
public IReadOnlyList<PropertyAccessor> ReadProperties => _ReadProperties;
public IReadOnlyList<string> AttributeNames => _AttributeNames;
public ObjectObservability Observability => ObjectObservability.None;
public ObjectObservability Observability { get; }

private readonly IDictionary<string, PropertyAccessor> _PropertyAccessoresDictionary;
private readonly List<PropertyAccessor> _ReadProperties;
Expand All @@ -21,6 +21,8 @@ internal DictionaryPropertyAccessor(IDictionary<string,T> dictionary)
_ReadProperties = readProperties;
_AttributeNames = readProperties.Select(p => p.Name).ToList();
_PropertyAccessoresDictionary = ReadProperties.ToDictionary(prop => prop.Name, prop => prop);
Observability = Types.NotifyPropertyChanged.IsInstanceOfType(dictionary) ?
ObjectObservability.ImplementNotifyPropertyChanged : ObjectObservability.None;
}

public PropertyAccessor GetAccessor(string propertyName)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Dynamic;
using System.Linq;
using FluentAssertions;
using MoreCollection.Extensions;
Expand Down Expand Up @@ -37,6 +39,16 @@ public void Observability_is_none()
_DictionaryPropertyAccessor.Observability.Should().Be(ObjectObservability.None);
}

[Theory]
[InlineData(typeof(Dictionary<string, object>), ObjectObservability.None)]
[InlineData(typeof(ExpandoObject), ObjectObservability.ImplementNotifyPropertyChanged)]
public void Observability_is_acurate(Type dynamicType, ObjectObservability expected)
{
var @object = (IDictionary<string, object>)Activator.CreateInstance(dynamicType);
var dictionaryPropertyAccessor = new DictionaryPropertyAccessor<object>(@object);
dictionaryPropertyAccessor.Observability.Should().Be(expected);
}

[Fact]
public void ReadProperties_are_ordered_by_position()
{
Expand Down

0 comments on commit ad60792

Please sign in to comment.