Ejemplo n.º 1
0
        /// <summary>Returns a resource type as specified by the test.</summary>
        /// <param name="metadata">The DSPMetadata to use.</param>
        /// <param name="typeSpecification">The type specification. If it's a string, then it means the name of the type to get. If it's a Type it means
        /// to return a primitive resource type of that type.</param>
        /// <returns>The ResourceType specified by the test.</returns>
        public static providers.ResourceType GetResourceTypeFromTestSpecification(this DSPMetadata metadata, object typeSpecification)
        {
            if (metadata == null)
            {
                return(null);
            }

            if (typeSpecification is Type)
            {
                return(providers.ResourceType.GetPrimitiveResourceType(typeSpecification as Type));
            }
            else
            {
                string typeName             = typeSpecification as string;
                providers.ResourceType type = metadata.GetResourceType(typeName);
                if (type == null)
                {
                    metadata.TryResolveResourceType(typeName, out type);
                }

                if (type == null)
                {
                    type = UnitTestsUtil.GetPrimitiveResourceTypes().FirstOrDefault(rt => rt.FullName == typeName);
                }

                if (type == null)
                {
                    type = UnitTestsUtil.GetPrimitiveResourceTypes().FirstOrDefault(rt => rt.Name == typeName);
                }

                return(type);
            }
        }
        private static DSPContext GetDefaultData(DSPMetadata metadata)
        {
            var peopleType = metadata.GetResourceType("PeopleType");
            var officeType = metadata.GetResourceType("OfficeType");

            #region Default Data for the Model
            var context = new DSPContext();

            DSPResource people1 = new DSPResource(peopleType);
            people1.SetValue("ID", 1);
            people1.SetValue("Name", "Foo");
            people1.SetValue("Body", Encoding.UTF8.GetBytes("a byte array"));          
            people1.SetValue("Age", 23);

            var office = new DSPResource(officeType);
            office.SetValue("Building", "Building 18");
            office.SetValue("OfficeNumber", 100);
            people1.SetValue("Office", office);

            var people = context.GetResourceSetEntities("People");
            people.Add( people1 );

            #endregion Default Data for the Model

            return context;
        }
Ejemplo n.º 3
0
        private static DSPResource CreateResource(DSPMetadata metadata, string entityTypeName, int idValue, KeyValuePair<string, object>[] propertyValues, bool useComplexType)
        {
            var entityType = metadata.GetResourceType(entityTypeName);

            DSPResource entity;
            if (useComplexType)
            {
                entity = new DSPResource(entityType);
            }
            else
            {
                entity = new DSPResource(entityType, propertyValues);
            }

            entity.SetValue("ID", idValue);

            DSPResource resourceForProperties;
            if (useComplexType)
            {

                string complexTypeName = GetComplexTypeName(entityTypeName);
                var complexType = metadata.GetResourceType(complexTypeName);
                resourceForProperties = new DSPResource(complexType, propertyValues);
                entity.SetValue("ComplexProperty", resourceForProperties);
            }
            else
            {
                resourceForProperties = entity;
            }
            return entity;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Creates a datasource from the given metadata.
        /// </summary>
        /// <param name="metadata">The metadata against which the datasource is created.</param>
        /// <returns>DSPContext representing the data source.</returns>
        private static DSPContext CreateDataSource(DSPMetadata metadata)
        {
            DSPContext context = new DSPContext();
            ResourceType customerType = metadata.GetResourceType("CustomerEntity");
            DSPResource entity1 = new DSPResource(customerType);
            entity1.SetValue("ID", 1);
            entity1.SetValue("Name", "Vineet");
            
            DSPResource entity2 = new DSPResource(customerType);
            entity2.SetValue("ID", 2);
            entity2.SetValue("Name", "Jimmy");

            context.GetResourceSetEntities("CustomerEntities").Add(entity1);
            context.GetResourceSetEntities("CustomerEntities").Add(entity2);
            return context;
        }
Ejemplo n.º 5
0
        private static DSPContext GetDefaultData(DSPMetadata metadata)
        {
            var peopleType = metadata.GetResourceType("PeopleType");
            var employeeType = metadata.GetResourceType("EmployeeType");
            var managerType = metadata.GetResourceType("ManagerType");
            var customerType = metadata.GetResourceType("CustomerType");
            var employeeAddressType = metadata.GetResourceType("EmployeeAddressType");
            var customerAddressType = metadata.GetResourceType("CustomerAddressType");

            #region Default Data for the Model
            var context = new DSPContext();

            DSPResource people1 = new DSPResource(peopleType);
            people1.SetValue("ID", 1);
            people1.SetValue("Name", "Foo");

            DSPResource andyAddress = new DSPResource(employeeAddressType);
            andyAddress.SetValue("ID", 1);
            andyAddress.SetValue("Street", "Andy's address");
            andyAddress.SetValue("City", "Sammamish");
            andyAddress.SetValue("State", "WA");

            DSPResource andy = new DSPResource(managerType);
            andy.SetValue("ID", 2);
            andy.SetValue("Name", "Andy");
            andy.SetValue("FullName", "Andy Conrad");
            andy.SetValue("Address", andyAddress);

            DSPResource pratikAddress = new DSPResource(employeeAddressType);
            pratikAddress.SetValue("ID", 2);
            pratikAddress.SetValue("Street", "pratik's address");
            pratikAddress.SetValue("City", "Bothell");
            pratikAddress.SetValue("State", "WA");

            DSPResource pratik = new DSPResource(employeeType);
            pratik.SetValue("ID", 3);
            pratik.SetValue("Name", "Pratik");
            pratik.SetValue("FullName", "Pratik Patel");
            pratik.SetValue("Manager", andy);
            pratik.SetValue("Address", pratikAddress);

            DSPResource jimmyAddress = new DSPResource(employeeAddressType);
            jimmyAddress.SetValue("ID", 3);
            jimmyAddress.SetValue("Street", "jimmy's address");
            jimmyAddress.SetValue("City", "somewhere in seattle");
            jimmyAddress.SetValue("State", "WA");

            DSPResource jimmy = new DSPResource(employeeType);
            jimmy.SetValue("ID", 4);
            jimmy.SetValue("Name", "Jimmy");
            jimmy.SetValue("FullName", "Jian Li");
            jimmy.SetValue("Manager", andy);
            jimmy.SetValue("Address", jimmyAddress);

            andy.SetValue("DirectReports", new List<DSPResource>() { pratik, jimmy });

            DSPResource shyamAddress = new DSPResource(employeeAddressType);
            shyamAddress.SetValue("ID", 4);
            shyamAddress.SetValue("Street", "shyam's address");
            shyamAddress.SetValue("City", "university district");
            shyamAddress.SetValue("State", "WA");

            DSPResource shyam = new DSPResource(managerType);
            shyam.SetValue("ID", 5);
            shyam.SetValue("Name", "Shyam");
            shyam.SetValue("FullName", "Shyam Pather");
            shyam.SetValue("Address", shyamAddress);

            DSPResource marceloAddress = new DSPResource(employeeAddressType);
            marceloAddress.SetValue("ID", 5);
            marceloAddress.SetValue("Street", "marcelo's address");
            marceloAddress.SetValue("City", "kirkland");
            marceloAddress.SetValue("State", "WA");

            DSPResource marcelo = new DSPResource(employeeType);
            marcelo.SetValue("ID", 6);
            marcelo.SetValue("Name", "Marcelo");
            marcelo.SetValue("FullName", "Marcelo Lopez Ruiz");
            marcelo.SetValue("Manager", shyam);
            marcelo.SetValue("Address", marceloAddress);

            andy.SetValue("Manager", shyam);

            shyam.SetValue("DirectReports", new List<DSPResource>() { andy, marcelo });

            DSPResource customer1Address = new DSPResource(customerAddressType);
            customer1Address.SetValue("ID", 6);
            customer1Address.SetValue("Street", "customer1's address");
            customer1Address.SetValue("City", "somewhere");
            customer1Address.SetValue("State", "WA");

            var customer1 = new DSPResource(customerType);
            customer1.SetValue("ID", 7);
            customer1.SetValue("FullName", "Customer FullName");
            customer1.SetValue("Address", customer1Address);

            var people = context.GetResourceSetEntities("People");
            people.AddRange(new object[] { people1, andy, pratik, jimmy, shyam, marcelo, customer1 });

            var addresses = context.GetResourceSetEntities("Addresses");
            addresses.AddRange(new object[] { andyAddress, pratikAddress, jimmyAddress, shyamAddress, marceloAddress, customer1Address });

            #endregion Default Data for the Model

            return context;
        }