コード例 #1
0
        public void Should_use_the_custom_formatter()
        {
            var fileExportSpecification = _specFactory.CreateSpec(cfg =>
            {
                cfg.ConfigureType <SimpleObject>(typeCfg =>
                {
                    typeCfg.AddPropertyFormatter(x => x.Id, context => context.ItemValue.ToString() + "_TEST");;
                });;
            });

            var simpleObject = new SimpleObject {
                Id = 2
            };

            fileExportSpecification.GetPropertiesForType <SimpleObject>()["Id"].GetFormattedValue(simpleObject).ShouldEqual("2_TEST");
        }
コード例 #2
0
        public void Should_use_a_specially_configured_type_default()
        {
            var exportSpecification = new FileExport <SimpleObject>();

            exportSpecification.AddDefault <int>(value => value + "_ASDF");

            var fileExportSpecification = exportSpecification.CreateSpec();

            var simpleObject = new SimpleObject {
                Id = 2, StringValue1 = "HELLO"
            };

            // Should use the "globally" configured formatter
            fileExportSpecification.GetPropertiesForType <SimpleObject>()["Id"].GetFormattedValue(simpleObject).ShouldEqual("2_ASDF");

            // Should not do any special formatting
            fileExportSpecification.GetPropertiesForType <SimpleObject>()["StringValue1"].GetFormattedValue(simpleObject).ShouldEqual("HELLO");
        }