Example #1
0
        public ThingContextFactoryTest()
        {
            _response = Substitute.For <IThingResponseBuilder>();
            _event    = Substitute.For <IEventBuilder>();
            _property = Substitute.For <IPropertyBuilder>();
            _action   = Substitute.For <IActionBuilder>();

            _factory = new ThingContextFactory(_event, _property, _response, _action);

            _event
            .Build()
            .Returns(new Dictionary <string, EventCollection>());

            _response
            .Build()
            .Returns(new Dictionary <string, object>());

            _action
            .Build()
            .Returns(new Dictionary <string, ActionCollection>());

            _property
            .Build()
            .Returns(new Dictionary <string, IThingProperty>());
        }
Example #2
0
 public CognitiveServicesController(ISitecoreContext sitecoreContext, IContextWrapper contextWrapper, IPropertyBuilder propertyBuilder, IFaceApiService faceApiService)
 {
     _sitecoreContext = sitecoreContext;
     _contextWrapper  = contextWrapper;
     _propertyBuilder = propertyBuilder;
     _faceApiService  = faceApiService;
 }
        public static SqlServerPropertyBuilder ForSqlServer <TPropertyBuilder>(
            [NotNull] this IPropertyBuilder <TPropertyBuilder> propertyBuilder)
            where TPropertyBuilder : IPropertyBuilder <TPropertyBuilder>
        {
            Check.NotNull(propertyBuilder, "propertyBuilder");

            return(new SqlServerPropertyBuilder(propertyBuilder.Metadata));
        }
Example #4
0
 public NavigationController(IContentContext context, ISitecoreContext scContext, IPropertyBuilder builder, INavigationRepository navigationRepository)
 {
     _context              = context;
     _scContext            = scContext;
     _builder              = builder;
     _navigationRepository = navigationRepository;
     (_navigationRepository as NavigationRepository).Initialize(RenderingContext.Current.ContextItem);
 }
Example #5
0
        public IClassBuilder WithProperty(Action <IPropertyBuilder> buildProperty)
        {
            IPropertyBuilder propertyBuilder = this.ServiceProvider.GetRequiredService <IPropertyBuilder>();

            buildProperty(propertyBuilder);
            this.PropertyBuilderList.Add(propertyBuilder);
            return(this);
        }
Example #6
0
 /// <summary>
 /// Initialize a new instance of <see cref="IEventBuilder"/>.
 /// </summary>
 /// <param name="event"></param>
 /// <param name="property"></param>
 /// <param name="response"></param>
 /// <param name="action"></param>
 public ThingContextFactory(IEventBuilder @event, IPropertyBuilder property,
                            IThingResponseBuilder response, IActionBuilder action)
 {
     _event    = @event;
     _property = property;
     _response = response;
     _action   = action;
 }
Example #7
0
        public ITableBuilder AddComplexProperty(IPropertyBuilder prop)
        {
            var data = new TableBuilder($"?{this}?CP?{prop}");
            var pe   = new PropertyEntry((PropertyBuilder)prop, data, PropertyEntry.TABLE);

            props.Add(pe);
            return(data);
        }
        public static RelationalPropertyBuilder ForRelational <TPropertyBuilder>(
            [NotNull] this IPropertyBuilder <TPropertyBuilder> propertyBuilder)
            where TPropertyBuilder : IPropertyBuilder <TPropertyBuilder>
        {
            Check.NotNull(propertyBuilder, "propertyBuilder");

            return(new RelationalPropertyBuilder(propertyBuilder.Metadata));
        }
Example #9
0
        public static AtsPropertyBuilder ForAzureTableStorage <TPropertyBuilder>(
            [NotNull] this IPropertyBuilder <TPropertyBuilder> propertyBuilder)
            where TPropertyBuilder : IPropertyBuilder <TPropertyBuilder>
        {
            Check.NotNull(propertyBuilder, "propertyBuilder");

            return(new AtsPropertyBuilder(propertyBuilder.Metadata));
        }
Example #10
0
        public static TBuilder SharedNameExtension <TBuilder>(this IPropertyBuilder <TBuilder> builder, string value)
            where TBuilder : IPropertyBuilder <TBuilder>
        {
            builder.Annotation("Annotation", value + ".Annotation");
            builder.Metadata["Metadata"] = value + ".Metadata";
            builder.Model["Model"]       = value + ".Model";

            return((TBuilder)builder);
        }
 public void accessing_the_indexer_with_an_unknown_key_throws()
 {
     given_builder_for <Customer>();
     Executing(() =>
     {
         IPropertyBuilder value = TypeBuilder.Changes["firstname"];
     })
     .ShouldThrow <ArgumentOutOfRangeException>();
 }
Example #12
0
        private string GetRegexGroupNameFor(MemberInfo mi, IPropertyBuilder builder)
        {
            if (builder == null)
            {
                throw new ArgumentNullException("builder");
            }

            return(String.Format("Grp_{0}", mi.Name));
        }
Example #13
0
 public static IPropertyBuilder <TPropertyType, TClassType> AsNumeric <TPropertyType, TClassType>(
     this IPropertyBuilder <TPropertyType, TClassType> propertyBuilder
     )
 {
     return(propertyBuilder
            .HasExportFormat("n0")
            .HasDisplayFormat("{0:n0}")
            .HasEditMask("n0"));
 }
Example #14
0
        public static IPropertyBuilder AssertHasAttribute <TAttribute>(this IPropertyBuilder builder)
            where TAttribute : Attribute
        {
            var attr = builder.MemberInfo.FindAttribute <TAttribute>();

            attr.ShouldNotBeNull();

            return(builder);
        }
 public MvxAndroidUserInterfaceBuilder(IMvxAndroidBindingContext context, object dataSource,
                                     IBuilderRegistry builderRegistry,
                                     string bindTag = MvxAutoViewConstants.MvxBindTag,
                                     string platformName = DroidConstants.PlatformName)
     : base(builderRegistry, platformName)
 {
     _propertyBuilder = new PropertyBuilder();
     var setter = new MvxBindingPropertySetter(context, dataSource);
     _propertyBuilder.CustomPropertySetters[bindTag] = setter;
 }
        public void SetUp()
        {
            _innerMock           = MockRepository.GenerateStrictMock <IPropertyBuilder>();
            _operandProviderMock = MockRepository.GenerateStrictMock <IEmittableOperandProvider>();

            _decorator = new PropertyBuilderDecorator(_innerMock, _operandProviderMock);

            _decoratedMethodBuilder = MockRepository.GenerateStub <IMethodBuilder> ();
            _methodBuilderDecorator = new MethodBuilderDecorator(_decoratedMethodBuilder, _operandProviderMock);
        }
 public MvxTouchUserInterfaceBuilder(IMvxTouchView activity, object dataSource,
                                     IBuilderRegistry builderRegistry,
                                     string bindTag = MvxAutoViewConstants.MvxBindTag,
                                     string platformName = TouchConstants.PlatformName)
     : base(builderRegistry, platformName)
 {
     _propertyBuilder = new PropertyBuilder();
     var setter = new MvxBindingPropertySetter(activity, dataSource);
     _propertyBuilder.CustomPropertySetters[bindTag] = setter;
 }
Example #18
0
        public MvxAndroidUserInterfaceBuilder(IMvxAndroidBindingContext context, object dataSource,
                                              IBuilderRegistry builderRegistry,
                                              string bindTag      = MvxAutoViewConstants.MvxBindTag,
                                              string platformName = DroidConstants.PlatformName)
            : base(builderRegistry, platformName)
        {
            this._propertyBuilder = new PropertyBuilder();
            var setter = new MvxBindingPropertySetter(context, dataSource);

            this._propertyBuilder.CustomPropertySetters[bindTag] = setter;
        }
Example #19
0
            public bool TryGetValue(string key, out IPropertyBuilder value)
            {
                if (ContainsKey(key))
                {
                    value = Owner.PropertiesCache[key];
                    return(true);
                }

                value = null;
                return(false);
            }
        public MvxTouchUserInterfaceBuilder(IMvxTouchView activity, object dataSource,
                                            IBuilderRegistry builderRegistry,
                                            string bindTag      = MvxAutoViewConstants.MvxBindTag,
                                            string platformName = TouchConstants.PlatformName)
            : base(builderRegistry, platformName)
        {
            _propertyBuilder = new PropertyBuilder();
            var setter = new MvxBindingPropertySetter(activity, dataSource);

            _propertyBuilder.CustomPropertySetters[bindTag] = setter;
        }
        public static TPropertyBuilder ForRelational <TPropertyBuilder>(
            [NotNull] this IPropertyBuilder <TPropertyBuilder> propertyBuilder,
            [NotNull] Action <RelationalPropertyBuilder> relationalPropertyBuilder)
            where TPropertyBuilder : IPropertyBuilder <TPropertyBuilder>
        {
            Check.NotNull(propertyBuilder, "propertyBuilder");
            Check.NotNull(relationalPropertyBuilder, "relationalPropertyBuilder");

            relationalPropertyBuilder(ForRelational(propertyBuilder));

            return((TPropertyBuilder)propertyBuilder);
        }
Example #22
0
        public static IPropertyBuilder <TPropertyType, TClassType> HasExportFormat <TPropertyType, TClassType>(
            this IPropertyBuilder <TPropertyType, TClassType> propertyBuilder,
            string exportFormat = null
            )
        {
            if (exportFormat == null)
            {
                return(propertyBuilder.WithAttribute <ExportFormatAttribute>());
            }

            return(propertyBuilder.WithAttribute(new ExportFormatAttribute(exportFormat)));
        }
Example #23
0
        public static TPropertyBuilder ForAzureTableStorage <TPropertyBuilder>(
            [NotNull] this IPropertyBuilder <TPropertyBuilder> propertyBuilder,
            [NotNull] Action <AtsPropertyBuilder> relationalPropertyBuilder)
            where TPropertyBuilder : IPropertyBuilder <TPropertyBuilder>
        {
            Check.NotNull(propertyBuilder, "propertyBuilder");
            Check.NotNull(relationalPropertyBuilder, "relationalPropertyBuilder");

            relationalPropertyBuilder(ForAzureTableStorage(propertyBuilder));

            return((TPropertyBuilder)propertyBuilder);
        }
        public static TPropertyBuilder ForSqlServer <TPropertyBuilder>(
            [NotNull] this IPropertyBuilder <TPropertyBuilder> propertyBuilder,
            [NotNull] Action <SqlServerPropertyBuilder> sqlServerPropertyBuilder)
            where TPropertyBuilder : IPropertyBuilder <TPropertyBuilder>
        {
            Check.NotNull(propertyBuilder, "propertyBuilder");
            Check.NotNull(sqlServerPropertyBuilder, "sqlServerPropertyBuilder");

            sqlServerPropertyBuilder(ForSqlServer(propertyBuilder));

            return((TPropertyBuilder)propertyBuilder);
        }
Example #25
0
        private static void SetupStart(IMethodBuilder method, Label endLabel,
                                       VariableBase returnValue, IPropertyBuilder aspectusStarting)
        {
            if (method == null)
            {
                throw new ArgumentNullException("method");
            }
            VariableBase startingArgs = method.NewObj(typeof(Starting).GetConstructor(new Type[0]));

            startingArgs.Call(typeof(Starting).GetProperty("MethodName").GetSetMethod(), new object[] { method.Name });

            VariableBase parameterList = startingArgs.Call(typeof(Starting).GetProperty("Parameters").GetGetMethod());

            for (int x = 1; x < method.Parameters.Count; ++x)
            {
                if (method.Parameters.ElementAt(x).DataType != null &&
                    method.Parameters.ElementAt(x).DataType.IsValueType)
                {
                    parameterList.Call(typeof(List <object>).GetMethod("Add"),
                                       new object[] { method.Box(method.Parameters.ElementAt(x)) });
                }
                else
                {
                    parameterList.Call(typeof(List <object>).GetMethod("Add"),
                                       new object[] { method.Parameters.ElementAt(x) });
                }
            }

            VariableBase eventsThis      = method.Cast(method.This, typeof(IEvents));
            Type         eventHelperType = typeof(DelegateExtensions);

            MethodInfo[] methods = eventHelperType.GetMethods()
                                   .Where(x => x.GetParameters().Length == 3)
                                   .ToArray();
            MethodInfo tempMethod = methods.Length > 0 ? methods[0] : null;

            tempMethod = tempMethod.MakeGenericMethod(new[] { typeof(Starting) });
            method.Call(null, tempMethod, new object[] { aspectusStarting, eventsThis, startingArgs });
            if (method.ReturnType != typeof(void))
            {
                VariableBase tempReturnValue =
                    startingArgs.Call(typeof(Starting).GetProperty("ReturnValue").GetGetMethod());
                VariableBase tempNull = method.CreateLocal("TempNull", typeof(object));
                If           If       = method.If(tempReturnValue, Comparison.NotEqual, tempNull);
                {
                    returnValue.Assign(tempReturnValue);
                    method.Generator.Emit(OpCodes.Br, endLabel);
                }
                method.SetCurrentMethod();
                If.EndIf();
            }
        }
Example #26
0
        public void AddPropertyBuilder(string keyword, IPropertyBuilder<IProperty> propertyBuilder)
        {
            if (string.IsNullOrWhiteSpace(keyword))
            {
                throw new ArgumentNullException("keyword");
            }
            if (propertyBuilder == null)
            {
                throw new ArgumentNullException("propertyBuilder");
            }

            _propertyBuilderTable.Add(keyword, propertyBuilder);
        }
Example #27
0
        public static IPropertyBuilder AssertAttribute <TAttribute, TProperty>(this IPropertyBuilder builder, Func <TAttribute, bool> assertion)
            where TAttribute : Attribute
        {
            var attr = builder.MemberInfo.FindAttribute <TAttribute>();

            attr.ShouldSatisfyAllConditions
            (
                () => attr.ShouldNotBeNull(),
                () => assertion.Invoke(attr).ShouldBe(true)
            );

            return(builder);
        }
        private void SetupEnd(IMethodBuilder Method, VariableBase ReturnValue, IPropertyBuilder AspectusEnding)
        {
            VariableBase EndingArgs = Method.NewObj(typeof(Ending).GetConstructor(new Type[0]));

            EndingArgs.Call(typeof(Ending).GetProperty("MethodName").GetSetMethod(), new object[] { Method.Name });
            if (Method.ReturnType != typeof(void) && ReturnValue.DataType != null && ReturnValue.DataType.IsValueType)
            {
                EndingArgs.Call(typeof(Ending).GetProperty("ReturnValue").GetSetMethod(), new object[] { Method.Box(ReturnValue) });
            }
            else if (Method.ReturnType != typeof(void))
            {
                EndingArgs.Call(typeof(Ending).GetProperty("ReturnValue").GetSetMethod(), new object[] { ReturnValue });
            }
            VariableBase ParameterList = EndingArgs.Call(typeof(Ending).GetProperty("Parameters").GetGetMethod());

            for (int x = 1; x < Method.Parameters.Count; ++x)
            {
                if (Method.Parameters[x].DataType != null && Method.Parameters[x].DataType.IsValueType)
                {
                    ParameterList.Call(typeof(List <object>).GetMethod("Add"), new object[] { Method.Box(Method.Parameters[x]) });
                }
                else
                {
                    ParameterList.Call(typeof(List <object>).GetMethod("Add"), new object[] { Method.Parameters[x] });
                }
            }

            VariableBase IEventsThis     = Method.Cast(Method.This, typeof(IEvents));
            Type         EventHelperType = typeof(Utilities.Events.EventHelper);

            MethodInfo[] Methods = EventHelperType.GetMethods()
                                   .Where <MethodInfo>(x => x.GetParameters().Length == 3)
                                   .ToArray();
            MethodInfo TempMethod = Methods.Length > 0 ? Methods[0] : null;

            TempMethod = TempMethod.MakeGenericMethod(new Type[] { typeof(Ending) });
            Method.Call(null, TempMethod, new object[] { AspectusEnding, IEventsThis, EndingArgs });
            if (Method.ReturnType != typeof(void))
            {
                VariableBase TempReturnValue             = EndingArgs.Call(typeof(Ending).GetProperty("ReturnValue").GetGetMethod());
                VariableBase TempNull                    = Method.CreateLocal("TempNull", typeof(object));
                Utilities.Reflection.Emit.Commands.If If = Method.If(TempReturnValue, Utilities.Reflection.Emit.Enums.Comparison.NotEqual, TempNull);
                {
                    ReturnValue.Assign(TempReturnValue);
                }
                Method.SetCurrentMethod();
                If.EndIf();
            }
        }
Example #29
0
        private static void SetupMethod(Type baseType, IMethodBuilder method, IPropertyBuilder aspectusStarting,
                                        IPropertyBuilder aspectusEnding, IPropertyBuilder aspectusException,
                                        MethodInfo baseMethod)
        {
            if (baseMethod == null)
            {
                baseMethod = baseType.GetMethod(method.Name);
            }
            method.SetCurrentMethod();
            Label        endLabel    = method.Generator.DefineLabel();
            VariableBase returnValue = method.ReturnType != typeof(void)
                                           ? method.CreateLocal("FinalReturnValue", method.ReturnType)
                                           : null;
            Try Try = method.Try();
            {
                SetupStart(method, endLabel, returnValue, aspectusStarting);
                _aspects.ForEach(x => x.SetupStartMethod(method, baseType));
                var parameters = new List <ParameterBuilder>();
                method.Parameters.For(1, method.Parameters.Count - 1, x => parameters.Add(x));
                if (method.ReturnType != typeof(void) && baseMethod != null)
                {
                    returnValue.Assign(method.This.Call(baseMethod, parameters.ToArray()));
                }
                else if (baseMethod != null)
                {
                    method.This.Call(baseMethod, parameters.ToArray());
                }
                SetupEnd(method, returnValue, aspectusEnding);
                _aspects.ForEach(x => x.SetupEndMethod(method, baseType, returnValue));
                method.Generator.MarkLabel(endLabel);
            }
            Catch Catch = Try.StartCatchBlock(typeof(System.Exception));

            {
                SetupException(method, Catch, aspectusException);
                _aspects.ForEach(x => x.SetupExceptionMethod(method, baseType));
                Catch.Rethrow();
            }
            Try.EndTryBlock();

            if (method.ReturnType != typeof(void))
            {
                method.Return(returnValue);
            }
            else
            {
                method.Return();
            }
        }
Example #30
0
        public void CreateDefaultProperty()
        {
            Utilities.Reflection.Emit.Assembly    Assembly = new Utilities.Reflection.Emit.Assembly("TestAssembly");
            Utilities.Reflection.Emit.TypeBuilder TestType = Assembly.CreateType("TestType");
            IPropertyBuilder TestProperty = TestType.CreateDefaultProperty("TestProperty", typeof(int));

            Assert.NotNull(TestProperty);
            Assert.Equal("TestProperty", TestProperty.Name);
            Assert.Equal(typeof(int), TestProperty.DataType);
            Assert.NotNull(TestProperty.Builder);
            Assert.Equal(PropertyAttributes.SpecialName, TestProperty.Attributes);
            Assert.NotNull(TestProperty.GetMethod);
            Assert.NotNull(TestProperty.SetMethod);
            Assert.Equal(MethodAttributes.Public | MethodAttributes.Virtual, TestProperty.GetMethodAttributes);
            Assert.Equal(MethodAttributes.Public | MethodAttributes.Virtual, TestProperty.SetMethodAttributes);
        }
Example #31
0
        public void assigning_properties_after_the_property_got_assigned_a_parent_updates_the_parent()
        {
            given_builder_for <Customer>();

            var customerInstance = new Customer();

            TypeBuilder.TrySetValue(customerInstance);

            IPropertyBuilder firstName = TypeBuilder.GetProperty("FirstName");

            //firstName.SetOwner(TypeBuilder);

            firstName.TrySetValue(new[] { "Smeagol" }, IdentityConverter);

            TypeBuilder.Update(customerInstance);
            customerInstance.FirstName.ShouldBe("Smeagol");
        }
        private void SetupMethod(Type BaseType, IMethodBuilder Method, IPropertyBuilder AspectusStarting,
                                 IPropertyBuilder AspectusEnding, IPropertyBuilder AspectusException, MethodInfo BaseMethod)
        {
            if (BaseMethod == null)
            {
                BaseMethod = BaseType.GetMethod(Method.Name);
            }
            Method.SetCurrentMethod();
            System.Reflection.Emit.Label EndLabel = Method.Generator.DefineLabel();
            VariableBase ReturnValue = Method.ReturnType != typeof(void) ? Method.CreateLocal("FinalReturnValue", Method.ReturnType) : null;

            Utilities.Reflection.Emit.Commands.Try Try = Method.Try();
            {
                SetupStart(Method, EndLabel, ReturnValue, AspectusStarting);
                Aspects.ForEach(x => x.SetupStartMethod(Method, BaseType));
                List <ParameterBuilder> Parameters = new List <ParameterBuilder>();
                Method.Parameters.For(1, Method.Parameters.Count - 1, x => Parameters.Add(x));
                if (Method.ReturnType != typeof(void) && BaseMethod != null)
                {
                    ReturnValue.Assign(Method.This.Call(BaseMethod, Parameters.ToArray()));
                }
                else if (BaseMethod != null)
                {
                    Method.This.Call(BaseMethod, Parameters.ToArray());
                }
                SetupEnd(Method, ReturnValue, AspectusEnding);
                Aspects.ForEach(x => x.SetupEndMethod(Method, BaseType, ReturnValue));
                Method.Generator.MarkLabel(EndLabel);
            }
            Utilities.Reflection.Emit.Commands.Catch Catch = Try.StartCatchBlock(typeof(System.Exception));
            {
                SetupException(Method, Catch, AspectusException);
                Aspects.ForEach(x => x.SetupExceptionMethod(Method, BaseType));
                Catch.Rethrow();
            }
            Try.EndTryBlock();

            if (Method.ReturnType != typeof(void))
            {
                Method.Return(ReturnValue);
            }
            else
            {
                Method.Return();
            }
        }
Example #33
0
        private static void SetupException(IMethodBuilder method, Catch Catch, IPropertyBuilder aspectusException)
        {
            VariableBase exceptionArgs = method.NewObj(typeof(Exception).GetConstructor(new Type[0]));

            exceptionArgs.Call(typeof(Exception).GetProperty("InternalException").GetSetMethod(),
                               new object[] { Catch.Exception });
            VariableBase eventsThis      = method.Cast(method.This, typeof(IEvents));
            Type         eventHelperType = typeof(DelegateExtensions);

            MethodInfo[] methods = eventHelperType.GetMethods()
                                   .Where(x => x.GetParameters().Length == 3)
                                   .ToArray();
            MethodInfo tempMethod = methods.Length > 0 ? methods[0] : null;

            tempMethod = tempMethod.MakeGenericMethod(new[] { typeof(Exception) });
            method.Call(null, tempMethod, new object[] { aspectusException, eventsThis, exceptionArgs });
        }
Example #34
0
 /// <summary>
 /// Set up interfaces
 /// </summary>
 /// <param name="TypeBuilder">Type builder to use</param>
 public void SetupInterfaces(Reflection.Emit.TypeBuilder TypeBuilder)
 {
     Fields = new List<Reflection.Emit.FieldBuilder>();
     SessionField = CreateProperty(TypeBuilder, "Session0", typeof(Session));
     CreateConstructor(TypeBuilder);
     SetupFields(TypeBuilder);
 }