当前位置: 首页>>代码示例>>C#>>正文


C# MappingConfiguration.Map方法代码示例

本文整理汇总了C#中MappingConfiguration.Map方法的典型用法代码示例。如果您正苦于以下问题:C# MappingConfiguration.Map方法的具体用法?C# MappingConfiguration.Map怎么用?C# MappingConfiguration.Map使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MappingConfiguration的用法示例。


在下文中一共展示了MappingConfiguration.Map方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Must_not_call_mapping_delegate_for_each_property_before_first_access

            public void Must_not_call_mapping_delegate_for_each_property_before_first_access()
            {
                var fooConfiguration = new MappingConfiguration<Foo, IFooView>();
                bool nameDelegateCalled = false;
                bool idDelegateCalled = false;
                bool factorDelegateCalled = false;

                fooConfiguration.Map(view => view.Name).From(foo =>
                                                             	{
                                                             		nameDelegateCalled = true;
                                                             		return foo.Name;
                                                             	});
                fooConfiguration.Map(view => view.Id).From(foo =>
                                                           	{
                                                           		idDelegateCalled = true;
                                                           		return foo.Id;
                                                           	});
                fooConfiguration.Map(view => view.Factor).From(foo =>
                                                               	{
                                                               		factorDelegateCalled = true;
                                                               		return foo.Factor;
                                                               	});

                var foo1 = new Foo("test", Guid.NewGuid(), 1);
                IAdapterFactory<Foo, IFooView> systemUnderTest = AdapterFactoryGenerator.Instance.Generate<Foo, IFooView>(fooConfiguration.Mappings);
                IFooView fooView = systemUnderTest.Create(foo1);

                Assert.That(nameDelegateCalled, Is.False);
                Assert.That(idDelegateCalled, Is.False);
                Assert.That(factorDelegateCalled, Is.False);

                // ReSharper disable UnusedVariable
                string name = fooView.Name;
                Guid id = fooView.Id;
                int factor = fooView.Factor.Factor;
                // ReSharper restore UnusedVariable

                Assert.That(nameDelegateCalled, Is.True);
                Assert.That(idDelegateCalled, Is.True);
                Assert.That(factorDelegateCalled, Is.True);
            }
开发者ID:malatx,项目名称:JuniorMap,代码行数:41,代码来源:AdapterFactoryGeneratorTester.cs

示例2: Must_wire_up_mapping_delegate_for_each_property

            public void Must_wire_up_mapping_delegate_for_each_property()
            {
                var fooConfiguration = new MappingConfiguration<Foo, IFooView>();
                bool nameDelegateCalled = false;
                bool idDelegateCalled = false;
                bool factorDelegateCalled = false;

                fooConfiguration.Map(view => view.Name).From(foo =>
                                                             	{
                                                             		nameDelegateCalled = true;
                                                             		return foo.Name;
                                                             	});
                fooConfiguration.Map(view => view.Id).From(foo =>
                                                           	{
                                                           		idDelegateCalled = true;
                                                           		return foo.Id;
                                                           	});
                fooConfiguration.Map(view => view.Factor).From(foo =>
                                                               	{
                                                               		factorDelegateCalled = true;
                                                               		return foo.Factor;
                                                               	});

                var foo1 = new Foo("test", Guid.NewGuid(), 1);
                IAdapterFactory<Foo, IFooView> systemUnderTest = AdapterFactoryGenerator.Instance.Generate<Foo, IFooView>(fooConfiguration.Mappings);
                IFooView fooView = systemUnderTest.Create(foo1);
                string name = fooView.Name;
                Guid id = fooView.Id;
                int factor = fooView.Factor.Factor;

                Assert.That(name, Is.EqualTo(foo1.Name));
                Assert.That(id, Is.EqualTo(foo1.Id));
                Assert.That(factor, Is.EqualTo(foo1.Factor.Factor));
                Assert.That(nameDelegateCalled, Is.True);
                Assert.That(idDelegateCalled, Is.True);
                Assert.That(factorDelegateCalled, Is.True);
            }
开发者ID:malatx,项目名称:JuniorMap,代码行数:37,代码来源:AdapterFactoryGeneratorTester.cs

示例3: Must_reuse_the_same_assembly_for_all_generated_adapter_factories

            public void Must_reuse_the_same_assembly_for_all_generated_adapter_factories()
            {
                var fooConfiguration = new MappingConfiguration<Foo, IFooView>();

                fooConfiguration.Map(view => view.Name).From(foo => foo.Name);
                fooConfiguration.Map(view => view.Id).From(foo => foo.Id);
                fooConfiguration.Map(view => view.Factor).From(foo => foo.Factor);

                IAdapterFactory<Foo, IFooView> fooFactory = AdapterFactoryGenerator.Instance.Generate<Foo, IFooView>(fooConfiguration.Mappings);
                var foo1 = new Foo("test", Guid.NewGuid(), 1);
                IFooView fooView = fooFactory.Create(foo1);
                var barConfiguration = new MappingConfiguration<Bar, IFooView>();

                barConfiguration.Map(view => view.Name).From(bar => bar.Name);
                barConfiguration.Map(view => view.Id).From(bar => bar.Id);
                barConfiguration.Map(view => view.Factor).From(bar => null);

                IAdapterFactory<Bar, IFooView> barFactory = AdapterFactoryGenerator.Instance.Generate<Bar, IFooView>(barConfiguration.Mappings);
                var bar1 = new Bar("test", Guid.NewGuid());
                IFooView barView = barFactory.Create(bar1);
                Type fooViewType = fooView.GetType();
                Type barViewType = barView.GetType();

                Assert.That(fooViewType.Assembly, Is.SameAs(barViewType.Assembly));
            }
开发者ID:malatx,项目名称:JuniorMap,代码行数:25,代码来源:AdapterFactoryGeneratorTester.cs

示例4: Must_throw_exception_if_not_all_desired_type_properties_are_mapped

            public void Must_throw_exception_if_not_all_desired_type_properties_are_mapped()
            {
                var fooConfiguration = new MappingConfiguration<Foo, IFooView>();

                fooConfiguration.Map(view => view.Name).From(foo => foo.Name);

                Assert.Throws<Exception>(() => AdapterFactoryGenerator.Instance.Generate<Foo, IFooView>(fooConfiguration.Mappings));
            }
开发者ID:malatx,项目名称:JuniorMap,代码行数:8,代码来源:AdapterFactoryGeneratorTester.cs

示例5: Must_perform_acceptably

            public void Must_perform_acceptably()
            {
                var configuration = new MappingConfiguration<Foo, IFooView>();

                configuration.Map(view => view.Name).From(foo => foo.Name);
                configuration.Map(view => view.Id).From(foo => foo.Id);
                configuration.Map(view => view.Factor).From(foo => foo.Factor);

                IAdapterFactory<Foo, IFooView> systemUnderTest = AdapterFactoryGenerator.Instance.Generate<Foo, IFooView>(configuration.Mappings);

                // Delay to allow CPU and I/O to drop
                Thread.Sleep(TimeSpan.FromSeconds(2));

                var foo1 = new Foo("test foo", Guid.NewGuid(), 1);
                const int numberOfInstances = 2000000;
                var mappingServiceMs = (long)StopwatchContext.Timed(() =>
                                                                        {
                                                                            for (int i = 0; i < numberOfInstances; i++)
                                                                            {
                                                                                systemUnderTest.Create(foo1);
                                                                            }
                                                                        }).TotalMilliseconds;
                var hardCodedMs = (long)StopwatchContext.Timed(() =>
                                                               	{
                                                               		for (int i = 0; i < numberOfInstances; i++)
                                                               		{
                                                               			new HardCodedFooAdapter(foo1);
                                                               		}
                                                               	}).TotalMilliseconds;
                double mappingServicePerInstanceSeconds = (mappingServiceMs / 1000.0) / numberOfInstances;
                double hardCodedPerInstanceSeconds = (hardCodedMs / 1000.0) / numberOfInstances;
                double performanceDifference = mappingServiceMs / (double)hardCodedMs;

                Console.WriteLine(String.Format("Generated Adapter:  {0:0.0000000000000}s per instance, {1:0.000}s total, {2} instances.", mappingServicePerInstanceSeconds, mappingServiceMs / 1000.0, numberOfInstances));
                Console.WriteLine(String.Format("Hard-coded Adapter: {0:0.0000000000000}s per instance, {1:0.000}s total, {2} instances.", hardCodedPerInstanceSeconds, hardCodedMs / 1000.0, numberOfInstances));
                Console.WriteLine();
                Console.WriteLine(String.Format("Relative time for generated version: {0:00.00}x slower", performanceDifference));
                Console.WriteLine(String.Format("Cost per 100 instances as percentage of 50ms page load: {0:000.000000}%", ((mappingServicePerInstanceSeconds * 100) / 0.050) * 100.0));

                Assert.That(performanceDifference, Is.LessThan(30.0));
            }
开发者ID:malatx,项目名称:JuniorMap,代码行数:41,代码来源:AdapterFactoryGeneratorTester.cs


注:本文中的MappingConfiguration.Map方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。