public void BuildWithInvalidParametersTest()
        {
            var assetType = _metaModel.GetAssetType("Member");

            _target.Build(null, null);
            _target.Build(new Query(assetType), new BuildResult());
            var result = new BuildResult();

            _target.Build(new Query(assetType), result);
            Assert.AreEqual(0, result.QuerystringParts.Count);
        }
        internal static string GetAssetIDFromName(string AssetType, string Name, IMetaModel MetaAPI, IServices DataAPI)
        {
            IAssetType           assetType     = MetaAPI.GetAssetType(AssetType);
            Query                query         = new Query(assetType);
            IAttributeDefinition nameAttribute = assetType.GetAttributeDefinition("Name");
            FilterTerm           term          = new FilterTerm(nameAttribute);

            term.Equal(Name);
            query.Filter = term;

            QueryResult result;

            try
            {
                result = DataAPI.Retrieve(query);
            }
            catch
            {
                return(String.Empty);
            }

            if (result.TotalAvaliable > 0)
            {
                return(result.Assets[0].Oid.Token);
            }
            else
            {
                return(String.Empty);
            }
        }
        /// <summary>
        /// Load required fields attribute definitions for provided Asset type.
        /// </summary>
        /// <returns>Collection of attribute definitions for required fields</returns>
        private ICollection <IAttributeDefinition> LoadRequiredFields(IAssetType assetType)
        {
            ICollection <IAttributeDefinition> requiredFieldsForType = new List <IAttributeDefinition>();

            IAssetType           attributeDefinitionAssetType = metaModel.GetAssetType("AttributeDefinition");
            IAttributeDefinition nameAttributeDef             = attributeDefinitionAssetType.GetAttributeDefinition("Name");
            IAttributeDefinition assetNameAttributeDef        =
                attributeDefinitionAssetType.GetAttributeDefinition("Asset.AssetTypesMeAndDown.Name");

            Query query = new Query(attributeDefinitionAssetType);

            query.Selection.Add(nameAttributeDef);
            FilterTerm assetTypeTerm = new FilterTerm(assetNameAttributeDef);

            assetTypeTerm.Equal(assetType.Token);
            query.Filter = new AndFilterTerm(new IFilterTerm[] { assetTypeTerm });

            QueryResult result = services.Retrieve(query);

            foreach (Asset asset in result.Assets)
            {
                string name = asset.GetAttribute(nameAttributeDef).Value.ToString();
                if (IsRequiredField(assetType, name))
                {
                    IAttributeDefinition definition = assetType.GetAttributeDefinition(name);
                    requiredFieldsForType.Add(definition);
                }
            }

            return(requiredFieldsForType);
        }
Exemple #4
0
        public static Oid FromToken(string oidtoken, IMetaModel meta)
        {
            try
            {
                if (oidtoken == NullOidToken)
                {
                    return(Null);
                }

                var parts  = oidtoken.Split(':');
                var type   = meta.GetAssetType(parts[0]);
                var id     = (int)DB.Int(parts[1]);
                int?moment = null;

                if (parts.Length > 2)
                {
                    moment = DB.Int(parts[2]);
                }

                return(new Oid(type, id, moment));
            }
            catch (Exception e)
            {
                throw new OidException("Invalid OID token", oidtoken, e);
            }
        }
        public static Oid FromToken(string oidtoken, IMetaModel meta)
        {
            try
            {
                if (oidtoken == NullOidToken)
                {
                    return Null;
                }

                var parts = oidtoken.Split(':');
                var type = meta.GetAssetType(parts[0]);
                var id = (int)DB.Int(parts[1]);
                int? moment = null;

                if (parts.Length > 2)
                {
                    moment = DB.Int(parts[2]);
                }

                return new Oid(type, id, moment);
            }
            catch (Exception e)
            {
                throw new OidException("Invalid OID token", oidtoken, e);
            }
        }
 public void Setup()
 {
     var environment = new EnvironmentContext();
     _metaModel = environment.MetaModel;
     _services = environment.Services;
     _storyAssetType = _metaModel.GetAssetType("Story");
     _projectId = LegacyIntegrationTestHelper.ProjectId;
 }
Exemple #7
0
        public void Setup()
        {
            var environment = new EnvironmentContext();

            _metaModel      = environment.MetaModel;
            _services       = environment.Services;
            _storyAssetType = _metaModel.GetAssetType("Story");
            _projectId      = LegacyIntegrationTestHelper.ProjectId;
        }
Exemple #8
0
        private List <RequiredFieldsDto> GetRequiredFields(string assetType)
        {
            var fields = new List <RequiredFieldsDto>();
            var attributeDefinitionAssetType = metaModel.GetAssetType("AttributeDefinition");
            var nameAttributeDef             = attributeDefinitionAssetType.GetAttributeDefinition("Name");
            var assetNameAttributeDef        = attributeDefinitionAssetType.GetAttributeDefinition("Asset.AssetTypesMeAndDown.Name");
            var taskType = metaModel.GetAssetType(assetType);

            var query = new Query(attributeDefinitionAssetType);

            query.Selection.Add(nameAttributeDef);
            var assetTypeTerm = new FilterTerm(assetNameAttributeDef);

            assetTypeTerm.Equal(assetType);
            query.Filter = new AndFilterTerm(new IFilterTerm[] { assetTypeTerm });

            QueryResult result;

            try {
                result = services.Retrieve(query);
            } catch (Exception ex) {
                logger.Error("Cannot get meta data for " + assetType, ex);
                return(null);
            }

            foreach (var asset in result.Assets)
            {
                try {
                    var name = asset.GetAttribute(nameAttributeDef).Value.ToString();

                    if (IsRequiredField(taskType, name))
                    {
                        var reqFieldData = new RequiredFieldsDto(name, taskType.GetAttributeDefinition(name).DisplayName);
                        fields.Add(reqFieldData);
                    }
                } catch (Exception ex) {
                    logger.Error("Cannot get meta data for " + assetType, ex);
                }
            }

            return(fields);
        }
Exemple #9
0
        /// <summary>
        /// Creates a new V1 project for integration test assets.
        /// </summary>
        private static void CreateTestProject()
        {
            var assetType     = _metaModel.GetAssetType("Scope");
            var nameAttribute = assetType.GetAttributeDefinition("Name");
            var projectId     = Oid.FromToken("Scope:0", _metaModel);
            var newAsset      = _services.New(assetType, projectId);

            newAsset.SetAttributeValue(nameAttribute, TestProjectName);
            _services.Save(newAsset);
            _projectId = newAsset.Oid.Momentless;
        }
Exemple #10
0
        public IDictionary <string, User> GetVersionOneUsers()
        {
            IAssetType memberType = _model.GetAssetType(V1Constants.MEMBER);
            Query      userQuery  = new Query(memberType);

            IAttributeDefinition username     = _model.GetAttributeDefinition(V1Constants.USERNAME);
            IAttributeDefinition isInactive   = _model.GetAttributeDefinition(V1Constants.ISINACTIVE);
            IAttributeDefinition ckInactivate = _model.GetAttributeDefinition(V1Constants.CHECKINACTIVATE);

            userQuery.Selection.Add(username);
            userQuery.Selection.Add(isInactive);
            userQuery.Selection.Add(ckInactivate);
            QueryResult result = _services.Retrieve(userQuery);

            IDictionary <string, User> v1UserList = BuildV1UsersList(result.Assets);

            logger.Info(v1UserList.Count + " users successfully retrieved from VersionOne.");
            //[count] users successfully retrieved from V1...

            return(v1UserList);
        }
        internal static string GetAssetIDFromCode(string AssetType, string Code, IMetaModel MetaAPI, IServices DataAPI)
        {
            IAssetType assetType = MetaAPI.GetAssetType(AssetType);
            Query query = new Query(assetType);
            IAttributeDefinition codeAttribute = assetType.GetAttributeDefinition("Code");
            FilterTerm term = new FilterTerm(codeAttribute);
            term.Equal(Code);
            query.Filter = term;
            QueryResult result = DataAPI.Retrieve(query);

            if (result.TotalAvaliable > 0)
                return result.Assets[0].Oid.Token;
            else
                return String.Empty;
        }
		public void TestFixtureSetUp() {
			var metaConnector = new V1APIConnector(V1Url + "/meta.v1/");
			var dataConnector = new V1APIConnector(V1Url + "/rest-1.v1/", Username, Password);
			metaModel = new MetaModel(metaConnector);
			services = new Services(metaModel, dataConnector);
			
			storyType = metaModel.GetAssetType("Story");
			storyDeleteOperation = storyType.GetOperation("Delete");

			nameDef = storyType.GetAttributeDefinition("Name");
			scopeDef = storyType.GetAttributeDefinition("Scope");
			changeDateDef = storyType.GetAttributeDefinition("ChangeDate");
			momentDef = storyType.GetAttributeDefinition("Moment");
			attributesToQuery = new[] {nameDef, scopeDef, changeDateDef, momentDef};
		}
Exemple #13
0
        public User CreateUserToDeactivate(string username)
        {
            User user = CreateTestUser(username);

            user.Deactivate = true;
            IAssetType member = model.GetAssetType("Member");
            Query      query  = new Query(member);
            FilterTerm term   = new FilterTerm(member.GetAttributeDefinition("Username"));

            term.Equal(username);
            query.Filter = term;
            QueryResult result = services.Retrieve(query);

            user.V1MemberAsset = result.Assets[0];
            return(user);
        }
Exemple #14
0
 private void CreateAssetStatesStorage()
 {
     if (!withoutAssetStates.ContainsKey(_instance.ApiClient.MetaModel))
     {
         IMetaModel meta = _instance.ApiClient.MetaModel;
         try
         {
             IAssetType assetType = meta.GetAssetType("Actual");
             withoutAssetStates.Add(meta, new List <IAssetType>(new IAssetType[] { assetType }));
         }
         catch (MetaException)
         {
             withoutAssetStates.Add(meta, new List <IAssetType>());
         }
     }
 }
Exemple #15
0
        public void TestFixtureSetUp()
        {
            var metaConnector = new V1APIConnector(V1Url + "/meta.v1/");
            var dataConnector = new V1APIConnector(V1Url + "/rest-1.v1/", Username, Password);

            metaModel = new MetaModel(metaConnector);
            services  = new Services(metaModel, dataConnector);

            storyType            = metaModel.GetAssetType("Story");
            storyDeleteOperation = storyType.GetOperation("Delete");

            nameDef           = storyType.GetAttributeDefinition("Name");
            scopeDef          = storyType.GetAttributeDefinition("Scope");
            changeDateDef     = storyType.GetAttributeDefinition("ChangeDate");
            momentDef         = storyType.GetAttributeDefinition("Moment");
            attributesToQuery = new[] { nameDef, scopeDef, changeDateDef, momentDef };
        }
Exemple #16
0
        private IAssetType CoerceAssetType(object value)
        {
            if (value == null)
            {
                return(null);
            }

            if (value is IAssetType)
            {
                return((IAssetType)value);
            }

            if (value is string)
            {
                return(metaModel.GetAssetType((string)value));
            }

            throw new MetaException("Object is not convertible to an AssetType", value.ToString());
        }
        private void UpdateStory(AssetID id, string originalName, string newName)
        {
            IMetaModel metaModel = Instance.ApiClient.MetaModel;
            IServices  services  = Instance.ApiClient.Services;

            Oid                  storyId       = Oid.FromToken(id.Token, metaModel);
            Query                query         = new Query(storyId);
            IAssetType           storyType     = metaModel.GetAssetType("Story");
            IAttributeDefinition nameAttribute = storyType.GetAttributeDefinition("Name");

            query.Selection.Add(nameAttribute);
            QueryResult result     = services.Retrieve(query);
            Asset       storyAsset = result.Assets[0];
            string      oldName    = storyAsset.GetAttribute(nameAttribute).Value.ToString();

            Assert.AreEqual(originalName, oldName);
            storyAsset.SetAttributeValue(nameAttribute, newName);
            services.Save(storyAsset);
        }
        public void FindMemberTest()
        {
            var memberType   = _metaModel.GetAssetType("Member");
            var memberQuery  = new Query(memberType);
            var userNameAttr = memberType.GetAttributeDefinition("Username");

            memberQuery.Selection.Add(userNameAttr);
            memberQuery.Find = new QueryFind("admin", new AttributeSelection("Username", memberType));
            QueryResult result = _services.Retrieve(memberQuery);

            foreach (var member in result.Assets)
            {
                var name = member.GetAttribute(userNameAttr).Value as string;
                Assert.IsFalse(string.IsNullOrEmpty(name));
                if (name != null)
                {
                    Assert.IsTrue(name.IndexOf("admin") > -1);
                }
            }
        }
 protected IAssetType AssetType(string token)
 {
     return(Meta.GetAssetType(token));
 }