public void when_behavior_unspecified_returns_mocked_instance_with_strict_behavior() { var actual = Mockery.Of <IMockable>(); Assert.NotNull(actual); Assert.Throws <MockException>(actual.DoWork); }
public void when_behavior_specified_returns_mock_with_given_behavior(MockBehavior behavior) { var actual = Mockery.Of(behavior, out IMockable mocked); Assert.IsType <Mock <IMockable> >(actual); Assert.Equal(behavior, actual.Behavior); Assert.Same(actual.Object, mocked); }
/// <summary> /// Registers a mocked instance of the specified type with the container. /// </summary> /// <typeparam name="T">Type to mock.</typeparam> /// <param name="registry">Lamar service registry.</param> /// <param name="behavior">Mock behavior.</param> /// <param name="mocked">Mocked instance.</param> /// <returns>The mock setup.</returns> public static Mock <T> Mock <T>(this ServiceRegistry registry, MockBehavior behavior, out T mocked) where T : class { if (registry == null) { throw new ArgumentNullException(nameof(registry)); } var mock = Mockery.Of(behavior, out mocked); registry.For <T>().Add(mocked); return(mock); }
public void when_behavior_specified_returns_mocked_instance_with_given_behavior(MockBehavior behavior) { var actual = Mockery.Of <IMockable>(behavior); Assert.NotNull(actual); switch (behavior) { case MockBehavior.Loose: actual.DoWork(); break; case MockBehavior.Strict: Assert.Throws <MockException>(actual.DoWork); break; default: throw new NotImplementedException(); } }