public void CreateArrangementWithVersions()
        {
            using (DatabaseContext ctx = new DatabaseContext())
            {
                ArrangementRepository repository = new ArrangementRepository(ctx);
                var arrangement = repository.Add();

                arrangement.Name = "Koops Furness";
                arrangement.BpNumber = "123456789";

                var version1 = new ArrangementVersion {Version = 1};
                var version2 = new ArrangementVersion {Version = 2};

                arrangement.Versions.Add(version1);
                arrangement.Versions.Add(version2);

                Assert.IsTrue(arrangement.Id == 0);
                Assert.IsTrue(version1.Id == 0);
                Assert.IsTrue(version2.Id == 0);

                ctx.SaveChanges();
                Assert.IsTrue(arrangement.Id > 0);
                Assert.IsTrue(version1.Id > 0);
                Assert.IsTrue(version2.Id > 0);
                Assert.AreEqual(arrangement, version1.Arrangement);
                Assert.AreEqual(arrangement, version2.Arrangement);
            }

            using (DatabaseContext ctx = new DatabaseContext())
            {
                var arrangement = ctx.Set<Arrangement>().Single();
                Assert.AreEqual("Koops Furness", arrangement.Name);
                Assert.AreEqual("123456789", arrangement.BpNumber);

                Assert.IsEmpty(arrangement.Users);
                Assert.IsNotEmpty(arrangement.Versions);
                Assert.AreEqual(2, arrangement.Versions.Count);
                Assert.AreEqual(arrangement, arrangement.Versions.First().Arrangement);
                Assert.AreEqual(arrangement, arrangement.Versions.Last().Arrangement);
            }
        }
        public void Sandbox()
        {
            using (DatabaseContext ctx = new DatabaseContext())
            {
                ArrangementRepository repository = new ArrangementRepository(ctx);
                var arrangement = repository.Add();
                arrangement.Name = "Koops Furness";
                arrangement.BpNumber = "123456789";

                var arrangement2 = repository.Add();
                arrangement2.Name = "H4";
                arrangement2.BpNumber = "987654321";

                var arrangementVersion1 = new ArrangementVersion();
                arrangementVersion1.Version = 1;
                arrangementVersion1.Status = VersionStatus.Editing;

                var arrangementVersion2 = new ArrangementVersion();
                arrangementVersion2.Version = 2;
                arrangementVersion2.Status = VersionStatus.Archived;

                arrangement.Versions.Add(arrangementVersion1);
                arrangement.Versions.Add(arrangementVersion2);

                ctx.SaveChanges();
            }

            using (DatabaseContext ctx = new DatabaseContext())
            {
                var arrangement = ctx.Set<Arrangement>().First();
                Assert.AreEqual(2, arrangement.Versions.Count());
                var av = ctx.ObjectContext.CreateObject<ArrangementVersion>();
                av.Version = 33;
                av.Status = VersionStatus.Published;

                arrangement.Versions.Add(av);

                ctx.SaveChanges();
                av.Version = 333;
                ctx.SaveChanges();
            }

            using (DatabaseContext ctx = new DatabaseContext())
            {
                int aantalversies = ctx.Set<Arrangement>().First().Versions.Count();
                Assert.AreEqual(3, aantalversies);
            }

            using (DatabaseContext ctx = new DatabaseContext())
            {
                var arrangement = ctx.Set<Arrangement>().First(a => a.Id == 1);
                var arrangement2 = ctx.Set<Arrangement>().First(a => a.Id == 2);

                var versie = arrangement.Versions.First(av => av.Version == 1);

                Assert.AreEqual(3, arrangement.Versions.Count);

                versie.Arrangement = arrangement2;

                Assert.IsFalse(arrangement.Versions.Any(v => v.Id == versie.Id));
                Assert.IsTrue(arrangement2.Versions.Any(v => v.Id == versie.Id));

                //arrangement.Versions.Remove(versie);
                //arrangement2.Versions.Add(versie);

                ctx.SaveChanges();
            }

            using (DatabaseContext ctx = new DatabaseContext())
            {

                Arrangement arrangement = ctx.Set<Arrangement>().First(a => a.Id == 1);

                var entry = ctx.Entry<Arrangement>(arrangement);
                Assert.AreEqual(EntityState.Unchanged, entry.State);
                var temp1 = ctx.ChangeTracker.Entries().Single();

                arrangement.Name = "Test 1234";

                Assert.AreEqual(EntityState.Modified, entry.State);
                var temp2 = ctx.ChangeTracker.Entries();

                ctx.SaveChanges();
                Assert.AreEqual(EntityState.Unchanged, entry.State);
            }

            //using (DatabaseContext ctx = new DatabaseContext())
            //{
            //    var arrangement = ctx.Set<Arrangement>().First(a => a.Id == 2);
            //    ctx.Arrangements.Remove(arrangement);

            //    ctx.SaveChanges();
            //}
        }