public Task Handle(PaymentRequest request)
        {
            switch (request.MethodAction)
            {
            case MethodAction.Deposit:
                _adapterFactory.Create <ISupportDeposit>(request.ProviderAccount).MakeDeposit(request);

            case MethodAction.Withdrawal:
                _adapterFactory.Create <ISupportWithdrawal>(request.ProviderAccount).MakeWithdrawal(request);
            }

            Console.WriteLine($"{GetType().Name}: {request.PublicPaymentId}");
            return(Task.CompletedTask);
        }
Exemple #2
0
            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));
            }
Exemple #3
0
        public Adapter AddAdapter(AdapterConfigurationModel model)
        {
            try
            {
                Adapter adapter = _adapterFactory.Create(model.TypeFullName, model.JsonConfiguration);
                adapter.Guid     = Guid.NewGuid();
                adapter.Name     = model.Name;
                adapter.IsSource = model.IsSource;

                return(AddAdapter(adapter));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
                return(null);
            }
        }
Exemple #4
0
            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;
                // ReSharper disable ImplicitlyCapturedClosure
                var hardCodedMs = (long)StopwatchContext.Timed(
                    () =>
                    // ReSharper restore ImplicitlyCapturedClosure
                {
                    for (int i = 0; i < numberOfInstances; i++)
                    {
                        // ReSharper disable ObjectCreationAsStatement
                        new HardCodedFooAdapter(foo1);
                        // ReSharper restore ObjectCreationAsStatement
                    }
                }).TotalMilliseconds;
                double mappingServicePerInstanceSeconds = (mappingServiceMs / 1000.0) / numberOfInstances;
                double hardCodedPerInstanceSeconds      = (hardCodedMs / 1000.0) / numberOfInstances;
                double performanceDifference            = mappingServiceMs / (double)hardCodedMs;

                Console.WriteLine("Generated Adapter:  {0:0.0000000000000}s per instance, {1:0.000}s total, {2} instances.", mappingServicePerInstanceSeconds, mappingServiceMs / 1000.0, numberOfInstances);
                Console.WriteLine("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("Relative time for generated version: {0:00.00}x slower", performanceDifference);
                Console.WriteLine("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));
            }
Exemple #5
0
            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);
            }
Exemple #6
0
            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);
            }
Exemple #7
0
 private static Database OpenFileMethod(string filename)
 {
     return(new Database(AdapterFactory.Create("Ado", new { Filename = filename })));
 }
 private IAdapter SelectAdapter(object targetObject)
 {
     return(_adapterFactory.Create(targetObject, _contractResolver));
 }
Exemple #9
0
 internal static Database OpenDefaultMethod()
 {
     return(new Database(AdapterFactory.Create("Ado", new { ConnectionName = "Simple.Data.Properties.Settings.DefaultConnectionString" })));
 }
 private IAdapter SelectAdapter(object targetObject, Type targetType)
 {
     return(_adapterFactory.Create(targetObject, targetType));
 }