Example #1
0
        public void CloneTemplateTest()
        {
            MockObjectRepository repo = TestDataGenerator.GenerateMockDataset1();
            var      user             = repo.FindOrCreateUser("test.user");
            Template firstTemplate    = repo.Templates.First();

            Template secondTemplate = firstTemplate.CloneTemplate(repo, user.Id);

            repo.Templates.Add(secondTemplate);
            Assert.AreNotEqual(firstTemplate.Name, secondTemplate.Name, "Title for the first template should be different than the cloned template.");
            Assert.AreEqual(firstTemplate.Oid + ".1", secondTemplate.Oid, "Expected the second template's oid to have .1 added to it.");

            // Test that other properties were copied
            Assert.AreEqual(firstTemplate.ImplementationGuideTypeId, secondTemplate.ImplementationGuideTypeId);
            Assert.AreEqual(firstTemplate.TemplateTypeId, secondTemplate.TemplateTypeId);
            Assert.AreEqual(firstTemplate.OwningImplementationGuideId, secondTemplate.OwningImplementationGuideId);
            Assert.AreEqual(firstTemplate.ImpliedTemplateId, secondTemplate.ImpliedTemplateId);
            Assert.AreEqual(firstTemplate.PrimaryContext, secondTemplate.PrimaryContext);
            Assert.AreEqual(firstTemplate.PrimaryContextType, secondTemplate.PrimaryContextType);
            Assert.AreEqual(firstTemplate.IsOpen, secondTemplate.IsOpen);

            // Test that making more than 10 copies properly generates the title and oid
            Template lastCopiedTemplate = null;
            int      count = 1;

            while (count < 11)
            {
                lastCopiedTemplate = firstTemplate.CloneTemplate(repo, user.Id);
                repo.Templates.Add(lastCopiedTemplate);
                count++;
            }

            Assert.AreEqual(firstTemplate.Oid + ".12", lastCopiedTemplate.Oid, "Generated oid for copied templates is not working when there are more than 10 copies.");
            Assert.AreEqual(firstTemplate.Name + " (Copy 11)", lastCopiedTemplate.Name, "Genrated title for copied templates is not working when there are more than 10 copies.");
        }