public async Task Models_Lifecycle() { DigitalTwinsClient client = GetClient(); string buildingModelId = await GetUniqueModelIdAsync(client, TestAssetDefaults.BuildingModelId).ConfigureAwait(false); string floorModelId = await GetUniqueModelIdAsync(client, TestAssetDefaults.FloorModelId).ConfigureAwait(false); string hvacModelId = await GetUniqueModelIdAsync(client, TestAssetDefaults.HvacModelId).ConfigureAwait(false); string wardModelId = await GetUniqueModelIdAsync(client, TestAssetDefaults.WardModelId).ConfigureAwait(false); try { string modelBuilding = TestAssetsHelper.GetBuildingModelPayload(buildingModelId, hvacModelId, floorModelId); string modelHvac = TestAssetsHelper.GetHvacModelPayload(hvacModelId, floorModelId); string modelWard = TestAssetsHelper.GetWardModelPayload(wardModelId); // CREATE models var modelsList = new List <string> { modelBuilding, modelHvac, modelWard }; await CreateAndListModelsAsync(client, modelsList).ConfigureAwait(false); // GET one created model Response <DigitalTwinsModelData> buildingModel = await client.GetModelAsync(buildingModelId).ConfigureAwait(false); Console.WriteLine($"Got {buildingModelId} as {buildingModel.Value.DtdlModel}"); // LIST all models AsyncPageable <DigitalTwinsModelData> models = client.GetModelsAsync(); await foreach (DigitalTwinsModelData model in models) { Console.WriteLine($"{model.Id}"); } // DECOMMISSION a model await client.DecommissionModelAsync(buildingModelId).ConfigureAwait(false); } catch (Exception ex) { Assert.Fail($"Failure in executing a step in the test case: {ex.Message}."); } finally { // Test DELETE all models. try { await client.DeleteModelAsync(buildingModelId).ConfigureAwait(false); await client.DeleteModelAsync(hvacModelId).ConfigureAwait(false); await client.DeleteModelAsync(wardModelId).ConfigureAwait(false); } catch (Exception ex) { Assert.Fail($"Test clean up failed: {ex.Message}"); } } }
public async Task ModelData_DisplayNameAndDescription_Deserializes() { // arrange DigitalTwinsClient client = GetClient(); string wardModelId = await GetUniqueModelIdAsync(client, TestAssetDefaults.WardModelId).ConfigureAwait(false); // add a model with a single value for displayName and for description, neither of which were defined as a map string modelWard = TestAssetsHelper.GetWardModelPayload(wardModelId); await client.CreateModelsAsync(new[] { modelWard }).ConfigureAwait(false); // act // should not throw on deserialization Response <DigitalTwinsModelData> wardModel = await client.GetModelAsync(wardModelId).ConfigureAwait(false); // assert wardModel.Value.DisplayName.Count.Should().Be(1, "Should have 1 entry for display name"); wardModel.Value.DisplayName.Keys.First().Should().Be("en"); }
public async Task Models_ModelAlreadyExists_ThrowsConflictException() { // arrange DigitalTwinsClient client = GetClient(); string wardModelId = await GetUniqueModelIdAsync(client, TestAssetDefaults.WardModelId).ConfigureAwait(false); string modelWard = TestAssetsHelper.GetWardModelPayload(wardModelId); var modelsList = new List <string> { modelWard }; // Create model once await client.CreateModelsAsync(modelsList).ConfigureAwait(false); // act Func <Task> act = async() => await client.CreateModelsAsync(modelsList).ConfigureAwait(false); // assert act.Should().Throw <RequestFailedException>() .And.Status.Should().Be((int)HttpStatusCode.Conflict); }