/// <summary> /// Test a user scenario. Create application, multiple get/put changed data, /// </summary> /// [Fact] public async void TestUserScenario() { InstanceClient storage = new InstanceClient(new HttpClient()); int instanceOwnerId = 42; // Create application instance string instanceId = await storage.PostInstances("TEST-sailor", instanceOwnerId); Instance instance = await storage.GetInstances(instanceId, instanceOwnerId); Dictionary <string, string> data = new Dictionary <string, string> { { "dataFor", instanceOwnerId.ToString() } }; await storage.PostDataReadFromFile(instanceId, instanceOwnerId, "test.json", "application/json"); Instance instanceUpdated = await storage.GetInstances(instanceId, instanceOwnerId); string dataId = instance.Data.Find(m => m.FormId.Equals("default")).Id; for (int i = 0; i < 100; i++) { data.Add("field" + i, RandomString(i)); logger.Information(data["field" + i]); /* * storage.PutData(instanceId, dataId, instanceOwnerId, "test.json", "applicatino/json", data); * * var storedData = storage.GetData(instanceId, dataId, instanceOwnerId); */ } }
public async Task <InstanceResult> GetByIDAsync(string token, Guid instanceID) { InstanceClient instanceClient = new InstanceClient(ConfigManager.GetValue("CompanyHost")); var platInstance = await instanceClient.GetInstanceAsync(token, instanceID); return(platInstance); }
public MastodonClient(Credential credential, HttpClientHandler innerHandler = null) : base(credential, new OAuth2HttpClientHandler(innerHandler), RequestMode.FormUrlEncoded) { BinaryParameters = new List <string> { "avatar", "header", "file" }; Account = new AccountsClient(this); Apps = new AppsClient(this); Auth = new AuthClient(this); Blocks = new BlocksClient(this); Conversations = new ConversationsClient(this); CustomEmojis = new CustomEmojisClient(this); DomainBlocks = new DomainBlocksClient(this); Endorsements = new EndorsementsClient(this); Favorites = new FavoritesClient(this); Filters = new FiltersClient(this); FollowRequests = new FollowRequestsClient(this); Follows = new FollowsClient(this); Instance = new InstanceClient(this); Lists = new ListsClient(this); Media = new MediaClient(this); Notifications = new NotificationsClient(this); Push = new PushClient(this); Reports = new ReportsClient(this); ScheduledStatuses = new ScheduledStatusesClient(this); SearchV1 = new SearchV1Client(this); SearchV2 = new SearchV2Client(this); Statuses = new StatusesClient(this); Streaming = new StreamingClient(this); Suggestions = new SuggestionsClient(this); Timelines = new TimelinesClient(this); }
public MastodonClient(string domain) : base($"https://{domain}", AuthMode.OAuth2, RequestMode.FormUrlEncoded) { Domain = domain; BinaryParameters = new List <string> { "avatar", "header", "file" }; Account = new AccountsClient(this); Apps = new AppsClient(this); Auth = new AuthClient(this); Blocks = new BlocksClient(this); CustomEmojis = new CustomEmojisClient(this); DomainBlocks = new DomainBlocksClient(this); Endorsements = new EndorsementsClient(this); Favorites = new FavoritesClient(this); Filters = new FiltersClient(this); FollowRequests = new FollowRequestsClient(this); Follows = new FollowsClient(this); Instance = new InstanceClient(this); Lists = new ListsClient(this); Media = new MediaClient(this); Notifications = new NotificationsClient(this); Push = new PushClient(this); Reports = new ReportsClient(this); SearchV1 = new SearchV1Client(this); SearchV2 = new SearchV2Client(this); Statuses = new StatusesClient(this); Streaming = new StreamingClient(this); Suggestions = new SuggestionsClient(this); Timelines = new TimelinesClient(this); }
public async Task <List <UserCompaniesResult> > GetAllAsync(string token) { InstanceClient instanceClient = new InstanceClient(ConfigManager.GetValue("CompanyHost")); var platInstances = await instanceClient.GetInstancesAsync(token, Guid.Parse(ConfigManager.GetValue("ServiceIDs"))); return(platInstances); }
/// <summary> /// Initializes a new instance of the <see cref="InstanceStorageTests"/> class. /// </summary> /// <param name="fixture">the fixture object which talks to the SUT (System Under Test)</param> public InstancesQueryAndHALTests(PlatformStorageFixture fixture) { this.fixture = fixture; this.storageClient = new InstanceClient(this.fixture.CreateClient()); CreateTestApplication(testAppId); }
/// <summary> /// Initializes a new instance of the <see cref="InstanceStorageTests"/> class. /// </summary> /// <param name="fixture">the fixture object which talks to the SUT (System Under Test)</param> public InstanceStorageTests(PlatformStorageFixture fixture) { this.fixture = fixture; this.client = this.fixture.Client; this.storageClient = new InstanceClient(this.client); CreateTestApplication(); }
/// <inheritdoc /> public IInstanceClient CreateClient(Instance instance) { if (!cachedClients.TryGetValue(instance.Id, out var client)) { client = new InstanceClient(apiClient, instance); cachedClients.Add(instance.Id, client); } return(client); }
/// <summary> /// Initializes a new instance of the <see cref="InstanceStorageTests"/> class. /// </summary> /// <param name="fixture">the fixture object which talks to the SUT (System Under Test)</param> public InstancesQueryTests(PlatformStorageFixture fixture) { _fixture = fixture; _instanceClient = new InstanceClient(_fixture.CreateClient()); _validOrgToken = PrincipalUtil.GetOrgToken(org: _testOrg, scope: "altinn:instances.read"); LoadTestData(); CreateTestApplication(_testAppId); }
/// <summary> /// Initializes a new instance of the <see cref="InstanceStorageTests"/> class. /// </summary> /// <param name="fixture">the fixture object which talks to the SUT (System Under Test)</param> public InstanceStorageTests(PlatformStorageFixture fixture) { this.fixture = fixture; this.client = this.fixture.Client; this.storageClient = new InstanceClient(this.client); // connect to azure blob storage StorageCredentials storageCredentials = new StorageCredentials("devstoreaccount1", "Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw=="); CloudStorageAccount storageAccount = new CloudStorageAccount(storageCredentials, true); StorageUri storageUrl = new StorageUri(new Uri("http://127.0.0.1:10000/devstoreaccount1")); _blobClient = new CloudBlobClient(storageUrl, storageCredentials); _blobContainer = _blobClient.GetContainerReference("servicedata"); CreateTestApplication(); }
/// <summary> /// Initializes a new instance of the <see cref="DataElementStorageTests"/> class. /// </summary> /// <param name="fixture">the fixture object which talks to the SUT (System Under Test)</param> public DataElementStorageTests(PlatformStorageFixture fixture) { this.fixture = fixture; this.client = this.fixture.Client; this.instanceClient = new InstanceClient(this.client); // connect to azure blob storage StorageSharedKeyCredential storageCredentials = new StorageSharedKeyCredential("devstoreaccount1", "Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw=="); Uri storageUrl = new Uri("http://127.0.0.1:10000/devstoreaccount1"); _blobClient = new BlobServiceClient(storageUrl, storageCredentials); _blobContainer = _blobClient.GetBlobContainerClient("servicedata"); _validToken = PrincipalUtil.GetToken(1); CreateTestApplication(); }
/// <summary> /// Initializes a new instance of the <see cref="MessageBoxInstancesControllerTest"/> class. /// </summary> /// <param name="fixture">the fixture object which talks to the SUT (System Under Test)</param> public MessageBoxInstancesControllerTest(PlatformStorageFixture fixture) { this.fixture = fixture; this.client = this.fixture.Client; this.instanceClient = new InstanceClient(this.client); this.appClient = new ApplicationClient(this.client); _client = new DocumentClient(new Uri(_cosmosSettings.EndpointUri), _cosmosSettings.PrimaryKey, new ConnectionPolicy { ConnectionMode = ConnectionMode.Gateway, ConnectionProtocol = Protocol.Https, }); testdata = new TestData(); appIds = testdata.GetAppIds(); CreateTestApplications(); }
/// <summary> /// Initializes a new instance of the <see cref="InstanceStorageTests"/> class. /// </summary> /// <param name="fixture">the fixture object which talks to the SUT (System Under Test)</param> public InstanceStorageTests(PlatformStorageFixture fixture) { _fixture = fixture; _client = _fixture.Client; _instanceClient = new InstanceClient(_client); // connect to azure blob storage StorageCredentials storageCredentials = new StorageCredentials("devstoreaccount1", "Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw=="); CloudStorageAccount storageAccount = new CloudStorageAccount(storageCredentials, true); StorageUri storageUrl = new StorageUri(new Uri("http://127.0.0.1:10000/devstoreaccount1")); _blobClient = new CloudBlobClient(storageUrl, storageCredentials); _blobContainer = _blobClient.GetContainerReference("servicedata"); _validToken = PrincipalUtil.GetToken(1); _validOrgToken = PrincipalUtil.GetOrgToken(org: testOrg, scope: "altinn:instances.read"); CreateTestApplication(); }
/// <summary> /// Method that loads the m1000 dataset into cosmos db /// </summary> /// <param name="appId">App id</param> /// <param name="client">instance client</param> public static void LoadData(string appId, InstanceClient client) { try { List <Instance> ins = client.GetInstancesForOrg(appId.Split("/")[0], 1000).Result; if (ins.Count == 1000) { return; } } catch { } string json = File.ReadAllText("data/m1000-instances.json"); JObject jsonObject = JObject.Parse(json); List <Instance> instances = jsonObject["instances"].ToObject <List <Instance> >(); foreach (Instance instance in instances) { Instance i = client.PostInstances(appId, instance).Result; } }
public async Task SetupAsync(Ec2Volume volume, InstanceClient client) { this.Client = client; this.Volume = volume; this.Volume.Logger = this.Logger; this.DisplayName = volume.Name; try { this.cancelCts = new CancellationTokenSource(); await this.Volume.SetupAsync(this.Client, this.cancelCts.Token); this.VolumeState = "mounted"; this.RunCommands = (await this.Client.GetRunCommandsAsync(this.Volume.MountPoint, this.cancelCts.Token)).ToArray(); this.UserInstruction = (await this.Client.GetUserInstructionAsync(this.Volume.MountPoint, this.cancelCts.Token)).Replace("<PUBLIC-IP>", this.Volume.Instance.PublicIp); await this.UpdateScriptsAsync(); } finally { this.CancelCts = null; } }
public async Task ReconnectAsync(Ec2Volume volume, InstanceClient client, CancellationToken?cancellationToken = null) { this.Client = client; this.Volume = volume; this.DisplayName = volume.Name; this.Volume.Logger = this.Logger; this.RunCommands = (await this.Client.GetRunCommandsAsync(this.Volume.MountPoint)).ToArray(); this.UserInstruction = (await this.Client.GetUserInstructionAsync(this.Volume.MountPoint)).Replace("<PUBLIC-IP>", this.Volume.Instance.PublicIp); this.Logger.Log("Reconnected to volume"); await this.UpdateScriptsAsync(); if (await this.Client.IsCommandSessionStartedAsync(this.Volume.MountPoint, cancellationToken)) { this.VolumeState = "started"; this.gameCts = new CancellationTokenSource(); await this.Client.ResumeSessionAsync(this.Volume.MountPoint, this.Logger, this.gameCts.Token); } else { this.VolumeState = "mounted"; } }
/// <summary> /// Initializes a new instance of the <see cref="InstanceEventsTest"/> class. /// </summary> /// <param name="fixture">the fixture object which talks to the SUT (System Under Test)</param> public InstanceEventsTest(PlatformStorageFixture fixture) { this.fixture = fixture; this.client = this.fixture.Client; this.storage = new InstanceClient(this.client); }
/// <summary> /// Lookup tests /// </summary> /// <param name="fixture">the fixture to simulate system under test</param> public LookupTests(PlatformStorageFixture fixture) { this.fixture = fixture; this.client = this.fixture.Client; this.storageClient = new InstanceClient(this.client); }
/// <summary> /// Creates 1000 instances with random dates. /// </summary> public static bool For1000InstanceOwners(HttpClient client) { string testAppId = "tdd/m1000"; string testOrg = "tdd"; CreateTestApplication(testAppId, client); InstanceClient instanceClient = new InstanceClient(client); string[] processTaskIds = { "FormFilling_1", "Submit_1", null }; string[] processEndStateIds = { "EndEvent_1", "ErrorEvent_1", null }; Random randomInt = new Random(); Random randomDay = new Random(); DateTime start = new DateTime(2019, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc); for (int i = 0; i < 1000; i++) { ProcessState processState = new ProcessState(); if (i < 200) { processState.CurrentTask = processTaskIds[0]; } else if (i < 400) { processState.CurrentTask = processTaskIds[1]; } else if (i < 900) { processState.IsComplete = true; processState.EndState = processEndStateIds[0]; } else { processState.IsInError = true; processState.EndState = "ErrorEvent_1"; } DateTime dueDate = start.AddDays(randomDay.Next(31, 366)); DateTime creationDate = dueDate.AddDays(-30); DateTime lastChangedDate = dueDate.AddDays(randomDay.Next(-20, 20)); Instance instance = new Instance { Org = testOrg, AppId = testAppId, InstanceOwnerId = (i + 1000).ToString(), Process = processState, LastChangedDateTime = lastChangedDate, CreatedDateTime = creationDate, DueDateTime = dueDate, VisibleDateTime = dueDate.AddDays(-30), Labels = new List <string>(), }; string[] labelIds = { "zero", "one", "two" }; if (i < 100) { instance.Labels = null; } else if (i < 300) { instance.Labels.Add(labelIds[0]); } else if (i < 600) { instance.Labels.Add(labelIds[1]); } else { instance.Labels.Add(labelIds[1]); instance.Labels.Add(labelIds[2]); } Instance resultInstance = instanceClient.PostInstances(testAppId, instance).Result; } return(true); }
public InitializationManager(InstanceClient instancecient) { instanceClient = instancecient; }
public InitializationManager() { instanceClient = new InstanceClient(ConfigManager.GetValue("companyhost")); }
/// <summary> /// Initializes a new instance of the <see cref="InstanceEventsTest"/> class. /// </summary> /// <param name="fixture">the fixture object which talks to the SUT (System Under Test)</param> public InstanceEventsTest(PlatformStorageFixture fixture) { _fixture = fixture; _client = _fixture.Client; _instanceClient = new InstanceClient(_client); }
/// <summary> /// Creates 1000 instances with random dates. /// </summary> public static bool For1000InstanceOwners(HttpClient client) { string testAppId = "tdd/m1000"; string testOrg = "tdd"; CreateTestApplication(testAppId, client); InstanceClient instanceClient = new InstanceClient(client); string[] processTaskIds = { "Data_1", "Submit_1", null }; string[] processEndStateIds = { "EndEvent_1", "ErrorEvent_1", null }; Random randomInt = new Random(); Random randomDay = new Random(); DateTime start = new DateTime(2019, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc); for (int i = 0; i < 1000; i++) { ProcessState processState = new ProcessState(); if (i < 200) { processState.CurrentTask = new ProcessElementInfo { Started = start, ElementId = processTaskIds[0], }; } else if (i < 400) { processState.CurrentTask = new ProcessElementInfo { Started = start, ElementId = processTaskIds[1], }; } else if (i < 900) { processState.Started = start; processState.Ended = start.AddDays(2); processState.EndEvent = processEndStateIds[0]; } else { processState.Started = start; processState.EndEvent = "ErrorEvent_1"; processState.Ended = start.AddDays(4); } DateTime dueDate = start.AddDays(randomDay.Next(31, 366)); DateTime creationDate = dueDate.AddDays(-30); DateTime lastChangedDate = dueDate.AddDays(randomDay.Next(-20, 20)); Instance instance = new Instance { Org = testOrg, AppId = testAppId, InstanceOwner = new InstanceOwner { PartyId = "1000" }, Process = processState, LastChanged = lastChangedDate, Created = creationDate, DueBefore = dueDate, VisibleAfter = dueDate.AddDays(-30), AppOwner = new ApplicationOwnerState { Labels = new List <string>(), } }; string[] labelIds = { "zero", "one", "two" }; if (i < 100) { instance.AppOwner.Labels = null; } else if (i < 300) { instance.AppOwner.Labels.Add(labelIds[0]); } else if (i < 600) { instance.AppOwner.Labels.Add(labelIds[1]); } else { instance.AppOwner.Labels.Add(labelIds[1]); instance.AppOwner.Labels.Add(labelIds[2]); } Instance resultInstance = instanceClient.PostInstances(testAppId, instance).Result; } return(true); }
public async Task ReconnectAsync(Ec2Volume volume, InstanceClient client, CancellationToken? cancellationToken = null) { this.Client = client; this.Volume = volume; this.DisplayName = volume.Name; this.Volume.Logger = this.Logger; this.RunCommands = (await this.Client.GetRunCommandsAsync(this.Volume.MountPoint)).ToArray(); this.UserInstruction = (await this.Client.GetUserInstructionAsync(this.Volume.MountPoint)).Replace("<PUBLIC-IP>", this.Volume.Instance.PublicIp); this.Logger.Log("Reconnected to volume"); await this.UpdateScriptsAsync(); if (await this.Client.IsCommandSessionStartedAsync(this.Volume.MountPoint, cancellationToken)) { this.VolumeState = "started"; this.gameCts = new CancellationTokenSource(); await this.Client.ResumeSessionAsync(this.Volume.MountPoint, this.Logger, this.gameCts.Token); } else { this.VolumeState = "mounted"; } }