Exemplo 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);
        }
Exemplo n.º 2
0
        public void XmlRepo_can_add_2_Infektion_und_unabhägige_Laender()
        {
            var repo = new XmlRepository();

            var inf1 = new Infektion()
            {
                Person = "Bernd"
            };
            var inf2 = new Infektion()
            {
                Person = "Brot"
            };

            var land = new Land()
            {
                Name = "Pestland"
            };
            var land2 = new Land()
            {
                Name = "Seuchenland"
            };

            land2.Region.Add(new Region()
            {
                Name = "Todeszones"
            });

            repo.Add(inf1);
            repo.Add(inf2);
            repo.Add(land);
            repo.Add(land2);
            repo.SaveAll();
        }
Exemplo n.º 3
0
        public void XmlRepo_can_add_2_Infektion_gleiches_Land()
        {
            var repo = new XmlRepository();

            var l = new Land()
            {
                Name = "Seuchenland"
            };

            var inf1 = new Infektion()
            {
                Person = "Bernd"
            };

            inf1.Wohnort = new Region()
            {
                Name = "Pesttal", Land = l
            };
            var inf2 = new Infektion()
            {
                Person = "Bernd"
            };

            inf2.Wohnort = new Region()
            {
                Name = "Rotzberg", Land = l
            };

            repo.Add(inf1);
            repo.Add(inf2);
            repo.SaveAll();
        }
Exemplo n.º 4
0
        public void XmlRepo_can_CR_Infektion_AutoFix_FluentAss()
        {
            var fn  = "AutoFix.xml";
            var fix = new Fixture();

            fix.Behaviors.Add(new OmitOnRecursionBehavior());
            for (int i = 0; i < 10; i++)
            {
                var inf = fix.Create <Infektion>();

                using (var repo = new XmlRepository(fn))
                {
                    inf.Viren.ToList().ForEach(x => repo.Add(x));
                    repo.Add(inf.Wohnort.Land);
                    repo.Add(inf.Wohnort);
                    repo.Add(inf);
                    repo.SaveAll();
                }

                using (var con = new XmlRepository(fn))
                {
                    var loaded = con.GetById <Infektion>(inf.Id);
                    loaded.Should().BeEquivalentTo(inf, c =>
                    {
                        c.Using <DateTime>(ctx => ctx.Subject.Should().BeCloseTo(ctx.Expectation))
                        .WhenTypeIs <DateTime>();
                        c.IgnoringCyclicReferences();
                        return(c);
                    });
                }
            }
        }
        public void Add_ShouldThrowsException_WhenIdIsNotUnique()
        {
            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.Add(entity);
        }
        public void GetAll_ShouldReturnsAllAddedEntities()
        {
            string fileName = Guid.NewGuid().ToString("N") + ".xml";

            int entityCount = 3;
            IEnumerable <Guid>       entityIds = Enumerable.Range(0, entityCount).Select(x => Guid.NewGuid()).ToList();
            IEnumerable <FakeEntity> entities  = entityIds.Select(x => new FakeEntity()
            {
                Id = x, Name = x.ToString()
            });
            XmlRepository <FakeEntity> repository = new XmlRepository <FakeEntity>(fileName);

            foreach (FakeEntity entity in entities)
            {
                repository.Add(entity);
            }

            repository.SaveChanges();

            repository = new XmlRepository <FakeEntity>(fileName);
            entities   = repository.GetAll();

            Assert.AreEqual(entityCount, entities.Count());
            foreach (Guid entityId in entityIds)
            {
                Assert.IsTrue(entities.SingleOrDefault(x => x.Id == entityId && x.Name == entityId.ToString()) != null);
            }

            File.Delete(fileName);
        }
        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);
        }
Exemplo n.º 8
0
        public void XmlRepo_can_add_Infektion_with_2_Virus_MitLand()
        {
            var repo = new XmlRepository();
            var inf  = new Infektion()
            {
                Person = "Bernd"
            };

            inf.Viren.Add(new Virus()
            {
                Name = "v1"
            });
            inf.Viren.Add(new Virus()
            {
                Name = "v2"
            });
            var l = new Land()
            {
                Name = "Seuchenland"
            };

            inf.Wohnort = new Region()
            {
                Name = "Pesttal", Land = l
            };

            repo.Add(inf);
            repo.SaveAll();
        }
Exemplo n.º 9
0
        public void XmlRepo_can_add_Infektion()
        {
            var repo = new XmlRepository();
            var inf  = new Infektion()
            {
                Person = "Bernd"
            };

            repo.Add(inf);
            repo.SaveAll();
        }
Exemplo n.º 10
0
        public void XmlRepo_can_add_Infektion_and_Laender_asign_later()
        {
            var testFile = "myFile.xml";

            if (File.Exists(testFile))
            {
                File.Delete(testFile);
            }

            var inf1 = new Infektion()
            {
                Person = "Bernd"
            };
            var land = new Land()
            {
                Name = "Seuchenland"
            };

            land.Region.Add(new Region()
            {
                Name = "Todeszones"
            });

            {
                var repo = new XmlRepository(testFile);
                repo.Add(inf1);
                repo.Add(land);
                repo.SaveAll();
            }

            {
                var repo    = new XmlRepository(testFile);
                var iLoaded = repo.GetAll <Infektion>().FirstOrDefault();
                var lLoaded = repo.GetAll <Land>().FirstOrDefault();
                iLoaded.Wohnort = lLoaded.Region.FirstOrDefault();

                //repo.Update(iLoaded);
                repo.SaveAll();
            }
        }
Exemplo n.º 11
0
		public XmlUnitOfWork(string fileName)
		{
			dataFileName = fileName;
			entities = new XmlRepository<IEntity>();

			if (!File.Exists(fileName))
				Commit();

			foreach (var wi in ReadXml())
			{
				entities.Add(wi);
			}
		}
        public void XmlRepo_add_sets_the_id()
        {
            var baum = new Tannenbaum()
            {
                Height = 17
            };

            Assert.AreEqual(0, baum.Id);

            var repo = new XmlRepository();

            repo.Add(baum);
            Assert.AreNotEqual(0, baum.Id);
        }
Exemplo n.º 13
0
        public XmlUnitOfWork(string fileName)
        {
            dataFileName = fileName;
            entities     = new XmlRepository <IEntity>();

            if (!File.Exists(fileName))
            {
                Commit();
            }

            foreach (var wi in ReadXml())
            {
                entities.Add(wi);
            }
        }
        public void XmlRepoTests_Can_CRUD_Baum()
        {
            var baum = new Tannenbaum()
            {
                Height = 17
            };
            var newHeight = 452;

            {//INSERT
                var repo = new XmlRepository();
                repo.Add(baum);
                repo.Save();
            }


            {//check Read
                var repo = new XmlRepository();

                Assert.IsTrue(repo.GetAll <Tannenbaum>().Any(x => x.Height == baum.Height));
                var loaded = repo.GetById <Tannenbaum>(baum.Id);
                Assert.IsNotNull(loaded);
                Assert.AreEqual(baum.Height, loaded.Height);

                //UPDATE
                loaded.Height = 452;
                repo.Save();
            }

            {//check UPDATE + DELETE
                var repo   = new XmlRepository();
                var loaded = repo.GetById <Tannenbaum>(baum.Id);
                Assert.AreEqual(newHeight, loaded.Height);

                repo.Delete(loaded);
                repo.Save();
            }

            {//check DELETE
                var repo   = new XmlRepository();
                var loaded = repo.GetById <Tannenbaum>(baum.Id);
                Assert.IsNull(loaded);
            }
        }
        public void Add_ShouldAddsEntity_WhenIdIsUnique()
        {
            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 = new XmlRepository <FakeEntity>(fileName);
            entity     = repository.Get(entityId);

            Assert.AreEqual(entityId.ToString(), entity.Name);
            File.Delete(fileName);
        }
Exemplo n.º 16
0
        public void XmlRepo_can_add_Infektion_with_2_Virus()
        {
            var repo = new XmlRepository();
            var inf  = new Infektion()
            {
                Person = "Bernd"
            };

            inf.Viren.Add(new Virus()
            {
                Name = "v1"
            });
            inf.Viren.Add(new Virus()
            {
                Name = "v2"
            });

            repo.Add(inf);
            repo.SaveAll();
        }
        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);
        }
Exemplo n.º 18
0
        static void Main(string[] args)
        {
            ILogger     logger     = new FileLogger();
            IDownloader downloader = new Downloader(logger);
            IRepository <FeatureCollection> repository =
                new XmlRepository <FeatureCollection>(logger);

            var data = downloader.DownloadInfo("https://earthquake.usgs.gov/fdsnws/event/1/query?format=geojson&limit=50");

            if (!string.IsNullOrEmpty(data))
            {
                var deserializeData =
                    JsonConvert.DeserializeObject <FeatureCollection>(data);
                repository.Add(deserializeData);
            }
            else
            {
                System.Console.WriteLine("Произошла ошибка, обратитесь к системному администратору!");
                System.Console.ReadLine();
            }
        }