Пример #1
0
        public void Enum_Gen_Warning_Throwing_CustomAttribute_Query()
        {
            foreach (bool isCSharp in new bool[] { true, false })
            {
                using (AssemblyGenerator asmGen = new AssemblyGenerator(
                           "CG_ENUM_THROW",
                           isCSharp,
                           new Type[] { typeof(Enum_Throwing_CustomAttribute_DomainService) }))
                {
                    // Force this type to be unshared to force failure
                    asmGen.MockSharedCodeService.AddUnsharedType(typeof(System.IO.FileAttributes));

                    string generatedCode = asmGen.GeneratedCode;
                    Assert.IsFalse(string.IsNullOrEmpty(generatedCode), "Expected to see generated code");

                    AttributeBuilderException expectedException = new AttributeBuilderException(ThrowingAttribute.ThrowingAttributeException, typeof(ThrowingAttribute), "Name");

                    string expectedBuildWarning = string.Format(
                        CultureInfo.CurrentCulture,
                        Resource.ClientCodeGen_Attribute_ThrewException_CodeTypeMember,
                        expectedException.Message,
                        "None",
                        typeof(EnumWithThrowingCustomAttributes).Name,
                        expectedException.InnerException.Message);

                    TestHelper.AssertGeneratedCodeContains(generatedCode, expectedException.Message);
                    TestHelper.AssertContainsWarnings(asmGen.ConsoleLogger, expectedBuildWarning);
                }
            }
        }
        public void CodeGen_CustomAttrGen_EntityAttributeThrows()
        {
            ConsoleLogger logger        = new ConsoleLogger();
            string        generatedCode = TestHelper.GenerateCode("C#", typeof(AttributeThrowingDomainService), logger);

            Assert.IsFalse(string.IsNullOrEmpty(generatedCode), "Code should have been generated");

            AttributeBuilderException expectedException = new AttributeBuilderException(
                new ThrowingEntityAttributeException(ThrowingEntityAttribute.ExceptionMessage),
                typeof(ThrowingEntityAttribute),
                ThrowingEntityAttribute.ThrowingPropertyName);

            string expectedBuildWarning = string.Format(
                CultureInfo.CurrentCulture,
                Resource.ClientCodeGen_Attribute_ThrewException_CodeType,
                expectedException.Message,
                typeof(AttributeThrowingEntity).Name,
                expectedException.InnerException.Message);

            TestHelper.AssertGeneratedCodeContains(generatedCode, expectedException.Message);
            TestHelper.AssertContainsWarnings(logger, expectedBuildWarning);
        }
        public void CodeGen_CustomAttrGen_DomainServiceAttributeThrows()
        {
            MockSharedCodeService sts    = TestHelper.CreateCommonMockSharedCodeService();
            ConsoleLogger         logger = new ConsoleLogger();
            string generatedCode         = TestHelper.GenerateCode("C#", new Type[] { typeof(AttributeThrowingDomainService) }, logger, sts);

            Assert.IsFalse(string.IsNullOrEmpty(generatedCode), "Should have generated code despite warnings");

            AttributeBuilderException expectedException = new AttributeBuilderException(
                new ThrowingServiceAttributeException(ThrowingServiceAttribute.ExceptionMessage),
                typeof(ThrowingServiceAttribute),
                ThrowingServiceAttribute.ThrowingPropertyName);

            string expectedBuildWarning = string.Format(
                CultureInfo.CurrentCulture,
                Resource.ClientCodeGen_Attribute_ThrewException_CodeType,
                expectedException.Message,
                AttributeThrowingDomainService.DomainContextTypeName,
                expectedException.InnerException.Message);

            TestHelper.AssertGeneratedCodeContains(generatedCode, expectedException.Message);
            TestHelper.AssertContainsWarnings(logger, expectedBuildWarning);
        }
        public void CodeGen_Attribute_DisplayAttribute_Fail_Private_ResourceType()
        {
            ConsoleLogger logger        = new ConsoleLogger();
            string        generatedCode = TestHelper.GenerateCode("C#", typeof(Mock_CG_DisplayAttr_Entity_Private_ResourceType_DomainService), logger);

            string expectedExceptionMessage = "Cannot retrieve property 'Name' because localization failed.  Type 'OpenRiaServices.DomainServices.Tools.Test.Mock_CG_DisplayAttr_Private_ResourceType' is not public or does not contain a public static string property with the name 'Resource2'.";

            AttributeBuilderException expectedException = new AttributeBuilderException(
                new InvalidOperationException(expectedExceptionMessage),
                typeof(DisplayAttribute),
                "Name");

            string expectedBuildWarning = string.Format(
                CultureInfo.CurrentCulture,
                Resource.ClientCodeGen_Attribute_ThrewException_CodeTypeMember,
                expectedException.Message,
                "TheResourcedProperty",
                typeof(Mock_CG_DisplayAttr_Entity_Private_ResourceType).Name,
                expectedException.InnerException.Message);

            TestHelper.AssertGeneratedCodeContains(generatedCode, expectedException.Message);
            TestHelper.AssertContainsWarnings(logger, expectedBuildWarning);
        }