public void AsyncParameterValidationTest() { var mockModule = new Mock <IMyAsyncModule>(MockBehavior.Strict); mockModule .Setup(m => m.Foo(It.IsAny <string>())) .Returns(Task.CompletedTask); var mockInjector = new Mock <IInjector>(MockBehavior.Strict); Type proxyType = ProxyGenerator <IMyAsyncModule, ParameterValidator <IMyAsyncModule> > .GetGeneratedType(); IMyAsyncModule module = (IMyAsyncModule)Activator.CreateInstance(proxyType, mockModule.Object, mockInjector.Object, false) !; Assert.DoesNotThrowAsync(() => module.Foo("cica")); var ex = Assert.ThrowsAsync <ValidationException>(() => module.Foo(null)); Assert.That(ex.Message, Is.EqualTo("ooops")); }
public void AsyncPropertyValidationTest() { var mockModule = new Mock <IMyAsyncModule>(MockBehavior.Loose); var mockInjector = new Mock <IInjector>(MockBehavior.Strict); mockInjector .Setup(i => i.TryGet(typeof(IRequestContext), null)) .Returns <Type, string>((iface, name) => null); Type proxyType = ProxyGenerator <IMyAsyncModule, ParameterValidator <IMyAsyncModule> > .GetGeneratedType(); IMyAsyncModule module = (IMyAsyncModule)Activator.CreateInstance(proxyType, mockModule.Object, mockInjector.Object) !; Assert.DoesNotThrowAsync(() => module.Foo(new MyArg { Value = "cica" })); Assert.ThrowsAsync <ValidationException>(() => module.Foo(new MyArg())); }