Comments (6)
Sadly it seems still something must be different. I tried to run it with some self imagined IEvent and INotification interfaces. Now even with exactly the ones you posted, I dont get any error.
Basically I did create a new .NET 7 console app, added NSubstitute NuGet package and pasted in basically your code:
using NSubstitute;
internal class Program
{
private static INotificationRecipientsProvider<CreatedEvent, Source> _recipientProviderMock;
static void Main(string[] args)
{
WithRecipients(Enumerable.Empty<string>());
}
private static void WithRecipients(IEnumerable<string> recipients)
{
_recipientProviderMock = Substitute.For<INotificationRecipientsProvider<CreatedEvent, Source>>();
_recipientProviderMock
.NotificationRecipients(Arg.Any<CreatedEvent>())
.Returns(x => recipients?.ToList());
}
}
public interface IEvent<T>
{
string Description { get; }
T Payload { get; }
}
public interface INotification
{
string NotificationType { get; }
long Key { get; }
string Operation { get; }
IDictionary<string, object> Properties { get; }
INotification CreateSnapshot();
}
public interface INotificationRecipientsProvider<T, E>
where T : EventBase<E>
where E : class
{
IList<string> NotificationRecipients(T notificastionEvent);
}
public abstract class EventBase<T> : IEvent<T>, INotification
{
protected EventBase(T payload)
{
Payload = payload;
}
public abstract string Description { get; }
public T Payload { get; }
public abstract string NotificationType { get; }
public abstract long Key { get; }
public abstract string Operation { get; }
public abstract IDictionary<string, object> Properties { get; }
public abstract INotification CreateSnapshot();
}
public class Source
{
}
public class CreatedEvent : EventBase<Source>
{
public CreatedEvent(Source source)
: base(source)
{
}
public override string Description => throw new NotImplementedException();
public override string NotificationType => throw new NotImplementedException();
public override long Key => throw new NotImplementedException();
public override string Operation => throw new NotImplementedException();
public override IDictionary<string, object> Properties => throw new NotImplementedException();
public override INotification CreateSnapshot()
{
throw new NotImplementedException();
}
}
And I dont get any excpetion. So it is hard to help, if you cannot reproduce the error.
from nsubstitute.
I am lacking the definitions for IEvent and INotification.
Can you provide a working sample to reproduce or at least tell what other sources are needed?
from nsubstitute.
@Ergamon although I am not sure these interfaces are in any way interesting (meaning you could remove the inheritance) this is IEvent definition
public interface IEvent<T> { string Description { get; } T Payload { get; } }
And this is INotification:
public interface INotification { string NotificationType { get; } long Key { get; } string Operation { get; } IDictionary<string, object> Properties { get; } INotification CreateSnapshot(); }
I hope this helps, if not please let me know what else is missing
from nsubstitute.
@hi Ergamon. Thank you for your time. I have done a similar setup, extracting all the classes to a simple test project and the setup does not fail. I even you the same events and entities as payload for the event. This is a concern as this means that there is some reference or project configuration in the real life scenario that causes this weird behaviour.
from nsubstitute.
Hi @Ergamon I finally managed to sort this out. I had to download NSubstitute latest code and debug.
It was a very tricky one. With Moq it is a common practice to use statements like:
T x = It.IsAny<T>();
which results in setting the default value of T.
This is used to "declare" that we do not care for the value x and can be any value.
Doing the equivalent (T x = Arg.Any<T>();
) SHOULD NEVER be used with NSubstitute because it adds T as argument definition in the thread context and will be added to the potential argument matches for the next setup.
This is where Int32 was coming from
from nsubstitute.
Thank you for looking into this @Ergamon and I have to apologise for not providing all the test setup code, but it seemed really irrelevant and "innocent".
from nsubstitute.
Related Issues (20)
- Is there a way of automatically auto generate mocks for a service? HOT 2
- Substitute not called, if argument variable is also out variable HOT 2
- Substiture for ILoggerFactory.CreateLogger<T> HOT 2
- NSubstitute/Castle proxy fail to create substitute that returns a derived class from abstract that satisfies interface implicitly HOT 5
- Return for specific args: Arrays HOT 2
- NSubstitute Received() throws System.NullReferenceException on Grpc mocked call HOT 4
- RobiniaDocs API Explorer
- Unable to replace Moq IsAnyType() to Arg.AnyType HOT 1
- `Arg.Any<T>()` behaves strangely when it's stored in a variable instead of being passed directly
- Properties from a substitute object are empty when accessing in a Received.InOrder bloc
- Create a spy of Func<> and make it return a specific value for testing HOT 3
- Compatibility issue with XUnit's `IClassFixture` HOT 2
- Cannot mock an interface method that returns a generic collection with dynamic type HOT 2
- Assertion passes when an argument is used from the substitute itself HOT 1
- Missing/Old explanation in documentation for exception extensions HOT 3
- Customize SubstituteFactory. HOT 3
- NSubstitute seems not to recognize the parameter order correctly (string default method parameter null) HOT 1
- Mocked Method returning null? HOT 1
- Compiler error when using Arg.Is<Arg.AnyType> HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nsubstitute.