Ejemplo n.º 1
0
        public void UseConverter()
        {
            var idColumn = new ColumnInfo()
            {
                Name         = nameof(ConverterDto.Id),
                PropertyInfo = GetPropertyInfo <ConverterDto>(nameof(ConverterDto.Id))
            };
            var nameColumn = new ColumnInfo()
            {
                Name         = nameof(ConverterDto.Name),
                PropertyInfo = GetPropertyInfo <ConverterDto>(nameof(ConverterDto.Name)),
                Converter    = new NullToStringConverter()
            };
            var tableInfo = new TableInfo(new[] { idColumn, nameColumn }, new List <PropertyInfo>(), null)
            {
                Name = nameof(ConverterDto)
            };

            KORM.Query.IQueryProvider queryProvider = Substitute.For <KORM.Query.IQueryProvider>();
            IDatabaseMapper           mapper        = Substitute.For <IDatabaseMapper>();

            mapper.GetTableInfo <ConverterDto>().Returns(tableInfo);
            var query = new Query <ConverterDto>(mapper, queryProvider);

            var generator = new CommandGenerator <ConverterDto>(tableInfo, queryProvider, query);
            var dto       = new ConverterDto()
            {
                Id = 1, Name = null
            };
            var convertedValue = generator.GetColumnValue(nameColumn, dto);

            convertedValue.Should().Be("NULL");
        }
Ejemplo n.º 2
0
        public void UseConverter()
        {
            TableInfo tableInfo = CreateTableInfoFromDto <ConverterDto>();

            tableInfo.Columns.Single(c => c.Name == nameof(ConverterDto.Name)).Converter = new NullToStringConverter();
            ColumnInfo nameColumn = tableInfo.Columns.Single(col => col.Name == nameof(ConverterDto.Name));

            CommandGenerator <ConverterDto> commandGenerator = CreateCommandGenerator <ConverterDto>(tableInfo);

            var dto = new ConverterDto()
            {
                Id = 1, Name = null
            };
            var convertedValue = commandGenerator.GetColumnValue(nameColumn, dto, ValueGenerated.Never);

            convertedValue.Should().Be("NULL");
        }
Ejemplo n.º 3
0
        public void UseValueGenerator()
        {
            TableInfo tableInfo = CreateTableInfoFromDto <ConverterDto>();

            tableInfo.Columns.Single(c => c.Name == nameof(ConverterDto.Id)).ValueGenerator = new AutoIncrementValueGenerator();
            ColumnInfo idColumn = tableInfo.Columns.Single(col => col.Name == nameof(ConverterDto.Id));

            CommandGenerator <ConverterDto> commandGenerator = CreateCommandGenerator <ConverterDto>(tableInfo);

            var dto = new ConverterDto()
            {
                Id = 1, Name = null
            };

            commandGenerator.SetColumnValueFromValueGenerator(idColumn, dto, ValueGenerated.Never);
            var convertedValue = commandGenerator.GetColumnValue(idColumn, dto, ValueGenerated.Never);

            convertedValue.Should().Be(AutoIncrementValueGenerator.GeneratedValue);
        }