public void Create() { User = new UserDetail { UserRole = UserRole.Admin, Password = "******", Name = "awesome", DateOfCreation = DateTime.UtcNow }; var initialCount = UserRepository.Query().Count(); UserRepository.Add(User); EfUoW.Commit(); var result = UserRepository.Query().Count(); Assert.AreEqual(initialCount + 1, result); }
public void Initialize() { Context = new ParikshaContext(); EfUoW = new EFUnitOfWork(Context); UserRepository = new EFRepository<UserDetail>(EfUoW, Context); QuestionRepository = new EFRepository<Question>(EfUoW, Context); StandardRepository = new EFRepository<Standard>(EfUoW, Context); SubjectRepository = new EFRepository<Subject>(EfUoW, Context); User = new UserDetail { UserRole = UserRole.Admin, Password = "******", Name = "ashutosh", DateOfCreation = DateTime.UtcNow }; Standard = new Standard { StandardName = "First" }; Subject = new Subject { SubjectName = "Mathematics", SubjectCategory = "Algebra", Standard = Standard }; UserRepository.Add(User); StandardRepository.Add(Standard); SubjectRepository.Add(Subject); EfUoW.Commit(); }
public void Initialize() { MockRepository = new Mock<IRepository<UserDetail>>(); _user = new UserDetail { Name = "Ashutosh", Password = "******", UserRole = UserRole.Admin, DateOfCreation = DateTime.UtcNow }; _users = new List<UserDetail> { _user }; _users = _users.Concat(new List<UserDetail> { new UserDetail { Name = "Monny", Password = "******", UserRole = UserRole.DeparmentHead, DateOfCreation = DateTime.UtcNow }, new UserDetail { Name = "Jhonny", Password = "******", UserRole = UserRole.Principal, DateOfCreation = DateTime.UtcNow }, new UserDetail { Name = "Pony", Password = "******", UserRole = UserRole.Student, DateOfCreation = DateTime.UtcNow }, new UserDetail { Name = "Tony", Password = "******", UserRole = UserRole.Teacher, DateOfCreation = DateTime.UtcNow }, new UserDetail { Name = "Sunny", Password = "******", UserRole = UserRole.Admin, DateOfCreation = DateTime.UtcNow } }); MockRepository.Setup(_ => _.Query()).Returns(_users.AsQueryable()); MockRepository.Setup(_ => _.Add(_user)).Returns(_user); MockRepository.Setup(_ => _.Remove(_user)).Returns(_user); _repository = MockRepository.Object; _service = new UserService(_repository, _unitOfWork); }
public void Initialize() { MockRepository = new Mock<IRepository<Test>>(); var firstQuestion = new Question { QuestionId = 1, Difficulty = Difficulty.Hard, Rating = 5 }; var secondQuestion = new Question { QuestionId = 2, Difficulty = Difficulty.Hard, Rating = 3 }; var brief = new Brief { Difficulty = Difficulty.Hard, Rating = 5, QuestionText = "Who let the dog's out ?", Answer = "It wasn't me" }; var choice = new Choice { Difficulty = Difficulty.Hard, Rating = 5, QuestionText = "Who let the dog's out ?", Choices = "Me,You,All of us all are the culprits", Answers = "Me", IsMultiplechoice = true }; _questions = new List<Question> { firstQuestion, secondQuestion, brief, choice }; _user = new UserDetail { Name = "Ashutosh", Password = "******", UserRole = UserRole.Admin, DateOfCreation = DateTime.UtcNow }; _subject = new Subject { SubjectName = "Mathematics", SubjectCategory = "Advanced" }; _tests = new List<Test> { new Test { TestId = 1, DateOfCreation = DateTime.UtcNow, Subject = _subject, Creator = _user, Questions = _questions }, new Test { TestId = 2, DateOfCreation = DateTime.UtcNow, Subject = _subject, Creator = _user, Questions = _questions } }; MockRepository.Setup(_ => _.Query()).Returns(_tests.AsQueryable()); _test = new Test { TestId = 3, DateOfCreation = DateTime.UtcNow, Subject = _subject, Creator = _user, Questions = _questions }; MockRepository.Setup(_ => _.Add(_test)).Returns(_test); _repository = MockRepository.Object; _service = new TestService(_repository, _unitOfWork); MockRepository.Setup(_ => _.Query()).Returns(_tests.AsQueryable()); }
public void CheckUserNameLengthForValidCases(string userName) { var user = new UserDetail { Name = userName, Password = "******", DateOfCreation = DateTime.UtcNow, UserRole = UserRole.Principal }; var result = UserRepository.Add(user); Assert.DoesNotThrow(() => EfUnitOfWork.Commit()); Assert.AreEqual(userName, result.Name); }
public void CheckUserNameLengthForException(string userName) { var user = new UserDetail { Name = userName, Password = "******", DateOfCreation = DateTime.UtcNow, UserRole = UserRole.Principal }; UserRepository.Add(user); Assert.Throws<DbEntityValidationException>(() => EfUnitOfWork.Commit()); }
public IQueryable<Test> GetTestsCreatedByUser(UserDetail user) { return _testrepository.Query().Where(_ => _.Creator == user); }
/// <summary> /// Removes the User /// </summary> /// <param name="user">User to be Removed</param> /// <returns>The removed User</returns> public UserDetail RemoveUser(UserDetail user) { return _userRepository.Remove(user); }
/// <summary> /// Creates a new User /// </summary> /// <param name="user">New User to be Created</param> /// <returns>The created User</returns> public UserDetail CreateNewUser(UserDetail user) { return _userRepository.Add(user); }