Skip to content

Commit d2b6c14

Browse files
authored
[MetricsAdvisor] Updated disposable test types to return whole created model (Azure#21781)
1 parent 729b709 commit d2b6c14

File tree

9 files changed

+96
-116
lines changed

9 files changed

+96
-116
lines changed

sdk/metricsadvisor/Azure.AI.MetricsAdvisor/tests/DisposableAlertConfiguration.cs

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
using System.Threading.Tasks;
66
using Azure.AI.MetricsAdvisor.Administration;
77
using Azure.AI.MetricsAdvisor.Models;
8-
using NUnit.Framework;
98

109
namespace Azure.AI.MetricsAdvisor.Tests
1110
{
@@ -25,39 +24,35 @@ public class DisposableAlertConfiguration : IAsyncDisposable
2524
/// Initializes a new instance of the <see cref="DisposableAlertConfiguration"/> class.
2625
/// </summary>
2726
/// <param name="adminClient">The client to use for deleting the configuration upon disposal.</param>
28-
/// <param name="id">The identifier of the alert configuration this instance is associated with.</param>
29-
private DisposableAlertConfiguration(MetricsAdvisorAdministrationClient adminClient, string id)
27+
/// <param name="configuration">The alert configuration this instance is associated with.</param>
28+
private DisposableAlertConfiguration(MetricsAdvisorAdministrationClient adminClient, AnomalyAlertConfiguration configuration)
3029
{
3130
_adminClient = adminClient;
32-
Id = id;
31+
Configuration = configuration;
3332
}
3433

3534
/// <summary>
36-
/// The identifier of the alert configuration this instance is associated with.
35+
/// The alert configuration this instance is associated with.
3736
/// </summary>
38-
public string Id { get; }
37+
public AnomalyAlertConfiguration Configuration { get; }
3938

4039
/// <summary>
4140
/// Creates an alert configuration using the specified <see cref="MetricsAdvisorAdministrationClient"/>.
42-
/// A <see cref="DisposableAlertConfiguration"/> instance is returned, from which the ID of the created
43-
/// configuration can be obtained. Upon disposal, the associated configuration will be deleted.
41+
/// A <see cref="DisposableAlertConfiguration"/> instance is returned, from which the created configuration
42+
/// can be obtained. Upon disposal, the associated configuration will be deleted.
4443
/// </summary>
4544
/// <param name="adminClient">The client to use for creating and for deleting the configuration.</param>
46-
/// <param name="hook">Specifies how the created <see cref="AnomalyAlertConfiguration"/> should be configured.</param>
47-
/// <returns>A <see cref="DisposableAlertConfiguration"/> instance from which the ID of the created configuration can be obtained.</returns>
45+
/// <param name="configuration">Specifies how the created <see cref="AnomalyAlertConfiguration"/> should be configured.</param>
46+
/// <returns>A <see cref="DisposableAlertConfiguration"/> instance from which the created configuration can be obtained.</returns>
4847
public static async Task<DisposableAlertConfiguration> CreateAlertConfigurationAsync(MetricsAdvisorAdministrationClient adminClient, AnomalyAlertConfiguration alertConfiguration)
4948
{
5049
AnomalyAlertConfiguration createdConfig = await adminClient.CreateAlertConfigurationAsync(alertConfiguration);
51-
52-
Assert.That(createdConfig, Is.Not.Null);
53-
Assert.That(createdConfig.Id, Is.Not.Null.And.Not.Empty);
54-
55-
return new DisposableAlertConfiguration(adminClient, createdConfig.Id);
50+
return new DisposableAlertConfiguration(adminClient, createdConfig);
5651
}
5752

5853
/// <summary>
5954
/// Deletes the configuration this instance is associated with.
6055
/// </summary>
61-
public async ValueTask DisposeAsync() => await _adminClient.DeleteAlertConfigurationAsync(Id);
56+
public async ValueTask DisposeAsync() => await _adminClient.DeleteAlertConfigurationAsync(Configuration.Id);
6257
}
6358
}

sdk/metricsadvisor/Azure.AI.MetricsAdvisor/tests/DisposableDataFeed.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@
55
using System.Threading.Tasks;
66
using Azure.AI.MetricsAdvisor.Administration;
77
using Azure.AI.MetricsAdvisor.Models;
8-
using NUnit.Framework;
98

109
namespace Azure.AI.MetricsAdvisor.Tests
1110
{
1211
/// <summary>
13-
/// Represents a <see cref="DataFeed"/> that has been created for testing purposes. In order to
12+
/// Represents a <see cref="Models.DataFeed"/> that has been created for testing purposes. In order to
1413
/// create a new instance of this class, the <see cref="CreateDataFeedAsync"/> static method must
1514
/// be invoked. The created data feed will be deleted upon disposal.
1615
/// </summary>

sdk/metricsadvisor/Azure.AI.MetricsAdvisor/tests/DisposableDatasourceCredential.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
using System.Threading.Tasks;
66
using Azure.AI.MetricsAdvisor.Administration;
77
using Azure.AI.MetricsAdvisor.Models;
8-
using NUnit.Framework;
98

109
namespace Azure.AI.MetricsAdvisor.Tests
1110
{
@@ -48,10 +47,6 @@ private DisposableDatasourceCredential(MetricsAdvisorAdministrationClient adminC
4847
public static async Task<DisposableDatasourceCredential> CreateDatasourceCredentialAsync(MetricsAdvisorAdministrationClient adminClient, DatasourceCredential credential)
4948
{
5049
DatasourceCredential createdCredential = await adminClient.CreateDatasourceCredentialAsync(credential);
51-
52-
Assert.That(createdCredential, Is.Not.Null);
53-
Assert.That(createdCredential.Id, Is.Not.Null.And.Not.Empty);
54-
5550
return new DisposableDatasourceCredential(adminClient, createdCredential);
5651
}
5752

sdk/metricsadvisor/Azure.AI.MetricsAdvisor/tests/DisposableDetectionConfiguration.cs

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
using System.Threading.Tasks;
66
using Azure.AI.MetricsAdvisor.Administration;
77
using Azure.AI.MetricsAdvisor.Models;
8-
using NUnit.Framework;
98

109
namespace Azure.AI.MetricsAdvisor.Tests
1110
{
@@ -25,39 +24,35 @@ public class DisposableDetectionConfiguration : IAsyncDisposable
2524
/// Initializes a new instance of the <see cref="DisposableDetectionConfiguration"/> class.
2625
/// </summary>
2726
/// <param name="adminClient">The client to use for deleting the configuration upon disposal.</param>
28-
/// <param name="id">The identifier of the detection configuration this instance is associated with.</param>
29-
private DisposableDetectionConfiguration(MetricsAdvisorAdministrationClient adminClient, string id)
27+
/// <param name="configuration">The detection configuration this instance is associated with.</param>
28+
private DisposableDetectionConfiguration(MetricsAdvisorAdministrationClient adminClient, AnomalyDetectionConfiguration configuration)
3029
{
3130
_adminClient = adminClient;
32-
Id = id;
31+
Configuration = configuration;
3332
}
3433

3534
/// <summary>
36-
/// The identifier of the detection configuration this instance is associated with.
35+
/// The detection configuration this instance is associated with.
3736
/// </summary>
38-
public string Id { get; }
37+
public AnomalyDetectionConfiguration Configuration { get; }
3938

4039
/// <summary>
4140
/// Creates a detection configuration using the specified <see cref="MetricsAdvisorAdministrationClient"/>.
42-
/// A <see cref="DisposableDetectionConfiguration"/> instance is returned, from which the ID of the created
43-
/// configuration can be obtained. Upon disposal, the associated configuration will be deleted.
41+
/// A <see cref="DisposableDetectionConfiguration"/> instance is returned, from which the created configuration
42+
/// can be obtained. Upon disposal, the associated configuration will be deleted.
4443
/// </summary>
4544
/// <param name="adminClient">The client to use for creating and for deleting the configuration.</param>
46-
/// <param name="hook">Specifies how the created <see cref="AnomalyDetectionConfiguration"/> should be configured.</param>
47-
/// <returns>A <see cref="DisposableDetectionConfiguration"/> instance from which the ID of the created configuration can be obtained.</returns>
48-
public static async Task<DisposableDetectionConfiguration> CreateDetectionConfigurationAsync(MetricsAdvisorAdministrationClient adminClient, AnomalyDetectionConfiguration detectionConfiguration)
45+
/// <param name="configuration">Specifies how the created <see cref="AnomalyDetectionConfiguration"/> should be configured.</param>
46+
/// <returns>A <see cref="DisposableDetectionConfiguration"/> instance from which the created configuration can be obtained.</returns>
47+
public static async Task<DisposableDetectionConfiguration> CreateDetectionConfigurationAsync(MetricsAdvisorAdministrationClient adminClient, AnomalyDetectionConfiguration configuration)
4948
{
50-
AnomalyDetectionConfiguration createdConfig = await adminClient.CreateDetectionConfigurationAsync(detectionConfiguration);
51-
52-
Assert.That(createdConfig, Is.Not.Null);
53-
Assert.That(createdConfig.Id, Is.Not.Null.And.Not.Empty);
54-
55-
return new DisposableDetectionConfiguration(adminClient, createdConfig.Id);
49+
AnomalyDetectionConfiguration createdConfig = await adminClient.CreateDetectionConfigurationAsync(configuration);
50+
return new DisposableDetectionConfiguration(adminClient, createdConfig);
5651
}
5752

5853
/// <summary>
5954
/// Deletes the configuration this instance is associated with.
6055
/// </summary>
61-
public async ValueTask DisposeAsync() => await _adminClient.DeleteDetectionConfigurationAsync(Id);
56+
public async ValueTask DisposeAsync() => await _adminClient.DeleteDetectionConfigurationAsync(Configuration.Id);
6257
}
6358
}

sdk/metricsadvisor/Azure.AI.MetricsAdvisor/tests/DisposableNotificationHook.cs

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
using System.Threading.Tasks;
66
using Azure.AI.MetricsAdvisor.Administration;
77
using Azure.AI.MetricsAdvisor.Models;
8-
using NUnit.Framework;
98

109
namespace Azure.AI.MetricsAdvisor.Tests
1110
{
@@ -25,39 +24,35 @@ public class DisposableNotificationHook : IAsyncDisposable
2524
/// Initializes a new instance of the <see cref="DisposableNotificationHook"/> class.
2625
/// </summary>
2726
/// <param name="adminClient">The client to use for deleting the hook upon disposal.</param>
28-
/// <param name="id">The identifier of the hook this instance is associated with.</param>
29-
private DisposableNotificationHook(MetricsAdvisorAdministrationClient adminClient, string id)
27+
/// <param name="hook">The hook this instance is associated with.</param>
28+
private DisposableNotificationHook(MetricsAdvisorAdministrationClient adminClient, NotificationHook hook)
3029
{
3130
_adminClient = adminClient;
32-
Id = id;
31+
Hook = hook;
3332
}
3433

3534
/// <summary>
36-
/// The identifier of the hook this instance is associated with.
35+
/// The hook this instance is associated with.
3736
/// </summary>
38-
public string Id { get; }
37+
public NotificationHook Hook { get; }
3938

4039
/// <summary>
4140
/// Creates a hook using the specified <see cref="MetricsAdvisorAdministrationClient"/>. A
42-
/// <see cref="DisposableNotificationHook"/> instance is returned, from which the ID of the
43-
/// created hook can be obtained. Upon disposal, the associated hook will be deleted.
41+
/// <see cref="DisposableNotificationHook"/> instance is returned, from which the created
42+
/// hook can be obtained. Upon disposal, the associated hook will be deleted.
4443
/// </summary>
4544
/// <param name="adminClient">The client to use for creating and for deleting the hook.</param>
4645
/// <param name="hook">Specifies how the created <see cref="NotificationHook"/> should be configured.</param>
47-
/// <returns>A <see cref="DisposableNotificationHook"/> instance from which the ID of the created hook can be obtained.</returns>
46+
/// <returns>A <see cref="DisposableNotificationHook"/> instance from which the created hook can be obtained.</returns>
4847
public static async Task<DisposableNotificationHook> CreateHookAsync(MetricsAdvisorAdministrationClient adminClient, NotificationHook hook)
4948
{
5049
NotificationHook createdHook = await adminClient.CreateHookAsync(hook);
51-
52-
Assert.That(createdHook, Is.Not.Null);
53-
Assert.That(createdHook.Id, Is.Not.Null.And.Not.Empty);
54-
55-
return new DisposableNotificationHook(adminClient, createdHook.Id);
50+
return new DisposableNotificationHook(adminClient, createdHook);
5651
}
5752

5853
/// <summary>
5954
/// Deletes the hook this instance is associated with.
6055
/// </summary>
61-
public async ValueTask DisposeAsync() => await _adminClient.DeleteHookAsync(Id);
56+
public async ValueTask DisposeAsync() => await _adminClient.DeleteHookAsync(Hook.Id);
6257
}
6358
}

0 commit comments

Comments
 (0)