public void SomethingElsePersistence_DeleteSomethingElseById_DeletionCascades()
        {
            int        id = 1;
            List <int> childIds;
            var        something1 = new Domain.Something()
            {
                Name = "Bob"
            };

            Domain.SomethingElse somethingElse1 = Domain.SomethingElse.CreateNamedSomethingElse("Fred Bloggs");
            using (var ctx = new DbContextFactory().CreateAppDbContext(nameof(SomethingElsePersistence_DeleteSomethingElseById_DeletionCascades)))
            {
                var persistence = new SomethingElsePersistence(ctx);
                persistence.SaveSomethingElse(somethingElse1);
                var updatedSomethingElse = persistence.UpdateSomethingElseByIdAddSomething(somethingElse1.Id, something1);
                var somethingElse        = ctx.SomethingElses.Include(s => s.Somethings).Where(r => r.Id == id).FirstOrDefault();
                childIds = somethingElse.Somethings.Select(c => c.Id).ToList();
                ctx.Remove(somethingElse);
                ctx.SaveChanges();
            }

            using (var ctx = new DbContextFactory().CreateAppDbContext(nameof(SomethingElsePersistence_DeleteSomethingElseById_DeletionCascades)))
            {
                Assert.Empty(ctx.Somethings.Where(c => childIds.Contains(c.Id)));
            };
        }
        public void SomethingElsePersistence__DeleteSomethingElseById__DeleteSomethingElseFromDatabaseById()
        {
            int id = 1;

            using (var ctx = new DbContextFactory().CreateAppDbContext(nameof(SomethingElsePersistence__DeleteSomethingElseById__DeleteSomethingElseFromDatabaseById)))
            {
                var persistence = new SomethingElsePersistence(ctx);
                persistence.SaveSomethingElse(somethingElse);
            };

            using (var ctx = new DbContextFactory().CreateAppDbContext(nameof(SomethingElsePersistence__DeleteSomethingElseById__DeleteSomethingElseFromDatabaseById)))
            {
                var persistence = new SomethingElsePersistence(ctx);
                persistence.DeleteSomethingElseById(id);
            };

            using (var ctx = new DbContextFactory().CreateAppDbContext(nameof(SomethingElsePersistence__DeleteSomethingElseById__DeleteSomethingElseFromDatabaseById)))
            {
                var persistence = new SomethingElsePersistence(ctx);

                var savedSomethingElses = persistence.GetSomethingElseIncludingSomethingList().Where(f => f.Id == id).ToList();

                int expected = 0;
                int actual   = savedSomethingElses.Count;
                Assert.Equal(expected, actual);
            };
        }
        public void SomethingElsePersistence__GetSomethingElseList__RetrievesSomethingElseListFromDatabase()
        {
            using (var ctx = new DbContextFactory().CreateAppDbContext(nameof(SomethingElsePersistence__GetSomethingElseList__RetrievesSomethingElseListFromDatabase)))
            {
                var persistence = new SomethingElsePersistence(ctx);
                persistence.SaveSomethingElse(somethingElse);
            };

            using (var ctx = new DbContextFactory().CreateAppDbContext(nameof(SomethingElsePersistence__GetSomethingElseList__RetrievesSomethingElseListFromDatabase)))
            {
                var persistence        = new SomethingElsePersistence(ctx);
                var savedSomethingElse = persistence.GetSomethingElseList();
                Assert.Equal(somethingElse.Name, savedSomethingElse.Single().Name);
            };
        }
        public void SomethingElsePersistence__SaveSomethingElse__SavesSomethingElseToDatabase()
        {
            using (var ctx = new DbContextFactory().CreateAppDbContext(nameof(SomethingElsePersistence__SaveSomethingElse__SavesSomethingElseToDatabase)))
            {
                var persistence = new SomethingElsePersistence(ctx);
                persistence.SaveSomethingElse(somethingElse);
            };

            using (var ctx = new DbContextFactory().CreateAppDbContext(nameof(SomethingElsePersistence__SaveSomethingElse__SavesSomethingElseToDatabase)))
            {
                var savedSomethingElse = ctx.SomethingElses.Include(s => s.Somethings).Single();
                Assert.Equal(somethingElse.Somethings[0].Name, savedSomethingElse.Somethings[0].Name);
                Assert.Equal(somethingElse.Name, savedSomethingElse.Name);
            };
        }
        public void SomethingElsePersistence__GetSomethingElseList__RetrievesListOfSomethingElseIncludingSomethingListFromDatabase()
        {
            using (var ctx = new DbContextFactory().CreateAppDbContext(nameof(SomethingElsePersistence__GetSomethingElseList__RetrievesListOfSomethingElseIncludingSomethingListFromDatabase)))
            {
                var persistence = new SomethingElsePersistence(ctx);
                persistence.SaveSomethingElse(somethingElse);
            };

            using (var ctx = new DbContextFactory().CreateAppDbContext(nameof(SomethingElsePersistence__GetSomethingElseList__RetrievesListOfSomethingElseIncludingSomethingListFromDatabase)))
            {
                var persistence         = new SomethingElsePersistence(ctx);
                var savedSomethingElses = persistence.GetSomethingElseIncludingSomethingList();
                foreach (var savedSomethingElse in savedSomethingElses)
                {
                    Assert.Equal(somethingElse.Somethings[0].Name, savedSomethingElse.Somethings[0].Name);
                }
            };
        }
        public void SomethingElsePersistence__UpdateSomethingElseByIdAddSomething__ThrowsInvalidOperationExceptionGivenNonexistentSomething()
        {
            int id = 5;

            using (var ctx = new DbContextFactory().CreateAppDbContext(nameof(SomethingElsePersistence__UpdateSomethingElseByIdAddSomething__ThrowsInvalidOperationExceptionGivenNonexistentSomething)))
            {
                var persistence = new SomethingElsePersistence(ctx);
                persistence.SaveSomethingElse(somethingElse);
            };

            Mock <ISomethingFactory> mockSomethingFactory = new Mock <ISomethingFactory>();

            mockSomethingFactory.Setup(x => x.Create(something.Name)).Returns((Domain.Something)null);

            using (var ctx = new DbContextFactory().CreateAppDbContext(nameof(SomethingElsePersistence__UpdateSomethingElseByIdAddSomething__ThrowsInvalidOperationExceptionGivenNonexistentSomething)))
            {
                var persistence             = new SomethingElsePersistence(ctx);
                Domain.Something something1 = mockSomethingFactory.Object.Create(something.Name);
                var exception = Assert.Throws <InvalidOperationException>(() => persistence.UpdateSomethingElseByIdAddSomething(id, something1));
            };
        }
        public void SomethingElsePersistence__UpdateSomethingElseByIdAddSomething__RetrievesSomethingElseByIdFromDatabase()
        {
            int id         = 1;
            var something1 = new Domain.Something()
            {
                Name = "Bob"
            };

            using (var ctx = new DbContextFactory().CreateAppDbContext(nameof(SomethingElsePersistence__UpdateSomethingElseByIdAddSomething__RetrievesSomethingElseByIdFromDatabase)))
            {
                var persistence = new SomethingElsePersistence(ctx);
                persistence.SaveSomethingElse(somethingElse);
            };

            using (var ctx = new DbContextFactory().CreateAppDbContext(nameof(SomethingElsePersistence__UpdateSomethingElseByIdAddSomething__RetrievesSomethingElseByIdFromDatabase)))
            {
                var persistence          = new SomethingElsePersistence(ctx);
                var updatedSomethingElse = persistence.UpdateSomethingElseByIdAddSomething(id, something1);
                Assert.Equal(somethingElse.Name, updatedSomethingElse.Name);
                Assert.Equal(somethingElse.Somethings.Count + 1, updatedSomethingElse.Somethings.Count);
            };
        }
        public void SomethingElsePersistence__UpdateSomethingElseByIdDeleteSomethingById__UpdatesSomethingElseByIdFromDatabaseWithSomethingDeleted()
        {
            int id           = 1;
            int something_id = 1;
            var something1   = new Domain.Something()
            {
                Name = "Bob"
            };

            using (var ctx = new DbContextFactory().CreateAppDbContext(nameof(SomethingElsePersistence__UpdateSomethingElseByIdDeleteSomethingById__UpdatesSomethingElseByIdFromDatabaseWithSomethingDeleted)))
            {
                var persistence = new SomethingElsePersistence(ctx);
                persistence.SaveSomethingElse(somethingElse);
            };

            using (var ctx = new DbContextFactory().CreateAppDbContext(nameof(SomethingElsePersistence__UpdateSomethingElseByIdDeleteSomethingById__UpdatesSomethingElseByIdFromDatabaseWithSomethingDeleted)))
            {
                var persistence          = new SomethingElsePersistence(ctx);
                var updatedSomethingElse = persistence.UpdateSomethingElseByIdDeleteSomethingById(id, something_id);
                Assert.Equal(somethingElse.Name, updatedSomethingElse.Name);
                Assert.Equal(somethingElse.Somethings.Count - 1, updatedSomethingElse.Somethings.Count);
            };
        }