0

Getting the following error trying to use CallTo() and .Returns() on methods of interfaces.

Severity Code Description Project File Line Suppression State Error CS1929 'IReturnValueArgumentValidationConfiguration' does not contain a definition for 'Returns' and the best extension method overload 'ReturnValueConfigurationExtensions.Returns(IReturnValueConfiguration>, string)' requires a receiver of type 'IReturnValueConfiguration>' CareControls.Ivis.Tests G:\Ivis\CareControls.Ivis.Tests\Framework\AbIo\TimerHandlerTests.cs 105 Active

Here is the test: I added comments to show what kind each type was and where the compiler errors were occurring.

[Fact]
public void Reads_AbPlc_at_each_inputs_label()
{
    var abPlc = A.Fake<AbPlc>(); // interface
    var input1 = A.Fake<ToggleUi>(); // interface
    var input2 = A.Fake<ToggleUi>(); // interface
    var w2 = A.Fake<MethodWeb>(); // class
    var f = this.fixture;
    input1.Label = f.Create<string>();
    input2.Label = f.Create<string>();
    A.CallTo(() => this.ui.Inputs)
        .Returns(new LinkedListLot<ToggleUi>(
            new[]
            {
                input1,
                input2
            }));
    var a = f.Create<bool>();
    A.CallTo(() => input1.GetHashCode())
        .Returns(0xFF); // error
    A
        .CallTo(() => abPlc.Read(input1.Label))
        .Returns(false); // error

    A.CallTo(() => w2.RegisterDependency(null, null))
        .Returns(false); // compiles fine
    var w = this.web;
    w.RegisterDependency(new UiReaderWriter());
    w.RegisterDependency(abPlc);

    this.handler.Handle(
        this.ui);

    A
        .CallTo(() => abPlc.Read(input1.Label))
        .MustHaveHappened();
    A
        .CallTo(() => abPlc.Read(input2.Label))
        .MustHaveHappened();
}

One last comment: these interface methods are not extension methods.

Edit 1: I believe properties of interfaces worked fine.

Edit 2: actually included error and updated GetHashCode() call to actually reflect GetHashCode() sig.

xofz
  • 5,600
  • 6
  • 45
  • 63
  • 1
    _"Getting the following error"_ - you didn't include the error! – stuartd Jun 14 '19 at 17:56
  • 1
    We need to see the interfaces. For instance I'd think `GetHashCode` would return an `int` and not a `string`, but we cannot be sure without the definition of `ToggleUi` – juharr Jun 14 '19 at 17:59
  • I foolishly added a bad line of code in that `GetHashCode()` call. Updated to return an int. – xofz Jun 14 '19 at 18:04
  • The return types weren't matching up. It works now. – xofz Jun 14 '19 at 18:07
  • @juharr drove right down into it and sealed this one off. I was returning the wrong types! – xofz Jun 14 '19 at 18:08

0 Answers0