public void PropertyGetAndSet()
        {
            DomainIdentifierAttribute dia = null;

            // Name
            dia = new DomainIdentifierAttribute(null);
            ExceptionHelper.ExpectException <InvalidOperationException>(
                () => Assert.IsNull(dia.Name, "This should fail."));

            string name = "name";

            dia = new DomainIdentifierAttribute(name);

            Assert.AreEqual(name, dia.Name,
                            "Names should be equal.");

            // IsApplicationService
            Assert.IsFalse(dia.IsApplicationService,
                           "IsApplicationService state should be false by default.");

            bool isApplicationService = true;

            dia.IsApplicationService = isApplicationService;

            Assert.AreEqual(isApplicationService, dia.IsApplicationService,
                            "IsApplicationService states should be equal.");
        }
        public void PropertyGetAndSet()
        {
            DomainIdentifierAttribute dia = null;

            // Name
            dia = new DomainIdentifierAttribute(null);
            ExceptionHelper.ExpectException<InvalidOperationException>(
                () => Assert.IsNull(dia.Name, "This should fail."));

            string name = "name";
            dia = new DomainIdentifierAttribute(name);

            Assert.AreEqual(name, dia.Name,
                "Names should be equal.");

            // IsApplicationService
            Assert.IsFalse(dia.IsApplicationService,
                "IsApplicationService state should be false by default.");

            bool isApplicationService = true;
            dia.IsApplicationService = isApplicationService;

            Assert.AreEqual(isApplicationService, dia.IsApplicationService,
                "IsApplicationService states should be equal.");
        }
        public void DomainIdentifier_Name_Property_Settable()
        {
            DomainIdentifierAttribute attr = new DomainIdentifierAttribute("aName");
            Assert.AreEqual("aName", attr.Name);

            attr.Name = "otherName";
            Assert.AreEqual("otherName", attr.Name);
        }
        public void DomainIdentifier_Ctor()
        {
            DomainIdentifierAttribute attr = new DomainIdentifierAttribute("aName");
            Assert.AreEqual("aName", attr.Name);
#if !SILVERLIGHT
            Assert.IsNull(attr.CodeProcessor);
#endif
        }
        public void DomainIdentifier_Name_Property_Settable()
        {
            DomainIdentifierAttribute attr = new DomainIdentifierAttribute("aName");

            Assert.AreEqual("aName", attr.Name);

            attr.Name = "otherName";
            Assert.AreEqual("otherName", attr.Name);
        }
        public void DomainIdentifier_Ctor()
        {
            DomainIdentifierAttribute attr = new DomainIdentifierAttribute("aName");

            Assert.AreEqual("aName", attr.Name);
#if !SILVERLIGHT
            Assert.IsNull(attr.CodeProcessor);
#endif
        }
        public void DomainIdentifier_CodeProcessor_Property_Settable()
        {
            Type type1 = typeof(string);
            Type type2 = typeof(int);

            DomainIdentifierAttribute attr = new DomainIdentifierAttribute("aName");
            attr.CodeProcessor = type1;
            Assert.AreEqual<Type>(type1, attr.CodeProcessor);

            attr.CodeProcessor = type2;
            Assert.AreEqual<Type>(type2, attr.CodeProcessor);
        }
        public void DomainIdentifier_CodeProcessor_Property_Settable()
        {
            Type type1 = typeof(string);
            Type type2 = typeof(int);

            DomainIdentifierAttribute attr = new DomainIdentifierAttribute("aName");

            attr.CodeProcessor = type1;
            Assert.AreEqual <Type>(type1, attr.CodeProcessor);

            attr.CodeProcessor = type2;
            Assert.AreEqual <Type>(type2, attr.CodeProcessor);
        }
        private string GenerateProxyClass()
        {
            string generatedCode = string.Empty;

            // Analyze the assemblies to extract all the DomainServiceDescriptions
            ICollection <DomainServiceDescription> allDescriptions = this._domainServiceDescriptions;
            List <Type> generatedEntityTypes  = new List <Type>();
            List <Type> generatedComplexTypes = new List <Type>();
            Dictionary <Type, CodeTypeDeclaration> typeMapping = new Dictionary <Type, CodeTypeDeclaration>();

            // Used to queue CodeProcessor invocations
            Queue <CodeProcessorWorkItem> codeProcessorQueue = new Queue <CodeProcessorWorkItem>();

            // Before we begin codegen, we want to register type names with our codegen
            // utilities so that we can avoid type name conflicts later.
            this.PreprocessProxyTypes();

            // Generate a new domain service proxy class for each domain service we found.
            // OrderBy type name of DomainService to give code-gen predictability
            foreach (DomainServiceDescription dsd in allDescriptions.OrderBy(d => d.DomainServiceType.Name))
            {
                // If we detect the client already has the DomainContext we would have
                // generated, skip it.  This condition arises when the client has references
                // to class libraries as well as a code-gen link to the server which has
                // references to the server-side equivalent libraries.  Without this check, we would
                // re-generate the same DomainContext that already lives in the class library.
                CodeMemberShareKind domainContextShareKind = this.GetDomainContextTypeMemberShareKind(dsd);
                if ((domainContextShareKind & CodeMemberShareKind.Shared) != 0)
                {
                    this.LogMessage(string.Format(CultureInfo.CurrentCulture, Resource.Shared_DomainContext_Skipped, dsd.DomainServiceType.Name));
                    continue;
                }

                // Log information level message to help users see progress and debug code-gen issues
                this.LogMessage(string.Format(CultureInfo.CurrentCulture, Resource.CodeGen_Generating_DomainService, dsd.DomainServiceType.FullName));

                new DomainServiceProxyGenerator(this, dsd, typeMapping).Generate();

                // Generate all entities.
                this.GenerateDataContractTypes(dsd.EntityTypes, generatedEntityTypes, Resource.ClientCodeGen_EntityTypesCannotBeShared_Reference, t =>
                {
                    new EntityProxyGenerator(this, t, allDescriptions, typeMapping).Generate();
                });

                // Generate all complex types.
                this.GenerateDataContractTypes(dsd.ComplexTypes, generatedComplexTypes, Resource.ClientCodeGen_ComplexTypesCannotBeShared_Reference, t =>
                {
                    new ComplexTypeProxyGenerator(this, t, dsd, typeMapping).Generate();
                });

                DomainIdentifierAttribute domainIdentifier = dsd.Attributes.OfType <DomainIdentifierAttribute>().SingleOrDefault();
                if (domainIdentifier != null)
                {
                    Type codeProcessorType = domainIdentifier.CodeProcessor;
                    if (codeProcessorType != null)
                    {
                        // Create a limited type-mapping dictionary that contains references to
                        // the DomainService and related entity type CodeTypeDeclarations.
                        Dictionary <Type, CodeTypeDeclaration> scopedTypeMapping =
                            typeMapping.Where(kvp => kvp.Key == dsd.DomainServiceType || dsd.EntityTypes.Contains(kvp.Key))
                            .ToDictionary(kvp => kvp.Key, kvp => kvp.Value);

                        // Register CodeProc
                        codeProcessorQueue.Enqueue(
                            new CodeProcessorWorkItem(codeProcessorType, dsd, scopedTypeMapping));
                    }
                }
            }

            // Generate an application-level WebContext class
            if (this.ClientProxyCodeGenerationOptions.IsApplicationContextGenerationEnabled)
            {
                new WebContextGenerator(this).Generate();
            }
            // If there are no descriptions, we do not generate any client proxies
            // We don't consider this an error, since this task might be invoked before the user has created any.
            else if (allDescriptions.Count == 0)
            {
                return(generatedCode);
            }

            // Generate any enum types we have decided we need to generate
            this.GenerateAllEnumTypes();

            // Fix up CodeDOM graph before invoking CodeProcessors
            this.FixUpCompileUnit(this.CompileUnit);

            // Invoke CodeProcessors after we've completed our CodeDOM graph
            while (codeProcessorQueue.Count > 0)
            {
                // Allow CodeProcessors to do post processing work
                CodeProcessorWorkItem workItem = codeProcessorQueue.Dequeue();
                this.InvokeDomainServiceCodeProcessor(workItem);
            }

            // Write the entire "file" to a single string to permit us to redirect it
            // to a file, a TextBuffer, etc
            if (!this.CodeGenerationHost.HasLoggedErrors)
            {
                using (TextWriter t = new StringWriter(CultureInfo.InvariantCulture))
                {
                    this.Provider.GenerateCodeFromCompileUnit(this.CompileUnit, t, this._options);
                    generatedCode = this.FixupVBOptionStatements(t.ToString());
                }
            }

            return(generatedCode);
        }
예제 #10
0
        public void Attributes_Cities_Entity_Has_DomainIdentifier()
        {
            DomainIdentifierAttribute attr = ExpectTypeAttribute <DomainIdentifierAttribute>(typeof(Zip));

            Assert.AreEqual("ZipPattern", attr.Name);
        }
예제 #11
0
        public void Attributes_Cities_DomainService_Has_DomainIdentifier()
        {
            DomainIdentifierAttribute attr = ExpectTypeAttribute <DomainIdentifierAttribute>(typeof(CityDomainContext));

            Assert.AreEqual("CityProvider", attr.Name);
        }