Esempio n. 1
0
        public void TestUsingDynamicRepository_ManualRegistration_Success()
        {
            ICustomerRepository customerRepository = new CustomerRepositoryPlugin();

            DynamicCommands.RegisterTarget(customerRepository);

            Command <ICustomerRepository> command = DynamicCommands.Get <ICustomerRepository>();

            Customer expected = command.Execute(repo => repo.AddCustomer("Bob"));
            Customer actual   = command.Execute(repo => repo.GetCustomer("Bob"));

            Assert.Equal(expected, actual);
            Assert.Equal("Bob", actual.Name);
        }
Esempio n. 2
0
        public void TestUsingDynamicRepository_DynamicRegistration_Success()
        {
            // Register all plugins, i.e., CustomerRepositoryPlugin and ProductRepositoryPlugin
            // in this test case.
            DynamicCommands.RegisterDynamicTargets();

            // Invoke ICustomerRepository methods on CustomerRepositoryPlugin target.
            Command <ICustomerRepository> customerCommand = DynamicCommands.Get <ICustomerRepository>();

            Customer expectedBob = customerCommand.Execute(repo => repo.AddCustomer("Bob"));
            Customer actualBob   = customerCommand.Execute(repo => repo.GetCustomer("Bob"));

            Assert.Equal(expectedBob, actualBob);
            Assert.Equal("Bob", actualBob.Name);

            // Invoke IProductRepository methods on ProductRepositoryPlugin target.
            Command <IProductRepository> productCommand = DynamicCommands.Get <IProductRepository>();

            Product expectedHammer = productCommand.Execute(repo => repo.AddProduct("Hammer"));
            Product actualHammer   = productCommand.Execute(repo => repo.GetProduct("Hammer"));

            Assert.Equal(expectedHammer, actualHammer);
            Assert.Equal("Hammer", actualHammer.Name);
        }