public void it_should_mark_a_deletable_entry_as_deleted()
        {
            const int    id = 1;
            const string expectedAddress = "Line 1";
            var          now             = new DateTime(2018, 1, 1);

            dtp.Now().Returns(now);

            using (var context = new GLAAContext(options))
            {
                context.Addresses.Add(new Address {
                    Id = id, AddressLine1 = expectedAddress
                });
                context.SaveChanges();
            }

            using (var context = new GLAAContext(options))
            {
                var repo = new EntityFrameworkRepositoryBase(context, dtp);
                repo.Delete <Address>(id);
                var result = repo.GetDeletedById <Address>(id);
                Assert.IsTrue(result.Deleted);
                Assert.AreEqual(now, result.DateDeleted);
                Assert.AreEqual(id, result.Id);
                Assert.AreEqual(expectedAddress, result.AddressLine1);
            }
        }
        public void it_should_retrieve_a_deleted_entity_by_id_if_specified()
        {
            const int    id = 1;
            const string expectedAddress = "Line 1";

            using (var context = new GLAAContext(options))
            {
                context.Addresses.Add(new Address {
                    Id = id, AddressLine1 = expectedAddress, Deleted = true
                });
                context.SaveChanges();
            }

            using (var context = new GLAAContext(options))
            {
                var repo   = new EntityFrameworkRepositoryBase(context, dtp);
                var result = repo.GetDeletedById <Address>(id);
                Assert.AreEqual(id, result.Id);
                Assert.AreEqual(expectedAddress, result.AddressLine1);
                Assert.IsTrue(result.Deleted);
            }
        }
        public void it_should_mark_items_marked_for_cascading_as_deleted()
        {
            const int    id = 1;
            const string expectedRestraintOrder = "ro";
            const string expectedConviction     = "conviction";
            const string expectedOffence        = "offence";
            var          now = new DateTime(2018, 1, 1);

            dtp.Now().Returns(now);

            using (var context = new GLAAContext(options))
            {
                context.NamedIndividuals.Add(new NamedIndividual
                {
                    Id = id,
                    RestraintOrders = new[]
                    {
                        new RestraintOrder
                        {
                            Id          = id,
                            Description = expectedRestraintOrder
                        }
                    },
                    UnspentConvictions = new[]
                    {
                        new Conviction
                        {
                            Id          = id,
                            Description = expectedConviction
                        }
                    },
                    OffencesAwaitingTrial = new[]
                    {
                        new OffenceAwaitingTrial
                        {
                            Id          = id,
                            Description = expectedOffence
                        }
                    }
                });
                context.SaveChanges();
            }

            using (var context = new GLAAContext(options))
            {
                var repo = new EntityFrameworkRepositoryBase(context, dtp);
                repo.Delete <NamedIndividual>(id);

                var ni = repo.GetDeletedById <NamedIndividual>(id);
                Assert.IsTrue(ni.Deleted);
                Assert.AreEqual(now, ni.DateDeleted);

                var ro = repo.GetDeletedById <RestraintOrder>(id);
                Assert.IsTrue(ro.Deleted);
                Assert.AreEqual(now, ro.DateDeleted);
                Assert.AreEqual(expectedRestraintOrder, ro.Description);

                var c = repo.GetDeletedById <Conviction>(id);
                Assert.IsTrue(c.Deleted);
                Assert.AreEqual(now, c.DateDeleted);
                Assert.AreEqual(expectedConviction, c.Description);

                var oat = repo.GetDeletedById <OffenceAwaitingTrial>(id);
                Assert.IsTrue(oat.Deleted);
                Assert.AreEqual(now, oat.DateDeleted);
                Assert.AreEqual(expectedOffence, oat.Description);
            }
        }