Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Michał Zegan
    @webczat
    also many of this is pretty logical, as in, reflection is not a c# specific api. it shouldn't technically get most of these... even some things it already got I'd say. it cannot recognize operators for example can it?
    Michał Zegan
    @webczat
    as for code dom I think this api is ... hmm deprecated?
    Daniel Cazzulino
    @kzu
    hi there folks!
    What does everyone think about moving the community support over to Discord? moq/moq4#1089
    Dominique Schuppli
    @stakx
    My trigger finger merged your PR before I saw thid post. :-D But if you're more active on Discord than here, then moving makes good sense. :+1:
    If we do move for good, would there be any way of making this chat read-only / archived after adding a final redirection message?
    Daniel Cazzulino
    @kzu
    Good point. I'll investigate if that's possible
    Michał Zegan
    @webczat
    @stakx it seems like you are able to create expression tree for a lambda accepting a span when using factories on Expression instead of just letting the compiler construct it.
    Dominique Schuppli
    @stakx
    @webczat that's interesting, I didn't know that. But where to from from there? The underlying code generation & interception strategy still don't support spans. Plus manually constructing expression trees isn't user-friendly at all, that's not really a feasible approach for using Moq from the end-user perspective. ;-(
    Michał Zegan
    @webczat
    yeah. I discovered you can do that so started to think if one could make some kind of helpers or something, but there would likely be problems along the way, spans cannot be generic arguments, etc, so not sure if the rest of moq would happily work with them if I handcrafted such a tree
    not sure where spans are special and where they are not, as in, what except this would require special handling code. and whether you could or couldn't make helpers. but it could likely break in many suptle ways
    Dominique Schuppli
    @stakx
    I know I've mentioned it a few times already, but it's a crucisl point so I'll say it again: the code generation & interception strategy that Moq 4 uses, i.e. the underlying proxy generator (DynamicProxy) does not support spans. DynamicProxy takes all method arguments and puts them in a object[] array. This cannot be done for spans because they are stack-only types that cannot be boxed (i.e. converted to object). There is no way around this.
    Michał Zegan
    @webczat
    okay. we'd have to live with that. I doupt this can change for moq5 tbh
    Dominique Schuppli
    @stakx
    Why do you doubt that? Have you investigated it?
    Michał Zegan
    @webczat
    well. not enough to be sure. on the other hand restrictions on ref structs are very problematic, for example the fact they cannot become generic arguments. I believe you can generate any method you want in IL, on the other hand the possible problem is the appropriate ... user interface. not sure if moq5 is gonna be expression based or different, I just don't fully imagine how could that work.
    Dominique Schuppli
    @stakx
    I suggest you take a closer look before making too many assumptions.
    Michał Zegan
    @webczat
    still interested, will moq5 be still expression based?
    Dominique Schuppli
    @stakx
    Michał Zegan
    @webczat
    interesting
    Michał Zegan
    @webczat
    interesting how all that works... hope it's going to be released soon :D
    bradford roarr
    @broarr
    :wave: - I'm trying to test a library that only contains concrete classes. Is there a way I can use Moq to mock those concrete classes, or do I need an interface?
    Kevin B
    @Keboo
    you can use it with concrete classes, but you will only be able to mock the virtual methods on them.
    bradford roarr
    @broarr
    Awesome, thanks!
    julian-code
    @julian-code

    Hey moq creators! Nice library. I really like it, and use it daily.

    I have alot of discussions about strict mocking vs. loose mocking. I know Loose mocking is the default. I have tried to find out why that is, but I cant seem to find anything about it. Can you explain why that is?

    I do prefer loose mocking, and just stubbing the relevant methods for my Assert. When is Strict preffered?

    Thumann
    @Thumann

    Hi, I'm trying to raise the following event but i'm getting a Parater count mismatch exception, any ideas?
    event Func<ProcessMessageEventArgs, Task> ProcessMessageAsync;

    processorMock.Raise(c => c.ProcessMessageAsync += null, new ProcessMessageEventArgs(msgMock.Object, receiverMock.Object, CancellationToken.None));

    Dominique Schuppli
    @stakx
    Without looking at this in detail, I'll hazard a guess. .NET events and async/Task don't mix. I suggest you convert your event definition to event Action<ProcessMessageEventArgs> and your handlers to [async] void methods.
    I cannot currently check, but IIRC there are different overloads of Raise. Some require an object sender argument, some don't. Make sure you're using the overload that doesn't want a sender.
    Alp
    @aysan0

    image.png

    going back to this post, I believe I have a similar issue. I have a mock that explicitly uses SetupAllProperties. Here is an example:
    (note, this mock doesn't have strict behavior, but I can add it. It is mocking myClass)

    this.myMock.SetupAllProperties()
    this.myMock.SetupGet( p => p.propertyA).Returns(<some_value>);

    Later, in the code (not in the test), there is a set on the property as following:

    myClass.propertyA = some_method_to_get_a(input1, input2, etc..);
    
    //and in another method
    
    var someTaskClass = new SomeTaskClass(myClass.propertyA);
    
    public SomeTaskClass(propertyA)
    {
          this.myProperty = propertyA
    }

    In the test code, I have an assert statement as follows:

    Assert.AreEqual(expectedA, this.SomeTaskClass.myProperty, "message here");

    In Moq 4.10.1, this worked and I believe it is due to the SetupGet method being called. I no longer have this working in version 4.15.2. I am very very new to Moq. Is there any suggestions on this?

    asked the similar question here: moq/moq4#1066 prior to finding this channel :)
    Alp
    @aysan0
    ^ ping on this in case anybody knows
    Peter G Jones
    @Jonesie

    Hi. Having problems with setup on my cache method. Im sure it's something simple but my brain is jelly.

    Task<T> GetAsync<T>(string key, Func<Task<T>> fetchValue);

    Ive got this:

    _cacheMock.Setup(m => m.GetAsync<Shard>(It.IsAny<string>(), It.IsAny<Func<Task<Shard>>>())).Returns<Func<Task<Shard>>>(async f => await f());

    But I get an error when I run the tests:

    System.ArgumentException : Invalid callback. Setup on method with 2 parameter(s) cannot invoke callback with different number of parameters (1).
    Peter G Jones
    @Jonesie
    Doh. Asking the question is sometimes enough to figure out the answer.
    _cacheMock.Setup(m => m.GetAsync<Shard>(It.IsAny<string>(), It.IsAny<Func<Task<Shard>>>())).Returns<string, Func<Task<Shard>>>(async (s,f) => await f());