-2
\$\begingroup\$

I have two questions.

  1. Does it make sense to test that an event will not be fired?
  2. If yes, what is the best way to accomplish that using the xUnit framework?

For example I have a class with a single property Mark,

    public class Box : INotifyPropertyChanged
    {
        private Marking mark = Marking.None;

        public Marking Mark
        {
            get
            {
                return mark;
            }
            set
            {
                mark = value;
                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Mark)));
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;
    }

and I want to test that when someone is going to set the value of Mark to the same value as the property points currently, then the PropertyChanged event will not be fired.

\$\endgroup\$
2
  • 1
    \$\begingroup\$ Cross-posted on Stack Overflow \$\endgroup\$ – Mast Apr 5 '20 at 12:49
  • 2
    \$\begingroup\$ This question does not match what this site is about. Code Review is about improving existing, working code. The example code that you have posted is not reviewable in this form because it leaves us guessing at your intentions. Unlike Stack Overflow, Code Review needs to look at concrete code in a real context. Please see Why is hypothetical example code off-topic for CR? \$\endgroup\$ – Mast Apr 5 '20 at 12:50
2
\$\begingroup\$
  1. Sound reasonable to test it. It is a logic in your application.
  2. You can do it without XUnit. You can test it by register to the event and changing a variable called eventWasFired which is initialized to false . Assert that eventWasFired is false.
\$\endgroup\$
3

Not the answer you're looking for? Browse other questions tagged or ask your own question.