コード例 #1
0
        /// <summary>
        /// Asserts that an object has not raised a particular event.
        /// </summary>
        /// <param name="eventSource">The object exposing the event.</param>
        /// <param name="eventName">
        /// The name of the event that should not be raised.
        /// </param>
        /// <param name="because">
        /// A formatted phrase explaining why the assertion should be satisfied. If the phrase does not
        /// start with the word <i>because</i>, it is prepended to the message.
        /// </param>
        /// <param name="reasonArgs">
        /// Zero or more values to use for filling in any <see cref="string.Format(string,object[])"/> compatible placeholders.
        /// </param>
        /// <remarks>
        /// You must call <see cref="MonitorEvents"/> on the same object prior to this call so that Fluent Assertions can
        /// subscribe for the events of the object.
        /// </remarks>
        public static void ShouldNotRaise(
            this object eventSource, string eventName, string because, params object[] reasonArgs)
        {
            EventRecorder eventRecorder = eventSource.GetRecorderForEvent(eventName);

            if (eventRecorder.Any())
            {
                Execute.Assertion
                .BecauseOf(because, reasonArgs)
                .FailWith("Expected object {0} to not raise event {1}{reason}, but it did.", eventSource, eventName);
            }
        }
コード例 #2
0
        /// <summary>
        /// Asserts that an object has raised a particular event at least once.
        /// </summary>
        /// <param name="eventSource">The object exposing the event.</param>
        /// <param name="eventName">
        /// The name of the event that should have been raised.
        /// </param>
        /// <param name="reason">
        /// A formatted phrase explaining why the assertion should be satisfied. If the phrase does not
        /// start with the word <i>because</i>, it is prepended to the message.
        /// </param>
        /// <param name="reasonArgs">
        /// Zero or more values to use for filling in any <see cref="string.Format(string,object[])"/> compatible placeholders.
        /// </param>
        /// <remarks>
        /// You must call <see cref="MonitorEvents"/> on the same object prior to this call so that Fluent Assertions can
        /// subscribe for the events of the object.
        /// </remarks>
        public static EventRecorder ShouldRaise(
            this object eventSource, string eventName, string reason, params object[] reasonArgs)
        {
            EventRecorder eventRecorder = eventSource.GetRecorderForEvent(eventName);

            if (!eventRecorder.Any())
            {
                Execute.Assertion
                .BecauseOf(reason, reasonArgs)
                .FailWith("Expected object {0} to raise event {1}{reason}, but it did not.", eventSource, eventName);
            }

            return(eventRecorder);
        }
コード例 #3
0
        /// <summary>
        /// Asserts that an object has not raised the <see cref="INotifyPropertyChanged.PropertyChanged"/> event for a particular property.
        /// </summary>
        /// <param name="eventSource">The object exposing the event.</param>
        /// <param name="propertyExpression">
        /// A lambda expression referring to the property for which the property changed event should have been raised.
        /// </param>
        /// <param name="reason">
        /// A formatted phrase explaining why the assertion should be satisfied. If the phrase does not
        /// start with the word <i>because</i>, it is prepended to the message.
        /// </param>
        /// <param name="reasonArgs">
        /// Zero or more values to use for filling in any <see cref="string.Format(string,object[])"/> compatible placeholders.
        /// </param>
        /// <remarks>
        /// You must call <see cref="MonitorEvents"/> on the same object prior to this call so that Fluent Assertions can
        /// subscribe for the events of the object.
        /// </remarks>
        public static void ShouldNotRaisePropertyChangeFor <T>(
            this T eventSource, Expression <Func <T, object> > propertyExpression,
            string reason, params object[] reasonArgs)
        {
            EventRecorder eventRecorder = eventSource.GetRecorderForEvent(PropertyChangedEventName);

            string propertyName = propertyExpression.GetPropertyInfo().Name;

            if (eventRecorder.Any(@event => GetAffectedPropertyName(@event) == propertyName))
            {
                Execute.Assertion
                .BecauseOf(reason, reasonArgs)
                .FailWith("Did not expect object {0} to raise the {1} event for property {2}{reason}, but it did.",
                          eventSource, PropertyChangedEventName, propertyName);
            }
        }
コード例 #4
0
        /// <summary>
        /// Asserts that an object has raised the <see cref="INotifyPropertyChanged.PropertyChanged"/> event for a particular property.
        /// </summary>
        /// <param name="eventSource">The object exposing the event.</param>
        /// <param name="propertyExpression">
        /// A lambda expression referring to the property for which the property changed event should have been raised, or
        /// <c>null</c> to refer to all properties.
        /// </param>
        /// <param name="reason">
        /// A formatted phrase explaining why the assertion should be satisfied. If the phrase does not
        /// start with the word <i>because</i>, it is prepended to the message.
        /// </param>
        /// <param name="reasonArgs">
        /// Zero or more values to use for filling in any <see cref="string.Format(string,object[])"/> compatible placeholders.
        /// </param>
        /// <remarks>
        /// You must call <see cref="MonitorEvents"/> on the same object prior to this call so that Fluent Assertions can
        /// subscribe for the events of the object.
        /// </remarks>
        public static IEventRecorder ShouldRaisePropertyChangeFor <T>(
            this T eventSource, Expression <Func <T, object> > propertyExpression,
            string reason, params object[] reasonArgs)
        {
            EventRecorder eventRecorder = eventSource.GetRecorderForEvent(PropertyChangedEventName);
            string        propertyName  = (propertyExpression != null) ? propertyExpression.GetPropertyInfo().Name : null;

            if (!eventRecorder.Any())
            {
                Execute.Assertion
                .BecauseOf(reason, reasonArgs)
                .FailWith("Expected object {0} to raise event {1} for property {2}{reason}, but it did not.",
                          eventSource, PropertyChangedEventName, propertyName);
            }

            return(eventRecorder.WithArgs <PropertyChangedEventArgs>(args => args.PropertyName == propertyName));
        }
コード例 #5
0
ファイル: ObjectExtensions.cs プロジェクト: Galad/Hanno
        public static void NotRaisedWithArgs <TEventArgs>(this EventRecorder recorder, Func <TEventArgs, bool> predicate)
        {
            var hasEvent = recorder.Any(r =>
            {
                var args = r.Parameters.FirstOrDefault(p => typeof(TEventArgs).GetTypeInfo().IsAssignableFrom(p.GetType()));
                if (args == null)
                {
                    return(false);
                }
                return(predicate((TEventArgs)args));
            });

            if (hasEvent)
            {
                Assert.Fail("{0} should have not raised event {1} with predicate but it did", recorder.EventObject, recorder.EventName);
            }
        }
コード例 #6
0
        /// <summary>
        /// Asserts that an object has not raised a particular event.
        /// </summary>
        /// <param name="eventSource">The object exposing the event.</param>
        /// <param name="eventName">
        /// The name of the event that should not be raised.
        /// </param>
        /// <param name="reason">
        /// A formatted phrase explaining why the assertion should be satisfied. If the phrase does not
        /// start with the word <i>because</i>, it is prepended to the message.
        /// </param>
        /// <param name="reasonArgs">
        /// Zero or more values to use for filling in any <see cref="string.Format(string,object[])"/> compatible placeholders.
        /// </param>
        /// <remarks>
        /// You must call <see cref="MonitorEvents"/> on the same object prior to this call so that Fluent Assertions can
        /// subscribe for the events of the object.
        /// </remarks>
        public static void ShouldNotRaise(
            this object eventSource, string eventName, string reason, params object[] reasonArgs)
        {
            EventRecorder eventRecorder = eventRecordersMap[eventSource].FirstOrDefault(r => r.EventName == eventName);

            if (eventRecorder == null)
            {
                string typeName = null;
                typeName = eventSource.GetType().Name;
                throw new InvalidOperationException(string.Format(
                                                        "Type <{0}> does not expose an event named \"{1}\".", typeName, eventName));
            }

            if (eventRecorder.Any())
            {
                Execute.Assertion
                .BecauseOf(reason, reasonArgs)
                .FailWith("Expected object {0} to not raise event {1}{reason}, but it did.", eventSource, eventName);
            }
        }
コード例 #7
0
 /// <summary>
 /// Determines whether this instance has state changes.
 /// </summary>
 /// <returns>
 ///   <c>true</c> if this instance has state changes; otherwise, <c>false</c>.
 /// </returns>
 public bool HasChanges()
 {
     return(_recorder.Any());
 }
コード例 #8
0
ファイル: AggregateRootEntity.cs プロジェクト: KreskaDev/DDD
 public virtual bool HasChanges()
 {
     return _recorder.Any();
 }