public string GetCategoriesPath(Id collectionId, AppCategories externalCats)
 {
   string filename = externalCats.GetProperty<string>(FileNs + "name");
   if (string.IsNullOrEmpty(filename)) filename = DefaultCategoriesFileName;
   string path = GetCollectionPath(collectionId);
   path = Path.Combine(path, filename);
   return path;
 }
 public AppCategories GetCategories(Id collectionId, AppCategories externalCats)
 {
   string path = pathResolver.GetCategoriesPath(collectionId, externalCats);
   try
   {
     return AppCategories.Load(path);//TODO: cache
   }
   catch (FileNotFoundException)
   {
     throw new ResourceNotFoundException("categories document", path);
   }
 }
        public void CreatAppCategorieseWithHrefTest()
        {
            AppCategories categories = new AppCategories()
                {
                    Scheme = new Uri("http://foo.com"),
                    Fixed = true,
                    Href = new Uri("http://bar.com"),
                };

            Assert.IsNotNull(categories);

            Assert.AreEqual(new Uri("http://foo.com"), categories.Scheme);
            Assert.IsTrue(categories.Fixed.HasValue);
            Assert.IsTrue(categories.Fixed.Value);
            Assert.AreEqual(new Uri("http://bar.com"), categories.Href);
            Assert.IsNull(categories.Categories);
        }
        public void CreateAppCategoriesNotFixedTest()
        {
            AppCategories categories = new AppCategories()
            {
                Scheme = new Uri("http://foo.com"),
                Fixed = false,
                Href = null,
                Categories = new List<AtomCategory>()
            };

            Assert.IsNotNull(categories);

            Assert.AreEqual(new Uri("http://foo.com"), categories.Scheme);
            Assert.IsTrue(categories.Fixed.HasValue);
            Assert.IsFalse(categories.Fixed.Value);
            Assert.IsNull(categories.Href);
            Assert.IsNotNull(categories.Categories);
        }
        internal static List<AppCategories> MakeAppCategoriesList(int count)
        {
            List<AppCategories> categories = new List<AppCategories>();

            for (int loopIndex = 0; loopIndex < count; loopIndex++)
            {

                AppCategories cat = new AppCategories()
                {
                    Scheme = new Uri("http://scheme" + loopIndex.ToString() + ".com"),
                    Fixed = true,
                    Href = new Uri("http://href" + loopIndex.ToString() + ".com"),
                };

                categories.Add(cat);
            }

            return categories;
        }
        public void UpdateAppServiceAddCategoryTest()
        {
            IAppServiceRepository repository = GetRepository();

            AppService appService = repository.GetService();

            Assert.IsNotNull(appService, "no app service");
            Assert.IsNotNull(appService.Workspaces);

            // put a new workspace in it
            AtomSite.Domain.AppWorkspace newWorkspace = TestDataHelper.MakeTestWorkspace();
            string workspaceName = newWorkspace.Name;

            // containing a collection
            AtomSite.Domain.AppCollection newCollection = TestDataHelper.MakeTestAppCollection();
            string collectionTitle = newCollection.Title.Text;

            // containing an app category
            AtomSite.Domain.AppCategories newCats = new AppCategories
            {
                Scheme = new Uri("http://www.foo.com"),
                Base = new Uri("http://www.base.com"),
                Fixed = true
            };

            // containing a category
            AtomSite.Domain.AtomCategory newAtomCat = new AtomSite.Domain.AtomCategory
                {
                    Base = new Uri("http://www.base.com"),
                    Label = Guid.NewGuid().ToString(),
                    Term = Guid.NewGuid().ToString(),
                    Lang = "EN",
                    Scheme = new Uri("http://www.foo.com")
                };

            newCats.Categories = newAtomCat.InList();

            newCollection.Categories = newCats.InList();
            newWorkspace.Collections = newCollection.InList();
            appService.Workspaces = appService.Workspaces.Add(newWorkspace);

            // persist it
            repository.UpdateService(appService);

            // and reload, check the collection
            // to verify that the data was saved and loaded

            IAppServiceRepository secondRepository = GetRepository();

            AppService loadedAppService = secondRepository.GetService();
            Assert.IsNotNull(loadedAppService);

            AppCollection loadedCollection = loadedAppService.Workspaces.FindByName(workspaceName).Collections.FindByTitle(collectionTitle);

            Assert.IsNotNull(loadedCollection);
            Assert.AreEqual(1, loadedCollection.Categories.Count());

            AppCategories loadedCats = loadedCollection.Categories.First();

            Assert.AreEqual(1, loadedCats.Categories.Count(), "Atom category not found");
            AtomSite.Domain.AtomCategory loadedAtomCat = loadedCats.Categories.First();

            DataTester.AssertCategoriesEqual(newAtomCat, loadedAtomCat);

            // delete the workspaces
            DeleteWorkspace(secondRepository, workspaceName);
        }
 public static void AssertAppCategoriesEqual(AppCategories expected, AppCategories actual)
 {
     Assert.AreEqual(expected.Href, actual.Href);
     Assert.AreEqual(expected.IsExternal, actual.IsExternal);
     Assert.AreEqual(expected.Fixed, actual.Fixed);
 }
    void ImportCategories(BlogMLBlog blog, AppCollection coll)
    {      
      var cats = coll.Categories.FirstOrDefault();
      if (cats == null)
      {
        cats = new AppCategories();
        coll.Categories = Enumerable.Repeat(cats, 1);
      }

      foreach (BlogMLCategory cat in blog.Categories)
      {
        LogProgress("Processing blog category with ID={0}", cat.ID);
        if (cats.AddCategory(new AtomCategory() { Term = cat.Title }))
          LogProgress("Adding blog category with ID={0}", cat.ID);
        else
          LogProgress("Blog category with ID={0} already exists", cat.ID);
      }
    }
 public void DeleteCategories(Id collectionId, AppCategories externalCategories)
 {
   throw new NotImplementedException();
 }
        public void SimpleCreateAppCategoriesTest()
        {
            AppCategories categories = new AppCategories();

            Assert.IsNotNull(categories);
        }
 public AppCategories CreateCategories(Id collectionId, AppCategories categories)
 {
   throw new NotImplementedException();
 }
        public void CreateAppCategoriesWithCategoryListTest()
        {
            AppCategories categories = new AppCategories()
            {
                Categories = TestHelper.MakeAtomCategoryList(5),
            };

            Assert.IsNotNull(categories);

            Assert.IsNotNull(categories.Categories);
            Assert.AreEqual(5, categories.Categories.Count());
        }
        public void CreatAppCategorieseWithBothTest()
        {
            AppCategories categories = new AppCategories()
               {
                   Scheme = new Uri("http://foo.com"),
                   Fixed = true,
                   Href = new Uri("http://bar.com"),
                   Categories = new List<AtomCategory>()
               };

        }
 public static AppCategories Load(string path)
 {
   AppCategories cats = new AppCategories();
   cats.Xml = XElement.Load(path, LoadOptions.None);
   return cats;
 }
 public AppCategories UpdateCategories(Id collectionId, AppCategories externalCats, AppCategories categories)
 {
   string path = pathResolver.GetCategoriesPath(collectionId, externalCats);
   categories.Save(path); //TODO: cache
   return categories;
 }
        private IEnumerable<AppCategories> MakeCollectionCategories()
        {
            AppCategories cats = new AppCategories
            {
                Scheme = new Uri("http://TestScheme.com"),
                Fixed = false,
            };

            // add two categories
            cats.Categories = new List<AtomSite.Domain.AtomCategory>
                {
                    TestDataHelper.MakeTestCategory(), TestDataHelper.MakeTestCategory()
                };

            return cats.InList();
        }
 public AppCategories UpdateCategories(Id collectionId, AppCategories externalCategories, AppCategories categories)
 {
     throw new NotImplementedException();
 }