Esempio n. 1
0
        public void ThrowExceptionIfInvalidAndTryBuild()
        {
            var options = new MariCommandsOptions();
            var factory = new ParameterFactory(options);

            Assert.ThrowsAny <ArgumentException>(() =>
            {
                _ = factory.BuildParameter(null, null);
            });
        }
Esempio n. 2
0
        public void CantGetTypeParserType()
        {
            var options = new MariCommandsOptions();
            var factory = new ParameterFactory(options);

            var commandBuilder = new Mock <ICommandBuilder>().Object;

            var parameter = typeof(TestParameterClass)
                            .GetMethod(nameof(TestParameterClass.TestMethod))
                            .GetParameters()
                            .FirstOrDefault();

            var builder = factory.BuildParameter(commandBuilder, parameter);

            Assert.NotNull(builder);
            Assert.Null(builder.TypeParserType);
        }
Esempio n. 3
0
        public void CantGetRemarksIfNotExists()
        {
            var options = new MariCommandsOptions();
            var factory = new ParameterFactory(options);

            var commandBuilder = new Mock <ICommandBuilder>().Object;

            var parameter = typeof(TestParameterClass)
                            .GetMethod(nameof(TestParameterClass.TestMethod))
                            .GetParameters()
                            .FirstOrDefault();

            var builder = factory.BuildParameter(commandBuilder, parameter);

            Assert.NotNull(builder);
            Assert.True(string.IsNullOrWhiteSpace(builder.Remarks));
        }
Esempio n. 4
0
        public void CanGetParameterName()
        {
            var options = new MariCommandsOptions();
            var factory = new ParameterFactory(options);

            var commandBuilder = new Mock <ICommandBuilder>().Object;

            var parameter = typeof(TestParameterClass)
                            .GetMethod(nameof(TestParameterClass.TestMethod))
                            .GetParameters()
                            .FirstOrDefault();

            var builder = factory.BuildParameter(commandBuilder, parameter);

            Assert.NotNull(builder);
            Assert.False(string.IsNullOrWhiteSpace(builder.Name));
            Assert.Equal(TestParameterClass.ParameterName, builder.Name);
        }
Esempio n. 5
0
        public void CanGetOptionalAndDefaultValue()
        {
            var options = new MariCommandsOptions();
            var factory = new ParameterFactory(options);

            var commandBuilder = new Mock <ICommandBuilder>().Object;

            var parameter = typeof(TestParameterClass)
                            .GetMethod(nameof(TestParameterClass.TestMethodOptional))
                            .GetParameters()
                            .FirstOrDefault();

            var builder = factory.BuildParameter(commandBuilder, parameter);

            Assert.NotNull(builder);
            Assert.True(builder.IsOptional);
            Assert.NotNull(builder.DefaultValue);
            Assert.Equal(TestParameterClass.ParameterDefaultValue, builder.DefaultValue);
        }
Esempio n. 6
0
        public void CanBuild()
        {
            var options = new MariCommandsOptions();
            var factory = new ParameterFactory(options);

            var commandBuilder = new Mock <ICommandBuilder>().Object;

            var parameterInfo = typeof(TestParameterClass)
                                .GetMethod(nameof(TestParameterClass.TestMethodAttribute))
                                .GetParameters()
                                .FirstOrDefault();

            var builder = factory.BuildParameter(commandBuilder, parameterInfo);

            var command = new Mock <ICommand>().Object;

            var parameter = builder.Build(command);

            Assert.NotNull(parameter);
        }
Esempio n. 7
0
        public void CanGetAllAttributes()
        {
            var options = new MariCommandsOptions();
            var factory = new ParameterFactory(options);

            var commandBuilder = new Mock <ICommandBuilder>().Object;

            var parameter = typeof(TestParameterClass)
                            .GetMethod(nameof(TestParameterClass.TestMethodAttribute))
                            .GetParameters()
                            .FirstOrDefault();

            var attributes = parameter.GetCustomAttributes();

            var builder = factory.BuildParameter(commandBuilder, parameter);

            Assert.NotNull(builder);
            Assert.NotEmpty(builder.Attributes);
            Assert.Equal(attributes, builder.Attributes);
        }
Esempio n. 8
0
        public void CanGetAllPreconditions()
        {
            var options = new MariCommandsOptions();
            var factory = new ParameterFactory(options);

            var commandBuilder = new Mock <ICommandBuilder>().Object;

            var parameter = typeof(TestParameterClass)
                            .GetMethod(nameof(TestParameterClass.TestMethodAttribute))
                            .GetParameters()
                            .FirstOrDefault();

            var preconditions = parameter
                                .GetCustomAttributes()
                                .Where(a => typeof(ParamPreconditionAttribute).IsAssignableFrom(a.GetType()))
                                .Select(a => a as ParamPreconditionAttribute)
                                .ToList();

            var builder = factory.BuildParameter(commandBuilder, parameter);

            Assert.NotNull(builder);
            Assert.NotEmpty(builder.Preconditions);
            Assert.Equal(preconditions, builder.Preconditions);
        }
Esempio n. 9
0
 public static SqlParameter BuildParameter(string parameterName, object value, DbType type, int size = 0)
 {
     return(ParameterFactory.BuildParameter(parameterName, value, type, size));
 }