Operator '==' cannot be applied to operands of type 'Task<(IEnumerable, int)>' and 'Task<IEnumerable>'










0















I had the following function to be mocked.



public interface IRepository

Task<IEnumerable<Item>> GetItems(int total);



And my mocking code was



private readonly IEnumerable<Item> stubList = new List<Item> new Item ;

mockRepository = Mock.Of<IRepository>(r => r.GetItems(50) == Task.FromResult(stubList));


It worked on both my desktop (Visual studio 2017) and msbuild (MSBuild auto-detection: using msbuild version '15.8.169.51996' from 'C:Program Files (x86)Microsoft Visual Studio2017BuildToolsMSBuild15.0bin') on Jenkin server.



Now the method has been changed to



public interface IRepository

Task<(IEnumerable<Item>, int)> GetItems(int total);



And the mocking code was changed to



private readonly IEnumerable<Item> stubList = new List<Item> new Item ;

var m = (stubList, 1);
mockRepository = Mock.Of<IRepository>(r => r.GetItems(50) == Task.FromResult(m));


It still works on my desktop (visual studio 2017). But msbuild failed with the following error message?



error CS0019: Operator '==' cannot be applied to operands of type
'Task<(IEnumerable<Item>, int)>' and 'Task<IEnumerable<Item>>'



build.log:




CoreResGen:
"C:Program FilesMicrosoft SDKsWindowsv6.0AbinResgen.exe" /useSourcePath /r:"D:Jenkinsworkspace...packagesDocumentFormat.OpenXml.2.8.1libnet35DocumentFormat.OpenXml.dll" /r:C:WindowsMicrosoft.NETFrameworkv2.0.50727Microsoft.JScript.dll /r:C:WindowsMicrosoft.NETFrameworkv2.0.50727mscorlib.dll /r:"C:Program Files (x86)Reference AssembliesMicrosoftFrameworkv3.5System.Core.dll" /r:"C:Program Files (x86)Reference AssembliesMicrosoftFrameworkv3.5System.Data.DataSetExtensions.dll" /r:C:WindowsMicrosoft.NETFrameworkv2.0.50727System.Data.dll /r:C:WindowsMicrosoft.NETFrameworkv2.0.50727System.Design.dll /r:C:WindowsMicrosoft.NETFrameworkv2.0.50727System.dll /r:C:WindowsMicrosoft.NETFrameworkv2.0.50727System.Drawing.dll /r:"C:Program Files (x86)Reference AssembliesMicrosoftFrameworkv3.0System.Runtime.Serialization.dll" /r:"C:Program Files (x86)Reference AssembliesMicrosoftFrameworkv3.0System.ServiceModel.dll" /r:C:WindowsMicrosoft.NETFrameworkv2.0.50727System.Web.Services.dll /r:C:WindowsMicrosoft.NETFrameworkv2.0.50727System.Windows.Forms.dll /r:C:WindowsMicrosoft.NETFrameworkv2.0.50727System.Xml.dll /r:"C:Program Files (x86)Reference AssembliesMicrosoftFrameworkv3.5System.Xml.Linq.dll" /r:"C:Program Files (x86)Reference AssembliesMicrosoftFrameworkv3.0WindowsBase.dll" /compile ComponentsCheckedComboBoxPopupComboBox.resx,objReleasePresentationControls.PopupComboBox.resources ComponentsDGVDgvDesignerColumnList.resx,objReleaseInfrastructure.DgvDesignerColumnList.resources ComponentsDGVfrmGridColumnsExt.resx,objReleaseInfrastructure.frmGridColumnsExt.resources ComponentsDGVdgv.resx,objReleaseInfrastructure.DGV.resources ComponentsDGVfrmChangeGridState.resx,objReleaseInfrastructure.frmChangeGridState.resources ComponentsDGVfrmGridColumns.resx,objReleaseInfrastructure.frmGridColumns.resources ComponentsUserControl_Folder.resx,objReleaseInfrastructure.UserControl_Folder.resources frmDropDownBox.resx,objReleaseInfrastructure.frmDropDownBox.resources frmUsersChangeHistory.resx,objReleaseInfrastructure.frmUsersChangeHistory.resources frmUserPermissions.resx,objReleaseInfrastructure.frmUserPermissions.resources frmUserRegProdGroups.resx,objReleaseInfrastructure.frmUserRegProdGroups.resources frmErrorBox.resx,objReleaseInfrastructure.frmErrorBox.resources frmGridBox.resx,objReleaseInfrastructure.frmGridBox.resources frmInputBox.resx,objReleaseInfrastructure.frmInputBox.resources frmLongTask.resx,objReleaseInfrastructure.frmLongTask.resources frmNoteBox.resx,objReleaseInfrastructure.frmNoteBox.resources ComponentsMonthPicker.resx,objReleaseInfrastructure.MonthPicker.resources frmUserGroups.resx,objReleaseInfrastructure.frmUserGroups.resources frmUsers.resx,objReleaseInfrastructure.frmUsers.resources PropertiesResources.resx,objReleaseInfrastructure.Properties.Resources.resources ReportsfrmEditReports.resx,objReleaseInfrastructure.frmEditReports.resources ReportsfrmJobsMaintenance.resx,objReleaseInfrastructure.frmJobsMaintenance.resources ReportsfrmRunReports.resx,objReleaseInfrastructure.frmRunReports.resources ReportsfrmSelectReport.resx,objReleaseInfrastructure.frmSelectReport.resources ReportsfrmShowReportLog.resx,objReleaseInfrastructure.frmShowReportLog.resources











share|improve this question
























  • You cannot compare Task<(IEnumerable<Item>, int)> and Task<IEnumerable<Item>>. The former is a task of enumerable of tuple of Item and int, the latter is a task of enumerable of Item. You see?

    – abatishchev
    Nov 13 '18 at 0:46











  • This is not the issue. The code doesn't compare with different type. The error message is a little bit confused

    – ca9163d9
    Nov 13 '18 at 0:49















0















I had the following function to be mocked.



public interface IRepository

Task<IEnumerable<Item>> GetItems(int total);



And my mocking code was



private readonly IEnumerable<Item> stubList = new List<Item> new Item ;

mockRepository = Mock.Of<IRepository>(r => r.GetItems(50) == Task.FromResult(stubList));


It worked on both my desktop (Visual studio 2017) and msbuild (MSBuild auto-detection: using msbuild version '15.8.169.51996' from 'C:Program Files (x86)Microsoft Visual Studio2017BuildToolsMSBuild15.0bin') on Jenkin server.



Now the method has been changed to



public interface IRepository

Task<(IEnumerable<Item>, int)> GetItems(int total);



And the mocking code was changed to



private readonly IEnumerable<Item> stubList = new List<Item> new Item ;

var m = (stubList, 1);
mockRepository = Mock.Of<IRepository>(r => r.GetItems(50) == Task.FromResult(m));


It still works on my desktop (visual studio 2017). But msbuild failed with the following error message?



error CS0019: Operator '==' cannot be applied to operands of type
'Task<(IEnumerable<Item>, int)>' and 'Task<IEnumerable<Item>>'



build.log:




CoreResGen:
"C:Program FilesMicrosoft SDKsWindowsv6.0AbinResgen.exe" /useSourcePath /r:"D:Jenkinsworkspace...packagesDocumentFormat.OpenXml.2.8.1libnet35DocumentFormat.OpenXml.dll" /r:C:WindowsMicrosoft.NETFrameworkv2.0.50727Microsoft.JScript.dll /r:C:WindowsMicrosoft.NETFrameworkv2.0.50727mscorlib.dll /r:"C:Program Files (x86)Reference AssembliesMicrosoftFrameworkv3.5System.Core.dll" /r:"C:Program Files (x86)Reference AssembliesMicrosoftFrameworkv3.5System.Data.DataSetExtensions.dll" /r:C:WindowsMicrosoft.NETFrameworkv2.0.50727System.Data.dll /r:C:WindowsMicrosoft.NETFrameworkv2.0.50727System.Design.dll /r:C:WindowsMicrosoft.NETFrameworkv2.0.50727System.dll /r:C:WindowsMicrosoft.NETFrameworkv2.0.50727System.Drawing.dll /r:"C:Program Files (x86)Reference AssembliesMicrosoftFrameworkv3.0System.Runtime.Serialization.dll" /r:"C:Program Files (x86)Reference AssembliesMicrosoftFrameworkv3.0System.ServiceModel.dll" /r:C:WindowsMicrosoft.NETFrameworkv2.0.50727System.Web.Services.dll /r:C:WindowsMicrosoft.NETFrameworkv2.0.50727System.Windows.Forms.dll /r:C:WindowsMicrosoft.NETFrameworkv2.0.50727System.Xml.dll /r:"C:Program Files (x86)Reference AssembliesMicrosoftFrameworkv3.5System.Xml.Linq.dll" /r:"C:Program Files (x86)Reference AssembliesMicrosoftFrameworkv3.0WindowsBase.dll" /compile ComponentsCheckedComboBoxPopupComboBox.resx,objReleasePresentationControls.PopupComboBox.resources ComponentsDGVDgvDesignerColumnList.resx,objReleaseInfrastructure.DgvDesignerColumnList.resources ComponentsDGVfrmGridColumnsExt.resx,objReleaseInfrastructure.frmGridColumnsExt.resources ComponentsDGVdgv.resx,objReleaseInfrastructure.DGV.resources ComponentsDGVfrmChangeGridState.resx,objReleaseInfrastructure.frmChangeGridState.resources ComponentsDGVfrmGridColumns.resx,objReleaseInfrastructure.frmGridColumns.resources ComponentsUserControl_Folder.resx,objReleaseInfrastructure.UserControl_Folder.resources frmDropDownBox.resx,objReleaseInfrastructure.frmDropDownBox.resources frmUsersChangeHistory.resx,objReleaseInfrastructure.frmUsersChangeHistory.resources frmUserPermissions.resx,objReleaseInfrastructure.frmUserPermissions.resources frmUserRegProdGroups.resx,objReleaseInfrastructure.frmUserRegProdGroups.resources frmErrorBox.resx,objReleaseInfrastructure.frmErrorBox.resources frmGridBox.resx,objReleaseInfrastructure.frmGridBox.resources frmInputBox.resx,objReleaseInfrastructure.frmInputBox.resources frmLongTask.resx,objReleaseInfrastructure.frmLongTask.resources frmNoteBox.resx,objReleaseInfrastructure.frmNoteBox.resources ComponentsMonthPicker.resx,objReleaseInfrastructure.MonthPicker.resources frmUserGroups.resx,objReleaseInfrastructure.frmUserGroups.resources frmUsers.resx,objReleaseInfrastructure.frmUsers.resources PropertiesResources.resx,objReleaseInfrastructure.Properties.Resources.resources ReportsfrmEditReports.resx,objReleaseInfrastructure.frmEditReports.resources ReportsfrmJobsMaintenance.resx,objReleaseInfrastructure.frmJobsMaintenance.resources ReportsfrmRunReports.resx,objReleaseInfrastructure.frmRunReports.resources ReportsfrmSelectReport.resx,objReleaseInfrastructure.frmSelectReport.resources ReportsfrmShowReportLog.resx,objReleaseInfrastructure.frmShowReportLog.resources











share|improve this question
























  • You cannot compare Task<(IEnumerable<Item>, int)> and Task<IEnumerable<Item>>. The former is a task of enumerable of tuple of Item and int, the latter is a task of enumerable of Item. You see?

    – abatishchev
    Nov 13 '18 at 0:46











  • This is not the issue. The code doesn't compare with different type. The error message is a little bit confused

    – ca9163d9
    Nov 13 '18 at 0:49













0












0








0


0






I had the following function to be mocked.



public interface IRepository

Task<IEnumerable<Item>> GetItems(int total);



And my mocking code was



private readonly IEnumerable<Item> stubList = new List<Item> new Item ;

mockRepository = Mock.Of<IRepository>(r => r.GetItems(50) == Task.FromResult(stubList));


It worked on both my desktop (Visual studio 2017) and msbuild (MSBuild auto-detection: using msbuild version '15.8.169.51996' from 'C:Program Files (x86)Microsoft Visual Studio2017BuildToolsMSBuild15.0bin') on Jenkin server.



Now the method has been changed to



public interface IRepository

Task<(IEnumerable<Item>, int)> GetItems(int total);



And the mocking code was changed to



private readonly IEnumerable<Item> stubList = new List<Item> new Item ;

var m = (stubList, 1);
mockRepository = Mock.Of<IRepository>(r => r.GetItems(50) == Task.FromResult(m));


It still works on my desktop (visual studio 2017). But msbuild failed with the following error message?



error CS0019: Operator '==' cannot be applied to operands of type
'Task<(IEnumerable<Item>, int)>' and 'Task<IEnumerable<Item>>'



build.log:




CoreResGen:
"C:Program FilesMicrosoft SDKsWindowsv6.0AbinResgen.exe" /useSourcePath /r:"D:Jenkinsworkspace...packagesDocumentFormat.OpenXml.2.8.1libnet35DocumentFormat.OpenXml.dll" /r:C:WindowsMicrosoft.NETFrameworkv2.0.50727Microsoft.JScript.dll /r:C:WindowsMicrosoft.NETFrameworkv2.0.50727mscorlib.dll /r:"C:Program Files (x86)Reference AssembliesMicrosoftFrameworkv3.5System.Core.dll" /r:"C:Program Files (x86)Reference AssembliesMicrosoftFrameworkv3.5System.Data.DataSetExtensions.dll" /r:C:WindowsMicrosoft.NETFrameworkv2.0.50727System.Data.dll /r:C:WindowsMicrosoft.NETFrameworkv2.0.50727System.Design.dll /r:C:WindowsMicrosoft.NETFrameworkv2.0.50727System.dll /r:C:WindowsMicrosoft.NETFrameworkv2.0.50727System.Drawing.dll /r:"C:Program Files (x86)Reference AssembliesMicrosoftFrameworkv3.0System.Runtime.Serialization.dll" /r:"C:Program Files (x86)Reference AssembliesMicrosoftFrameworkv3.0System.ServiceModel.dll" /r:C:WindowsMicrosoft.NETFrameworkv2.0.50727System.Web.Services.dll /r:C:WindowsMicrosoft.NETFrameworkv2.0.50727System.Windows.Forms.dll /r:C:WindowsMicrosoft.NETFrameworkv2.0.50727System.Xml.dll /r:"C:Program Files (x86)Reference AssembliesMicrosoftFrameworkv3.5System.Xml.Linq.dll" /r:"C:Program Files (x86)Reference AssembliesMicrosoftFrameworkv3.0WindowsBase.dll" /compile ComponentsCheckedComboBoxPopupComboBox.resx,objReleasePresentationControls.PopupComboBox.resources ComponentsDGVDgvDesignerColumnList.resx,objReleaseInfrastructure.DgvDesignerColumnList.resources ComponentsDGVfrmGridColumnsExt.resx,objReleaseInfrastructure.frmGridColumnsExt.resources ComponentsDGVdgv.resx,objReleaseInfrastructure.DGV.resources ComponentsDGVfrmChangeGridState.resx,objReleaseInfrastructure.frmChangeGridState.resources ComponentsDGVfrmGridColumns.resx,objReleaseInfrastructure.frmGridColumns.resources ComponentsUserControl_Folder.resx,objReleaseInfrastructure.UserControl_Folder.resources frmDropDownBox.resx,objReleaseInfrastructure.frmDropDownBox.resources frmUsersChangeHistory.resx,objReleaseInfrastructure.frmUsersChangeHistory.resources frmUserPermissions.resx,objReleaseInfrastructure.frmUserPermissions.resources frmUserRegProdGroups.resx,objReleaseInfrastructure.frmUserRegProdGroups.resources frmErrorBox.resx,objReleaseInfrastructure.frmErrorBox.resources frmGridBox.resx,objReleaseInfrastructure.frmGridBox.resources frmInputBox.resx,objReleaseInfrastructure.frmInputBox.resources frmLongTask.resx,objReleaseInfrastructure.frmLongTask.resources frmNoteBox.resx,objReleaseInfrastructure.frmNoteBox.resources ComponentsMonthPicker.resx,objReleaseInfrastructure.MonthPicker.resources frmUserGroups.resx,objReleaseInfrastructure.frmUserGroups.resources frmUsers.resx,objReleaseInfrastructure.frmUsers.resources PropertiesResources.resx,objReleaseInfrastructure.Properties.Resources.resources ReportsfrmEditReports.resx,objReleaseInfrastructure.frmEditReports.resources ReportsfrmJobsMaintenance.resx,objReleaseInfrastructure.frmJobsMaintenance.resources ReportsfrmRunReports.resx,objReleaseInfrastructure.frmRunReports.resources ReportsfrmSelectReport.resx,objReleaseInfrastructure.frmSelectReport.resources ReportsfrmShowReportLog.resx,objReleaseInfrastructure.frmShowReportLog.resources











share|improve this question
















I had the following function to be mocked.



public interface IRepository

Task<IEnumerable<Item>> GetItems(int total);



And my mocking code was



private readonly IEnumerable<Item> stubList = new List<Item> new Item ;

mockRepository = Mock.Of<IRepository>(r => r.GetItems(50) == Task.FromResult(stubList));


It worked on both my desktop (Visual studio 2017) and msbuild (MSBuild auto-detection: using msbuild version '15.8.169.51996' from 'C:Program Files (x86)Microsoft Visual Studio2017BuildToolsMSBuild15.0bin') on Jenkin server.



Now the method has been changed to



public interface IRepository

Task<(IEnumerable<Item>, int)> GetItems(int total);



And the mocking code was changed to



private readonly IEnumerable<Item> stubList = new List<Item> new Item ;

var m = (stubList, 1);
mockRepository = Mock.Of<IRepository>(r => r.GetItems(50) == Task.FromResult(m));


It still works on my desktop (visual studio 2017). But msbuild failed with the following error message?



error CS0019: Operator '==' cannot be applied to operands of type
'Task<(IEnumerable<Item>, int)>' and 'Task<IEnumerable<Item>>'



build.log:




CoreResGen:
"C:Program FilesMicrosoft SDKsWindowsv6.0AbinResgen.exe" /useSourcePath /r:"D:Jenkinsworkspace...packagesDocumentFormat.OpenXml.2.8.1libnet35DocumentFormat.OpenXml.dll" /r:C:WindowsMicrosoft.NETFrameworkv2.0.50727Microsoft.JScript.dll /r:C:WindowsMicrosoft.NETFrameworkv2.0.50727mscorlib.dll /r:"C:Program Files (x86)Reference AssembliesMicrosoftFrameworkv3.5System.Core.dll" /r:"C:Program Files (x86)Reference AssembliesMicrosoftFrameworkv3.5System.Data.DataSetExtensions.dll" /r:C:WindowsMicrosoft.NETFrameworkv2.0.50727System.Data.dll /r:C:WindowsMicrosoft.NETFrameworkv2.0.50727System.Design.dll /r:C:WindowsMicrosoft.NETFrameworkv2.0.50727System.dll /r:C:WindowsMicrosoft.NETFrameworkv2.0.50727System.Drawing.dll /r:"C:Program Files (x86)Reference AssembliesMicrosoftFrameworkv3.0System.Runtime.Serialization.dll" /r:"C:Program Files (x86)Reference AssembliesMicrosoftFrameworkv3.0System.ServiceModel.dll" /r:C:WindowsMicrosoft.NETFrameworkv2.0.50727System.Web.Services.dll /r:C:WindowsMicrosoft.NETFrameworkv2.0.50727System.Windows.Forms.dll /r:C:WindowsMicrosoft.NETFrameworkv2.0.50727System.Xml.dll /r:"C:Program Files (x86)Reference AssembliesMicrosoftFrameworkv3.5System.Xml.Linq.dll" /r:"C:Program Files (x86)Reference AssembliesMicrosoftFrameworkv3.0WindowsBase.dll" /compile ComponentsCheckedComboBoxPopupComboBox.resx,objReleasePresentationControls.PopupComboBox.resources ComponentsDGVDgvDesignerColumnList.resx,objReleaseInfrastructure.DgvDesignerColumnList.resources ComponentsDGVfrmGridColumnsExt.resx,objReleaseInfrastructure.frmGridColumnsExt.resources ComponentsDGVdgv.resx,objReleaseInfrastructure.DGV.resources ComponentsDGVfrmChangeGridState.resx,objReleaseInfrastructure.frmChangeGridState.resources ComponentsDGVfrmGridColumns.resx,objReleaseInfrastructure.frmGridColumns.resources ComponentsUserControl_Folder.resx,objReleaseInfrastructure.UserControl_Folder.resources frmDropDownBox.resx,objReleaseInfrastructure.frmDropDownBox.resources frmUsersChangeHistory.resx,objReleaseInfrastructure.frmUsersChangeHistory.resources frmUserPermissions.resx,objReleaseInfrastructure.frmUserPermissions.resources frmUserRegProdGroups.resx,objReleaseInfrastructure.frmUserRegProdGroups.resources frmErrorBox.resx,objReleaseInfrastructure.frmErrorBox.resources frmGridBox.resx,objReleaseInfrastructure.frmGridBox.resources frmInputBox.resx,objReleaseInfrastructure.frmInputBox.resources frmLongTask.resx,objReleaseInfrastructure.frmLongTask.resources frmNoteBox.resx,objReleaseInfrastructure.frmNoteBox.resources ComponentsMonthPicker.resx,objReleaseInfrastructure.MonthPicker.resources frmUserGroups.resx,objReleaseInfrastructure.frmUserGroups.resources frmUsers.resx,objReleaseInfrastructure.frmUsers.resources PropertiesResources.resx,objReleaseInfrastructure.Properties.Resources.resources ReportsfrmEditReports.resx,objReleaseInfrastructure.frmEditReports.resources ReportsfrmJobsMaintenance.resx,objReleaseInfrastructure.frmJobsMaintenance.resources ReportsfrmRunReports.resx,objReleaseInfrastructure.frmRunReports.resources ReportsfrmSelectReport.resx,objReleaseInfrastructure.frmSelectReport.resources ReportsfrmShowReportLog.resx,objReleaseInfrastructure.frmShowReportLog.resources








c# visual-studio msbuild moq






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 13 '18 at 16:52







ca9163d9

















asked Nov 12 '18 at 23:58









ca9163d9ca9163d9

8,1532391201




8,1532391201












  • You cannot compare Task<(IEnumerable<Item>, int)> and Task<IEnumerable<Item>>. The former is a task of enumerable of tuple of Item and int, the latter is a task of enumerable of Item. You see?

    – abatishchev
    Nov 13 '18 at 0:46











  • This is not the issue. The code doesn't compare with different type. The error message is a little bit confused

    – ca9163d9
    Nov 13 '18 at 0:49

















  • You cannot compare Task<(IEnumerable<Item>, int)> and Task<IEnumerable<Item>>. The former is a task of enumerable of tuple of Item and int, the latter is a task of enumerable of Item. You see?

    – abatishchev
    Nov 13 '18 at 0:46











  • This is not the issue. The code doesn't compare with different type. The error message is a little bit confused

    – ca9163d9
    Nov 13 '18 at 0:49
















You cannot compare Task<(IEnumerable<Item>, int)> and Task<IEnumerable<Item>>. The former is a task of enumerable of tuple of Item and int, the latter is a task of enumerable of Item. You see?

– abatishchev
Nov 13 '18 at 0:46





You cannot compare Task<(IEnumerable<Item>, int)> and Task<IEnumerable<Item>>. The former is a task of enumerable of tuple of Item and int, the latter is a task of enumerable of Item. You see?

– abatishchev
Nov 13 '18 at 0:46













This is not the issue. The code doesn't compare with different type. The error message is a little bit confused

– ca9163d9
Nov 13 '18 at 0:49





This is not the issue. The code doesn't compare with different type. The error message is a little bit confused

– ca9163d9
Nov 13 '18 at 0:49












2 Answers
2






active

oldest

votes


















1














Try using the more verbose approach instead of the LINQ to Mocks



private readonly IEnumerable<Item> stubList = new List<Item> new Item ;

//...

var expected = (stubList, 1);

var mock = new Mock<IRepository>();
mock
.Setup(_ => _.GetItems(50))
.ReturnsAsync(expected);

IRepository mockRepository = mock.Object;

//...


The framework may be having issues trying to evaluate the expression with the new syntax






share|improve this answer

























  • msbuild working now. Thanks. Why Linq to Mock failed on msbuild though?

    – ca9163d9
    Nov 13 '18 at 0:19











  • @ca9163d9 The framework probably could not evaluate the expression with the new syntax.

    – Nkosi
    Nov 13 '18 at 0:22


















-1














When I try your code:



class Program

static void Main(string args)

var stubList = new List<Item>

new Item()
;

var m = (stubList, 1);

var mockRepository = Mock.Of<IRepository>(r => r.GetItems(50) == Task.FromResult(m));



interface IRepository

Task<(IEnumerable<Item>, int)> GetItems(int total);


class Item




I'm getting different compiler error:




CS0019 Operator '==' cannot be applied to operands of type 'Task<(IEnumerable, int)>' and 'Task<(List stubList, int)>'




This happens because you compare Task<(List<Item>, int)> and Task<(IEnumerable<Item>, int)>. Task<T> is not co-variant (opposite to List<T> for instance) so the error is expected.



But why your question contains different compiler error?




If I change the code to this:



var m = ((IEnumerable<Item>)stubList, 1);


or this:



(IEnumerable<Item>, int) m = (stubList, 1);


then it complies fine.






share|improve this answer























  • The stubList in my code is defined as a field with the type of IEnumerable<Item>.

    – ca9163d9
    Nov 13 '18 at 2:25











  • @ca9163d9: Oh, right, I see. Then it's not an issue, I cannot reproduce it.

    – abatishchev
    Nov 13 '18 at 18:01










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53271844%2foperator-cannot-be-applied-to-operands-of-type-taskienumerableitem-in%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














Try using the more verbose approach instead of the LINQ to Mocks



private readonly IEnumerable<Item> stubList = new List<Item> new Item ;

//...

var expected = (stubList, 1);

var mock = new Mock<IRepository>();
mock
.Setup(_ => _.GetItems(50))
.ReturnsAsync(expected);

IRepository mockRepository = mock.Object;

//...


The framework may be having issues trying to evaluate the expression with the new syntax






share|improve this answer

























  • msbuild working now. Thanks. Why Linq to Mock failed on msbuild though?

    – ca9163d9
    Nov 13 '18 at 0:19











  • @ca9163d9 The framework probably could not evaluate the expression with the new syntax.

    – Nkosi
    Nov 13 '18 at 0:22















1














Try using the more verbose approach instead of the LINQ to Mocks



private readonly IEnumerable<Item> stubList = new List<Item> new Item ;

//...

var expected = (stubList, 1);

var mock = new Mock<IRepository>();
mock
.Setup(_ => _.GetItems(50))
.ReturnsAsync(expected);

IRepository mockRepository = mock.Object;

//...


The framework may be having issues trying to evaluate the expression with the new syntax






share|improve this answer

























  • msbuild working now. Thanks. Why Linq to Mock failed on msbuild though?

    – ca9163d9
    Nov 13 '18 at 0:19











  • @ca9163d9 The framework probably could not evaluate the expression with the new syntax.

    – Nkosi
    Nov 13 '18 at 0:22













1












1








1







Try using the more verbose approach instead of the LINQ to Mocks



private readonly IEnumerable<Item> stubList = new List<Item> new Item ;

//...

var expected = (stubList, 1);

var mock = new Mock<IRepository>();
mock
.Setup(_ => _.GetItems(50))
.ReturnsAsync(expected);

IRepository mockRepository = mock.Object;

//...


The framework may be having issues trying to evaluate the expression with the new syntax






share|improve this answer















Try using the more verbose approach instead of the LINQ to Mocks



private readonly IEnumerable<Item> stubList = new List<Item> new Item ;

//...

var expected = (stubList, 1);

var mock = new Mock<IRepository>();
mock
.Setup(_ => _.GetItems(50))
.ReturnsAsync(expected);

IRepository mockRepository = mock.Object;

//...


The framework may be having issues trying to evaluate the expression with the new syntax







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 13 '18 at 0:23

























answered Nov 13 '18 at 0:07









NkosiNkosi

113k16124191




113k16124191












  • msbuild working now. Thanks. Why Linq to Mock failed on msbuild though?

    – ca9163d9
    Nov 13 '18 at 0:19











  • @ca9163d9 The framework probably could not evaluate the expression with the new syntax.

    – Nkosi
    Nov 13 '18 at 0:22

















  • msbuild working now. Thanks. Why Linq to Mock failed on msbuild though?

    – ca9163d9
    Nov 13 '18 at 0:19











  • @ca9163d9 The framework probably could not evaluate the expression with the new syntax.

    – Nkosi
    Nov 13 '18 at 0:22
















msbuild working now. Thanks. Why Linq to Mock failed on msbuild though?

– ca9163d9
Nov 13 '18 at 0:19





msbuild working now. Thanks. Why Linq to Mock failed on msbuild though?

– ca9163d9
Nov 13 '18 at 0:19













@ca9163d9 The framework probably could not evaluate the expression with the new syntax.

– Nkosi
Nov 13 '18 at 0:22





@ca9163d9 The framework probably could not evaluate the expression with the new syntax.

– Nkosi
Nov 13 '18 at 0:22













-1














When I try your code:



class Program

static void Main(string args)

var stubList = new List<Item>

new Item()
;

var m = (stubList, 1);

var mockRepository = Mock.Of<IRepository>(r => r.GetItems(50) == Task.FromResult(m));



interface IRepository

Task<(IEnumerable<Item>, int)> GetItems(int total);


class Item




I'm getting different compiler error:




CS0019 Operator '==' cannot be applied to operands of type 'Task<(IEnumerable, int)>' and 'Task<(List stubList, int)>'




This happens because you compare Task<(List<Item>, int)> and Task<(IEnumerable<Item>, int)>. Task<T> is not co-variant (opposite to List<T> for instance) so the error is expected.



But why your question contains different compiler error?




If I change the code to this:



var m = ((IEnumerable<Item>)stubList, 1);


or this:



(IEnumerable<Item>, int) m = (stubList, 1);


then it complies fine.






share|improve this answer























  • The stubList in my code is defined as a field with the type of IEnumerable<Item>.

    – ca9163d9
    Nov 13 '18 at 2:25











  • @ca9163d9: Oh, right, I see. Then it's not an issue, I cannot reproduce it.

    – abatishchev
    Nov 13 '18 at 18:01















-1














When I try your code:



class Program

static void Main(string args)

var stubList = new List<Item>

new Item()
;

var m = (stubList, 1);

var mockRepository = Mock.Of<IRepository>(r => r.GetItems(50) == Task.FromResult(m));



interface IRepository

Task<(IEnumerable<Item>, int)> GetItems(int total);


class Item




I'm getting different compiler error:




CS0019 Operator '==' cannot be applied to operands of type 'Task<(IEnumerable, int)>' and 'Task<(List stubList, int)>'




This happens because you compare Task<(List<Item>, int)> and Task<(IEnumerable<Item>, int)>. Task<T> is not co-variant (opposite to List<T> for instance) so the error is expected.



But why your question contains different compiler error?




If I change the code to this:



var m = ((IEnumerable<Item>)stubList, 1);


or this:



(IEnumerable<Item>, int) m = (stubList, 1);


then it complies fine.






share|improve this answer























  • The stubList in my code is defined as a field with the type of IEnumerable<Item>.

    – ca9163d9
    Nov 13 '18 at 2:25











  • @ca9163d9: Oh, right, I see. Then it's not an issue, I cannot reproduce it.

    – abatishchev
    Nov 13 '18 at 18:01













-1












-1








-1







When I try your code:



class Program

static void Main(string args)

var stubList = new List<Item>

new Item()
;

var m = (stubList, 1);

var mockRepository = Mock.Of<IRepository>(r => r.GetItems(50) == Task.FromResult(m));



interface IRepository

Task<(IEnumerable<Item>, int)> GetItems(int total);


class Item




I'm getting different compiler error:




CS0019 Operator '==' cannot be applied to operands of type 'Task<(IEnumerable, int)>' and 'Task<(List stubList, int)>'




This happens because you compare Task<(List<Item>, int)> and Task<(IEnumerable<Item>, int)>. Task<T> is not co-variant (opposite to List<T> for instance) so the error is expected.



But why your question contains different compiler error?




If I change the code to this:



var m = ((IEnumerable<Item>)stubList, 1);


or this:



(IEnumerable<Item>, int) m = (stubList, 1);


then it complies fine.






share|improve this answer













When I try your code:



class Program

static void Main(string args)

var stubList = new List<Item>

new Item()
;

var m = (stubList, 1);

var mockRepository = Mock.Of<IRepository>(r => r.GetItems(50) == Task.FromResult(m));



interface IRepository

Task<(IEnumerable<Item>, int)> GetItems(int total);


class Item




I'm getting different compiler error:




CS0019 Operator '==' cannot be applied to operands of type 'Task<(IEnumerable, int)>' and 'Task<(List stubList, int)>'




This happens because you compare Task<(List<Item>, int)> and Task<(IEnumerable<Item>, int)>. Task<T> is not co-variant (opposite to List<T> for instance) so the error is expected.



But why your question contains different compiler error?




If I change the code to this:



var m = ((IEnumerable<Item>)stubList, 1);


or this:



(IEnumerable<Item>, int) m = (stubList, 1);


then it complies fine.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 13 '18 at 2:14









abatishchevabatishchev

69.3k70263393




69.3k70263393












  • The stubList in my code is defined as a field with the type of IEnumerable<Item>.

    – ca9163d9
    Nov 13 '18 at 2:25











  • @ca9163d9: Oh, right, I see. Then it's not an issue, I cannot reproduce it.

    – abatishchev
    Nov 13 '18 at 18:01

















  • The stubList in my code is defined as a field with the type of IEnumerable<Item>.

    – ca9163d9
    Nov 13 '18 at 2:25











  • @ca9163d9: Oh, right, I see. Then it's not an issue, I cannot reproduce it.

    – abatishchev
    Nov 13 '18 at 18:01
















The stubList in my code is defined as a field with the type of IEnumerable<Item>.

– ca9163d9
Nov 13 '18 at 2:25





The stubList in my code is defined as a field with the type of IEnumerable<Item>.

– ca9163d9
Nov 13 '18 at 2:25













@ca9163d9: Oh, right, I see. Then it's not an issue, I cannot reproduce it.

– abatishchev
Nov 13 '18 at 18:01





@ca9163d9: Oh, right, I see. Then it's not an issue, I cannot reproduce it.

– abatishchev
Nov 13 '18 at 18:01

















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53271844%2foperator-cannot-be-applied-to-operands-of-type-taskienumerableitem-in%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Use pre created SQLite database for Android project in kotlin

Darth Vader #20

Ondo