Ejemplo n.º 1
0
        public void Test()
        {
            var repository = new XmlRepository <XmlEntity>("D:\\Repo.xml");

            repository.Add(new XmlEntity()
            {
                Name = "Hello"
            });
            repository.Add(new XmlEntity()
            {
                Name = "Hello2"
            });

            repository.ForEach(x => Console.WriteLine(x.Name));

            var element = repository.Find(x => x.Name == "Hello").First();

            Console.WriteLine("Count: {0}\n", repository.Count);

            repository.Remove(element);

            repository.ForEach(x => Console.WriteLine(x.Name));
            Console.WriteLine("Count: {0}\n", repository.Count);

            var element2 = repository.Find(x => x.Name == "Hello2").First();

            element2.Name = "NewHelo2";

            repository.Update(element2);

            repository.ForEach(x => Console.WriteLine(x.Name));
            Console.WriteLine("Count: {0}\n", repository.Count);
        }
        public void Remove_ShouldThrowsException_IfIdNotExists()
        {
            string fileName = Guid.NewGuid().ToString("N") + ".xml";

            Guid entityId = Guid.NewGuid();
            XmlRepository <FakeEntity> repository = new XmlRepository <FakeEntity>(fileName);

            repository.Remove(entityId);
        }
        public void Remove_ShouldRemovesEntity_IfIdExists()
        {
            string fileName = Guid.NewGuid().ToString("N") + ".xml";

            Guid       entityId = Guid.NewGuid();
            FakeEntity entity   = new FakeEntity()
            {
                Id = entityId, Name = entityId.ToString()
            };
            XmlRepository <FakeEntity> repository = new XmlRepository <FakeEntity>(fileName);

            repository.Add(entity);
            repository.SaveChanges();
            repository.Remove(entityId);
            repository.SaveChanges();

            repository = new XmlRepository <FakeEntity>(fileName);

            Assert.AreEqual(0, repository.GetAll().Count());
            File.Delete(fileName);
        }