You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
our project tried to upgrade to the latest Moq and found an issue. Lots of our tests started failing with regards to property change notification. After some digging we isolated the issue and found the culprit. Of course, what we do not know why it was introduced or what else would be broken by it's removal.
Basically, after 4.2.1402.2112, starting with 4.2.1408.619, the following code changes it's behavior:
publicclassProgram{staticvoidMain(string[]args){EventHolderConcretetestSubject=newMock<EventHolderConcrete>{CallBase=true}.Object;vareventConsumer=newEventConsumer(testSubject);testSubject.Something="something";Console.Out.WriteLine($"{eventConsumer.Count}, should be 1");Console.ReadKey(true);}publicinterfaceIEnhancedNotifyPropertyChanged:INotifyPropertyChanged{}publicabstractclassEventHolderBase:IEnhancedNotifyPropertyChanged{publiceventPropertyChangedEventHandlerPropertyChanged;protectedvoidOnPropertyChanged(stringpropertyName){PropertyChanged?.Invoke(this,newPropertyChangedEventArgs(propertyName));}}publicclassEventHolderConcrete:EventHolderBase{publicstringSomething{get{returnthis.something;}set{this.something=value;OnPropertyChanged(nameof(Something));}}privatestringsomething;}publicclassEventConsumer{publicEventConsumer(INotifyPropertyChangedeventSource){eventSource.PropertyChanged+=EventSource_PropertyChanged;}publicintCount{get;set;}privatevoidEventSource_PropertyChanged(objectsender,PropertyChangedEventArgse){Count++;}}}
The line in the Moq source which triggers this change in behavior is: this.ImplementedInterfaces.AddRange(typeof(T).GetInterfaces().Where(i => (i.IsPublic || i.IsNestedPublic) && !i.IsImport));
It was introduced at line 115 in Mock.Generic.cs with the tag version 4.2.1408.619.
This issue might be related to: #275 Still, this is more generic as one do not need to have the same property on two interface ... a simple interface inheritance kills the tests.
Hope the bug report and the investigation will help fixing this.
Thank you,
Alpár
The text was updated successfully, but these errors were encountered:
you are right, it has been fixed in 4.5.22. Unfortunately we cannot update the project to 4.5 as of now (we have still to support .NET 4 for some time). Will keep you updated if we find any issues on the latest version after we upgrade!
Hello,
our project tried to upgrade to the latest Moq and found an issue. Lots of our tests started failing with regards to property change notification. After some digging we isolated the issue and found the culprit. Of course, what we do not know why it was introduced or what else would be broken by it's removal.
Basically, after 4.2.1402.2112, starting with 4.2.1408.619, the following code changes it's behavior:
The line in the Moq source which triggers this change in behavior is:
this.ImplementedInterfaces.AddRange(typeof(T).GetInterfaces().Where(i => (i.IsPublic || i.IsNestedPublic) && !i.IsImport));
It was introduced at line 115 in Mock.Generic.cs with the tag version 4.2.1408.619.
This issue might be related to: #275 Still, this is more generic as one do not need to have the same property on two interface ... a simple interface inheritance kills the tests.
Hope the bug report and the investigation will help fixing this.
Thank you,
Alpár
The text was updated successfully, but these errors were encountered: