{"record":{"id":"e1c936da96c9504a","repo":"devlooped/moq","slug":"argumentoutofrangeexception-callcount-0-value-must-be","errorCode":null,"errorMessage":"ArgumentOutOfRangeException: callCount ('{0}' value must be greater than or equal to '1').","messagePattern":"ArgumentOutOfRangeException: callCount \\('(.+?)' value must be greater than or equal to '1'\\)\\.","errorType":"validation","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/Moq/Times.cs","lineNumber":65,"sourceCode":"            }\n            else\n            {\n                from = this.from;\n                to = this.to;\n            }\n        }\n\n        /// <summary>\n        ///   Specifies that a mocked method should be invoked <paramref name=\"callCount\"/> times\n        ///   as minimum.\n        /// </summary>\n        /// <param name=\"callCount\">The minimum number of times.</param>\n        /// <returns>An object defining the allowed number of invocations.</returns>\n        public static Times AtLeast(int callCount)\n        {\n            if (callCount < 1)\n            {\n                throw new ArgumentOutOfRangeException(nameof(callCount));\n            }\n\n            return new Times(Kind.AtLeast, callCount, int.MaxValue);\n        }\n\n        /// <summary>\n        ///   Specifies that a mocked method should be invoked one time as minimum.\n        /// </summary>\n        /// <returns>An object defining the allowed number of invocations.</returns>\n        public static Times AtLeastOnce()\n        {\n            return new Times(Kind.AtLeastOnce, 1, int.MaxValue);\n        }\n\n        /// <summary>\n        ///   Specifies that a mocked method should be invoked <paramref name=\"callCount\"/> times\n        ///   as maximum.\n        /// </summary>","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/devlooped/moq/blob/89a5be629c752960fe403e95ff583e4ae6f00542/src/Moq/Times.cs#L47-L83","documentation":"Times.AtLeast(callCount) requires a minimum count of at least 1; passing a smaller value throws ArgumentOutOfRangeException named callCount. AtLeast(0) is meaningless — use Times.Never for zero expected calls.","triggerScenarios":"Calling Times.AtLeast(0) or Times.AtLeast(negative), directly or via Verify(..., Times.AtLeast(0)) or a minCount derived from a variable/computation that can be 0.","commonSituations":"Computing the minimum from config or a counter that is 0 when nothing happened; typos writing AtLeast where Never was intended.","solutions":["Ensure the value passed is >= 1 (clamp or validate before calling)","Use Times.Never instead of AtLeast(0) when zero calls should be asserted","Guard computed values: if (n < 1) n = 1; or branch to Times.Never"],"exampleFix":"// before\nmock.Verify(m => m.Foo(), Times.AtLeast(count)); // count may be 0\n// after\nmock.Verify(m => m.Foo(), count < 1 ? Times.Never : Times.AtLeast(count));","handlingStrategy":"validation","validationCode":"if (minCalls >= 1)\n    mock.Verify(m => m.Foo(), Times.AtLeast(minCalls));\nelse\n    mock.Verify(m => m.Foo(), Times.Never);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never call AtLeast with 0 — use Times.Never","Validate computed minimums before building Times","Wrap count math in a small helper that clamps to >= 1"],"tags":["argument-out-of-range","moq","verification"],"backgroundTag":"argument-out-of-range","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"}