示例#1
0
    public void BasicConst()
    {
        var f1 = GetBasicExpr1();
        var f2 = GetBasicExpr2();

        Assert.IsTrue(LambdaCompare.Eq(f1, f2));
    }
示例#2
0
    public void PropAndMethodCall()
    {
        var f1 = GetPropAndMethodExpr1();
        var f2 = GetPropAndMethodExpr2();

        Assert.IsTrue(LambdaCompare.Eq(f1, f2));
    }
示例#3
0
    public void MemberInitWithConditional()
    {
        var f1 = GetMemberInitExpr1();
        var f2 = GetMemberInitExpr2();

        Assert.IsTrue(LambdaCompare.Eq(f1, f2));
    }
        public void Register_TryAddNewUserWithAlreadyUseUsername_ReturnResponseDuplicateUsername()
        {
            //Arrange
            string alreadyUsername = It.IsAny <string>();
            Expression <Func <User, bool> > expr = u => u.Username == alreadyUsername;

            userRepositoryMock.Setup(urm => urm.Any(It.Is <Expression <Func <User, bool> > >(x => LambdaCompare.Eq(x, expr))))
            .Returns(true);
            //Act
            RegisterServiceResponse result = registerService.Register(new User()
            {
                Username = alreadyUsername
            });

            //Assert
            result.Should().Be(RegisterServiceResponse.DuplicateUsername);
        }
示例#5
0
    public void setup()
    {
        List <ParameterGetal> dateParameterGetallen = new List <ParameterGetal>
        {
            new ParameterGetal {
                ID = 29, parameter = "Datum", parameterwaarde = string.Format("{0:dd/MM/yyyy}", DateTime.Today.AddDays(-1))
            }
        };
        List <ParameterGetal> tellerParameterGetallen = new List <ParameterGetal>
        {
            new ParameterGetal {
                ID = 3, parameter = "orderteller", parameterwaarde = "4"
            }
        };
        IQueryFluent <ParameterGetal>     datefluent               = MockRepository.GenerateStub <IQueryFluent <ParameterGetal> >();
        IQueryFluent <ParameterGetal>     tellerfluent             = MockRepository.GenerateStub <IQueryFluent <ParameterGetal> >();
        IRepositoryAsync <ParameterGetal> parametergetalrepository = MockRepository.GenerateStub <IRepositoryAsync <ParameterGetal> >();

        _unitOfWork = MockRepository.GenerateStub <IUnitOfWorkAsync>();
        _unitOfWork.Stub(u => u.RepositoryAsync <ParameterGetal>())
        .Return(parametergetalrepository);
        parametergetalrepository.Stub(r => r.Query(Arg <Expression <Func <ParameterGetal, bool> > > .Matches(a => LambdaCompare.Eq(a, o => o.parameter == "Datum"))))
        .Return(datefluent);
        parametergetalrepository.Stub(r => r.Query(Arg <Expression <Func <ParameterGetal, bool> > > .Matches(a => LambdaCompare.Eq(a, o => o.parameter == "orderteller"))))
        .Return(tellerfluent);
        datefluent.Stub(q => q.Select())
        .Return(dateParameterGetallen);
        tellerfluent.Stub(q => q.Select())
        .Return(tellerParameterGetallen);
    }
        private static Expression CreateLambdaExpression(ParameterExpression parameter, string property, object value, LambdaCompare compare)
        {
            //var propertyExpression = Expression.Convert(Expression.Property(parameter, property), value.GetType());
            var propertyExpression = Expression.Property(parameter, property);
            var valueExpression    = Expression.Constant(value);

            switch (compare)
            {
            case LambdaCompare.LessThan:
                return(Expression.LessThan(propertyExpression, valueExpression));

            case LambdaCompare.LessThanOrEqual:
                return(Expression.LessThanOrEqual(propertyExpression, valueExpression));

            case LambdaCompare.GreaterThan:
                return(Expression.GreaterThan(propertyExpression, valueExpression));

            case LambdaCompare.GreaterThanOrEqual:
                return(Expression.GreaterThanOrEqual(propertyExpression, valueExpression));

            case LambdaCompare.Equal:
                return(Expression.Equal(propertyExpression, valueExpression));

            case LambdaCompare.NotEqual:
                return(Expression.NotEqual(propertyExpression, valueExpression));

            case LambdaCompare.Contains:
                return(Expression.Call(propertyExpression, MethodCreator.CreateStringContainMethod(), valueExpression));

            case LambdaCompare.Unknown:
            default:
                throw new ArgumentOutOfRangeException(nameof(compare), compare, null);
            }
        }
示例#7
0
        public void Login_WhenUserIsInDatabaseAndPasswordDoesntMatch_ReturnsIncorrectPassword
            (string password)
        {
            const string ExplicitPassword = "******";
            string       usernameInDb     = It.IsAny <string>();
            Expression <Func <User, bool> > expression = u => u.Username == usernameInDb;

            byte[]            salt      = cryptographyService.GenerateRandomSalt();
            IQueryable <User> queryable = (new User[] { new User {
                                                            Username = usernameInDb, Password = Convert.ToBase64String(cryptographyService.GenerateSHA512(ExplicitPassword, salt)), Salt = salt
                                                        } }).AsQueryable();

            repository.Setup(repo => repo.Any(It.IsAny <Expression <Func <User, bool> > >()))
            .Returns(true);
            repository.Setup(repo => repo.FindBy(It.Is <Expression <Func <User, bool> > >(x => LambdaCompare.Eq(x, expression))))
            .Returns(() => queryable);

            LoginServiceResponse response = loginService.Login(new User()
            {
                Username = usernameInDb, Password = password
            });

            response.Should().Be(LoginServiceResponse.IncorrectPassword);
        }
示例#8
0
        public void Login_WhenUserNameIsNotInDatabase_ReturnUserDoesntExist()
        {
            string usernameNotInDb = It.IsNotIn(new[] { "meAmnestic" });
            Expression <Func <User, bool> > expression = u => u.Username == usernameNotInDb;

            repository.Setup(repo => repo.Any(It.Is <Expression <Func <User, bool> > >(x => LambdaCompare.Eq(x, expression))))
            .Returns(false);
            repository.Setup(repo => repo.FindBy(It.Is <Expression <Func <User, bool> > >(x => LambdaCompare.Eq(x, expression))))
            .Returns <IQueryable <User> >(null);

            LoginServiceResponse response = loginService.Login(new User()
            {
                Username = usernameNotInDb
            });

            response.Should().Be(LoginServiceResponse.UserDoesntExist);
        }