private Dictionary <DtoRetriveMethods, Func <object> > InitCreateDtoMethods <TDto, TDtoFaker>() where TDtoFaker : class, IDtoFaker <TDto> where TDto : class, IDto { TDtoFaker dtoFaker = ResolverFactory.CreateInstance <TDtoFaker>(typeof(TDtoFaker).AssemblyQualifiedName); var methodMap = new Dictionary <DtoRetriveMethods, Func <object> >(); methodMap.Add(DtoRetriveMethods.FakeOne, () => dtoFaker.CreateDto()); methodMap.Add(DtoRetriveMethods.FakeInvalidOne, () => dtoFaker.CreateInvalidDto()); return(methodMap); }
private ValidationDto CheckValidation(TDto model) { var attrs = typeof(TDto).GetCustomAttributes(true); ValidatorAttribute attr = (ValidatorAttribute)Attribute.GetCustomAttribute(typeof(TDto), typeof(ValidatorAttribute)); if (attr != null) { IValidator validator = ResolverFactory.CreateInstance <IValidator>(attr.ValidatorType.AssemblyQualifiedName); return(new ValidationDto(validator.Validate(model))); } else { return(new ValidationDto()); } }
protected virtual TController InitController(object[] args) { var controller = ResolverFactory.CreateInstance <ApiController>( typeof(TController).AssemblyQualifiedName, args); controller.Request = new HttpRequestMessage { RequestUri = new Uri(_url) }; controller.Configuration = new HttpConfiguration(); controller.Configuration.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional }); controller.RequestContext.RouteData = new HttpRouteData( route: new HttpRoute(), values: _httpRouteValueDictionary); return(controller as TController); }