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

            // Act
            // Assert
            Assert.ThrowsException <ArgumentNullException>(() => subjectRepository.Delete(entityToDelete: null));
        }
Exemplo n.º 2
0
        public void GetByWrongId_Null()
        {
            // Arrange
            NonGenericRepository subjectRepository = new NonGenericRepository(dbContext, typeof(Subject));
            Guid    wrongId = default(Guid);
            Subject expectedSubjectFromDb = null;

            // Act
            Subject actualSubjectFromDb = subjectRepository.Get(wrongId) as Subject;

            // Assert
            Assert.AreEqual(expectedSubjectFromDb, actualSubjectFromDb);
        }
Exemplo n.º 3
0
        public void GetById()
        {
            // Arrange
            NonGenericRepository subjectRepository = new NonGenericRepository(dbContext, typeof(Subject));
            Guid    idToSearch      = dbContext.Subjects.First().Id;
            Subject expectedSubject = dbContext.Subjects.Find(idToSearch);

            // Act
            Subject subjectFromDB = subjectRepository.Get(idToSearch) as Subject;

            // Assert
            Assert.AreEqual(expectedSubject, subjectFromDB);
        }
Exemplo n.º 4
0
        public void AddRegularSubject()
        {
            // Arrange
            NonGenericRepository subjectRepository = new NonGenericRepository(dbContext, typeof(Subject));
            Subject subject = new Subject {
                Name = Convert.ToString(TestContext.DataRow["Name"])
            };

            // Act
            subjectRepository.Insert(subject);
            dbContext.SaveChanges();

            // Assert
            CollectionAssert.Contains(dbContext.Subjects.ToList(), subject);
        }
Exemplo n.º 5
0
        public void Update()
        {
            // Arrange
            NonGenericRepository subjectRepository = new NonGenericRepository(dbContext, typeof(Subject));
            Subject subjectToUpdate = dbContext.Subjects.First(s => s.Name == "Subject 1");
            string  newSubjectName  = "New Subject Name";

            // Act
            subjectToUpdate.Name = newSubjectName;
            subjectRepository.Update(subjectToUpdate);
            dbContext.SaveChanges();

            // Assert
            Assert.AreEqual(dbContext.Subjects.Find(subjectToUpdate.Id).Name, newSubjectName);
        }
Exemplo n.º 6
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));
        }
Exemplo n.º 7
0
        public void AddSubjectWithWrongNameLength()
        {
            // Arrange
            NonGenericRepository subjectRepository = new NonGenericRepository(dbContext, typeof(Subject));
            Subject subject = new Subject {
                Name = Convert.ToString(TestContext.DataRow["Name"])
            };

            // Act
            subjectRepository.Insert(subject);

            // Assert
            Assert.ThrowsException <System.Data.Entity.Validation.DbEntityValidationException>(() => dbContext.SaveChanges());
            // undo adding
            ((IObjectContextAdapter)dbContext).ObjectContext.Detach(subject);
        }
Exemplo n.º 8
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));
        }