예제 #1
0
 public void InvokeNonPublicMethod()
 {
     var @class = new Class(typeof(ClassForMethodTest));
     var method = @class.GetMethod("_GetFoo");
     var test = new ClassForMethodTest("bar");
     Assert.AreEqual("bar", method.Invoke(test));
 }
예제 #2
0
        public virtual void Write(Type uiItemType, string actionName, string identification, object[] parameters)
        {
            StringBuilder builder = new StringBuilder(CodeForGettingUIItem(uiItemType, identification));

            builder.Append(".").Append(actionName);
            Class uiItemClass = new Class(uiItemType);
            if (uiItemClass.IsProperty(actionName))
            {
                builder.Append(" = ");
                if (parameters[0] is bool) builder.Append((bool) parameters[0] ? "true" : "false");
                else builder.Append("\"" + parameters[0] + "\"");
            }
            else
            {
                builder.Append("(");
                for (int i = 0; i < parameters.Length; i++)
                {
                    builder.Append("\"").Append(parameters[i]).Append("\"");
                    if (i != parameters.Length - 1) builder.Append(", ");
                }
                builder.Append(")");
            }

            builder.Append(";");
            code = builder.ToString();
        }
예제 #3
0
        public virtual void Populate(FieldMap fieldMap, Entity entity)
        {
            var fieldsWithNoValueOnEntity = new List<string>();

            var @class = new Class(GetType());
            @class.EachField(delegate(FieldInfo fieldInfo)
                                 {
                                     var uiItem = fieldInfo.GetValue(this) as UIItem;
                                     if (uiItem == null || !ControlDictionary.Instance.IsEditable(uiItem)) return;

                                     string fieldName = fieldMap.GetFieldNameFor(fieldInfo.Name, fieldInfo.FieldType);
                                     if (string.IsNullOrEmpty(fieldName)) return;

                                     try
                                     {
                                         EntityField entityField = entity.Field(fieldName);
                                         if (entityField == null)
                                             fieldsWithNoValueOnEntity.Add(fieldName);
                                         else
                                             entityField.SetValueOn(uiItem);
                                     }
                                     catch (TargetInvocationException e)
                                     {
                                         throw new AppScreenException(
                                             string.Format("Error assigning {0}.{1} to {2}.{3} ", entity.GetType(), fieldName, GetType(), fieldInfo.Name),
                                             e.InnerException);
                                     }
                                 });

            if (fieldsWithNoValueOnEntity.Count == 0) return;

            string message = string.Join(",", fieldsWithNoValueOnEntity.ToArray());
            WhiteLogger.Instance.WarnFormat("Mapping to screen: {0} with {1}, No value specified for fields {2}", this, entity.GetType(), message);
        }
 public static ControlType ControlType(Type type)
 {
     var @class = new Class(type);
     if ([email protected](typeof (ControlTypeMappingAttribute)))
         throw new CustomUIItemException("ControlTypeMappingAttribute needs to be defined for this type: " + type.FullName);
     var controlTypeMappingAttribute = @class.Attribute<ControlTypeMappingAttribute>();
     return ControlType(controlTypeMappingAttribute.CustomUIItemType);
 }
예제 #5
0
 public void NewScreenContainingComponent()
 {
     var mocks = new MockRepository();
     var window = mocks.StrictMock<Window>();
     var screenRepository = mocks.StrictMock<ScreenRepository>();
     mocks.ReplayAll();
     var @class = new Class(typeof(ScreenClassContainingComponent));
     new ScreenClass(@class).New(window, screenRepository);
 }
예제 #6
0
 public void New_screen_containing_component()
 {
     MockRepository mocks = new MockRepository();
     Window window = mocks.CreateMock<Window>();
     ScreenRepository screenRepository = mocks.CreateMock<ScreenRepository>();
     mocks.ReplayAll();
     Class @class = new Class(typeof(ScreenClassContainingComponent));
     new ScreenClass(@class).New(window, screenRepository);
 }
예제 #7
0
 public virtual EntityField Field(string fieldName)
 {
     foreach (Entity entity in NestedEntities)
     {
         Class @class = new Class(entity.GetType());
         FieldInfo field = @class.GetField(fieldName);
         if (null != field) return new EntityField(entity, field);
     }
     return null;
 }
예제 #8
0
 public ReflectedObject(object o, LeafRegistry registry)
 {
     this.o = o;
     leafRegister = registry;
     if (o != null)
     {
         @class = new Class(o.GetType());
         @class.IgnoreClass(ignoredType);
         fields = new Fields(this.o);
     }
 }
예제 #9
0
 public virtual ApplicationClass ClassFor(object test)
 {
     var @class = new Class(test.GetType());
     if (@class.HasAttribute(typeof (CategoryAttribute)))
     {
         List<CategoryAttribute> categoryAttributes = @class.Attributes<CategoryAttribute>();
         if (ContainsName(categoryAttributes, DefaultAppClass))
             return DefaultAppClass;
         string category = categoryAttributes[0].Name;
         if (categories.ContainsKey(category)) return categories[category];
     }
     return applicationClass.Equals(ApplicationClass.None) ? DefaultAppClass : applicationClass;
 }
예제 #10
0
        private void AllSubsclassesHaveEmptyConstructor(BricksCollection<Class> collection, Type type)
        {
            var @class = new Class(type);
            Classes classes = @class.SubClassesInAssembly();
            foreach (Class subClass in classes)
            {
                bool hasDefaultConstructor = false;
                subClass.EachConstructor(delegate(ConstructorInfo constructorInfo)
                                             {
                                                 if (constructorInfo.GetParameters().Length == 0 || subClass.Name.Equals(typeof(ToggleableItem).Name))
                                                     hasDefaultConstructor = true;
                                             });
                if (!hasDefaultConstructor &&  subClass.ClassType.IsVisible && !subClass.Name.Equals("Desktop")) collection.Add(subClass);
            }

            Assert.AreEqual(0, collection.Count, collection.ToString());
        }
예제 #11
0
 public void EachField(Class.FieldDelegate operation)
 {
     @class.EachField(operation);
 }
예제 #12
0
 public void NonVirtuals()
 {
     var @class = new Class(typeof(ClassForClassTest));
     Assert.AreEqual(2, @class.NonVirtuals.Count);
 }
예제 #13
0
 public void SubClasses()
 {
     var @class = new Class(typeof(ClassForClassTest));
     Assert.AreEqual(1, @class.SubClassesInAssembly().Count);
 }
예제 #14
0
 public void NewWhenObjectTypeIsSubtype()
 {
     var @class = new Class(typeof(ClassForClassTest));
     @class.New(string.Empty);
 }
예제 #15
0
 public void NewWhenTheParametersAreWrong()
 {
     var @class = new Class(typeof(ClassForClassTest));
     @class.New(0, 0);
 }
예제 #16
0
 public void SetUp()
 {
     forPropertyTest = new ForPropertyTest("bar");
     @class = new Class(typeof(ForPropertyTest));
 }
예제 #17
0
 public void New()
 {
     var @class = new Class(typeof(ClassForClassTest));
     Assert.AreNotEqual(null, @class.New());
 }
예제 #18
0
 public void HasAttribute()
 {
     var @class = new Class(typeof(ClassForClassTest));
     Assert.AreEqual(true, @class.HasAttribute(typeof (SerializableAttribute)));
     Assert.AreEqual(false, @class.HasAttribute(typeof (TestFixtureAttribute)));
 }
예제 #19
0
 public void HasAttributes()
 {
     var @class = new Class(typeof(ClassForClassTest));
     bool b = @class.GetProperty("SomeProperty").HasAttribute(typeof(XmlIgnoreAttribute));
     Assert.AreEqual(true, b);
 }
예제 #20
0
 public void ShouldStoreParameterTypeOfMethod()
 {
     var @class = new Class(typeof(TestServiceForServiceCallTest));
     var serviceCall = new ServiceCall(new TestServiceForServiceCallTest(), @class.GetMethod("Method").MethodInfo);
     Assert.AreEqual("System.String", serviceCall.ParameterTypes[0]);
 }
예제 #21
0
 public void GetProperty()
 {
     var @class = new Class(typeof(ClassForClassTest));
     Assert.AreNotEqual(null, @class.GetProperty("SomeProperty"));
 }
예제 #22
0
 public void SetUp()
 {
     @class = new Class(typeof(TestService));
     executionHistory = new ExecutionHistory();
     serviceExecution = new ServiceExecution(executionHistory, new NullWorkEnvironment());
 }
예제 #23
0
 public void AllNonStandardTypesFromArray()
 {
     var @class = new Class(typeof(object[]));
     @class.AllNonAutoSerializableTypes();
 }
예제 #24
0
 public void AllNonStandardTypes()
 {
     var @class = new Class(typeof(ClassContainingVarietyOfTypes));
     List<Type> types = @class.AllNonAutoSerializableTypes();
     Assert.AreEqual(5, types.Count);
     Assert.AreEqual(true, types.Contains(typeof(ClassContainingVarietyOfTypes)));
     Assert.AreEqual(true, types.Contains(typeof(NestedClassContainingVarietyOfTypes)));
     Assert.AreEqual(true, types.Contains(typeof(FileOptions)));
     Assert.AreEqual(true, types.Contains(typeof(BaseClassForClassTest)));
     Assert.AreEqual(true, types.Contains(typeof(InternalConstructorClass)));
 }
예제 #25
0
 public void AttributeValue()
 {
     Class @class = new Class(typeof(TestClass_WithAttribute));
     CategoryAttribute categoryAttribute = @class.Attribute<CategoryAttribute>();
     Assert.AreEqual("Normal", categoryAttribute.Name);
 }
예제 #26
0
 public void IsProperty()
 {
     var @class = new Class(typeof(ClassForClassTest));
     Assert.AreEqual(true, @class.IsProperty("StringProperty"));
     Assert.AreEqual(false, @class.IsProperty("ToString"));
 }
예제 #27
0
 public void GetFieldGetsFieldsFromBaseClasses()
 {
     var @class = new Class(typeof(ClassForClassTest));
     Assert.AreNotEqual(null, @class.GetField("fieldInBaseClass"));
 }
예제 #28
0
 public ScreenClass(Class @class)
 {
     this.@class = @class;
     if (@class.NonVirtuals.Count != 0) throw AppScreenException.NonVirtualMethods(@class.NonVirtuals);
 }
예제 #29
0
 public void GetMethodFromTheBaseClassToo()
 {
     var @class = new Class(typeof(ClassForClassTest));
     Assert.AreNotEqual(null, @class.GetMethod("SomeBaseClassMethod"));
 }
예제 #30
0
        private string BuildStringRepresentation(Translate translate)
        {
            StringBuilder builder = new StringBuilder();
            Class @class = new Class(GetType());
            @class.EachField(delegate(FieldInfo fieldInfo)
                                 {
                                     if (fieldInfo.GetCustomAttributes(typeof (ScreenIgnoreAttribute), false).Length != 1)
                                         builder.Append(translate(fieldInfo));
                                 });

            return builder.ToString();
        }