Пример #1
0
        public List<Category> Read(string filename)
        {
            List<Category> categories = new List<Category>();

            try
            {
                if (!File.Exists(filename)) return categories;

                XmlDocument document = new XmlDocument();
                document.Load(filename);

                foreach (XmlNode node in document.DocumentElement.SelectNodes("Category"))
                {
                    Category category = new Category();

                    category.Name = InnerTextOrNull(node.SelectSingleNode("Name"));

                    categories.Add(category);
                }
            }
            catch (Exception e)
            {
                MessageBox.Show("Ett fel har uppstått:\n\n" + e.Message);
            }

            return categories;
        }
Пример #2
0
        public void canRemoveCategory()
        {
            var newCategoryID = Guid.NewGuid();
            var categoryToDelete = new Category() { Id = newCategoryID, Name = "To delete." };
            repository.Add(categoryToDelete);
            repository.Delete(categoryToDelete);
            var fromRepository = repository.Find(newCategoryID);
            Assert.IsNull(fromRepository, "Repository returned deleted Category");

            fromRepository = null;
            foreach (var category in repository.GetAll())
                if (category.Id == newCategoryID) fromRepository = category;
            Assert.IsNull(fromRepository, "Get all contained deleted category");

            Assert.IsTrue(removedCategory.Id == categoryToDelete.Id, "ObserveCollection did not report back correct object");
        }
Пример #3
0
        public void canCompareCategories()
        {
            var IdX = Guid.NewGuid();
            var IdY = Guid.NewGuid();

            var category1 = new Category() { Id = IdX, Name = "Category X" };
            var category2 = new Category() { Id = IdX, Name = "Category Y" };
            var category3 = new Category() { Id = IdY, Name = "Category Y" };

            Assert.IsTrue(category1.Equals(category2), "Object.Equals() false negative");
            Assert.IsFalse(category1.Equals(category3), "Object.Equals() false positive");

            Assert.IsFalse(category2 == category3, "== operator overload false positive");
            Assert.IsTrue(category2 != category3, "== operator overload false negative");
            Assert.IsTrue(category1 != category3, "!= operator overload false positive");
            Assert.IsTrue(category1 != category3, "!= operator overload false negative");

            Assert.IsFalse(category1.Equals(new Object()), "false positive comparing category to object");
        }
Пример #4
0
        public void canUpdateCategory()
        {
            var newCategoryID = Guid.NewGuid();
            var categoryToUpdate = new Category() { Id = newCategoryID, Name = "To update." };
            repository.Add(categoryToUpdate);
            var oldName = categoryToUpdate.Name;
            var newName = "Updated unit test category";
            categoryToUpdate.Name = newName;
            repository.Update(categoryToUpdate);
            var updatedCategory = repository.Find(newCategoryID);
            repository.Delete(categoryToUpdate);

            Assert.IsTrue(updatedCategory.Name == newName, "Repository find did not return changed category");
            Assert.IsTrue(changedFromCategory.Name == oldName,
                String.Format("ObserveCollection did not report back correct old object. Should have been {0}, was {1}",
                oldName,
                changedFromCategory.Name));
            Assert.IsTrue(changedToCategory.Name == newName, "ObserveCollection did not report back correct new object");
        }
Пример #5
0
        public void canEvaluateContains()
        {
            var IdX = Guid.NewGuid();
            var IdY = Guid.NewGuid();
            var IdZ = Guid.NewGuid();
            var IdU = Guid.NewGuid();

            var category1 = new Category() { Id = IdX, Name = "Category X" };
            var category2 = new Category() { Id = IdX, Name = "Category Y" };
            var category3 = new Category() { Id = IdY, Name = "Category Y" };
            var category4 = new Category() { Id = IdZ, Name = "Category Z " };
            var category5 = new Category() { Id = IdU, Name = "another category" };

            var categories = new List<IEntity>();
            categories.Add(category1);
            categories.Add(category3);
            categories.Add(category4);

            var feed1 = new Feed() { Id = IdZ, Name = "Feed X" };
            var feed2 = new Feed() { Id = IdZ, Name = "Feed Y" };
            var feed3 = new Feed() { Id = IdY, Name = "Feed Z" };
            var feed4 = new Feed() { Id = IdX, Name = "Feed X" };
            var feed5 = new Feed() { Id = IdU, Name = "Feed me" };

            var feeds = new List<IEntity>();
            feeds.Add(feed1);
            feeds.Add(feed4);
            feeds.Add(feed3);

            Assert.IsTrue(categories.Contains(category2), "We consider a collection that contains an entity with the same ID as comparator as containing it.");
            Assert.IsFalse(categories.Contains(category5), "Contains false positive");

            Assert.IsTrue(feeds.Contains(feed2), "We consider a collection that contains an entity with the same ID as comparator as containing it.");
            Assert.IsFalse(feeds.Contains(feed5), "Contains false positive");

            Assert.IsFalse(feeds.Contains(category4), "Contains false positive");
        }
Пример #6
0
        public void canAddNewCategory()
        {
            var newID = Guid.NewGuid();
            var categoryToAdd = new Category() { Id = newID, Name = "TestCategory" };
              repository.Add(categoryToAdd);
            repository.Add(categoryToAdd);
            repository.Add(categoryToAdd);

            var fromFind = repository.Find(newID);

            var fromGetAll = new List<Category>();
            foreach (var category in repository.GetAll())
                if (category.Id == newID) fromGetAll.Add(category);

            repository.Delete(categoryToAdd);

            Assert.IsNotNull(fromFind, "Find failed to return newly added Category");
            Assert.IsTrue(categoryToAdd.Id == fromFind.Id && categoryToAdd.Name == fromFind.Name,
                "Category returned from Find not identical to added TestCategory");

            Assert.IsFalse(fromGetAll.Count == 0, "GetAll did not contain newly added Category");
            Assert.IsTrue(addedCategory.Id == categoryToAdd.Id, "repository eventhandler contained wrong catergory");
            Assert.IsFalse(fromGetAll.Count > 1, "Guid is not unique");
        }
Пример #7
0
 public CategoryViewModel(Category category)
 {
     setupCategory(category);
     setupNameEditing(category);
 }
Пример #8
0
 private void setupNameEditing(Category category)
 {
     name = category.Name;
     doneEditing = true;
     Edit = new RelayCommand(startEditing, canEdit);
     Commit = new RelayCommand(commit, canCommit);
 }
Пример #9
0
 private void setupCategory(Category category)
 {
     this.Category = category;
     DataConnection.getFeeds().CollectionChanged += feedsChanged;
     updateInfo();
 }
Пример #10
0
 static void ChangeCategory(Feed feed, Category newCategory)
 {
     feed.Category = newCategory;
 }
Пример #11
0
 private static void listener(object sender, NotifyCollectionChangedEventArgs e)
 {
     if (e.Action == NotifyCollectionChangedAction.Add)
         addedCategory = e.NewItems[0] as Category;
     else if (e.Action == NotifyCollectionChangedAction.Replace)
     {
         changedFromCategory = e.OldItems[0] as Category;
         changedToCategory = e.NewItems[0] as Category;
     }
     else if (e.Action == NotifyCollectionChangedAction.Remove)
         removedCategory = e.OldItems[0] as Category;
 }
Пример #12
0
        public void getAllReturnsPersistedData()
        {
            var newCategoryId = Guid.NewGuid();
            var categoryToPersist = new Category() { Id = newCategoryId, Name = "NewCategory" };
              repository.Add(categoryToPersist);

            foreach (Category c in repository.GetAll())
                c.Name = "";
            var persistedCategory = repository.Find(newCategoryId);

            var fromGetAll = new List<Category>();
            foreach (Category c in repository.GetAll())
                if (c.Id == newCategoryId) fromGetAll.Add(c);
            repository.Delete(categoryToPersist);

            Assert.IsNotNull(persistedCategory, "repository find dit not return added category");
            Assert.IsTrue(persistedCategory.Name.Length > 0, "repository find returned unpersisted data");

            Assert.IsFalse(fromGetAll.Count == 0, "repository get all dit not return added category");
        }
 public EditCategoryForm(Category category)
 {
     InitializeComponent();
     textBoxNewName.Text = category.Name;
     NewCategory = category;
 }
Пример #14
0
 /// <summary>
 /// Kontrollerar om en kategori tillåts att tas bort av användaren
 /// </summary>
 /// <param name="category">instans av Category</param>
 /// <returns>true om kategorin inte har några tillhörande Feeds</returns>
 public static bool validDeletion(Category category)
 {
     var numberOfFeedsWitCategory = DataConnection.getFeeds().GetAll().Where(feed => feed.Category == category.Id).Count();
     return numberOfFeedsWitCategory == 0;
 }
Пример #15
0
 public bool Validate(string urlValue, Category category)
 {
     throw new NotImplementedException();
 }