public void Setup_ValueTypeMethodWithArguments_InvokesOriginalMethodWhenNotMatched() { Smock.Run(context => { context.Setup(() => It.IsAny <int>().ToString("NonExistantFormat")).Returns("Test"); string result = 42.ToString("X"); Assert.AreEqual("2A", result); }); }
public void Setup_VoidMethod_DoesntInvokeOriginalWhenMatched() { Smock.Run(context => { context.Setup(() => VoidMethod(It.IsAny <string>())).Verifiable(); VoidMethod("Foo"); Assert.AreEqual(false, _voidMethodInvoked); }); }
public void CheckDirectoryExistsTest() { Smock.Run(context => { Assert.Throws <ArgumentNullException>(() => ((string)null).CheckDirectoryExists("param")); context.Setup(() => Directory.Exists("path")).Returns(false); Assert.Throws <DirectoryNotFoundException>(() => "path".CheckDirectoryExists("param")); context.Setup(() => Directory.Exists("path")).Returns(true); "path".CheckDirectoryExists("param"); }); }
public void CheckFileExistsTest() { Smock.Run(context => { Assert.Throws <ArgumentNullException>(() => ((string)null).CheckFileExists("param")); context.Setup(() => File.Exists("filename")).Returns(false); Assert.Throws <FileNotFoundException>(() => "filename".CheckFileExists("param")); context.Setup(() => File.Exists("filename")).Returns(true); "filename".CheckFileExists("param"); }); }
public void Setup_AnyValueTypeArgument_MatchesAnyInstance() { Smock.Run(context => { context.Setup(() => Enumerable.Range(It.IsAny <int>(), 1)).Returns(new List <int>()); Assert.AreEqual(0, Enumerable.Range(100, 1).Count()); Assert.AreEqual(0, Enumerable.Range(200, 1).Count()); Assert.AreEqual(2, Enumerable.Range(200, 2).Count()); }); }
public void Setup_ReferenceTypeArgument_MatchesOnlyEqualInstance() { Smock.Run(context => { context.Setup(() => int.Parse("111")).Returns(10); Assert.AreEqual(10, int.Parse("111")); Assert.AreEqual(10, int.Parse(new string('1', 3))); Assert.AreEqual(100, int.Parse("100")); }); }
public void Setup_ValueTypeTarget_MatchesOnlyEqualInstance(int valueType, int otherValueType) { Smock.Run(context => { const int expected = 1337; context.Setup(() => valueType.GetHashCode()).Returns(expected); Assert.AreEqual(expected, valueType.GetHashCode()); Assert.AreNotEqual(expected, otherValueType.GetHashCode()); }); }
public void Setup_AnyValueTypeTarget_MatchesAnyInstance() { Smock.Run(context => { const int expected = 1337; context.Setup(() => It.IsAny <int>().GetHashCode()).Returns(expected); Assert.AreEqual(expected, 1.GetHashCode()); Assert.AreEqual(expected, 2.GetHashCode()); }); }
public void Setup_AnyReferenceTypeTarget_MatchesAnyInstance() { Smock.Run(context => { const int expected = 1337; context.Setup(() => It.IsAny <string>().Length).Returns(expected); Assert.AreEqual(expected, "Hello".Length); Assert.AreEqual(expected, "World".Length); }); }
public void Raise_StaticEvent_RaisesInvokedEvent() { bool invoked = false; Smock.Run(context => { Console.CancelKeyPress += (sender, args) => invoked = true; context.Raise(() => Console.CancelKeyPress += null, () => Console.CancelKeyPress -= null, default(EventArgs)); }); Assert.IsTrue(invoked); }
public void Callback_LessThanExpectedTwelveArguments_ThrowsException() { Assert.Throws <ArgumentException>(() => { Smock.Run(context => { context .Setup(() => TestFunctions.TwelveArguments(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12)) .Callback <int, int, int, int, int, int, int, int, int, int, int>((a, b, c, d, e, f, g, h, i, j, k) => { }); }); }); }
public void Callback_MoreThanExpectedOneArgument_ThrowsException() { Assert.Throws <ArgumentException>(() => { Smock.Run(context => { context .Setup(() => TestFunctions.OneArgument(1)) .Callback <int, int>((a, z) => { }); }); }); }
public void ReturnsCallback_EightMatchingArgs_ReturnsResultFromCallback() { Smock.Run(context => { context .Setup(() => TestFunctions.EightArguments(1, 2, 3, 4, 5, 6, 7, 8)) .Returns <int, int, int, int, int, int, int, int>((a, b, c, d, e, f, g, h) => a + b + c + d + e + f + g + h); var result = TestFunctions.EightArguments(1, 2, 3, 4, 5, 6, 7, 8); Assert.AreEqual(36, result); }); }
public void ReturnsCallback_TooFewArguments_ThrowsException() { Assert.Throws <ArgumentException>(() => { Smock.Run(context => { context .Setup(() => TestFunctions.TwoArguments(1, 2)) .Returns <int>(a => 42); }); }); }
public void ReturnsCallback_FourMatchingArgs_ReturnsResultFromCallback() { Smock.Run(context => { context .Setup(() => TestFunctions.FourArguments(1, 2, 3, 4)) .Returns <int, int, int, int>((a, b, c, d) => a + b + c + d); var result = TestFunctions.FourArguments(1, 2, 3, 4); Assert.AreEqual(10, result); }); }
public void Setup_MultipleItIsSetups_MatchesTheCorrectSetup() { Smock.Run(context => { context.Setup(() => string.Format(It.Is <string>(format => format.Contains("A")))).Returns("Foo"); context.Setup(() => string.Format(It.Is <string>(format => format.Contains("B")))).Returns("Bar"); Assert.AreEqual("Foo", string.Format("AA")); Assert.AreEqual("Bar", string.Format("BB")); Assert.AreEqual("CC", string.Format("CC")); }); }
public void Callback_SingleConvertibleArg_InvokesCallbackWithArguments() { Smock.Run(context => { int result = 0; context.Setup(() => Math.Sqrt(It.IsAny <double>())).Callback <int>(d => result = d * d); Math.Sqrt(2.0); Assert.AreEqual(4, result); }); }
public void Callback_TooManyVoidMethodArguments_ThrowsException() { Assert.Throws <ArgumentException>(() => { Smock.Run(context => { context .Setup(() => Console.WriteLine("{0}")) .Callback <string, int>((a, b) => { }); }); }); }
public void Callback_VoidLessThanExpectedTwoArguments_ThrowsException() { Assert.Throws <ArgumentException>(() => { Smock.Run(context => { context .Setup(() => TestFunctions.VoidTwoArguments(1, 2)) .Callback <int>((a) => { }); }); }); }
public void Callback_LessThanExpectedSixteenArguments_ThrowsException() { Assert.Throws <ArgumentException>(() => { Smock.Run(context => { context .Setup(() => TestFunctions.SixteenArguments(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16)) .Callback <int, int, int, int, int, int, int, int, int, int, int, int, int, int, int>((a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) => { }); }); }); }
public void ReturnsCallback_TooManyArguments_ThrowsException() { Assert.Throws <ArgumentException>(() => { Smock.Run(context => { context .Setup(() => TestFunctions.OneArgument(1)) .Returns <int, int>((a, b) => 42); }); }); }
public void Run_GuidFunc_ReturnsCorrectValue() { Guid expected = Guid.Parse("{2988B6BD-B4D7-476D-B432-19D781FC9B20}"); Guid value = Smock.Run(context => { context.Setup(() => Guid.Parse(It.IsAny <string>())).Returns(expected); return(Guid.Parse(string.Empty)); }); Assert.AreEqual(expected, value); }
public void ReturnsCallback_SixMatchingArgs_ReturnsResultFromCallback() { Smock.Run(context => { context .Setup(() => TestFunctions.SixArguments(1, 2, 3, 4, 5, 6)) .Returns <int, int, int, int, int, int>((a, b, c, d, e, f) => a + b + c + d + e + f); var result = TestFunctions.SixArguments(1, 2, 3, 4, 5, 6); Assert.AreEqual(21, result); }); }
public void Run_UriFunc_ReturnsCorrectValue() { Uri expected = new Uri("http://www.google.com"); Uri value = Smock.Run(context => { context.Setup(() => new Uri(It.IsAny <string>())).Returns(expected); return(new Uri(string.Empty)); }); Assert.AreEqual(expected, value); }
public void NewCombTest() { DateTime now = DateTime.Now; Smock.Run(context => { context.Setup(() => DateTime.Now).Returns(now); Guid id = CombHelper.NewComb(); DateTime time = CombHelper.GetDateFromComb(id); Assert.True(time.Subtract(now).TotalSeconds < 1); }); }
public void Callback_VoidMoreThanExpectedThirteenArguments_ThrowsException() { Assert.Throws <ArgumentException>(() => { Smock.Run(context => { context .Setup(() => TestFunctions.VoidThirteenArguments(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13)) .Callback <int, int, int, int, int, int, int, int, int, int, int, int, int, int>((a, b, c, d, e, f, g, h, i, j, k, l, m, z) => { }); }); }); }
public void Run_ISerializableFunc_ReturnsCorrectValue() { Exception expected = new Exception("Test"); Exception value = Smock.Run(context => { context.Setup(() => new Exception(It.IsAny <string>())).Returns(expected); return(new Exception(string.Empty)); }); Assert.AreEqual(expected, value); }
public void test() { Smock.Run(context => { context.Setup(() => DateTime.Now).Returns(new DateTime(2000, 1, 1)); var dateNow = DateTime.Now; Assert.That(dateNow, Is.EqualTo(new DateTime(3000, 1, 1))); Console.WriteLine("ttu"); Thread.Sleep(2220); }); }
public void Run_DecimalFunc_ReturnsCorrectValue() { decimal expected = 1.23m; decimal value = Smock.Run(context => { context.Setup(() => decimal.Parse(It.IsAny <string>())).Returns(expected); return(decimal.Parse("0")); }); Assert.AreEqual(expected, value); }
public void Callback_MoreThanExpectedNineArguments_ThrowsException() { Assert.Throws <ArgumentException>(() => { Smock.Run(context => { context .Setup(() => TestFunctions.NineArguments(1, 2, 3, 4, 5, 6, 7, 8, 9)) .Callback <int, int, int, int, int, int, int, int, int, int>((a, b, c, d, e, f, g, h, i, z) => { }); }); }); }