public async Task GetDefaultQuotas()
        {
            using (var httpTest = new HttpTest())
            {
                httpTest.RespondWith(JObject.Parse(@"
{
  'quota_set': {
    'injected_file_content_bytes': 10240,
    'metadata_items': 128,
    'server_group_members': 10,
    'server_groups': 10,
    'ram': 51200,
    'floating_ips': 10,
    'key_pairs': 100,
    'id': 'defaults',
    'instances': 10,
    'security_group_rules': 20,
    'injected_files': 5,
    'cores': 20,
    'fixed_ips': -1,
    'injected_file_path_bytes': 255,
    'security_groups': 10
  }
}").ToString());

                var quotas = await _compute.GetDefaultQuotasAsync();

                httpTest.ShouldHaveCalled("*/os-quota-sets/defaults");
                Assert.NotNull(quotas);

                Assert.Equal(100, quotas.KeyPairs);
                Assert.Equal(-1, quotas.FixedIPs);
            }
        }
        public void FindServiceOnAPage()
        {
            using (var httpTest = new HttpTest())
            {
                httpTest.RespondWithJson(new ServiceCollection
                {
                    Services = {new Service()},
                    ServiceLinks = {new Link("next", "http://api.com/next")}
                });
                httpTest.RespondWithJson(new ServiceCollection
                {
                    Services = {new Service {Name = "MyService"}}
                });

                var currentPage = _cdnService.ListServices();
                Service myService;
                do
                {
                    myService = currentPage.FirstOrDefault(x => x.Name == "MyService");
                    if (myService != null)
                        break;

                    currentPage = currentPage.GetNextPage();
                } while (currentPage.Any());

                Assert.NotNull(myService);
            }
        }
示例#3
0
 public void SerializeListServerOptionsInUrl()
 {
     using (var httpTest = new HttpTest())
     {
         httpTest.RespondWithJson(new ServerSummaryCollection());
         _compute.ListServerSummaries(new ServerListOptions());
         httpTest.ShouldNotHaveCalled("*metadata*");
     }   
 }
        public async void When401AuthenticationFailsMultipleTimes_ThrowException()
        {
            using (var httpTest = new HttpTest())
            {
                httpTest.RespondWith((int)HttpStatusCode.Unauthorized, "Your token has expired");
                httpTest.RespondWith((int)HttpStatusCode.Unauthorized, "Your token has expired");

                var service = new ContentDeliveryNetworkService(Stubs.AuthenticationProvider, "DFW");
                await Assert.ThrowsAsync<FlurlHttpException>(() => service.GetFlavorAsync("flavor-id"));
            }
        }
        public void GetService()
        {
            using (var httpTest = new HttpTest())
            {
                httpTest.RespondWithJson(new Service{Id = "service-id"});

                var service = _cdnService.GetService("service-id");

                Assert.NotNull(service);
                Assert.Equal("service-id", service.Id);
            }
        }
        public async void When401UnauthorizedIsReturned_RetryRequest()
        {
            using (var httpTest = new HttpTest())
            {
                httpTest.RespondWith((int)HttpStatusCode.Unauthorized, "Your token has expired");
                httpTest.RespondWithJson(new Flavor());

                var service = new ContentDeliveryNetworkService(Stubs.AuthenticationProvider, "DFW");
                var flavor = await service.GetFlavorAsync("flavor-id");
                Assert.NotNull(flavor);
            }
        }
示例#7
0
        public async void UserAgentTest()
        {
            using (var httpTest = new HttpTest())
            {
                OpenStackNet.Configure();

                await "http://api.com".GetAsync();

                var userAgent = httpTest.CallLog[0].Request.Headers.UserAgent.ToString();
                Assert.Contains("openstack.net", userAgent);
            }
        }
示例#8
0
        public async void UserAgentWithApplicationSuffixTest()
        {
            using (var httpTest = new HttpTest())
            {
                OpenStackNet.Configure(configure: options => options.UserAgents.Add(new ProductInfoHeaderValue("(unittests)")));
                
                await "http://api.com".GetAsync();

                var userAgent = httpTest.CallLog[0].Request.Headers.UserAgent.ToString();
                Assert.Contains("openstack.net", userAgent);
                Assert.Contains("unittests", userAgent);
            }
        }
        public async void UserAgentOnlyListOnceTest()
        {
            using (var httpTest = new HttpTest())
            {
                OpenStackNet.Configure();
                OpenStackNet.Configure(); // Duplicate call to Configure should be ignored

                await "http://api.com".GetAsync();

                var userAgent = httpTest.CallLog[0].Request.Headers.UserAgent.ToString();
                Assert.Contains("openstack.net", userAgent);
            }
        }
示例#10
0
        public void GetVolumeSnapshot()
        {
            using (var httpTest = new HttpTest())
            {
                Identifier snapshotId = Guid.NewGuid();
                httpTest.RespondWithJson(new VolumeSnapshot { Id = snapshotId });

                var result = _compute.GetVolumeSnapshot(snapshotId);

                httpTest.ShouldHaveCalled($"*/os-snapshots/{snapshotId}");
                Assert.NotNull(result);
                Assert.Equal(snapshotId, result.Id);
            }
        }
示例#11
0
        public void GetPorts()
        {
            using (var httpTest = new HttpTest())
            {
                Identifier portId = Guid.NewGuid();
                httpTest.RespondWithJson(new Port { Id = portId });

                var port = _networkingService.GetPort(portId);

                httpTest.ShouldHaveCalled("*/ports/" + portId);
                Assert.NotNull(port);
                Assert.Equal(portId, port.Id);
            }
        }
        public void DeleteServerGroup(HttpStatusCode responseCode)
        {
            using (var httpTest = new HttpTest())
            {
                Identifier serverGroupId = Guid.NewGuid();
                httpTest.RespondWithJson(new ServerGroup { Id = serverGroupId });
                httpTest.RespondWith((int)responseCode, "All gone!");

                var serverGroup = _compute.GetServerGroup(serverGroupId);

                serverGroup.Delete();
                httpTest.ShouldHaveCalled($"*/os-server-groups/{serverGroupId}");
            }
        }
        public void GetNetwork()
        {
            using (var httpTest = new HttpTest())
            {
                Identifier networkId = Guid.NewGuid();
                httpTest.RespondWithJson(new Network { Id = networkId });

                var network = _networkingService.GetNetwork(networkId);

                httpTest.ShouldHaveCalled("*/networks/" + networkId);
                Assert.NotNull(network);
                Assert.Equal(networkId, network.Id);
            }
        }
示例#14
0
        public void GetConsole()
        {
            using (var httpTest = new HttpTest())
            {
                Identifier serverId = Guid.NewGuid();
                httpTest.RespondWithJson(new Console {Type = RemoteConsoleType.NoVnc});

                Console result = _computeService.GetConsole(serverId, ConsoleProtocol.VNC, RemoteConsoleType.NoVnc);
                
                httpTest.ShouldHaveCalled($"*/servers/{serverId}/remote-consoles");
                Assert.NotNull(result);
                Assert.Equal(RemoteConsoleType.NoVnc, result.Type);
            }
        }
        public void GetSubnets()
        {
            using (var httpTest = new HttpTest())
            {
                Identifier subnetId = Guid.NewGuid();
                httpTest.RespondWithJson(new Subnet { Id = subnetId });

                var subnet = _networkingService.GetSubnet(subnetId);

                httpTest.ShouldHaveCalled("*/subnets/" + subnetId);
                Assert.NotNull(subnet);
                Assert.Equal(subnetId, subnet.Id);
            }
        }
        public void CreateServerGroup()
        {
            using (var httpTest = new HttpTest())
            {
                Identifier serverGroupId = Guid.NewGuid();
                httpTest.RespondWithJson(new ServerGroup {Id = serverGroupId});

                var request = new ServerGroupDefinition("{name}", "{policy-name}");
                var result = _compute.CreateServerGroup(request);

                httpTest.ShouldHaveCalled("*/os-server-groups");
                Assert.Equal(serverGroupId, result.Id);
                Assert.IsType<ComputeApi>(((IServiceResource)result).Owner);
            }
        }
示例#17
0
        public void GetVolume()
        {
            using (var httpTest = new HttpTest())
            {
                Identifier volumeId = Guid.NewGuid();
                httpTest.RespondWithJson(new Volume { Id = volumeId });

                var result = _compute.GetVolume(volumeId);

                httpTest.ShouldHaveCalled($"*/os-volumes/{volumeId}");
                Assert.NotNull(result);
                Assert.Equal(volumeId, result.Id);
                Assert.IsType<ComputeApi>(((IServiceResource)result).Owner);
            }
        }
        public void CreateNetwork()
        {
            using (var httpTest = new HttpTest())
            {
                Identifier networkId = Guid.NewGuid();
                httpTest.RespondWithJson(new Network{Id = networkId});

                var definition = new NetworkDefinition();
                var network = _networkingService.CreateNetwork(definition);

                httpTest.ShouldHaveCalled("*/networks");
                Assert.NotNull(network);
                Assert.Equal(networkId, network.Id);
            }
        }
        public void GetServerGroup()
        {
            using (var httpTest = new HttpTest())
            {
                Identifier serverGroupId = Guid.NewGuid();
                httpTest.RespondWithJson(new ServerGroup { Id = serverGroupId });

                var result = _compute.GetServerGroup(serverGroupId);

                httpTest.ShouldHaveCalled($"*/os-server-groups/{serverGroupId}");
                Assert.NotNull(result);
                Assert.Equal(serverGroupId, result.Id);
                Assert.IsType<ComputeApi>(((IServiceResource)result).Owner);
            }
        }
示例#20
0
        public void CreateVolume()
        {
            using (var httpTest = new HttpTest())
            {
                Identifier volumeId = Guid.NewGuid();
                httpTest.RespondWithJson(new Volume {Id = volumeId});

                var request = new VolumeDefinition(size: 1);
                var result = _compute.CreateVolume(request);

                httpTest.ShouldHaveCalled("*/os-volumes");
                Assert.Equal(volumeId, result.Id);
                Assert.IsType<ComputeApi>(((IServiceResource)result).Owner);
            }
        }
        public void ListSubnets()
        {
            using (var httpTest = new HttpTest())
            {
                Identifier subnetId = Guid.NewGuid();
                httpTest.RespondWithJson(new SubnetCollection(new[] {new Subnet {Id = subnetId}}));

                var subnets = _networkingService.ListSubnets();

                httpTest.ShouldHaveCalled("*/subnets");
                Assert.NotNull(subnets);
                Assert.Equal(1, subnets.Count());
                Assert.Equal(subnetId, subnets.First().Id);
            }
        }
示例#22
0
        public void GetRouter()
        {
            using (var httpTest = new HttpTest())
            {
                Identifier routerId = Guid.NewGuid();
                httpTest.RespondWithJson(new Router { Id = routerId });

                var result = _networking.GetRouter(routerId);

                httpTest.ShouldHaveCalled($"*/routers/{routerId}");
                Assert.NotNull(result);
                Assert.Equal(routerId, result.Id);
                Assert.IsType<NetworkingApiBuilder>(((IServiceResource)result).Owner);
            }
        }
        public void ListNetworks()
        {
            using (var httpTest = new HttpTest())
            {
                Identifier networkId = Guid.NewGuid();
                httpTest.RespondWithJson(new NetworkCollection(new[] {new Network {Id = networkId}}));

                var networks = _networkingService.ListNetworks();

                httpTest.ShouldHaveCalled("*/networks");
                Assert.NotNull(networks);
                Assert.Equal(1, networks.Count());
                Assert.Equal(networkId, networks.First().Id);
            }
        }
示例#24
0
        public void CreateServerMetadata()
        {
            using (var httpTest = new HttpTest())
            {
                const string key = "stuff";
                Identifier serverId = "1";
                httpTest.RespondWithJson(new Server { Id = serverId });

                var server = _compute.GetServer(serverId);
                server.Metadata.Create(key, "things");

                Assert.True(server.Metadata.ContainsKey(key));
                httpTest.ShouldHaveCalled($"*/servers/{serverId}/metadata/{key}");
            }
        }
示例#25
0
        public void CreatePort()
        {
            using (var httpTest = new HttpTest())
            {
                Identifier networkId = Guid.NewGuid();
                Identifier portId = Guid.NewGuid();
                httpTest.RespondWithJson(new Port { Id = portId });

                var definition = new PortCreateDefinition(networkId);
                var port = _networkingService.CreatePort(definition);

                httpTest.ShouldHaveCalled("*/ports");
                Assert.NotNull(port);
                Assert.Equal(portId, port.Id);
            }
        }
        public void CreateSubnet()
        {
            using (var httpTest = new HttpTest())
            {
                Identifier networkId = Guid.NewGuid();
                Identifier subnetId = Guid.NewGuid();
                httpTest.RespondWithJson(new Subnet { Id = subnetId });

                var definition = new SubnetCreateDefinition(networkId, IPVersion.IPv4, "10.0.0.0/24");
                var subnet = _networkingService.CreateSubnet(definition);
                
                httpTest.ShouldHaveCalled("*/subnets");
                Assert.NotNull(subnet);
                Assert.Equal(subnetId, subnet.Id);
            }
        }
示例#27
0
        public void CreateServer()
        {
            using (var httpTest = new HttpTest())
            {
                Identifier serverId = Guid.NewGuid();
                httpTest.RespondWithJson(new Server {Id = serverId});

                var definition = new ServerCreateDefinition("{name}", Guid.NewGuid(), "{flavor-id}");
                var result = _compute.CreateServer(definition);

                httpTest.ShouldHaveCalled("*/servers");
                Assert.NotNull(result);
                Assert.Equal(serverId,result.Id);
                Assert.IsType<ComputeApi>(((IServiceResource)result).Owner);
            }
        }
示例#28
0
        public async Task EvacuateServer()
        {
            using (var httpTest = new HttpTest())
            {
                Identifier serverId = Guid.NewGuid();
                httpTest.RespondWithJson(new Server { Id = serverId });
                httpTest.RespondWith((int)HttpStatusCode.Accepted, "Roger that, boss");

                var server = _compute.GetServer(serverId);
                await server.EvacuateAsync(new EvacuateServerRequest(false));

                httpTest.ShouldHaveCalled($"*/servers/{serverId}/action");
                string lastRequest = httpTest.CallLog.Last().RequestBody;
                Assert.True(lastRequest.Contains("evacuate"));
            }
        }
        public void CreateNetworks()
        {
            using (var httpTest = new HttpTest())
            {
                httpTest.RespondWithJson(new NetworkCollection(new[] { new Network { Name = "network-1"}, new Network{Name = "network-2"} }));

                var definitions = new[] {new NetworkDefinition(), new NetworkDefinition()};
                var networks = _networkingService.CreateNetworks(definitions);

                httpTest.ShouldHaveCalled("*/networks");
                Assert.NotNull(networks);
                Assert.Equal(2, networks.Count());
                Assert.Equal("network-1", networks.First().Name);
                Assert.Equal("network-2", networks.Last().Name);
            }
        }
示例#30
0
        public void CreateRouter()
        {
            using (var httpTest = new HttpTest())
            {
                Identifier networkId = Guid.NewGuid();
                Identifier routerId = Guid.NewGuid();
                httpTest.RespondWithJson(new Router { Id = routerId, ExternalGateway = new ExternalGateway { ExternalNetworkId = networkId } });

                var definition = new RouterCreateDefinition();
                var result = _networking.CreateRouter(definition);

                httpTest.ShouldHaveCalled("*/routers");
                Assert.NotNull(result);
                Assert.Equal(routerId, result.Id);
                Assert.Equal(networkId, result.ExternalGateway.ExternalNetworkId);
                Assert.IsType<NetworkingApiBuilder>(((IServiceResource)result).Owner);
            }
        }
示例#31
0
 public TestHttpClientFactory(HttpTest test)
 {
     _testMessageHandler         = new Flurl.Http.Testing.TestHttpClientFactory(test);
     _authenticatedClientFactory = new AuthenticatedHttpClientFactory();
 }