public static void AssertCategoriesEqual(AtomCategory category, AtomCategory testCategory) { Assert.AreEqual(category.Label, testCategory.Label); Assert.AreEqual(category.Term, testCategory.Term); //Assert.AreEqual(category.Lang, testCategory.Lang); Assert.AreEqual(category.Scheme, testCategory.Scheme); //Assert.AreEqual(category.Base, testCategory.Base); }
public void FullCreateAtomCategoryTest() { AtomCategory atomCategory = new AtomCategory() { Label = "aLabel", Lang = "EN", Scheme = new Uri("http://scheme.com"), Term = "term", Base = new Uri("http://base.com") }; Assert.IsNotNull(atomCategory); Assert.AreEqual("aLabel", atomCategory.Label); Assert.AreEqual("EN", atomCategory.Lang); Assert.AreEqual(new Uri("http://scheme.com"), atomCategory.Scheme); Assert.AreEqual("term", atomCategory.Term); Assert.AreEqual(new Uri("http://base.com"), atomCategory.Base); }
internal static List<AtomCategory> MakeAtomCategoryList(int count) { List<AtomCategory> categories = new List<AtomCategory>(); for (int loopIndex = 0; loopIndex < count; loopIndex++) { AtomCategory atomCategory = new AtomCategory() { Label = "aLabel" + loopIndex.ToString(), Lang = "EN", Scheme = new Uri("http://scheme.com"), Term = "term" + loopIndex.ToString(), Base = new Uri("http://base.com") }; categories.Add(atomCategory); } return categories; }
public bool AddCategory(AtomCategory cat) { //TODO: support parent scheme according to standard //validate category term does not contain special characters, // if it does, remove them and use original term as label (when no label) if (cat.Term.ToLowerInvariant() != cat.Term.CleanSlug().ToLowerInvariant()) { if (string.IsNullOrEmpty(cat.Label)) { cat.Label = cat.Term; } cat.Term = cat.Term.CleanSlug(); //no need for a label if same as term if (cat.Label == cat.Term) cat.Label = null; } if (!Categories.Contains(cat)) { //The absence of the "fixed" attribute is equivalent to the presence of //a "fixed" attribute with a value of "no". if (Fixed.HasValue && Fixed.Value) throw new CategoryAddWhenFixedException(cat.ToString()); List<AtomCategory> list = Categories.ToList(); //TODO: add the category, but ignore the scheme if it matches the parent //list.Add(new AtomCategory() { Term = cat.Term, Label = cat.Label }); list.Add(cat); Categories = list.AsEnumerable(); return true; } else { //normalize label cat.Label = Categories.Where(c => c.Scheme == cat.Scheme && c.Term == cat.Term).Single().Label; } return false; }
public AtomCategory AddCategory(Id collectionId, string category, Uri scheme) { LogService.Info("AtomPubService.AddCategory collectionId={0}, category={1}", collectionId, category); AppService service = AppServiceRepository.GetService(); AppCollection coll = service.GetCollection(collectionId); AtomCategory cat = new AtomCategory() { Term = category, Scheme = scheme }; //TODO: support external categories //TODO: support scheme bool changed = coll.Categories.First().AddCategory(cat); //save when changed if (changed) { LogService.Info("Saving service doc for internal category change."); AppServiceRepository.UpdateService(service); } return cat; }
public void SimpleCreateAtomCategoryTest() { AtomCategory atomCategory = new AtomCategory(); Assert.IsNotNull(atomCategory); }
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); }