コード例 #1
0
        public QuizManagementServiceTest()
        {
            _entityValidator = A.Fake<EntityValidator>();
            _quizRepository = A.Fake<IQuizRepository>();
            _quizDtoMapper = A.Fake<IQuizDtoMapper>();
            _questionDtoMapper = A.Fake<IQuestionDtoMapper>();
            _assignedQuizDtoMapper = A.Fake<IAssignedQuizDtoMapper>();

            _quizManagementService = new QuizManagementService(_quizRepository, _quizDtoMapper, _entityValidator, _questionDtoMapper, _assignedQuizDtoMapper);

            _validQuiz = new Entities.Quiz
                         {
                             Name = "Test",
                             Description = "Description",
                             Questions =
                                 new List<Question>
                                 {
                                     A.Fake<Question>(),
                                     A.Fake<Question>()
                                 }
                         };

            _validAssignment = new AssignedQuizModel
                         {
                            Quiz = new Entities.Quiz(),
                            Group = new Group(),
                            StartDate = DateTime.Now,
                            EndDate = DateTime.Now.AddDays(1)
                         };
        }
コード例 #2
0
        public QuizManagementService(IQuizRepository quizRepository, IQuizDtoMapper quizDtoMapper, EntityValidator entityValidator, 
            IQuestionDtoMapper questionDtoMapper, IAssignedQuizDtoMapper assignedQuizDtoMapper)
        {
            if (quizRepository == null)
            {
                throw new ArgumentNullException("quizRepository");
            }

            if (quizDtoMapper == null)
            {
                throw new ArgumentNullException("quizDtoMapper");
            }

            if (entityValidator == null)
            {
                throw new ArgumentNullException("entityValidator");
            }

            if (questionDtoMapper == null)
            {
                throw new ArgumentNullException("questionDtoMapper");
            }

            if (assignedQuizDtoMapper == null)
            {
                throw new ArgumentNullException("assignedQuizDtoMapper");
            }

            _quizRepository = quizRepository;
            _quizDtoMapper = quizDtoMapper;
            _entityValidator = entityValidator;
            _questionDtoMapper = questionDtoMapper;
            _assignedQuizDtoMapper = assignedQuizDtoMapper;
        }
コード例 #3
0
ファイル: GroupServiceTest.cs プロジェクト: WadeOne/EasyTeach
 public GroupServiceTest()
 {
     _entityValidator = A.Fake<EntityValidator>();
     _groupRepository = A.Fake<IGroupRepository>();
     _groupDtoMapper = A.Fake<IGroupDtoMapper>();
     _groupService = new GroupService(_entityValidator, _groupRepository, _groupDtoMapper);
 }
コード例 #4
0
ファイル: UserService.cs プロジェクト: WadeOne/EasyTeach
        public UserService(UserManager<IUserDto, int> userManager,
            IUserDtoMapper userDtoMapper,
            IEmailService emailService,
            EntityValidator entityValidator,
            IUserRepository userRepository,
            Func<object, ValidationContext> validationContextFactory = null)
        {
            if (userManager == null)
            {
                throw new ArgumentNullException("userManager");
            }

            if (userDtoMapper == null)
            {
                throw new ArgumentNullException("userDtoMapper");
            }

            if (emailService == null)
            {
                throw new ArgumentNullException("emailService");
            }

            _userRepository = userRepository;
            _userDtoMapper = userDtoMapper;
            _emailService = emailService;
            _entityValidator = entityValidator;
            _validationContextFactory = validationContextFactory ?? (o => new ValidationContext(o, null, null));
            _userManager = userManager;
            _userManager.UserValidator = new UserValidator<IUserDto, int>(_userManager){AllowOnlyAlphanumericUserNames = false};
        }
        protected override void OnModelUpdated(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            var validator = new EntityValidator();

            var result = validator.Validate(bindingContext.Model);

            result.AddToModelState(bindingContext.ModelState);
        }
コード例 #6
0
        public LessonServiceTest()
        {
            _entityValidator = A.Fake<EntityValidator>();
            _lessonRepository = A.Fake<ILessonRepository>();
            _lessonDtoMapper = A.Fake<ILessonDtoMapper>();

            _lessonService = new LessonService(
                _entityValidator,
                _lessonRepository,
                _lessonDtoMapper);
        }
コード例 #7
0
        public EntityValidatorTest()
        {
            _entityValidator = new EntityValidator();
            _validEntity = new TestEntityWithDataAnnotations
            {
                RequiredStringProperty = "property",
                PositiveIntegerProperty = 10
            };

            _invalidEntity = new TestEntityWithDataAnnotations
            {
                PositiveIntegerProperty = -1
            };
        }
コード例 #8
0
        public AuthLessonServiceWrapper(
            ILessonService lessonService,
            ClaimsPrincipal principal,
            EntityValidator entityValidator,
            IUserStore<IUserDto, int> userStore,
            ClaimsAuthorizationManager authorizationManager)
        {
            if (lessonService == null)
            {
                throw new ArgumentNullException("lessonService");
            }

            if (principal == null)
            {
                throw new ArgumentNullException("principal");
            }

            if (principal.Identity == null)
            {
                throw new ArgumentException("Principal doesn't contian identity");
            }

            if (!principal.Identity.IsAuthenticated)
            {
                throw new ArgumentException("Identity is not authenticated");
            }

            if (entityValidator == null)
            {
                throw new ArgumentNullException("entityValidator");
            }

            if (userStore == null)
            {
                throw new ArgumentNullException("userStore");
            }

            if (authorizationManager == null)
            {
                throw new ArgumentNullException("authorizationManager");
            }

            _lessonService = lessonService;
            _principal = principal;
            _entityValidator = entityValidator;
            _userStore = userStore;
            _authorizationManager = authorizationManager;
        }
コード例 #9
0
ファイル: ScoreService.cs プロジェクト: WadeOne/EasyTeach
        public ScoreService(
            EntityValidator entityValidator, 
            IScoreRepository scoreRepository, 
            IScoreDtoMapper scoreDtoMapper, 
            IVisitRepository visitRepository, 
            ILessonRepository lessonRepository,
            IVisitDtoMapper visitDtoMapper
            )
        {
            if (entityValidator == null)
            {
                throw new ArgumentNullException("entityValidator");
            }

            if (scoreRepository == null)
            {
                throw new ArgumentNullException("scoreRepository");
            }

            if (scoreDtoMapper == null)
            {
                throw new ArgumentNullException("scoreDtoMapper");
            }

            if (visitRepository == null)
            {
                throw new ArgumentNullException("visitRepository");
            }

            if (lessonRepository == null)
            {
                throw new ArgumentNullException("lessonRepository");
            }

            if (visitDtoMapper == null)
            {
                throw new ArgumentNullException("visitDtoMapper");
            }

            _entityValidator = entityValidator;
            _scoreRepository = scoreRepository;
            _scoreDtoMapper = scoreDtoMapper;
            _visitRepository = visitRepository;
            _lessonRepository = lessonRepository;
            _visitDtoMapper = visitDtoMapper;
        }
コード例 #10
0
ファイル: EntityValidator_Specs.cs プロジェクト: KevM/Magnum
        public void The_attributes_on_the_properties_should_be_used_for_validation()
        {
            IValidator<Member> validator = new EntityValidator<Member>();

            Member member = new Member();

            IEnumerable<IViolation> violations;

            member.Validate(validator, out violations);

            Assert.That(validator.IsValid(member, out violations), Is.False);

            List<IViolation> violationList = new List<IViolation>(violations);

            Assert.That(violationList.Count, Is.EqualTo(2));

            Assert.That(violationList[0], Is.TypeOf(typeof(NullValueViolation)));
            Assert.That(violationList[1], Is.TypeOf(typeof(NullValueViolation)));
        }
コード例 #11
0
        public AuthLessonServiceWrapperTest()
        {
            _lessonService = A.Fake<ILessonService>();
            _principal = A.Fake<ClaimsPrincipal>();
            _identity = A.Fake<IIdentity>();
            A.CallTo(() => _principal.Identity).Returns(_identity);
            A.CallTo(() => _identity.IsAuthenticated).Returns(true);

            _entityValidator = A.Fake<EntityValidator>();
            _userStore = A.Fake<IUserStore<IUserDto, int>>();
            _authorizationManager = new ClaimsAuthorizationManager();

            _authLessonServiceWrapper = new AuthLessonServiceWrapper(
                _lessonService,
                _principal,
                _entityValidator,
                _userStore,
                _authorizationManager);
        }
コード例 #12
0
ファイル: GroupService.cs プロジェクト: WadeOne/EasyTeach
        public GroupService(EntityValidator entityValidator, IGroupRepository groupReository, IGroupDtoMapper groupDtoMapper)
        {
            if (groupReository == null)
            {
                throw new ArgumentNullException("groupReository");
            }
            _groupRepository = groupReository;

            if (entityValidator == null)
            {
                throw new ArgumentNullException("entityValidator");
            }
            _entityValidator = entityValidator;

            if (groupDtoMapper == null)
            {
                throw new ArgumentNullException("groupDtoMapper");
            }
            _groupnDtoMapper = groupDtoMapper;
        }
コード例 #13
0
ファイル: LessonService.cs プロジェクト: WadeOne/EasyTeach
        public LessonService(EntityValidator entityValidator, ILessonRepository lessonRepository, ILessonDtoMapper lessonDtoMapper)
        {
            if (entityValidator == null)
            {
                throw new ArgumentNullException("entityValidator");
            }

            if (lessonRepository == null)
            {
                throw new ArgumentNullException("lessonRepository");
            }

            if (lessonDtoMapper == null)
            {
                throw new ArgumentNullException("lessonDtoMapper");
            }

            _entityValidator = entityValidator;
            _lessonRepository = lessonRepository;
            _lessonDtoMapper = lessonDtoMapper;
        }
コード例 #14
0
        public AuthScoreServiceWrapper(
            IScoreService scoreService,
            ClaimsPrincipal principal,
            EntityValidator entityValidator,
            IUserStore<IUserDto, int> userStore,
            ClaimsAuthorizationManager authorizationManager)
        {
            if (scoreService == null)
            {
                throw new ArgumentNullException("scoreService");
            }

            if (principal == null)
            {
                throw new ArgumentNullException("principal");
            }

            if (entityValidator == null)
            {
                throw new ArgumentNullException("entityValidator");
            }

            if (userStore == null)
            {
                throw new ArgumentNullException("userStore");
            }

            if (authorizationManager == null)
            {
                throw new ArgumentNullException("authorizationManager");
            }

            _scoreService = scoreService;
            _principal = principal;
            _entityValidator = entityValidator;
            _userStore = userStore;
            _authorizationManager = authorizationManager;
        }
コード例 #15
0
ファイル: VisitService.cs プロジェクト: WadeOne/EasyTeach
        public VisitService(
            IVisitRepository visitRepository,
            ILessonRepository lessonRepository,
            IUserRepository userRepository,
            EntityValidator entityValidator,
            IVisitDtoMapper visitDtoMapper)
        {
            if (visitRepository == null)
            {
                throw new ArgumentNullException("visitRepository");
            }

            if (lessonRepository == null)
            {
                throw new ArgumentNullException("lessonRepository");
            }

            if (userRepository == null)
            {
                throw new ArgumentNullException("userRepository");
            }

            if (entityValidator == null)
            {
                throw new ArgumentNullException("entityValidator");
            }

            if (visitDtoMapper == null)
            {
                throw new ArgumentNullException("visitDtoMapper");
            }

            _visitRepository = visitRepository;
            _lessonRepository = lessonRepository;
            _userRepository = userRepository;
            _entityValidator = entityValidator;
            _visitDtoMapper = visitDtoMapper;
        }
コード例 #16
0
        public AuthVisitServiceWrapper(
            IVisitService visitService, 
            ClaimsPrincipal principal,
            EntityValidator entityValidator,
            IUserStore<IUserDto, int> userStore,
            ClaimsAuthorizationManager authorizationManager)
        {
            if (visitService == null)
            {
                throw new ArgumentNullException("visitService");
            }
            _visitService = visitService;

            if (principal == null)
            {
                throw new ArgumentNullException("principal");
            }
            _principal = principal;

            if (entityValidator == null)
            {
                throw new ArgumentNullException("entityValidator");
            }
            _entityValidator = entityValidator;

            if (userStore == null)
            {
                throw new ArgumentNullException("userStore");
            }
            _userStore = userStore;

            if (authorizationManager == null)
            {
                throw new ArgumentNullException("authorizationManager");
            }
            _authorizationManager = authorizationManager;
        }
コード例 #17
0
ファイル: UserServiceTest.cs プロジェクト: WadeOne/EasyTeach
        public UserServiceTest()
        {
            _userManager = A.Fake<UserManager<IUserDto, int>>();
            _userDtoMapper = A.Fake<IUserDtoMapper>();
            _emailService = A.Fake<IEmailService>();
            _entityValidator = A.Fake<EntityValidator>();
            _userRepository = A.Fake<IUserRepository>();

            _userService = new UserService(_userManager,
                _userDtoMapper,
                _emailService,
                _entityValidator,
                _userRepository,
                o => new ValidationContext(o, null, null));
            _validUser = new User
            {
                FirstName = "test",
                LastName = "test",
                UserType = UserType.Student,
                Group = new Group { GroupNumber = 2, Year = 2009 },
                Email = "*****@*****.**"
            };
            _invalidEmptyUser = new User();
        }
コード例 #18
0
 public void MapEntityValidator(EntityValidator <TEntity> entityValidator)
 {
     ValidationManager.SetEntityValidator <TEntity>(entityValidator);
 }
 public void SetUp() {
     validator = new EntityValidator(Instance);
 }
コード例 #20
0
        private List<ValidationResult> Validate(Item item)
        {
            // Validate item
            var itemValidator = new EntityValidator<Item>();
            _validationErrors.AddRange(itemValidator.GetValidationErrors(item));

            // Validate header
            if (item.Header != null)
            {
                var headerValidator = new EntityValidator<Header>();
                _validationErrors.AddRange(headerValidator.GetValidationErrors(item.Header));
            }

            // Validate entry
            if (item.Entry != null)
            {
                var entryValidator = new EntityValidator<Entry>();
                _validationErrors.AddRange(entryValidator.GetValidationErrors(item.Entry));
            }

            return _validationErrors;
        }