public void TestMethod3() { // // version 2 var persistenceMock = Factory.CreateMock <IPersistence>(); persistenceMock.Expects.One.Method(_ => _.Save(null, null)) .With( Is.Match <string>(key => key == "b"), Is.Match <DateTime>(d => d > DateTime.Now.AddSeconds(-5)) ); persistenceMock.MockObject.Save("b", DateTime.Now); }
private void WithArgumentsTest(IParentInterface instance) { using (Factory.Ordered()) { Expect.On(instance).One.Method(_ => _.MethodVoid(0, 0, 0)).With(1, 2, 3); Expect.On(instance).One.Method(_ => _.MethodVoid(0, 0, 0)).With(Is.EqualTo(4), Is.AtLeast(5), Is.AtMost(6)); Expect.On(instance).One.Method(_ => _.MethodVoid(0, 0, 0)).With(7, Is.AtLeast(8), 9); Expect.On(instance).One.Method(_ => _.MethodVoid(0, 0, 0)).With( new PredicateMatcher <int>(parameter => parameter == 10), Is.Match <int>(parameter => parameter == 11), Is.Anything); } instance.MethodVoid(1, 2, 3); instance.MethodVoid(4, 5, 6); instance.MethodVoid(7, 8, 9); instance.MethodVoid(10, 11, 12); }
private void WithArgumentsTest1(Mock <IParentInterface> mock) { var expectations = new Expectations(4); using (Factory.Ordered()) { expectations[0] = mock.Expects.One.Method(_ => _.MethodVoid(0, 0, 0)).With(1, 2, 3); expectations[1] = mock.Expects.One.Method(_ => _.MethodVoid(0, 0, 0)).With(Is.EqualTo(4), Is.AtLeast(5), Is.AtMost(6)); expectations[2] = mock.Expects.One.Method(_ => _.MethodVoid(0, 0, 0)).With(7, Is.AtLeast(8), 9); expectations[3] = mock.Expects.One.Method(_ => _.MethodVoid(0, 0, 0)).With( new PredicateMatcher <int>(parameter => parameter == 10), Is.Match <int>(parameter => parameter == 11), Is.Anything); } mock.MockObject.MethodVoid(1, 2, 3); mock.MockObject.MethodVoid(4, 5, 6); mock.MockObject.MethodVoid(7, 8, 9); mock.MockObject.MethodVoid(10, 11, 12); expectations.ForEach(_ => _.Assert()); }