Last active
August 29, 2015 14:06
-
-
Save urasandesu/4f931b79a24ed90cda7d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Moq; | |
using NUnit.Framework; | |
namespace MoqVerifyBehaviorDemo | |
{ | |
[TestFixture] | |
public class MoqVerifyBehaviorTest | |
{ | |
[Test] | |
public void Setup_with_argument_matcher_and_Setup_with_constant_should_be_same_behavior() | |
{ | |
// Arrange | |
var m1 = new Mock<IFoo>(); | |
m1.Setup(_ => _.SetContent(It.IsAny<string>())); | |
var target1 = m1.Object; | |
var m2 = new Mock<IFoo>(); | |
m2.Setup(_ => _.SetContent("bar")); | |
var target2 = m2.Object; | |
var m3 = new Mock<IFoo>(); | |
m3.Setup(_ => _.SetContent(It.Is<string>(s => s == "bar"))); | |
var target3 = m3.Object; | |
// Act | |
target1.SetContent("bar"); | |
target2.SetContent("barbar"); | |
target3.SetContent("barbar"); | |
// Assert | |
m1.Verify(_ => _.SetContent("bar"), Times.Once()); | |
m2.VerifyAll(); | |
m3.VerifyAll(); | |
// PS Debug> & "C:\Program Files (x86)\NUnit 2.6.3\bin\nunit-console.exe" MoqVerifyBehaviorDemo.dll /domain=None /framework=v4.0 | |
// NUnit-Console version 2.6.3.13283 | |
// Copyright (C) 2002-2012 Charlie Poole. | |
// Copyright (C) 2002-2004 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov. | |
// Copyright (C) 2000-2002 Philip Craig. | |
// All Rights Reserved. | |
// | |
// Runtime Environment - | |
// OS Version: Microsoft Windows NT 6.2.9200.0 | |
// CLR Version: 2.0.50727.8009 ( Net 3.5 ) | |
// | |
// ProcessModel: Default DomainUsage: None | |
// Execution Runtime: v4.0 | |
// .F | |
// Tests run: 1, Errors: 1, Failures: 0, Inconclusive: 0, Time: 0.5067794484072 seconds | |
// Not run: 0, Invalid: 0, Ignored: 0, Skipped: 0 | |
// | |
// Errors and Failures: | |
// 1) Test Error : MoqVerifyBehaviorDemo.MoqVerifyBehaviorTest.Setup_with_argument_matcher_and_Setup_with_constant_should_be_same_behavior | |
// Moq.MockVerificationException : The following setups were not matched: | |
// IFoo _ => _.SetContent("bar") | |
// | |
// 場所 Moq.Mock.VerifyAll() | |
// 場所 MoqVerifyBehaviorDemo.MoqVerifyBehaviorTest.Setup_with_argument_matcher_and_Setup_with_constant_should_be_same_behavior() 場所 c:\Users\Akira\Documents\Visual Studio 2013\Projects\MoqVerifyBehaviorDemo\MoqVerifyBehaviorDemo\MoqVerifyBehaviorTest.cs:行 34 | |
// | |
} | |
} | |
public interface IFoo | |
{ | |
void SetContent(string value); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment