public void Implementation_IsReadonly_ObservedPropertyShouldThrowException() { // Arrange Mock <IObservableProperty> nestedObservableMock = new Mock <IObservableProperty>(); nestedObservableMock.SetupGet(x => x.ObservedType).Returns(typeof(ISimpleInterface)); nestedObservableMock.Setup(x => x.GetObservedProperties()).Returns(new Dictionary <string, IObservableProperty>()); nestedObservableMock.Setup(x => x.GetObservedCollections()).Returns(new Dictionary <string, IObservableCollection>()); nestedObservableMock.Setup(x => x.TryGetMember(It.IsAny <string>(), out It.Ref <object> .IsAny)).Returns(true); var nestedObservable = (object)nestedObservableMock.Object; Mock <IObservableProperty> observableMock = new Mock <IObservableProperty>(); observableMock.Setup(x => x.GetObservedProperties()).Returns(new Dictionary <string, IObservableProperty> { [nameof(IInterfaceWithNestedObservable.NestedObservable)] = nestedObservableMock.Object }); observableMock.Setup(x => x.GetObservedCollections()).Returns(new Dictionary <string, IObservableCollection>()); observableMock.Setup(x => x.TryGetMember(It.IsAny <string>(), out nestedObservable)).Returns(true); Mock <IPropertyAccessedSubscriber> subscriberMock = new Mock <IPropertyAccessedSubscriber>(); // Act var manager = new RuntimeProxyManager <IInterfaceWithNestedObservable>(observableMock.Object, true); manager.Subscribe(subscriberMock.Object); IInterfaceWithNestedObservable impl = manager.Implementation; impl.NestedObservable.StringValue = "test"; // Assert // exc }
public void Implementation_NestedObservedProperty_NotifyAllPropertyAccessed() { // Arrange Mock <IObservableProperty> nestedObservableMock = new Mock <IObservableProperty>(); nestedObservableMock.SetupGet(x => x.ObservedType).Returns(typeof(ISimpleInterface)); nestedObservableMock.Setup(x => x.GetObservedProperties()).Returns(new Dictionary <string, IObservableProperty>()); nestedObservableMock.Setup(x => x.GetObservedCollections()).Returns(new Dictionary <string, IObservableCollection>()); nestedObservableMock.Setup(x => x.TryGetMember(It.IsAny <string>(), out It.Ref <object> .IsAny)).Returns(true); var nestedObservable = (object)nestedObservableMock.Object; Mock <IObservableProperty> observableMock = new Mock <IObservableProperty>(); observableMock.Setup(x => x.GetObservedProperties()).Returns(new Dictionary <string, IObservableProperty> { [nameof(IInterfaceWithNestedObservable.NestedObservable)] = nestedObservableMock.Object }); observableMock.Setup(x => x.GetObservedCollections()).Returns(new Dictionary <string, IObservableCollection>()); observableMock.Setup(x => x.TryGetMember(nameof(IInterfaceWithNestedObservable.NestedObservable), out nestedObservable)).Returns(true); Mock <IPropertyAccessedSubscriber> subscriberMock = new Mock <IPropertyAccessedSubscriber>(); // Act var manager = new RuntimeProxyManager <IInterfaceWithNestedObservable>(observableMock.Object); manager.Subscribe(subscriberMock.Object); IInterfaceWithNestedObservable impl = manager.Implementation; Trace.WriteLine(impl.NestedObservable.StringValue); // Assert subscriberMock.Verify(x => x.OnPropertyAccessed(It.Is <PropertyAccessedArgs>(args => args.PropertyName == nameof(IInterfaceWithNestedObservable.NestedObservable))), Times.Once); subscriberMock.Verify(x => x.OnPropertyAccessed(It.Is <PropertyAccessedArgs>(args => args.PropertyName == nameof(ISimpleInterface.StringValue))), Times.Once); }
public void Implementation_IsReadonly_ThrowException() { // Arrange Mock <IObservableProperty> observableMock = new Mock <IObservableProperty>(); observableMock.Setup(x => x.GetObservedProperties()).Returns(new Dictionary <string, IObservableProperty>()); observableMock.Setup(x => x.GetObservedCollections()).Returns(new Dictionary <string, IObservableCollection>()); observableMock.Setup(x => x.TryGetMember(It.IsAny <string>(), out It.Ref <object> .IsAny)).Returns(true); Mock <IPropertyAccessedSubscriber> subscriberMock = new Mock <IPropertyAccessedSubscriber>(); // Act var manager = new RuntimeProxyManager <ISimpleInterface>(observableMock.Object, true); manager.Subscribe(subscriberMock.Object); ISimpleInterface impl = manager.Implementation; impl.StringValue = "test"; // Assert // exc }
public void Implementation_ValueType_NotifyPropertyAccessed() { // Arrange object value = 10; Mock <IObservableProperty> observableMock = new Mock <IObservableProperty>(); observableMock.Setup(x => x.GetObservedProperties()).Returns(new Dictionary <string, IObservableProperty>()); observableMock.Setup(x => x.GetObservedCollections()).Returns(new Dictionary <string, IObservableCollection>()); observableMock.Setup(x => x.TryGetMember(nameof(ISimpleInterface.ValueTypeValue), out value)).Returns(true); Mock <IPropertyAccessedSubscriber> subscriberMock = new Mock <IPropertyAccessedSubscriber>(); // Act var manager = new RuntimeProxyManager <ISimpleInterface>(observableMock.Object); manager.Subscribe(subscriberMock.Object); ISimpleInterface impl = manager.Implementation; Trace.WriteLine(impl.ValueTypeValue); // Assert subscriberMock.Verify(x => x.OnPropertyAccessed(It.Is <PropertyAccessedArgs>(args => args.PropertyName == nameof(impl.ValueTypeValue))), Times.Once); }
public void Implementation_InterfaceWithReadonlyProperty_NotifyPropertyAccessed() { // Arrange Mock <IObservableProperty> observableMock = new Mock <IObservableProperty>(); observableMock.Setup(x => x.GetObservedProperties()).Returns(new Dictionary <string, IObservableProperty>()); observableMock.Setup(x => x.GetObservedCollections()).Returns(new Dictionary <string, IObservableCollection>()); observableMock.Setup(x => x.TryGetMember(It.IsAny <string>(), out It.Ref <object> .IsAny)).Returns(true); Mock <IPropertyAccessedSubscriber> subscriberMock = new Mock <IPropertyAccessedSubscriber>(); // Act var manager = new RuntimeProxyManager <IInterfaceWithReadonlyProperty>(observableMock.Object); manager.Subscribe(subscriberMock.Object); IInterfaceWithReadonlyProperty impl = manager.Implementation; Trace.WriteLine(impl.ReadonlyStringProperty); // Assert subscriberMock.Verify(x => x.OnPropertyAccessed(It.Is <PropertyAccessedArgs>(args => args.PropertyName == nameof(impl.ReadonlyStringProperty))), Times.Once); }