public void CodeGen_Attribute_DisplayAttribute_Resourced_DifferentNamespace() { MockSharedCodeService sts = TestHelper.CreateCommonMockSharedCodeService(); string generatedCode = TestHelper.GenerateCodeAssertSuccess("C#", new Type[] { typeof(Mock_CG_DisplayAttr_Entity_Shared_ResourceType_DifferentNamespace) }, null, sts); TestHelper.AssertGeneratedCodeContains(generatedCode, @"[Display(Description=""Resource4"", Name=""Resource2"", Prompt=""Resource3"", ResourceType=typeof(Mock_CG_DisplayAttr_Shared_ResourceType_DifferentNamespace), ShortName=""Resource1"")]"); TestHelper.AssertGeneratedCodeContains(generatedCode, @"[Display(Description=""Literal4"", Name=""Literal2"", Prompt=""Literal3"", ShortName=""Literal1"")]"); }
public void CodeGen_Attribute_UIHint_ControlParameters() { string generatedCode = TestHelper.GenerateCodeAssertSuccess("C#", typeof(Mock_CG_Attr_Entity_UIHint_ControlParameters)); TestHelper.AssertGeneratedCodeContains(generatedCode, @"[UIHint(""theUIHint"", ""thePresentationLayer"",", @", ""key1"", 100", @", ""key2"", ((double)(2D))"); // odd syntax reflect CodeDom workaround }
public void CodeGen_Attribute_StringLength_Fail_No_ResourceType() { string generatedCode = TestHelper.GenerateCodeAssertSuccess("C#", typeof(Mock_CG_Attr_Entity_StringLength_Missing_ResourceType)); TestHelper.AssertGeneratedCodeContains( generatedCode, Resource.ClientCodeGen_Attribute_FailedToGenerate, string.Format(Resource.ClientCodeGen_ValidationAttribute_Requires_ResourceType_And_Name, typeof(StringLengthAttribute), "<unspecified>", "TheResource")); }
public void CodeGen_Attribute_StringLength_Valid_ResourceType_And_Name() { MockSharedCodeService sts = TestHelper.CreateCommonMockSharedCodeService(); string generatedCode = TestHelper.GenerateCodeAssertSuccess("C#", new[] { typeof(Mock_CG_Attr_Entity_StringLength_Valid) }, null, sts); TestHelper.AssertGeneratedCodeContains(generatedCode, "[StringLength(10, ErrorMessageResourceName=\"TheResource\", ErrorMessageResourceType=typeof(Mock_CG_Attr_Entity_StringLength_ResourceType))] " + "public string StringProperty"); }
public void CodeGen_Attribute_StringLength_Fail_No_ResourceName() { var generatedCode = TestHelper.GenerateCodeAssertSuccess("C#", typeof(Mock_CG_Attr_Entity_StringLength_Missing_ResourceName)); TestHelper.AssertGeneratedCodeContains(generatedCode, " // " + Resource.ClientCodeGen_Attribute_FailedToGenerate + " // " + " // - " + string.Format(Resource.ClientCodeGen_ValidationAttribute_Requires_ResourceType_And_Name, typeof(StringLengthAttribute), "Mock_CG_Attr_Entity_StringLength_ResourceType", "<unspecified>") + " // [StringLengthAttribute(10, ErrorMessageResourceType = typeof(Luma.SimpleEntity.Tests.Mock_CG_Attr_Entity_StringLength_ResourceType))]" + " // "); }
public void CodeGen_Attribute_StringLength_Invalid_PropertyName() { string generatedCode = TestHelper.GenerateCodeAssertSuccess("C#", typeof(Mock_CG_Attr_Entity_StringLength_Invalid_PropertyName)); TestHelper.AssertGeneratedCodeContains(generatedCode, " // " + Resource.ClientCodeGen_Attribute_FailedToGenerate + " // " + " // - " + string.Format(Resource.ClientCodeGen_ValidationAttribute_ResourcePropertyNotFound, typeof(StringLengthAttribute), "InvalidPropertyName", typeof(Mock_CG_Attr_Entity_StringLength_ResourceType)) + " // [StringLengthAttribute(10, ErrorMessageResourceName = \"InvalidPropertyName\", ErrorMessageResourceType = typeof(Luma.SimpleEntity.Tests.Mock_CG_Attr_Entity_StringLength_ResourceType))]" + " // [DataMember()] public string StringProperty"); }
public void CodeGen_Attribute_EditableAttribute() { string generatedCode = TestHelper.GenerateCodeAssertSuccess("C#", typeof(Mock_CG_Attr_Entity_Editable)); TestHelper.AssertGeneratedCodeContains(generatedCode, "[Editable(true)] public string EditableTrue"); TestHelper.AssertGeneratedCodeContains(generatedCode, "[Editable(false)] public string EditableFalse"); TestHelper.AssertGeneratedCodeContains(generatedCode, "[Editable(true)] public string EditableTrue_AllowInitialValueTrue"); TestHelper.AssertGeneratedCodeContains(generatedCode, "[Editable(true, AllowInitialValue=false)] public string EditableTrue_AllowInitialValueFalse"); TestHelper.AssertGeneratedCodeContains(generatedCode, "[Editable(false, AllowInitialValue=true)] public string EditableFalse_AllowInitialValueTrue"); TestHelper.AssertGeneratedCodeContains(generatedCode, "[Editable(false)] public string EditableFalse_AllowInitialValueFalse"); }
public void CodeGen_CustomAttrGen_AttributeType_Shared() { // Create a shared type service that says the entity's attribute is "shared" when asked whether it is shared var mockSts = new MockSharedCodeService( new[] { typeof(Mock_CG_Attr_Gen_Type), typeof(Mock_CG_Attr_Gen_TestAttribute) }, new MethodBase[0], new string[0]); string generatedCode = TestHelper.GenerateCodeAssertSuccess("C#", new[] { typeof(Mock_CG_Attr_Gen_Entity) }, mockSts); TestHelper.AssertGeneratedCodeContains(generatedCode, "[Mock_CG_Attr_Gen_Test(typeof(Mock_CG_Attr_Gen_Type))]"); }
public void CodeGen_Attribute_CustomValidation_Multiple() { ISharedCodeService sts = new MockSharedCodeService( new Type[] { typeof(Mock_CG_Attr_Validator) }, new MethodBase[] { typeof(Mock_CG_Attr_Validator).GetMethod("IsValid"), typeof(Mock_CG_Attr_Validator).GetMethod("IsValid2") }, new string[0]); string generatedCode = TestHelper.GenerateCodeAssertSuccess("C#", new[] { typeof(Mock_CG_Attr_Entity_Multiple) }, sts); TestHelper.AssertGeneratedCodeContains(generatedCode, @"[CustomValidation(typeof(Mock_CG_Attr_Validator), ""IsValid"")]", @"[CustomValidation(typeof(Mock_CG_Attr_Validator), ""IsValid2"")]"); }
public void CodeGen_CustomAttrGen_BindableAttribute() { // Create a shared type service that says the entity's attribute is "shared" when asked whether it is shared MockSharedCodeService mockSts = new MockSharedCodeService( new[] { typeof(System.ComponentModel.BindableAttribute) }, new MethodBase[0], new string[0]); string generatedCode = TestHelper.GenerateCodeAssertSuccess("C#", new Type[] { typeof(Mock_CG_Attr_Entity_Bindable) }, new ConsoleLogger(), mockSts, /*useFullNames*/ false); TestHelper.AssertGeneratedCodeContains(generatedCode, "[Bindable(true, BindingDirection.TwoWay)]"); generatedCode = TestHelper.GenerateCodeAssertSuccess("C#", new Type[] { typeof(Mock_CG_Attr_Entity_Bindable) }, new ConsoleLogger(), mockSts, true); TestHelper.AssertGeneratedCodeContains(generatedCode, "[global::System.ComponentModel.BindableAttribute(true, global::System.ComponentModel.BindingDirection.TwoWay)]"); }
public void CodeGen_CustomAttrGen_Attribute_References_Type_NotKnowable() { var logger = new ConsoleLogger(); // Create a shared type service that says the entity's attribute is "shared" when asked whether it is shared MockSharedCodeService mockSts = new MockSharedCodeService( new[] { typeof(Mock_CG_Attr_Gen_TestAttribute) }, new MethodBase[0], new string[0]); // Explicitly make the typeof() ref in the attribute say it is unshared mockSts.AddUnknowableType(typeof(Mock_CG_Attr_Gen_Type)); string generatedCode = TestHelper.GenerateCodeAssertSuccess("C#", new[] { typeof(Mock_CG_Attr_Gen_Entity) }, logger, mockSts); string warningComment = string.Format( CultureInfo.CurrentCulture, Resource.ClientCodeGen_Attribute_RequiresShared, typeof(Mock_CG_Attr_Gen_TestAttribute), "MockProject"); TestHelper.AssertGeneratedCodeContains(generatedCode, "[Mock_CG_Attr_Gen_Test(typeof(global::Luma.SimpleEntity.Tests.Mock_CG_Attr_Gen_Type))]"); }
internal static string GenerateCodeAssertSuccess(string language, IEnumerable <Type> entityTypes, ISharedCodeService typeService) { return(TestHelper.GenerateCodeAssertSuccess(language, entityTypes, new ConsoleLogger(), typeService)); }
public void CodeGen_Attribute_StringLength_Valid_MissingBoth() { var generatedCode = TestHelper.GenerateCodeAssertSuccess("C#", typeof(Mock_CG_Attr_Entity_StringLength_Missing_Both)); }
public void CodeGen_Attribute_UIHint() { string generatedCode = TestHelper.GenerateCodeAssertSuccess("C#", typeof(Mock_CG_Attr_Entity_UIHint)); TestHelper.AssertGeneratedCodeContains(generatedCode, @"[UIHint(""theUIHint"", ""thePresentationLayer"")]"); }