public static IEventRecorder RaiseCollectionChange <T>(this EventAssertions <T> self,
                                                               object subject,
                                                               NotifyCollectionChangedEventArgs args)
        {
            var wrappedA = new NColChngEvtArgFix(args);

            bool AssertEvent(NotifyCollectionChangedEventArgs arg)
            {
                return(new NColChngEvtArgFix(arg).IsSameOrEqualTo(wrappedA));
            }

            var eventRecorder = self.Raise(nameof(INotifyCollectionChanged.CollectionChanged)).WithSender(subject);

            var targetEvents = eventRecorder.First().Parameters.OfType <NotifyCollectionChangedEventArgs>().ToList();

            if (!targetEvents.Any())
            {
                throw new ArgumentException("No argument of event " + eventRecorder.EventName + " is of type <" + (object)typeof(NotifyCollectionChangedEventArgs) + ">.");
            }

            if (!targetEvents.Any(AssertEvent))
            {
                Execute.Assertion.FailWith("Expected at least one event with arguments matching {0}, but found {1}.", args, eventRecorder.ToList());
            }
            return(eventRecorder);
        }
 public static IEventRecorder RaisePropertyChange <T>(this EventAssertions <T> self,
                                                      object subject,
                                                      string propertyName)
 {
     return(self.Raise(nameof(INotifyPropertyChanged.PropertyChanged))
            .WithSender(subject)
            .WithArgs <PropertyChangedEventArgs>(a => a.PropertyName == propertyName));
 }
示例#3
0
        public void Create_From_ObservableCollection()
        {
            var backend = new ObservableCollection <string>();
            var binding = backend.ToBinding();

            using (var monitoredBinding = binding.Monitor <INotifyCollectionChanged>())
            {
                backend.Add("first");
                EventAssertions <INotifyCollectionChanged> ass = monitoredBinding.Should();
                ass
                .RaiseCollectionChange(binding, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, BindingAssertions.AsList("first"), 0));
            }
        }