Esempio n. 1
0
        public void DeleteByNullValue()
        {
            // Arrange
            NonGenericRepository subjectRepository = new NonGenericRepository(dbContext, typeof(Subject));

            // Act
            // Assert
            Assert.ThrowsException <ArgumentNullException>(() => subjectRepository.Delete(entityToDelete: null));
        }
Esempio n. 2
0
        public void DeleteByValue()
        {
            // Arrange
            NonGenericRepository subjectRepository = new NonGenericRepository(dbContext, typeof(Subject));
            Subject subjectToDelete = dbContext.Subjects.First(s => s.Name == "Subject 1");

            // Act
            // This subject has messages that must have "subject: null" when one will be deleted.
            subjectRepository.Delete(subjectToDelete);
            dbContext.SaveChanges();

            // Assert
            CollectionAssert.DoesNotContain(dbContext.Subjects.ToArray(), subjectToDelete);
            // Checks if all subject's messages are null.
            Assert.IsTrue(dbContext.Messages.AsEnumerable().Any(m => m.Subject == null || m.Subject.Id != subjectToDelete.Id));
        }
Esempio n. 3
0
        public void DeleteByChangedValue()
        {
            // Arrange
            NonGenericRepository subjectRepository = new NonGenericRepository(dbContext, typeof(Subject));
            Subject changedSubjectToDelete         = dbContext.Subjects.First(s => s.Name == "Subject 1");

            changedSubjectToDelete.Name += "Changed it";

            // Act
            subjectRepository.Delete(entityToDelete: changedSubjectToDelete);
            dbContext.SaveChanges();

            // Assert
            CollectionAssert.DoesNotContain(dbContext.Subjects.ToArray(), changedSubjectToDelete);
            // Checks if all subject's messages are null.
            Assert.IsTrue(dbContext.Messages.AsEnumerable().Any(m => m.Subject == null || m.Subject.Id != changedSubjectToDelete.Id));
        }