Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 184: allow null to match nullable value types #185

Merged
merged 1 commit into from
Jun 25, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions Source/Match.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD
//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD
//http://code.google.com/p/moq/
//All rights reserved.

Expand Down Expand Up @@ -128,7 +128,10 @@ internal override bool Matches(object value)
{
return false;
}
if (value == null && typeof(T).IsValueType)

var matchType = typeof(T);
if (value == null && matchType.IsValueType
&& ( !matchType.IsGenericType || matchType.GetGenericTypeDefinition() != typeof(Nullable<>)))
{
// If this.Condition expects a value type and we've been passed null,
// it can't possibly match.
Expand Down
25 changes: 23 additions & 2 deletions UnitTests/Regressions/IssueReportsFixture.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
Expand Down Expand Up @@ -234,7 +234,28 @@ public void when_a_method_doesnt_have_generic_parameters_exception_doesnt_includ

#endregion // #176

// Old @ Google Code
#region #184

public class Issue184
{
public interface ISimpleInterface
{
void Method(Guid? g);
}

[Fact]
public void strict_mock_accepts_null_as_nullable_guid_value()
{
var mock = new Mock<ISimpleInterface>(MockBehavior.Strict);
mock.Setup(x => x.Method(It.IsAny<Guid?>()));
mock.Object.Method(null);
mock.Verify();
}
}

#endregion // #184

// Old @ Google Code

#region #47

Expand Down