Ejemplo n.º 1
0
        public void Adds_ITypeRepository_MvcOptions_ServiceRegistrations()
        {
            var sut        = new ModelBuilderExtensionGenerator();
            var code       = sut.CreateModelBuilder("new LaDeak.JsonMergePatch.SourceGenerator.AspNetCore.Tests.TypeRepositoryHook()");
            var mvcBuilder = Substitute.For <IMvcBuilder>();
            var services   = Substitute.For <IServiceCollection>();

            mvcBuilder.Services.Returns(services);

            GetMethodDelegate(code)(mvcBuilder, null, null);

            services.Received().Add(Arg.Is <ServiceDescriptor>(x => x.ServiceType == typeof(ITypeRepository)));
            services.Received().Add(Arg.Is <ServiceDescriptor>(x => x.ServiceType == typeof(IConfigureOptions <Microsoft.AspNetCore.Mvc.MvcOptions>)));
        }
Ejemplo n.º 2
0
        public void AddsJsonMergePatchInputReader_ToMvcOptions()
        {
            var sut        = new ModelBuilderExtensionGenerator();
            var code       = sut.CreateModelBuilder("new LaDeak.JsonMergePatch.SourceGenerator.AspNetCore.Tests.TypeRepositoryHook()");
            var mvcBuilder = Substitute.For <IMvcBuilder>();
            var services   = Substitute.For <IServiceCollection>();

            mvcBuilder.Services.Returns(services);

            IConfigureOptions <Microsoft.AspNetCore.Mvc.MvcOptions> optionsSetup = null;

            services.When(y => y.Add(Arg.Is <ServiceDescriptor>(x => x.ServiceType == typeof(IConfigureOptions <Microsoft.AspNetCore.Mvc.MvcOptions>))))
            .Do(callInfo => optionsSetup = (callInfo[0] as ServiceDescriptor).ImplementationInstance as IConfigureOptions <Microsoft.AspNetCore.Mvc.MvcOptions>);
            var options = new Microsoft.AspNetCore.Mvc.MvcOptions();

            GetMethodDelegate(code)(mvcBuilder, null, null);
            optionsSetup.Configure(options);

            Assert.Contains(options.InputFormatters, x => x is JsonMergePatchInputReader);
        }
Ejemplo n.º 3
0
        protected object ExecuteGetCommand(ParametersValidation validationRequest, GetMethodDelegate method)
        {
            object        res;
            int           timeOut;
            SoapException ex;
            StepType      stepType;

            res = method(validationRequest, out stepType, out ex, out timeOut);
            StepTypeProcessing(stepType, ex, timeOut);

            return(res);
        }
Ejemplo n.º 4
0
        public void PassesCustom_TypeRepository_RegistersToServices()
        {
            var sut        = new ModelBuilderExtensionGenerator();
            var code       = sut.CreateModelBuilder("new LaDeak.JsonMergePatch.SourceGenerator.AspNetCore.Tests.TypeRepositoryHook()");
            var mvcBuilder = Substitute.For <IMvcBuilder>();
            var services   = Substitute.For <IServiceCollection>();

            mvcBuilder.Services.Returns(services);

            ITypeRepository registeredTypeRepository = null;

            services.When(y => y.Add(Arg.Is <ServiceDescriptor>(x => x.ServiceType == typeof(ITypeRepository))))
            .Do(callInfo => registeredTypeRepository = (callInfo[0] as ServiceDescriptor).ImplementationInstance as ITypeRepository);
            var options = new Microsoft.AspNetCore.Mvc.MvcOptions();

            var typeRepository = new TypeRepositoryHook();

            GetMethodDelegate(code)(mvcBuilder, null, typeRepository);

            Assert.Same(typeRepository, registeredTypeRepository);
        }
Ejemplo n.º 5
0
 public void GetMethod(dynamic instance, string strMethodName, object[] arguments)
 {
     if (instance.InvokeRequired)
     {
         GetMethodDelegate gmd = new GetMethodDelegate(GetMethod);
         instance.Invoke(gmd, new object[] { instance, strMethodName, arguments });
     }
     else
     {
         Type       type       = instance.GetType();
         MethodInfo methodInfo = type.GetMethod(strMethodName);
         methodInfo.Invoke(instance, arguments);
     }
 }
Ejemplo n.º 6
0
 // TODO: Make these abstract
 /// <summary>Gets the value of the property for an object instance.</summary>
 /// <param name="instance">The instance whose property's value to get.</param>
 public virtual object Get(object instance) => GetMethodDelegate?.DynamicInvoke(instance);