{"record":{"id":"42647bb6f82152ed","repo":"devlooped/moq","slug":"expectset-has-been-renamed-to-setupset-and-the-new-syntax","errorCode":null,"errorMessage":"ExpectSet has been renamed to SetupSet, and the new syntax allows you to pass the value in the expression itself, like f => f.Value = 25. (thrown unconditionally via [Obsolete(..., true)])","messagePattern":"ExpectSet has been renamed to SetupSet, and the new syntax allows you to pass the value in the expression itself, like f => f\\.Value = 25\\. \\(thrown unconditionally via \\[Obsolete\\(\\.\\.\\., true\\)\\]\\)","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/Moq/Obsolete/Mock.Generic.Legacy.cs","lineNumber":68,"sourceCode":"\n        /// <summary>\n        /// Obsolete.\n        /// </summary>\n        [Obsolete(\"ExpectSet has been renamed to SetupSet.\", false)]\n        [EditorBrowsable(EditorBrowsableState.Never)]\n        public ISetupSetter<T, TProperty> ExpectSet<TProperty>(Expression<Func<T, TProperty>> expression)\n        {\n            return this.SetupSet(expression);\n        }\n\n        /// <summary>\n        /// Obsolete.\n        /// </summary>\n        [Obsolete(\"ExpectSet has been renamed to SetupSet, and the new syntax allows you to pass the value in the expression itself, like f => f.Value = 25.\", true)]\n        [EditorBrowsable(EditorBrowsableState.Never)]\n        public ISetupSetter<T, TProperty> ExpectSet<TProperty>(Expression<Func<T, TProperty>> expression, TProperty value)\n        {\n            throw new NotSupportedException();\n        }\n    }\n\n    /// <summary>\n    /// Contains obsolete API members as extension methods so that existing code continues to compile,\n    /// but new code doesn't see them.\n    /// </summary>\n    [EditorBrowsable(EditorBrowsableState.Never)]\n    public static class MockLegacyExtensions\n    {\n        /// <summary>\n        /// Obsolete.\n        /// </summary>\n        [EditorBrowsable(EditorBrowsableState.Never)]\n        [Obsolete(\"The new syntax allows you to pass the value in the expression itself, like f => f.Value = 25.\", true)]\n        public static ISetupSetter<T, TProperty> SetupSet<T, TProperty>(this Mock<T> mock, Expression<Func<T, TProperty>> expression, TProperty value)\n            where T : class\n        {","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/devlooped/moq/blob/89a5be629c752960fe403e95ff583e4ae6f00542/src/Moq/Obsolete/Mock.Generic.Legacy.cs#L50-L86","documentation":"Moq's legacy ExpectSet<TProperty>(expression, value) is marked [Obsolete(..., true)] — a compile-time error API — and its body throws NotSupportedException if somehow invoked. It was replaced by the SetupSet syntax where the assigned value is written directly into the lambda expression.","triggerScenarios":"Calling mock.ExpectSet(m => m.Value, 25) — any invocation of the obsolete ExpectSet overload in src/Moq/Obsolete/Mock.Generic.Legacy.cs:68; compilation itself fails when the API is referenced.","commonSituations":"Upgrading old Moq 2.x/3.x test code (pre-4.0 'Expect' era) to modern Moq; copy-pasting legacy example snippets from old blog posts.","solutions":["Replace ExpectSet(expr, value) with SetupSet: mock.SetupSet(m => m.Value = 25).","Use It.Is<TProperty> for flexible matching: mock.SetupSet(m => m.Value = It.Is<int>(v => v > 0)).","Run the compiler first — with true-as-error Obsolete, the build points at every call site to migrate."],"exampleFix":"// before\nmock.ExpectSet(f => f.Value, 25);\n// after\nmock.SetupSet(f => f.Value = 25);","handlingStrategy":"try-catch","validationCode":"if (methodBeingCalledIs(\"ExpectSet\")) throw new InvalidOperationException(\"Use SetupSet instead.\");","typeGuard":null,"tryCatchPattern":"try { legacyMock.ExpectSet(f => f.Value, 25); } catch (NotSupportedException) { mock.SetupSet(f => f.Value = 25); }","preventionTips":["Treat error-level [Obsolete] build warnings as blocking errors","Migrate Expect*/Verify* APIs when upgrading to Moq 4.x","Search codebase for 'ExpectSet' during upgrades"],"tags":["moq","obsolete","expectset","deprecated-api"],"backgroundTag":"deprecated-api-usage","analyzedSha":"89a5be629c752960fe403e95ff583e4ae6f00542","analyzedAt":"2026-09-16T05:31:39.496Z","contentChangedAt":"2026-09-16T05:31:39.496Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}