private static void InitializeAutoMapper() { Mapper.Initialize( cfg => cfg.CreateMap <Postdb, Post>() .AfterMap((s, d) => { //Author IStudentDbRepository <Studentdb> rStudents = new StudentDbRepository(); Studentdb studentdb = rStudents.Get(s.StudentId); d.Author = $"{studentdb.FirstName} {studentdb.LastName}"; //Commentsdb ICommentDbRepository <Commentdb> rCommentsdb = new CommentDbRepository(); IEnumerable <Commentdb> commentsdb = rCommentsdb.GetAll(s.Id); // List <Comment> comments = new List <Comment>(); //Commentdb+Author foreach (var commentdb in commentsdb) { Comment comment = new Comment() { Id = commentdb.Id, Content = commentdb.Content, Created = commentdb.Created }; Studentdb student = rStudents.Get(commentdb.StudentId); comment.Author = $"{student.FirstName} {student.LastName}"; comments.Add(comment); } // d.Comments = comments; //Tags ITagDbRepository <Tagdb> rTags = new TagDbRepository(); d.Tags = rTags.GetAll(s.Id); })); }
public void AddStudentTest() { // Arrange var mockSet = new Mock <DbSet <Student> >(); var mockContext = new Mock <ExamDbContext>(); mockContext.Setup(m => m.Students).Returns(mockSet.Object); // Result var service = new StudentDbRepository(mockContext.Object); service.AddStudent(_studentsdata.ElementAt(0)); // Assert mockSet.Verify(m => m.Add(It.IsAny <Student>()), Times.Once()); mockContext.Verify(m => m.SaveChanges(), Times.Once()); }
public object GetService(Type serviceType) { if (serviceType == typeof(SchoolsController)) { IRepository <School> repository = new SchoolDbRepository(placesContext); return(new SchoolsController(repository)); } else if (serviceType == typeof(StudentsController)) { IStudentRepository <Student> repository = new StudentDbRepository(placesContext); return(new StudentsController(repository)); } else { return(null); } }
public void DeleteByIdTest() { // Arrange var data = _studentsdata.ToList <Student>(); _mockSet.Setup(m => m.Remove(It.IsAny <Student>())).Callback <Student>((entity) => data.Remove(entity)); _mockContext.Setup(x => x.Students).Returns(_mockSet.Object); IStudentDbRepository dataAccess = new StudentDbRepository(_mockContext.Object); //Act int idToDelete = 666; dataAccess.DeleteById(idToDelete); //Assert Assert.AreEqual(data.Count, 3); }
public void GetByIdTest() { // Arrange int id = 666; Student expectedEntity = _studentsdata.ElementAt(0); DbSet <Student> dbSet = Mock.Of <DbSet <Student> >(set => set.Find((id)) == expectedEntity); ExamDbContext context = new ExamDbContext(); context.Students = dbSet; IStudentDbRepository repository = new StudentDbRepository(context); // Act var result = repository.GetById(id); // Assert Assert.AreSame(expectedEntity, result); }
public StudentService(StudentDbRepository _repository) { repository = _repository; }
public MarksService(StudentDbRepository _repository) { repository = _repository; }