/// <summary>
        /// Returns the identifier of a VM
        ///
        /// Note: The method assumes that there is only one VM and datacenter
        ///  with the specified names.
        /// </summary>
        /// <param name="stubFactory">Stub factory for api endpoint</param>
        /// <param name="sessionStubConfig">stub configuration for the current
        ///  session
        /// </param>
        /// <param name="vmName">name of the vm</param>
        /// <returns>the identifier of a VM</returns>
        public static String GetVm(StubFactory stubFactory,
                                   StubConfiguration sessionStubConfig, string vmName)
        {
            VMTypes.FilterSpec vmFilterSpec = new VMTypes.FilterSpec();
            vmFilterSpec.SetNames(new HashSet <String> {
                vmName
            });

            VM vmService = stubFactory.CreateStub <VM>(sessionStubConfig);
            List <VMTypes.Summary> vmSummaries = vmService.List(vmFilterSpec);

            if (vmSummaries.Count > 1)
            {
                throw new Exception(String.Format("More than one vm" +
                                                  " with the specified name {0} exist",
                                                  vmName));
            }

            if (vmSummaries.Count <= 0)
            {
                throw new Exception(String.Format("VM with name {0}" +
                                                  "not found !", vmName));
            }

            return(vmSummaries[0].GetVm());
        }
Пример #2
0
        /// <summary>
        /// Returns the identifier of the datacenter.
        ///
        /// Note: The method assumes that there is only one datacenter with the
        /// specified name
        /// </summary>
        /// <param name="stubFactory">Stub factory for api endpoint</param>
        /// <param name="sessionStubConfig">stub configuration for the current
        ///  session
        /// </param>
        /// <param name="datacenterName">name of the datacenter</param>
        /// <returns>identifier of a datacenter</returns>
        public static String GetDatacenter(
            StubFactory stubFactory, StubConfiguration sessionStubConfig,
            string datacenterName)
        {
            Datacenter datacenterService =
                stubFactory.CreateStub <Datacenter>(sessionStubConfig);
            HashSet <String> datacenterNames = new HashSet <String>
            {
                datacenterName
            };

            DatacenterTypes.FilterSpec dcFilterSpec =
                new DatacenterTypes.FilterSpec();
            dcFilterSpec.SetNames(datacenterNames);
            List <DatacenterTypes.Summary> dcSummaries =
                datacenterService.List(dcFilterSpec);

            if (dcSummaries.Count > 1)
            {
                throw new Exception(String.Format("More than one datacenter" +
                                                  " with the specified name {0} exist", datacenterName));
            }

            if (dcSummaries.Count <= 0)
            {
                throw new Exception(String.Format("Datacenter with name {0}" +
                                                  " not found !", datacenterName));
            }

            return(dcSummaries[0].GetDatacenter());
        }
        public override void Run()
        {
            System.Net.ServicePointManager.SecurityProtocol |=
                System.Net.SecurityProtocolType.Tls12;

            Console.WriteLine("\n\n#### Example: Login to vCenter server with "
                              + "external Platform Services Controller");

            VapiAuthenticationHelper vapiAuthHelper =
                new VapiAuthenticationHelper();

            SetupSslTrustForServer();

            Console.WriteLine("\nStep 1: Connect to the lookup service on the "
                              + "Platform Services Controller node.");
            LookupServiceHelper lookupServiceHelper = new LookupServiceHelper(
                LookupServiceUrl);

            Console.WriteLine("\nStep 2: Discover the Single Sign-On service "
                              + "URL from lookup service.");
            String ssoUrl = lookupServiceHelper.FindSsoUrl();

            Console.WriteLine("\nStep 3: Connect to the Single Sign-On URL and"
                              + " retrieve the SAML bearer token.");
            SamlToken samlBearerToken = SsoHelper.GetSamlBearerToken(ssoUrl,
                                                                     UserName, Password);

            Console.WriteLine("\nStep 4. Login to vAPI services using the "
                              + "SAML bearer token.");
            StubConfiguration sessionStubConfig =
                vapiAuthHelper.LoginBySamlBearerToken(Server,
                                                      samlBearerToken);

            Console.WriteLine("\nStep 5: Perform certain tasks using the vAPI "
                              + "services.");
            Console.WriteLine("\nListing all tags on the vCenter Server ...");
            Tag taggingService =
                vapiAuthHelper.StubFactory.CreateStub <Tag>(sessionStubConfig);
            List <string> tagList = taggingService.List();

            if (!tagList.Any())
            {
                Console.WriteLine("\nNo tags found !");
            }
            else
            {
                Console.WriteLine("\nTag Name\tTag Description");
                foreach (string tagId in tagList)
                {
                    Console.WriteLine(
                        taggingService.Get(tagId).GetName()
                        + "\t" + taggingService.Get(tagId).GetDescription());
                }
            }
            vapiAuthHelper.Logout();
        }
        public override void Run()
        {
            System.Net.ServicePointManager.SecurityProtocol |=
                System.Net.SecurityProtocolType.Tls12;

            Console.WriteLine("\n\n#### Example: Login to vCenter server with "
                              + "embedded Platform Services Controller");

            VapiAuthenticationHelper vapiAuthHelper =
                new VapiAuthenticationHelper();

            /*
             * Since the platform services controller is embedded, the sso
             * server is the same as the vcenter server.
             */
            String ssoUrl = "https://" + Server + SSO_PATH;

            SetupSslTrustForServer();

            Console.WriteLine("\nStep 1: Connect to the Single Sign-On URL "
                              + "and retrieve the SAML bearer token.");
            SamlToken samlBearerToken = SsoHelper.GetSamlBearerToken(ssoUrl,
                                                                     UserName, Password);

            Console.WriteLine("\nStep 2. Login to vAPI services using the "
                              + "SAML bearer token.");
            StubConfiguration sessionStubConfig =
                vapiAuthHelper.LoginBySamlBearerToken(Server,
                                                      samlBearerToken);

            Console.WriteLine("\nStep 3: Perform certain tasks using the vAPI "
                              + "services.");
            Console.WriteLine("\nListing all tags on the vCenter Server ...");
            Tag taggingService =
                vapiAuthHelper.StubFactory.CreateStub <Tag>(sessionStubConfig);
            List <string> tagList = taggingService.List();

            if (!tagList.Any())
            {
                Console.WriteLine("\nNo tags found !");
            }
            else
            {
                Console.WriteLine("\nTag Name\tTag Description");
                foreach (string tagId in tagList)
                {
                    Console.WriteLine(
                        taggingService.Get(tagId).GetName()
                        + "\t" + taggingService.Get(tagId).GetDescription());
                }
            }
            vapiAuthHelper.Logout();
        }
Пример #5
0
        public void Dispose_DisposingWithNServiceBusSerializer_NoTransientsLyingAround()
        {
            // Arrange
            StubConfiguration configuration = Configure.Stub();
            ServiceStub       service       = configuration.NServiceBusSerializers().Create(@".\Private$\orderservice");

            // Act
            service.Dispose();

            // Assert
            AssertThatNoTransientsAreLyingAround(configuration);
        }
Пример #6
0
        public void Dispose_DisposingWithNServiceBusSerializerAndRestEndPoint_NoTransientsLyingAround()
        {
            // Arrange
            StubConfiguration configuration = Configure.Stub();
            ServiceStub       service       = configuration.NServiceBusSerializers().Restful().Create(@".\Private$\orderservice");

            service.RestEndpoint("http://localhost:9202/orderservice/");

            // Act
            service.Dispose();

            // Assert
            AssertThatNoTransientsAreLyingAround(configuration);
        }
        public override void Run()
        {
            System.Net.ServicePointManager.SecurityProtocol |=
                System.Net.SecurityProtocolType.Tls12;

            Console.WriteLine("\n\n#### Example: Login to vCenter server with "
                              + "external Platform Services Controller");

            VapiAuthenticationHelper vapiAuthHelper =
                new VapiAuthenticationHelper();

            SetupSslTrustForServer();

            Console.WriteLine("\nStep 1: Connect to the lookup service on the "
                              + "Platform Services Controller node.");
            LookupServiceHelper lookupServiceHelper = new LookupServiceHelper(
                LookupServiceUrl);

            Console.WriteLine("\nStep 2: Discover the Single Sign-On service "
                              + "URL from lookup service.");
            String ssoUrl = lookupServiceHelper.FindSsoUrl();

            Console.WriteLine("\nStep 3: Connect to the Single Sign-On URL and"
                              + " retrieve the SAML bearer token.");
            SamlToken samlBearerToken = SsoHelper.GetSamlBearerToken(ssoUrl,
                                                                     UserName, Password);

            Console.WriteLine("\nStep 4. Login to vAPI services using the "
                              + "SAML bearer token.");
            StubConfiguration sessionStubConfig =
                vapiAuthHelper.LoginBySamlBearerToken(Server,
                                                      samlBearerToken);

            Console.WriteLine("\nStep 5: Perform certain tasks using the vAPI "
                              + "services.");
            Datacenter datacenterService =
                vapiAuthHelper.StubFactory.CreateStub <Datacenter>(
                    sessionStubConfig);
            List <DatacenterTypes.Summary> dcList =
                datacenterService.List(new DatacenterTypes.FilterSpec());

            Console.WriteLine("\nList of datacenters on the vcenter server:");
            foreach (DatacenterTypes.Summary dcSummary in dcList)
            {
                Console.WriteLine(dcSummary);
            }
            vapiAuthHelper.Logout();
        }
Пример #8
0
        /// <summary>
        /// Creates a session with the server using username and password
        /// </summary>
        /// <param name="server">hostname of the server to login</param>
        /// <param name="username">username for login</param>
        /// <param name="password">password for login</param>
        /// <returns>the stub configuration configured with an authenticated
        ///          session
        /// </returns>
        public StubConfiguration LoginByUsernameAndPassword(string server,
                                                            string username, string password)
        {
            if (this.sessionSvc != null)
            {
                throw new Exception("Session already created");
            }

            StubFactory = CreateApiStubFactory(server);

            // Create a security context for username/password authentication
            ExecutionContext.SecurityContext securityContext =
                new UserPassSecurityContext(
                    username, password.ToCharArray());

            /*
             * Create a stub configuration with username/password security
             * context
             */
            StubConfiguration stubConfig = new StubConfiguration();

            stubConfig.SetSecurityContext(securityContext);

            // Create a session stub using the stub configuration.
            Session session =
                StubFactory.CreateStub <Session>(stubConfig);

            // Login and create a session
            char[] sessionId = session.Create();

            /*
             * Initialize a session security context from the generated
             * session id
             */
            SessionSecurityContext sessionSecurityContext =
                new SessionSecurityContext(sessionId);

            // Update the stub configuration to use the session id
            stubConfig.SetSecurityContext(sessionSecurityContext);

            /*
             * Create a stub for the session service using the authenticated
             * session
             */
            this.sessionSvc =
                StubFactory.CreateStub <Session>(stubConfig);
            return(stubConfig);
        }
Пример #9
0
        private static void AssertThatNoTransientsAreLyingAround(StubConfiguration configuration)
        {
            var diagnostics = configuration.Container.Kernel.GetSubSystem(SubSystemConstants.DiagnosticsKey) as IDiagnosticsHost;
            var diagnostic  = diagnostics.GetDiagnostic <ITrackedComponentsDiagnostic>();

            ILookup <IHandler, object> handlers = diagnostic.Inspect();

            foreach (var handler in handlers)
            {
                if (handler.Key.ComponentModel.LifestyleType != LifestyleType.Singleton &&
                    !typeof(TypedFactoryInterceptor).IsAssignableFrom(handler.Key.ComponentModel.Implementation))
                {
                    Assert.Fail("Component {0} is still hanging in there after dispose", handler.Key.ComponentModel.Implementation);
                }
            }
        }
Пример #10
0
        /// <summary>
        /// Creates a session with the server using SAML Bearer Token
        /// </summary>
        /// <param name="server">hostname of the server to login</param>
        /// <param name="username">username for login</param>
        /// <param name="password">password for login</param>
        /// <returns>the stub configuration configured with an authenticated
        ///          session
        /// </returns>
        public StubConfiguration LoginBySamlBearerToken(string server,
                                                        SamlToken samlBearerToken)
        {
            if (this.sessionSvc != null)
            {
                throw new Exception("Session already created");
            }

            StubFactory = CreateApiStubFactory(server);

            // Create a SAML security context using SAML bearer token
            ExecutionContext.SecurityContext samlSecurityContext = new SamlTokenSecurityContext(
                samlBearerToken, null);

            /*
             * Create a stub configuration with username/password security
             * context
             */
            StubConfiguration stubConfig = new StubConfiguration();

            stubConfig.SetSecurityContext(samlSecurityContext);

            // Create a session stub using the stub configuration.
            Session session =
                StubFactory.CreateStub <Session>(stubConfig);

            // Login and create a session
            char[] sessionId = session.Create();

            /*
             * Initialize a session security context from the generated
             * session id
             */
            SessionSecurityContext sessionSecurityContext =
                new SessionSecurityContext(sessionId);

            // Update the stub configuration to use the session id
            stubConfig.SetSecurityContext(sessionSecurityContext);

            /*
             * Create a stub for the session service using the authenticated
             * session
             */
            this.sessionSvc =
                StubFactory.CreateStub <Session>(stubConfig);
            return(stubConfig);
        }
Пример #11
0
        public void ShouldHitDB()
        {
            var Configuration = StubConfiguration.GetTestAppsettings();

            var str        = Configuration["ConnectionString"];
            var connection = new NpgsqlConnection(

                str //"Host=localhost;Port=5432;Username=ahatch1490;Database=exposure;"
                );

            var compiler = new PostgresCompiler();

            var q     = new QueryFactory(connection, compiler);
            var sites = q.Query("sites").Limit(10).Get <Site>();

            Assert.True(sites.Count() == 1);
        }
        public override void Run()
        {
            System.Net.ServicePointManager.SecurityProtocol |=
                System.Net.SecurityProtocolType.Tls12;

            Console.WriteLine("\n\n#### Example: Login to vCenter server with "
                              + "embedded Platform Services Controller");

            VapiAuthenticationHelper vapiAuthHelper =
                new VapiAuthenticationHelper();

            /*
             * Since the platform services controller is embedded, the sso
             * server is the same as the vcenter server.
             */
            String ssoUrl = "https://" + Server + SSO_PATH;

            SetupSslTrustForServer();

            Console.WriteLine("\nStep 1: Connect to the Single Sign-On URL "
                              + "and retrieve the SAML bearer token.");
            SamlToken samlBearerToken = SsoHelper.GetSamlBearerToken(ssoUrl,
                                                                     UserName, Password);

            Console.WriteLine("\nStep 2. Login to vAPI services using the "
                              + "SAML bearer token.");
            StubConfiguration sessionStubConfig =
                vapiAuthHelper.LoginBySamlBearerToken(Server,
                                                      samlBearerToken);

            Console.WriteLine("\nStep 3: Perform certain tasks using the vAPI "
                              + "services.");
            Datacenter datacenterService =
                vapiAuthHelper.StubFactory.CreateStub <Datacenter>(
                    sessionStubConfig);
            List <DatacenterTypes.Summary> dcList =
                datacenterService.List(new DatacenterTypes.FilterSpec());

            Console.WriteLine("\nList of datacenters on the vcenter server:");
            foreach (DatacenterTypes.Summary dcSummary in dcList)
            {
                Console.WriteLine(dcSummary);
            }
            vapiAuthHelper.Logout();
        }
Пример #13
0
        public void Init()
        {
            GrpcEnvironment.Initialize();

            server = new Server();
            server.AddServiceDefinition(Math.BindService(new MathServiceImpl()));
            int port = server.AddListeningPort(host, Server.PickUnusedPort);

            server.Start();
            channel = new Channel(host, port);

            // TODO(jtattermusch): get rid of the custom header here once we have dedicated tests
            // for header support.
            var stubConfig = new StubConfiguration((headerBuilder) =>
            {
                headerBuilder.Add(new Metadata.MetadataEntry("customHeader", "abcdef"));
            });

            client = Math.NewStub(channel, stubConfig);
        }
        public void GivenFactoryThatUsesConfiguration_WhenCreateContainer_ThenResultingBundlesAreProcessed()
        {
            using (var path = new TempDirectory())
            {
                Directory.CreateDirectory(Path.Combine(path, "scripts"));

                var configuration = new StubConfiguration(bundles => bundles.Add<ScriptBundle>("scripts"));
                var factory = new CassetteApplicationContainerFactory(
                    new DelegateCassetteConfigurationFactory(() => new[] { configuration }),
                    new CassetteConfigurationSection(),
                    path,
                    "/",
                    false,
                    Mock.Of<HttpContextBase>
                );

                var container = factory.CreateContainer();
                var bundle = container.Application.FindBundleContainingPath<ScriptBundle>("~/scripts");
                bundle.IsProcessed.ShouldBeTrue();
            }
        }
Пример #15
0
        private void Run()
        {
            GrpcEnvironment.Initialize();

            Credentials credentials = null;

            if (options.useTls)
            {
                credentials = TestCredentials.CreateTestClientCredentials(options.useTestCa);
            }

            List <ChannelOption> channelOptions = null;

            if (!string.IsNullOrEmpty(options.serverHostOverride))
            {
                channelOptions = new List <ChannelOption>
                {
                    new ChannelOption(ChannelOptions.SslTargetNameOverride, options.serverHostOverride)
                };
            }

            using (Channel channel = new Channel(options.serverHost, options.serverPort.Value, credentials, channelOptions))
            {
                var stubConfig = StubConfiguration.Default;
                if (options.testCase == "service_account_creds" || options.testCase == "compute_engine_creds")
                {
                    var credential = GoogleCredential.GetApplicationDefault();
                    if (credential.IsCreateScopedRequired)
                    {
                        credential = credential.CreateScoped(new[] { AuthScope });
                    }
                    stubConfig = new StubConfiguration(OAuth2InterceptorFactory.Create(credential));
                }

                TestService.ITestServiceClient client = new TestService.TestServiceClient(channel, stubConfig);
                RunTestCase(options.testCase, client);
            }

            GrpcEnvironment.Shutdown();
        }
        /// <summary>
        /// Returns the identifier of a distributed network
        ///
        /// Note: The method assumes that there is only one distributed portgroup
        ///  and datacenter with the specified names.
        /// </summary>
        /// <param name="serviceManager">Helper for instantiating vapi services</param>
        /// <param name="datacenterName">name of the datacenter</param>
        /// <param name="distPortgroupName">name of the distributed portgroup</param>
        /// <returns>identifier of the distributed network</returns>
        public static string GetDistributedNetworkBacking(
            StubFactory stubFactory, StubConfiguration sessionStubConfig,
            string datacenterName, string distPortgroupName)
        {
            HashSet<string> datacenters = new HashSet<string>
            {
                DatacenterHelper.GetDatacenter(
                    stubFactory, sessionStubConfig, datacenterName)
            };
            NetworkTypes.FilterSpec networkFilterSpec =
                new NetworkTypes.FilterSpec();
            networkFilterSpec.SetNames(
                new HashSet<string> { distPortgroupName });
            networkFilterSpec.SetDatacenters(datacenters);
            networkFilterSpec.SetTypes(new HashSet<NetworkTypes.Type>
            {
                NetworkTypes.Type.DISTRIBUTED_PORTGROUP
            });
            Network networkService =
                stubFactory.CreateStub<Network>(sessionStubConfig);
            List<NetworkTypes.Summary> networkSummaries =
                networkService.List(networkFilterSpec);

            if (networkSummaries.Count > 1)
            {
                throw new Exception(String.Format("More than one distributed" +
                    " portgroup with the specified name {0} exist",
                    distPortgroupName));

            }

            if (networkSummaries.Count <= 0)
            {
                throw new Exception(String.Format("Distributed portgroup " +
                                    "with name {0} not found !",
                                    distPortgroupName));
            }

            return networkSummaries[0].GetNetwork();
        }
Пример #17
0
        /// <summary>
        /// Returns the identifier of a cluster.
        ///
        /// Note: The method assumes that there is only one cluster and
        /// datacenter with the specified names
        /// </summary>
        /// <param name="stubFactory">Stub factory for api endpoint</param>
        /// <param name="sessionStubConfig">stub configuration for the current
        ///  session
        /// </param>
        /// <param name="datacenterName">name of the datacenter</param>
        /// <param name="clusterName">name of the cluster</param>
        /// <returns>identifier of the cluster</returns>
        public static String GetCluster(
            StubFactory stubFactory, StubConfiguration sessionStubConfig,
            string datacenterName, string clusterName)
        {
            HashSet <string> datacenters = new HashSet <string>
            {
                DatacenterHelper.GetDatacenter(stubFactory, sessionStubConfig,
                                               datacenterName)
            };

            ClusterTypes.FilterSpec clusterFilterSpec =
                new ClusterTypes.FilterSpec();
            HashSet <string> clusters = new HashSet <string> {
                clusterName
            };

            clusterFilterSpec.SetNames(clusters);
            clusterFilterSpec.SetDatacenters(datacenters);

            Cluster clusterService = stubFactory.CreateStub <Cluster>(
                sessionStubConfig);
            List <ClusterTypes.Summary> clusterSummaries =
                clusterService.List(clusterFilterSpec);

            if (clusterSummaries.Count > 1)
            {
                throw new Exception(String.Format("More than one cluster with"
                                                  + " the specified name {0} exist", clusterName));
            }

            if (clusterSummaries.Count <= 0)
            {
                throw new Exception(String.Format("Cluster with name {0}" +
                                                  " not found !", clusterName));
            }

            return(clusterSummaries[0].GetCluster());
        }
Пример #18
0
        /// <summary>
        /// Returns a VM placement spec for a cluster. Ensures that the
        /// cluster, resource pool, vm folder and datastore are all in the same
        /// datacenter which is specified.
        ///
        /// Note: The method assumes that there is only one of each resource
        /// type (i.e.datacenter, resource pool, cluster, folder, datastore)
        /// with the specified names.
        /// </summary>
        /// <param name="stubFactory">Stub factory for api endpoint</param>
        /// <param name="sessionStubConfig">stub configuration for the current
        ///  session
        /// </param>
        /// <param name="datacenterName">name of the datacenter</param>
        /// <param name="clusterName">name of the cluster</param>
        /// <param name="folderName">name of the folder</param>
        /// <param name="datastoreName">name of the datastore</param>
        /// <returns>a VM placement spec for the specified cluster</returns>
        public static VMTypes.PlacementSpec GetPlacementSpecForCluster(
            StubFactory stubFactory, StubConfiguration sessionStubConfig,
            string datacenterName, string clusterName, string folderName,
            string datastoreName)
        {
            string clusterId =
                ClusterHelper.GetCluster(stubFactory, sessionStubConfig,
                                         datacenterName, clusterName);

            Console.WriteLine("Selecting cluster " + clusterName + "(id=" +
                              clusterId + ")");

            string folderId = FolderHelper.GetFolder(stubFactory,
                                                     sessionStubConfig, datacenterName, folderName);

            Console.WriteLine("Selecting folder " + folderName + "(id=" +
                              folderId + ")");

            string datastoreId =
                DatastoreHelper.GetDatastore(stubFactory, sessionStubConfig,
                                             datacenterName, datastoreName);

            Console.WriteLine("Selecting datastore " + datastoreName + "(id=" +
                              datastoreId + ")");

            /*
             *  Create the vm placement spec with the datastore, resource pool,
             *  cluster and vm folder
             */
            VMTypes.PlacementSpec vmPlacementSpec =
                new VMTypes.PlacementSpec();
            vmPlacementSpec.SetDatastore(datastoreId);
            vmPlacementSpec.SetCluster(clusterId);
            vmPlacementSpec.SetFolder(folderId);

            return(vmPlacementSpec);
        }
Пример #19
0
        /// <summary>
        /// Returns the identifier of a datastore.
        ///
        /// Note: The method assumes that there is only one datacenter and
        /// datastore with the specified names.
        /// </summary>
        /// <param name="stubFactory">Stub factory for api endpoint</param>
        /// <param name="sessionStubConfig">stub configuration for the current
        ///  session
        /// </param>
        /// <param name="datacenterName">name of the datacenter</param>
        /// <param name="datastoreName">name of the datastore</param>
        /// <returns>identifier of a datastore</returns>
        public static String GetDatastore(
            StubFactory stubFactory, StubConfiguration sessionStubConfig,
            string datacenterName, string datastoreName)
        {
            HashSet <string> datacenters = new HashSet <string>
            {
                DatacenterHelper.GetDatacenter(
                    stubFactory, sessionStubConfig, datacenterName)
            };

            DatastoreTypes.FilterSpec dsFilterSpec =
                new DatastoreTypes.FilterSpec();
            dsFilterSpec.SetNames(new HashSet <string> {
                datastoreName
            });
            dsFilterSpec.SetDatacenters(datacenters);

            Datastore datastoreService =
                stubFactory.CreateStub <Datastore>(sessionStubConfig);
            List <DatastoreTypes.Summary> dsSummaries =
                datastoreService.List(dsFilterSpec);

            if (dsSummaries.Count > 1)
            {
                throw new Exception(String.Format("More than one datastore" +
                                                  " with the specified name {0} exist", datastoreName));
            }

            if (dsSummaries.Count <= 0)
            {
                throw new Exception(String.Format("Datastore with name {0}" +
                                                  "not found !", datastoreName));
            }

            return(dsSummaries[0].GetDatastore());
        }
        /// <summary>
        /// Returns the identifier of a folder.
        ///
        /// Note: The method assumes that there is only one folder and
        ///  datacenter with the specified names.
        /// </summary>
        /// <param name="stubFactory">Stub factory for api endpoint</param>
        /// <param name="sessionStubConfig">stub configuration for the current
        ///  session
        /// </param>
        /// <param name="datacenterName">name of the datacenter</param>
        /// <param name="folderName">name of the folder</param>
        /// <returns>identifier of a folder</returns>
        public static String GetFolder(
            StubFactory stubFactory, StubConfiguration sessionStubConfig,
            string datacenterName, string folderName)
        {
            HashSet <string> datacenters = new HashSet <string>
            {
                DatacenterHelper.GetDatacenter(
                    stubFactory, sessionStubConfig, datacenterName)
            };

            FolderTypes.FilterSpec folderFilterSpec =
                new FolderTypes.FilterSpec();
            folderFilterSpec.SetNames(new HashSet <String> {
                folderName
            });
            folderFilterSpec.SetDatacenters(datacenters);

            Folder folderService = stubFactory.CreateStub <Folder>(
                sessionStubConfig);
            List <FolderTypes.Summary> folderSummaries =
                folderService.List(folderFilterSpec);

            if (folderSummaries.Count > 1)
            {
                throw new Exception(String.Format("More than one folder" +
                                                  " with the specified name {0} exist", folderName));
            }

            if (folderSummaries.Count <= 0)
            {
                throw new Exception(String.Format("Folder with name {0}" +
                                                  "not found !", folderName));
            }

            return(folderSummaries[0].GetFolder());
        }
Пример #21
0
        public void GivenStylesheetWithExternalReference_WhenCreateContainer_ThenExternalBundleAddedToBundleCollection()
        {
            using (var path = new TempDirectory())
            {
                Directory.CreateDirectory(Path.Combine(path, "styles"));
                File.WriteAllText(PathUtilities.Combine(path, "styles", "asset.css"), "/* @reference http://example.com */");

                var configuration = new StubConfiguration(bundles => bundles.Add <StylesheetBundle>("styles"));
                var factory       = new CassetteApplicationContainerFactory(
                    new DelegateCassetteConfigurationFactory(() => new[] { configuration }),
                    new CassetteConfigurationSection(),
                    path,
                    "/",
                    false,
                    Mock.Of <HttpContextBase>
                    );

                var container = factory.CreateContainer();

                container.Application.Bundles.Any(
                    b => b is ExternalStylesheetBundle && b.Path == "http://example.com"
                    ).ShouldBeTrue();
            }
        }
        public void GivenStylesheetWithExternalReference_WhenCreateContainer_ThenExternalBundleAddedToBundleCollection()
        {
            using (var path = new TempDirectory())
            {
                Directory.CreateDirectory(Path.Combine(path, "styles"));
                File.WriteAllText(Path.Combine(path, "styles", "asset.css"), "/* @reference http://example.com */");

                var configuration = new StubConfiguration(bundles => bundles.Add<StylesheetBundle>("styles"));
                var factory = new CassetteApplicationContainerFactory(
                    new DelegateCassetteConfigurationFactory(() => new[] { configuration }),
                    new CassetteConfigurationSection(),
                    path,
                    "/",
                    false,
                    Mock.Of<HttpContextBase>
                );

                var container = factory.CreateContainer();

                container.Application.Bundles.Any(
                    b => b is ExternalStylesheetBundle && b.Path == "http://example.com"
                ).ShouldBeTrue();
            }
        }
Пример #23
0
 // creates a new client stub
 public static IMathClient NewStub(Channel channel, StubConfiguration config)
 {
     return(new MathClient(channel, config));
 }
Пример #24
0
 public static StubConfiguration Restful(this StubConfiguration configuration)
 {
     configuration.Container.Install(FromAssembly.This());
     return(configuration);
 }
Пример #25
0
 // creates a new client stub
 public static IRouteGuideClient NewStub(Channel channel, StubConfiguration config)
 {
     return(new RouteGuideClient(channel, config));
 }
 public static StubConfiguration WcfEndPoints(this StubConfiguration configuration)
 {
     configuration.Container.Install(FromAssembly.This());
     return(configuration);
 }
Пример #27
0
 // creates a new client stub
 public static IControllerClient NewStub(Channel channel, StubConfiguration config)
 {
     return(new ControllerClient(channel, config));
 }
Пример #28
0
 // creates a new client stub
 public static ITestServiceClient NewStub(Channel channel, StubConfiguration config)
 {
     return(new TestServiceClient(channel, config));
 }
Пример #29
0
 // creates a new client stub
 public static IGreeterClient NewStub(Channel channel, StubConfiguration config)
 {
     return(new GreeterClient(channel, config));
 }
Пример #30
0
 public PlatformStubService(HttpRequestHandler requestHandler, StubConfiguration configuration)
 {
     _requestHandler = requestHandler;
     _configuration  = configuration;
 }
Пример #31
0
 public static StubConfiguration NServiceBusSerializers(this StubConfiguration configuration)
 {
     configuration.Container.Install(FromAssembly.This());
     return(configuration);
 }