public static void SaveRegressionSuites(Project project, IList<Member> owners )
        {
            IAssetType suiteType = Program.MetaModel.GetAssetType("RegressionSuite");
            IAttributeDefinition suiteName = suiteType.GetAttributeDefinition("Name");
            IAttributeDefinition suiteRegressionPlan = suiteType.GetAttributeDefinition("RegressionPlan");
            IAttributeDefinition regressionTests = suiteType.GetAttributeDefinition("RegressionTests");

            foreach (RegressionSuite suite in project.RegressionSuites)
            {
                Asset asset = Program.Services.New(suiteType, Oid.FromToken(project.Id, Program.MetaModel));
                asset.SetAttributeValue(suiteName, suite.Name);

                RegressionTest.SaveRegressionTests(suite.RegressionTests, project);

                RegressionPlan plan = project.RegressionPlans[suite.RegressionPlanForSuite];
                asset.SetAttributeValue(suiteRegressionPlan, Oid.FromToken(plan.Id, Program.MetaModel));

                foreach (RegressionTest test in suite.RegressionTests)
                {
                    asset.AddAttributeValue(regressionTests, Oid.FromToken(test.Id, Program.MetaModel));
                }

                Program.Services.Save(asset);
                suite.Id = asset.Oid.Momentless.Token;
                RegressionTestSet.SaveTestSets(suite, project, owners);
            }
        }
 public static void AddReleaseGoals(Project project)
 {
     project.Goals.Add(new Goal("Improve Performance by 5%", "", Utils.GoalPriorityLow, Utils.GoalCategoryCompetitive));
     project.Goals.Add(new Goal("Increase Cust Satisfaction by 10%", "", Utils.GoalPriorityHigh, Utils.GoalCategoryStrategic));
     project.Goals.Add(new Goal("Increase Prospect Conversion by 5%", "", Utils.GoalPriorityLow, Utils.GoalCategoryFinancial));
     project.Goals.Add(new Goal("Reduce Customer Support Calls by 20%", "", Utils.GoalPriorityMedium, Utils.GoalCategoryFinancial));
 }
        public static void SaveIterations(Project project)
        {
            IAssetType iterationType = Program.MetaModel.GetAssetType("Timebox");
            IAttributeDefinition iterationName = iterationType.GetAttributeDefinition("Name");
            IAttributeDefinition iterationState = iterationType.GetAttributeDefinition("State");
            IAttributeDefinition iterationBeginDate = iterationType.GetAttributeDefinition("BeginDate");
            IAttributeDefinition iterationEndDate = iterationType.GetAttributeDefinition("EndDate");
            IAttributeDefinition targetEstimate = iterationType.GetAttributeDefinition("TargetEstimate");
            IList<Iteration> iterations = project.Iterations;

            foreach (Iteration iteration in iterations)
            {
                //shouldn't have to do this - assetState should not be sent in initialized object when calling services.New
                Asset asset = Program.Services.New(iterationType, Oid.FromToken(project.Id, Program.MetaModel));
                asset.Attributes.Remove("Timebox.AssetState");
                asset.SetAttributeValue(iterationName, iteration.Name);
                asset.SetAttributeValue(iterationState, Oid.FromToken(iteration.StateId, Program.MetaModel));
                asset.SetAttributeValue(iterationBeginDate, iteration.BeginDate);
                asset.SetAttributeValue(iterationEndDate, iteration.EndDate);
                asset.SetAttributeValue(targetEstimate, iteration.Target);

                Program.Services.Save(asset);
                iteration.Id = asset.Oid.Momentless.Token;
            }
        }
        public static void SaveItemAssociations(Project project)
        {
            if (project.BuildRuns.Count > 0)
            {
                // There is no direct association between workitems and affected/included build runs.
                // The indirect association occurs by relationship to ChangeSets.

                string defectId = project.Defects.First(x => x.Name.Equals("Fix performance SLA on load")).Id;

                IAssetType defectType = Program.MetaModel.GetAssetType("Defect");
                Query query = new Query(Oid.FromToken(defectId, Program.MetaModel));

                IAttributeDefinition foundDefectsDef = defectType.GetAttributeDefinition("FoundInBuildRuns");
                IAttributeDefinition completedDef = defectType.GetAttributeDefinition("CompletedInBuildRuns");
                IAttributeDefinition changeSetsDef = defectType.GetAttributeDefinition("ChangeSets");

                QueryResult result = Program.Services.Retrieve(query);
                Asset asset = result.Assets[0];

                // Found in first build run and completed in last build run
                // Included in build runs 2 and 3 (via ChangeSets)
                asset.AddAttributeValue(foundDefectsDef, Oid.FromToken(project.BuildRuns[0].Id, Program.MetaModel));
                asset.AddAttributeValue(completedDef, Oid.FromToken(project.BuildRuns[2].Id, Program.MetaModel));
                asset.AddAttributeValue(changeSetsDef, Oid.FromToken(project.ChangeSets[1].Id, Program.MetaModel));
                asset.AddAttributeValue(changeSetsDef, Oid.FromToken(project.ChangeSets[2].Id, Program.MetaModel));
                Program.Services.Save(asset);

                string storyId = project.Stories.First(x => x.Name.Equals("List of Books by Author")).Id;

                IAssetType storyType = Program.MetaModel.GetAssetType("Story");
                query = new Query(Oid.FromToken(storyId, Program.MetaModel));

                IAttributeDefinition completedStoryDef = storyType.GetAttributeDefinition("CompletedInBuildRuns");
                IAttributeDefinition changeSetsStoryDef = storyType.GetAttributeDefinition("ChangeSets");

                result = Program.Services.Retrieve(query);
                asset = result.Assets[0];

                // Completed in last build run
                // Included in build runs 2 and 3 (via ChangeSets)
                asset.AddAttributeValue(completedStoryDef, Oid.FromToken(project.BuildRuns[2].Id, Program.MetaModel));
                asset.AddAttributeValue(changeSetsStoryDef, Oid.FromToken(project.ChangeSets[1].Id, Program.MetaModel));
                asset.AddAttributeValue(changeSetsStoryDef, Oid.FromToken(project.ChangeSets[2].Id, Program.MetaModel));
                Program.Services.Save(asset);

                storyId = project.Stories.First(x => x.Name.Equals("View Book Details")).Id;
                query = new Query(Oid.FromToken(storyId, Program.MetaModel));

                result = Program.Services.Retrieve(query);
                asset = result.Assets[0];

                // Included in all 3 build runs (via ChangeSets)
                // Not completed yet
                asset.AddAttributeValue(changeSetsStoryDef, Oid.FromToken(project.ChangeSets[0].Id, Program.MetaModel));                
                asset.AddAttributeValue(changeSetsStoryDef, Oid.FromToken(project.ChangeSets[1].Id, Program.MetaModel));
                asset.AddAttributeValue(changeSetsStoryDef, Oid.FromToken(project.ChangeSets[2].Id, Program.MetaModel));
                Program.Services.Save( asset );
            }
        }
 public static void AddIterationStories(Project project, Iteration iteration)
 {
     project.Stories.Add(CreateIterationStory("List of Books by Author", 1, Utils.PriorityHigh, Utils.StatusNone, iteration, Theme.ThemeStorefront, Team.TeamBeta)); 
     project.Stories.Add(CreateIterationStory("List of Books by Title", 3, Utils.PriorityMedium, Utils.StatusNone, iteration, Theme.ThemeStorefront, Team.TeamAlpha)); 
     project.Stories.Add(CreateIterationStory("List of Books by Genre", 5, Utils.PriorityHigh, Utils.StatusNone, iteration, Theme.ThemeStorefront, Team.TeamBeta)); 
     project.Stories.Add(CreateIterationStory("View Book Details", 2, Utils.PriorityMedium, Utils.StatusNone, iteration, Theme.ThemeStorefront, Team.TeamBeta)); 
     project.Stories.Add(CreateIterationStory("Search by Author", 5, Utils.PriorityMedium, Utils.StatusDone, iteration, Theme.ThemeStorefront, Team.TeamAlpha)); 
 }
 public static void GenerateStoryFromRequest(Project project)
 {
     if (project.Requests.Count > 0)
     {
         Oid requestOid = Oid.FromToken(project.Requests[0].Id, Program.MetaModel);
         IAssetType storyType = Program.MetaModel.GetAssetType("Story");
         Asset newStory = Program.Services.New(storyType, requestOid);
         Program.Services.Save(newStory);
     }
 }
 public static void AddReleaseStories(Project project)
 {
     project.Stories.Add(new Story("Search by Keyword", 2, Utils.PriorityHigh, Utils.StatusNone, Theme.ThemeStorefront, Team.TeamAlpha)); //0
     project.Stories.Add(new Story("View Account Details", 2, Utils.PriorityLow, Utils.StatusNone, Theme.ThemeStorefront, Team.TeamBeta)); //1
     project.Stories.Add(new Story("Add Book to Shopping Cart", 2, Utils.PriorityMedium, Utils.StatusNone, Theme.ThemeOrderProc, Team.TeamBeta)); //2
     project.Stories.Add(new Story("Remove Book from Shopping Cart", 1, Utils.PriorityMedium, Utils.StatusNone, Theme.ThemeOrderProc, Team.TeamAlpha)); //3
     project.Stories.Add(new Story("Save Order", 3, Utils.PriorityLow, Utils.StatusNone, Theme.ThemeOrderProc, Team.TeamBeta)); //4
     project.Stories.Add(new Story("List of Books by ISBN", 3, Utils.PriorityHigh, Utils.StatusNone, Theme.ThemeStorefront, Team.TeamAlpha)); //5
     project.Stories.Add(new Story("Search by Title", 10, Utils.PriorityHigh, Utils.StatusNone, Theme.ThemeStorefront, Team.TeamBeta)); //6
     project.Stories.Add(new Story("Search by Genre", 2, Utils.PriorityLow, Utils.StatusNone, Theme.ThemeStorefront, Team.TeamAlpha)); //7
 }
        public static void SaveTestSets(RegressionSuite suite, Project project, IList<Member> owners)
        {
            IAssetType testSetType = Program.MetaModel.GetAssetType("TestSet");
            IAttributeDefinition testSetName = testSetType.GetAttributeDefinition("Name");
            IAttributeDefinition testSetRegressionSuite = testSetType.GetAttributeDefinition("RegressionSuite");
            IAttributeDefinition testSetPriority = testSetType.GetAttributeDefinition("Priority");
            IAttributeDefinition testSetStatus = testSetType.GetAttributeDefinition("Status");
            IAttributeDefinition testSetEstimate = testSetType.GetAttributeDefinition("Estimate");
            IAttributeDefinition testSetEnvironment = testSetType.GetAttributeDefinition("Environment");
            IAttributeDefinition testSetIteration = testSetType.GetAttributeDefinition("Timebox");
            IAttributeDefinition testSetOwners = testSetType.GetAttributeDefinition("Owners");

            int randomForEnvironment = 1;
            foreach (RegressionTestSet testSet in suite.RegressionTestSets)
            {
                //Asset asset = Program.Services.New(testSetType, Oid.FromToken(project.Id, Program.MetaModel));
                Asset asset = Program.Services.New(testSetType, Oid.FromToken(project.Releases[0].Id, Program.MetaModel));
                asset.SetAttributeValue(testSetName, testSet.Name);
                asset.SetAttributeValue(testSetRegressionSuite, Oid.FromToken(suite.Id, Program.MetaModel));
                asset.SetAttributeValue(testSetPriority, Oid.FromToken(testSet.Priority, Program.MetaModel));
                asset.SetAttributeValue(testSetEstimate, testSet.Estimate);

                if (project.Environments.Count > 0)
                {
                    randomForEnvironment %= project.Environments.Count;
                    asset.SetAttributeValue(testSetEnvironment, project.Environments[randomForEnvironment].Id);
                }

                //if ( testSet.Iteration != null )
                //{
                    //asset.SetAttributeValue( testSetIteration, Oid.FromToken( testSet.Iteration.Id, Program.MetaModel ) );
                    asset.SetAttributeValue(testSetIteration, Oid.FromToken(project.Iterations[0].Id, Program.MetaModel));

                    // Only add owner if story is in iteration
                    asset.AddAttributeValue(testSetOwners, Oid.FromToken(owners[0].Id, Program.MetaModel));
                //}

                if (testSet.Status != Utils.StatusNone)
                    asset.SetAttributeValue(testSetStatus, Oid.FromToken(testSet.Status, Program.MetaModel));

                Program.Services.Save(asset);
                testSet.Id = asset.Oid.Momentless.Token;
                randomForEnvironment++;

                IOperation copyTest = Program.MetaModel.GetOperation("TestSet.CopyAcceptanceTestsFromRegressionSuite");
                Oid testSetOid = Program.Services.ExecuteOperation(copyTest, Oid.FromToken( testSet.Id, Program.MetaModel));

                // Update owner, detail estimate, todo and status for all TestSet tests in an iteration
                //if ( testSet.Iteration != null )
                //    UpdateIterationTests( testSetOid, owners );
            }
        }
        public static void SaveDefects(Project project, IList<Member> owners, bool isCatalyst)
        {
            IAssetType defectType = Program.MetaModel.GetAssetType("Defect");
            IAttributeDefinition defectName = defectType.GetAttributeDefinition("Name");
            IAttributeDefinition defectEstimate = defectType.GetAttributeDefinition("Estimate");
            IAttributeDefinition defectPriority = defectType.GetAttributeDefinition("Priority");
            IAttributeDefinition defectStatus = defectType.GetAttributeDefinition("Status");
            IAttributeDefinition defectTeam = defectType.GetAttributeDefinition("Team");
            IAttributeDefinition defectOwners = defectType.GetAttributeDefinition("Owners");
            IAttributeDefinition defectIteration = defectType.GetAttributeDefinition("Timebox");
            IAttributeDefinition defectTheme = defectType.GetAttributeDefinition("Parent");

            IList<Defect> defects = project.Defects;

            foreach (Defect defect in defects)
            {
                Asset asset = Program.Services.New(defectType, Oid.FromToken( project.Id, Program.MetaModel));
                asset.SetAttributeValue(defectName, defect.Name);
                asset.SetAttributeValue(defectEstimate, defect.Estimate);
                asset.SetAttributeValue(defectPriority, Oid.FromToken(defect.PriorityId, Program.MetaModel));
                if ( !string.IsNullOrEmpty(defect.StatusId))
                    asset.SetAttributeValue(defectStatus, Oid.FromToken(defect.StatusId, Program.MetaModel));
                
                //Catalyst does not support Teams.
                if (isCatalyst == false)
                {
                    if (defect.Team != null)
                        asset.SetAttributeValue(defectTeam, Oid.FromToken(defect.Team.Id, Program.MetaModel));
                }
                
                if (defect.Iteration != null)
                {
                    asset.SetAttributeValue(defectIteration, Oid.FromToken(defect.Iteration.Id, Program.MetaModel));

                    // Only add owner if story is in iteration
                    asset.AddAttributeValue(defectOwners, Oid.FromToken(owners[0].Id, Program.MetaModel));
                }

                //Catalyst does not support Themes.
                if (isCatalyst == false)
                {
                    if (defect.Theme != null)
                        asset.SetAttributeValue(defectTheme, Oid.FromToken(defect.Theme.Id, Program.MetaModel));
                }
                
                Program.Services.Save(asset);
                defect.Id = asset.Oid.Momentless.Token;

                Task.SaveTasks(defect, owners);
                Test.SaveTests(defect, owners);
            }
        }
        public static void SaveRegressionPlans(Project project)
        {
            IAssetType regressionPlanType = Program.MetaModel.GetAssetType("RegressionPlan");
            IAttributeDefinition regressionPlanName = regressionPlanType.GetAttributeDefinition("Name");

            foreach (RegressionPlan plan in project.RegressionPlans)
            {
                Asset asset = Program.Services.New(regressionPlanType, Oid.FromToken(project.Id, Program.MetaModel));
                asset.SetAttributeValue(regressionPlanName, plan.Name);

                Program.Services.Save(asset);
                plan.Id = asset.Oid.Momentless.Token;
            }
        }
        public static void BlockDefectWithIssue(Project project)
        {
            if (project.Issues.Count > 0)
            {
                Query query = new Query(Oid.FromToken(project.Issues[0].Id, Program.MetaModel));
                IAttributeDefinition workitemsDef = Program.MetaModel.GetAttributeDefinition("Issue.BlockedPrimaryWorkitems");
                QueryResult result = Program.Services.Retrieve(query);
                Asset issue = result.Assets[0];

                string defectId = project.Defects.First(x => x.Name.Equals("Fix performance SLA on load")).Id;
                issue.AddAttributeValue(workitemsDef, Oid.FromToken(defectId, Program.MetaModel));
                Program.Services.Save(issue);
            }
        }
        public static void AddIterations(Project project)
        {
            switch (Program._v1ClientTarget)
            {
                case "CapitalOne":
                {
                    //Iteration 1
                    DateTime beginDate = Utils.GetTodaysDateNoTime().AddDays(-2);
                    DateTime endDate = Utils.GetTodaysDateNoTime().AddDays(12);
                    Iteration iteration = new Iteration("Sprint 1", "State:101", beginDate, endDate) { Target = 14 };
                    project.Iterations.Add(iteration);

                    //Iteration 2
                    beginDate = endDate;
                    endDate = beginDate.AddDays(14);
                    iteration = new Iteration("Sprint 2", "State:101", beginDate, endDate) { Target = 14 };
                    project.Iterations.Add(iteration);

                    //Iteration 3
                    beginDate = endDate;
                    endDate = beginDate.AddDays(14);
                    iteration = new Iteration("Sprint 3", "State:100", beginDate, endDate) { Target = 14 };
                    project.Iterations.Add(iteration);
                    break;
                }

                default:
                {
                    //Iteration 1
                    DateTime beginDate = Utils.GetTodaysDateNoTime();
                    DateTime endDate = Utils.GetTodaysDateNoTime().AddDays(7);
                    Iteration iteration = new Iteration("Iteration 1", "State:101", beginDate, endDate) { Target = 16 };
                    project.Iterations.Add(iteration);

                    //Iteration 2
                    beginDate = endDate;
                    endDate = beginDate.AddDays(7);
                    iteration = new Iteration("Iteration 2", "State:100", beginDate, endDate) { Target = 16 };
                    project.Iterations.Add(iteration);

                    //Iteration 3
                    beginDate = endDate;
                    endDate = beginDate.AddDays(7);
                    iteration = new Iteration("Iteration 3", "State:100", beginDate, endDate) { Target = 16 };
                    project.Iterations.Add(iteration);
                    break;
                }
            }
        }
        // 8/7/2012 AJB Commented out to replace with new version of method based on API changes for Epics.
        //public static void SaveEpics(Project project, IList<Member> owners)
        //{
        //    IAssetType storyType = Program.MetaModel.GetAssetType("Story");
        //    IAttributeDefinition nameDef = storyType.GetAttributeDefinition("Name");
        //    IAttributeDefinition ownersDef = storyType.GetAttributeDefinition("Owners");
        //    Utils.Logger.Info("ABOUT TO SAVE EPICS FOR: " + project.Name);

        //    foreach (Epic epic in project.Epics)
        //    {
        //        Asset asset = Program.Services.New(storyType, Oid.FromToken(project.Id, Program.MetaModel));
        //        asset.SetAttributeValue(nameDef, epic.Name);
        //        asset.AddAttributeValue(ownersDef, Oid.FromToken(owners[0].Id, Program.MetaModel));

        //        Program.Services.Save(asset);
        //        epic.Id = asset.Oid.Momentless.Token;

        //        IOperation storyToEpic = storyType.GetOperation("StoryToEpic");
        //        Program.Services.ExecuteOperation(storyToEpic, asset.Oid);
        //    }
        //}

        public static void AddStoriesToEpic(Project project)
        {
            var stories = project.Stories.Where(x => x.Name.StartsWith("Search by"));

            foreach (Story item in stories)
            {
                Query query = new Query(Oid.FromToken(item.Id, Program.MetaModel));
                IAssetType storyType = Program.MetaModel.GetAssetType("Story");
                IAttributeDefinition superDef = storyType.GetAttributeDefinition("Super");
                QueryResult result = Program.Services.Retrieve(query);
                Asset story = result.Assets[0];
                story.SetAttributeValue(superDef, project.Epics[0].Id);
                Program.Services.Save(story);
            }
        }
        public static void SaveEpics(Project project, IList<Member> owners)
        {
            IAssetType epicType = Program.MetaModel.GetAssetType("Epic");
            IAttributeDefinition nameDef = epicType.GetAttributeDefinition("Name");
            IAttributeDefinition ownersDef = epicType.GetAttributeDefinition("Owners");

            foreach (Epic epic in project.Epics)
            {
                Asset asset = Program.Services.New(epicType, Oid.FromToken(project.Id, Program.MetaModel));
                asset.SetAttributeValue(nameDef, epic.Name);
                asset.AddAttributeValue(ownersDef, Oid.FromToken(owners[0].Id, Program.MetaModel));
                Program.Services.Save(asset);
                epic.Id = asset.Oid.Momentless.Token;
            }
        }
        // This method creates Regression Suites AND the Regression Tests that are associated to them.
        // To create RTs just for the inventory add them via the RegressionTest class.
        public static void AddRegressionSuites(Project project)
        {
            RegressionSuite suite;

            suite = new RegressionSuite("Login/out", 0);
            suite.RegressionTests.Add(new RegressionTest("Login - Web security", "", "", "Login"));
            suite.RegressionTests.Add(new RegressionTest("Login - Integrated security", "", "", "Login"));
            suite.RegressionTests.Add(new RegressionTest("Logout check", "", "", "Logout"));
            suite.RegressionTests.Add(new RegressionTest("Session restored from previous", "", "", "User Login"));
            RegressionTestSet.AddReleaseTestSets(suite);
            project.RegressionSuites.Add(suite);

            suite = new RegressionSuite("Settings", 0);
            suite.RegressionTests.Add(new RegressionTest("Update User Settings", "", "", "User Account"));
            suite.RegressionTests.Add(new RegressionTest("Save User Settings", "", "", "User Account"));
            project.RegressionSuites.Add(suite);
            
            suite = new RegressionSuite("Bookstore Quicklist", 1);
            suite.RegressionTests.Add(new RegressionTest("Listings by Genre", "", "", "Quicklist"));
            suite.RegressionTests.Add(new RegressionTest("Recommended listings based on prior purchases", "", "", "Quicklist User"));
            project.RegressionSuites.Add(suite);
            
            suite = new RegressionSuite("Cart", 1);
            suite.RegressionTests.Add(new RegressionTest("Cart persisted across sessions", "", "", "Cart"));
            suite.RegressionTests.Add(new RegressionTest("Add/Remove Cart Item", "", "", "Account Cart"));
            project.RegressionSuites.Add(suite);

            suite = new RegressionSuite("Search", 1);
            suite.RegressionTests.Add(new RegressionTest("Search books by Genre", "", "", "Search"));
            suite.RegressionTests.Add(new RegressionTest("Search books by ISBN", "", "", "Search"));
            suite.RegressionTests.Add(new RegressionTest("Search books by Title", "", "", "Search"));
            project.RegressionSuites.Add(suite);
            
            suite = new RegressionSuite("Cancel Order", 2);
            suite.RegressionTests.Add(new RegressionTest("Order not Processed", "", "", "Orders"));
            suite.RegressionTests.Add(new RegressionTest("Order in Shipping", "", "", "Orders"));
            project.RegressionSuites.Add(suite);

            suite = new RegressionSuite("Checkout", 2);
            suite.RegressionTests.Add(new RegressionTest("1-Click Order", "", "", "Orders"));
            suite.RegressionTests.Add(new RegressionTest("Send as Gift Item", "", "", "Orders"));
            project.RegressionSuites.Add(suite);
            
            suite = new RegressionSuite("Special Orders", 2);
            suite.RegressionTests.Add(new RegressionTest("Apply Coupon Code", "", "", "Orders"));
            suite.RegressionTests.Add(new RegressionTest("Super Saver Shipping", "", "", "Orders"));                       
            project.RegressionSuites.Add(suite);
        }
        public static void SaveEnvironments(Project project)
        {
            IAssetType environmentType = Program.MetaModel.GetAssetType("Environment");
            IAttributeDefinition environmentName = environmentType.GetAttributeDefinition("Name");
            IAttributeDefinition environmentScope = environmentType.GetAttributeDefinition("Scope");
            IList<Environment> envrionments = project.Environments;

            foreach (Environment environment in envrionments)
            {
                Asset asset = Program.Services.New(environmentType, Oid.FromToken(project.Id, Program.MetaModel));
                asset.SetAttributeValue(environmentName, environment.Name);
                asset.SetAttributeValue(environmentScope, Oid.FromToken(project.Id, Program.MetaModel));
                Program.Services.Save(asset);
                environment.Id = asset.Oid.Momentless.Token;
            }
        }
        public static void SaveMembers(Project project)
        {
            IAssetType memberType = Program.MetaModel.GetAssetType("Member");
            IAttributeDefinition memberName = memberType.GetAttributeDefinition("Name");
            IAttributeDefinition memberUserName = memberType.GetAttributeDefinition("Username");
            IAttributeDefinition memberPassword = memberType.GetAttributeDefinition("Password");
            IAttributeDefinition memberNickname = memberType.GetAttributeDefinition("Nickname");
            IAttributeDefinition memberEmail = memberType.GetAttributeDefinition("Email");
            IAttributeDefinition memberDefaultRole = memberType.GetAttributeDefinition("DefaultRole");
            IAttributeDefinition memberScopes = memberType.GetAttributeDefinition("Scopes");
            IList<Member> members = project.Members;

            foreach (Member member in members)
            {
                Asset asset = Program.Services.New(memberType, Oid.Null);
                asset.SetAttributeValue(memberName, member.Name);
                asset.SetAttributeValue(memberUserName, member.UserName);
                asset.SetAttributeValue(memberPassword, member.Password);
                asset.SetAttributeValue(memberNickname, member.ShortName);
                asset.SetAttributeValue(memberEmail, member.Email);
                asset.SetAttributeValue(memberDefaultRole, Oid.FromToken(member.DefaultRoleId, Program.MetaModel));
                asset.AddAttributeValue(memberScopes, Oid.FromToken(project.Id, Program.MetaModel));

                try
                {
                    Program.Services.Save(asset);
                    member.Id = asset.Oid.Momentless.Token;
                }
                catch
                {
                    Utils.Logger.Error("ERROR SAVING MEMBER: " + member.Name);
                    Utils.Logger.Error("ATTEMPTING TO LOOKUP");

                    if ("TRUE".Equals( ConfigurationManager.AppSettings["IfExistingMembersThenMatch"]))
                    {
                        QueryToFindExistingMember(member);
                    }
                    else
                    {
                        Utils.Logger.Error("REMOVING MEMBERS CREATED WITH THIS RUN");
                        RemoveCreatedMembers(members);
                        break;
                    }
                }
            }
        }
        public static void SaveThemes(Project project)
        {
            IAssetType themeType = Program.MetaModel.GetAssetType("Theme");
            IAttributeDefinition themeName = themeType.GetAttributeDefinition("Name");
            IAttributeDefinition themeScope = themeType.GetAttributeDefinition("Scope");

            IList<Theme> themes = project.Themes;

            foreach (Theme theme in themes)
            {
                Asset asset = Program.Services.New(themeType, Oid.FromToken(project.Id, Program.MetaModel));
                asset.SetAttributeValue(themeName, theme.Name);
                asset.SetAttributeValue(themeScope, Oid.FromToken(project.Id, Program.MetaModel));
                Program.Services.Save(asset);
                theme.Id = asset.Oid.Momentless.Token;
            }
        }
        public static void SaveBuildProjects(Project project)
        {
            IAssetType buildProjectType = Program.MetaModel.GetAssetType("BuildProject");
            IAttributeDefinition nameDef = buildProjectType.GetAttributeDefinition("Name");
            IAttributeDefinition refDef = buildProjectType.GetAttributeDefinition("Reference");
            IAttributeDefinition scopesDef = buildProjectType.GetAttributeDefinition("Scopes");

            foreach (BuildProject buildProject in project.BuildProjects)
            {
                Asset asset = Program.Services.New(buildProjectType, null);
                asset.SetAttributeValue(nameDef, buildProject.Name);
                asset.SetAttributeValue(refDef, buildProject.Reference);
                asset.AddAttributeValue(scopesDef, Oid.FromToken( project.Id, Program.MetaModel));

                Program.Services.Save(asset);
                buildProject.Id = asset.Oid.Momentless.Token;
            }
        }
 // These tests exist in the inventory but are not assigned to any suite.
 public static void AddRegressionTests(Project project)
 {
     project.RegressionTests.Add(new RegressionTest("Valid user logs in", 
                                                    "Create user account user password.  Close Any Sessions, clean browser cache", 
                                                    "1. Open Browser\n 2.Go To homepage\n 3.Login with user password", 
                                                    "User Account Login"));
     project.RegressionTests.Add(new RegressionTest("Valid user logs out", 
                                                    "Close Any Sessions, clean browser cache", 
                                                    "1. Open Browser\n 2.Go To homepage\n 3.Login with user password\n 4.Click logout", 
                                                    "User Account Logout"));
     project.RegressionTests.Add(new RegressionTest("Unknown user tries to login", 
                                                    "Close Any Sessions, clean browser cache", 
                                                    "1. Open Browser\n 2.Go To homepage\n 3.Login with baduser password", 
                                                    "User Login LDAP"));
     project.RegressionTests.Add(new RegressionTest("Valid user logs in with invalid password", 
                                                    "Close Any Sessions, clean browser cache", 
                                                    "1. Open Browser\n 2.Go To homepage\n 3.Login with user badpassword", 
                                                    "User Login Credentials"));
 }
        public static void SaveRegressionTests(IEnumerable<RegressionTest> regressionTests, Project project)
        {
            IAssetType regressionTestType = Program.MetaModel.GetAssetType("RegressionTest");
            IAttributeDefinition regressionTestName = regressionTestType.GetAttributeDefinition("Name");
            IAttributeDefinition regressionTestSetup = regressionTestType.GetAttributeDefinition("Setup");
            IAttributeDefinition regressionTestSteps = regressionTestType.GetAttributeDefinition("Steps");
            IAttributeDefinition regressionTestTags = regressionTestType.GetAttributeDefinition("Tags");

            foreach (RegressionTest regressionTest in regressionTests)
            {
                Asset asset = Program.Services.New(regressionTestType, Oid.FromToken(project.Id, Program.MetaModel));
                asset.SetAttributeValue(regressionTestName, regressionTest.Name);
                asset.SetAttributeValue(regressionTestSetup, regressionTest.Setup);
                asset.SetAttributeValue(regressionTestSteps, regressionTest.Steps);
                asset.SetAttributeValue(regressionTestTags, regressionTest.Tags);
                Program.Services.Save(asset);
                regressionTest.Id = asset.Oid.Momentless.Token;
            }
        }
        public static void AddStoriesToGoal(Project project)
        {
            var matchingGoal = project.Goals.FirstOrDefault(x => x.Name.Equals("Increase Cust Satisfaction by 10%"));

            if (matchingGoal != null)
            {
                string goalId = matchingGoal.Id;

                Query query = new Query(Oid.FromToken(goalId, Program.MetaModel));
                IAttributeDefinition workitemsDef = Program.MetaModel.GetAttributeDefinition("Goal.Workitems");
                QueryResult result = Program.Services.Retrieve(query);
                Asset goal = result.Assets[0];

                string storyId1 = project.Stories.First(x => x.Name.Equals("List of Books by Author")).Id;
                string storyId2 = project.Stories.First(x => x.Name.Equals("List of Books by Genre")).Id;
                goal.AddAttributeValue(workitemsDef, Oid.FromToken(storyId1, Program.MetaModel));
                goal.AddAttributeValue(workitemsDef, Oid.FromToken(storyId2, Program.MetaModel));
                Program.Services.Save(goal);
            }
        }
        public static Asset CreateTeamRoom(Project project, Asset schedule)
        {
            IAssetType assetType = Program.MetaModel.GetAssetType("TeamRoom");
            IAttributeDefinition nameAttribute = assetType.GetAttributeDefinition("Name");
            IAttributeDefinition scheduleAttribute = assetType.GetAttributeDefinition("Schedule");
            IAttributeDefinition scopeAttribute = assetType.GetAttributeDefinition("Scope");
            IAttributeDefinition participantAttribute = assetType.GetAttributeDefinition("Participants");
            
            Asset newTeamRoom = Program.Services.New(assetType, null);
            newTeamRoom.SetAttributeValue(nameAttribute, project.Name + " TeamRoom");
            newTeamRoom.SetAttributeValue(scheduleAttribute, schedule.Oid);
            newTeamRoom.SetAttributeValue(scopeAttribute, project.Id);

            foreach (Member member in project.Members)
            {
                newTeamRoom.AddAttributeValue(participantAttribute, member.Id);
            }

            Program.Services.Save(newTeamRoom);
            return newTeamRoom;
        }
        public static void SaveIssues(Project project, IList<Member> owners)
        {
            IAssetType issueType = Program.MetaModel.GetAssetType("Issue");
            IAttributeDefinition nameDef = issueType.GetAttributeDefinition("Name");
            IAttributeDefinition targetDateDef = issueType.GetAttributeDefinition("TargetDate");
            IAttributeDefinition priorityDef = issueType.GetAttributeDefinition("Priority");
            IAttributeDefinition typeDef = issueType.GetAttributeDefinition("Category");
            IAttributeDefinition ownersDef = issueType.GetAttributeDefinition("Owner");

            foreach (Issue issue in project.Issues)
            {
                Asset asset = Program.Services.New(issueType, Oid.FromToken(project.Id, Program.MetaModel));
                asset.SetAttributeValue(nameDef, issue.Name);
                asset.SetAttributeValue(targetDateDef, issue.TargetDate);
                asset.SetAttributeValue(priorityDef, Oid.FromToken(issue.PriorityId, Program.MetaModel));
                asset.SetAttributeValue(typeDef, Oid.FromToken(issue.TypeId, Program.MetaModel));
                asset.SetAttributeValue(ownersDef, Oid.FromToken(owners[0].Id, Program.MetaModel)); // can only have a single owner on an Issue

                Program.Services.Save(asset);
                issue.Id = asset.Oid.Momentless.Token;
            }
        }
        public static void SaveRequests(Project project)
        {
            IAssetType requestType = Program.MetaModel.GetAssetType("Request");
            IAttributeDefinition nameDef = requestType.GetAttributeDefinition("Name");
            IAttributeDefinition descDef = requestType.GetAttributeDefinition("Description");
            IAttributeDefinition priorityDef = requestType.GetAttributeDefinition("Priority");
            IAttributeDefinition statusDef = requestType.GetAttributeDefinition("Status");
            IAttributeDefinition requestedByDef = requestType.GetAttributeDefinition("RequestedBy");

            foreach (Request request in project.Requests)
            {
                Asset asset = Program.Services.New(requestType, Oid.FromToken( project.Id, Program.MetaModel));
                asset.SetAttributeValue(nameDef, request.Name);
                asset.SetAttributeValue(descDef, request.Description);
                asset.SetAttributeValue(priorityDef, Oid.FromToken(request.PriorityId, Program.MetaModel));
                asset.SetAttributeValue(statusDef, Oid.FromToken(request.StatusId, Program.MetaModel));
                asset.SetAttributeValue(requestedByDef, request.RequestedBy);

                Program.Services.Save(asset);
                request.Id = asset.Oid.Momentless.Token;
            }
        }
        public static void SaveGoals(Project project)
        {
            IAssetType goalType = Program.MetaModel.GetAssetType("Goal");
            IAttributeDefinition nameDef = goalType.GetAttributeDefinition("Name");
            IAttributeDefinition descDef = goalType.GetAttributeDefinition("Description");
            IAttributeDefinition priorityDef = goalType.GetAttributeDefinition("Priority");
            IAttributeDefinition categoryDef = goalType.GetAttributeDefinition("Category");
            IAttributeDefinition targetedByDef = goalType.GetAttributeDefinition("TargetedBy");

            foreach (Goal goal in project.Goals)
            {
                Asset asset = Program.Services.New(goalType, Oid.FromToken(project.Id, Program.MetaModel));
                asset.SetAttributeValue(nameDef, goal.Name);
                asset.SetAttributeValue(descDef, goal.Description);
                asset.SetAttributeValue(priorityDef, Oid.FromToken(goal.PriorityId, Program.MetaModel));
                asset.SetAttributeValue(categoryDef, Oid.FromToken(goal.CategoryId, Program.MetaModel));
                asset.AddAttributeValue(targetedByDef, Oid.FromToken(project.Id, Program.MetaModel));

                Program.Services.Save(asset);
                goal.Id = asset.Oid.Momentless.Token;
            }
        }
        public static void SaveChangeSets(Project project)
        {
            if (project.ChangeSets.Count > 0)
            {
                IAssetType changeSetType = Program.MetaModel.GetAssetType("ChangeSet");
                IAttributeDefinition nameDef = changeSetType.GetAttributeDefinition("Name");
                IAttributeDefinition descDef = changeSetType.GetAttributeDefinition("Description");
                IAttributeDefinition refDef = changeSetType.GetAttributeDefinition("Reference");
                IAttributeDefinition buildRunDef = changeSetType.GetAttributeDefinition("BuildRuns");

                foreach (ChangeSet changeSet in project.ChangeSets)
                {
                    Asset asset = Program.Services.New(changeSetType, null);
                    asset.SetAttributeValue(nameDef, changeSet.Name);
                    asset.SetAttributeValue(descDef, changeSet.Description);
                    asset.SetAttributeValue(refDef, changeSet.Reference);
                    asset.AddAttributeValue(buildRunDef, Oid.FromToken(project.BuildRuns[changeSet.BuildRun].Id, Program.MetaModel));

                    Program.Services.Save(asset);
                    changeSet.Id = asset.Oid.Momentless.Token;
                }
            }
        }
        public static void SaveBuildRuns(Project project)
        {
            IAssetType buildRunType = Program.MetaModel.GetAssetType("BuildRun");
            IAttributeDefinition nameDef = buildRunType.GetAttributeDefinition("Name");
            IAttributeDefinition refDef = buildRunType.GetAttributeDefinition("Reference");
            IAttributeDefinition sourceDef = buildRunType.GetAttributeDefinition("Source");
            IAttributeDefinition statusDef = buildRunType.GetAttributeDefinition("Status");
            IAttributeDefinition dateDef = buildRunType.GetAttributeDefinition("Date");
            IAttributeDefinition buildProjectDef = buildRunType.GetAttributeDefinition("BuildProject");

            foreach (BuildRun buildRun in project.BuildRuns)
            {
                Asset asset = Program.Services.New(buildRunType, null);
                asset.SetAttributeValue(nameDef, buildRun.Name);
                asset.SetAttributeValue(refDef, buildRun.Reference);
                asset.SetAttributeValue(sourceDef, Oid.FromToken(buildRun.Source, Program.MetaModel));
                asset.SetAttributeValue(statusDef, Oid.FromToken(buildRun.Status, Program.MetaModel));
                asset.SetAttributeValue(dateDef, buildRun.Date);
                asset.SetAttributeValue(buildProjectDef, Oid.FromToken(project.BuildProjects[0].Id, Program.MetaModel));

                Program.Services.Save(asset);
                buildRun.Id = asset.Oid.Momentless.Token;
            }
        }
 public static void AddIterationDefects(Project project, Iteration iteration)
 {
     project.Defects.Add(CreateIterationDefect("Fix performance SLA on load", 1, Utils.PriorityHigh, Utils.StatusInProgress, iteration, Theme.ThemeStorefront, Team.TeamBeta));
     project.Defects.Add(CreateIterationDefect("Correct warning message label", 3, Utils.PriorityMedium, Utils.StatusNone, iteration, Theme.ThemeStorefront, Team.TeamAlpha));
 }
 public static void AddReleaseDefects(Project project)
 {
     project.Defects.Add(new Defect("Fix book details when Genre 'mystery'", 2, Utils.PriorityHigh, Utils.StatusNone, Theme.ThemeStorefront, Team.TeamAlpha)); //0
     project.Defects.Add(new Defect("Incorrect response label when saving order", 1, Utils.PriorityHigh, Utils.StatusNone, Theme.ThemeOrderProc, Team.TeamBeta)); //1
     project.Defects.Add(new Defect("Title display incorrect on IE", 1, Utils.PriorityHigh, Utils.StatusNone, Theme.ThemeOrderProc, Team.TeamBeta)); //2
 }