I have the following piece of code from a unit test:
[Test]
public void ValidCancel_ReturnsSuccess()
{
// TODO: Rewrite this action to really check the cancel
bool cancel;
var message =
new MessageHubCancellableGenericMessage<string>(this, "Test", () => cancel = true);
Assert.IsNotNull(message.Sender);
Assert.IsNotNull(message.Content);
}
MessageHubCancellableGenericMessage
is a constructor that receives a sender
, a content
and a Action
to perform as arguments. In the third argument I am changing the variable cancel
to true
. The detail here is that if I want to do a Assert.IsTrue
of the variable it brings false
. Is there a way to check that change in the variable, or is it not possible?
This is the class I'm trying:
using System;
public abstract class MessageHubMessageBase : IMessageHubMessage
{
private readonly WeakReference _sender;
protected MessageHubMessageBase(object sender)
{
if (sender == null)
throw new ArgumentNullException(nameof(sender));
_sender = new WeakReference(sender);
}
public object Sender => _sender?.Target;
}
public class MessageHubGenericMessage<TContent>
: MessageHubMessageBase
{
public MessageHubGenericMessage(object sender, TContent content)
: base(sender)
{
Content = content;
}
public TContent Content { get; protected set; }
}
public class MessageHubCancellableGenericMessage<TContent>
: MessageHubMessageBase
{
public MessageHubCancellableGenericMessage(object sender, TContent content, Action cancelAction)
: base(sender)
{
Content = content;
Cancel = cancelAction ?? throw new ArgumentNullException(nameof(cancelAction));
}
public Action Cancel { get; protected set; }
public TContent Content { get; protected set; }
}