Example #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 Update_ShouldSavesChanges_IfEntityExists()
        {
            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();

            entity = new FakeEntity()
            {
                Id = entityId, Name = "NewValue"
            };

            repository = new XmlRepository <FakeEntity>(fileName);
            repository.Update(entity);
            repository.SaveChanges();

            repository = new XmlRepository <FakeEntity>(fileName);
            entity     = repository.Get(entityId);

            Assert.AreEqual("NewValue", entity.Name);
            File.Delete(fileName);
        }
Example #3
0
        public void Get_GetAll_and_Update_should_throw_for_unknown_Type()
        {
            const string file = "\\somefile.xml";

            var repository = new XmlRepository(file, serializationProvider, pathResolver);

            Assert.Throws<InvalidOperationException>(() => repository.Get<MeetingRepository>(0));
            Assert.Throws<InvalidOperationException>(() => repository.GetAll<MeetingRepository>());
            Assert.Throws<InvalidOperationException>(() => repository.Update("", 0));

            new FileInfo(file).Delete();
        }
        public void Update_ShouldThrowsException_IfEntityNotExists()
        {
            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.Update(entity);
        }