Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Azure Cloud storage #64

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"sdk": {
"version": "3.0.100"
"version": "3.1.401"
}
}
76 changes: 33 additions & 43 deletions src/AzureCloud/AzureResource.cs
Original file line number Diff line number Diff line change
@@ -1,47 +1,37 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using Xunit;
using Xunit.Abstractions;

namespace Squadron.AzureCloud
{
/// <summary>
/// Base class to use with Azure Cloud resources
/// </summary>
/// <typeparam name="TOptions"></typeparam>
public class AzureResource<TOptions>
where TOptions : AzureResourceOptions, new()
{
/// <summary>
/// Azure configuration to work with Azure management api
/// </summary>
protected AzureResourceConfiguration AzureConfig { get; private set; }

/// <summary>
/// Initialize the resource
/// </summary>
/// <returns></returns>
public virtual Task InitializeAsync()
{
//var options = new TOptions();
//AzureResourceOptionsBuilder builder = new AzureResourceOptionsBuilder();
//AzureResourceOptions options = builder.Build();
//AzureConfig = options.ConfigResolver();
Trace.WriteLine("Loading Azure Configuration");
return Task.CompletedTask;
}

using System.Diagnostics;
using System.Threading.Tasks;

namespace Squadron.AzureCloud
{
/// <summary>
/// Base class to use with Azure Cloud resources
/// </summary>
/// <typeparam name="TOptions"></typeparam>
public class AzureResource<TOptions>
where TOptions : AzureResourceOptions, new()
{
/// <summary>
/// Azure configuration to work with Azure management api
/// </summary>
protected AzureResourceConfiguration AzureConfig { get; private set; }

/// <summary>
/// Initialize the resource
/// </summary>
/// <returns></returns>
public virtual Task InitializeAsync()
{
Trace.WriteLine("Loading Azure Configuration");
return Task.CompletedTask;
}

/// <summary>
/// Loads the azure resource configuration.
/// </summary>
/// <param name="builder">The builder.</param>
protected void LoadResourceConfiguration(AzureResourceOptionsBuilder builder)
{
AzureConfig = builder.ConfigResolver();
}
}
}
protected void LoadResourceConfiguration(AzureResourceOptionsBuilder builder)
{
AzureConfig = builder.ConfigResolver();
}
}
}
31 changes: 15 additions & 16 deletions src/AzureCloud/AzureResourceIdentifier.cs
Original file line number Diff line number Diff line change
@@ -1,37 +1,36 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace Squadron.AzureCloud
{
using System;
using System.Collections.Generic;
using System.Text;
namespace Squadron.AzureCloud
{
/// <summary>
/// Azure resource identifier
/// </summary>
public class AzureResourceIdentifier
{
public class AzureResourceIdentifier
{
/// <summary>
/// Gets or sets the Azure subscriptionId.
/// </summary>
/// <value>
/// The subscriptionId.
/// </value>
public string SubscriptionId { get; set; }

public string SubscriptionId { get; set; }
/// <summary>
/// Gets or sets the name of the resource group.
/// </summary>
/// <value>
/// The name of the resource group.
/// </value>
public string ResourceGroupName { get; set; }


public string ResourceGroupName { get; set; }

/// <summary>
/// Gets or sets the name of the resource
/// </summary>
/// <value>
/// The name.
/// </value>
public string Name { get; set; }
}
}
public string Name { get; set; }
}
}
22 changes: 22 additions & 0 deletions src/AzureCloud/Model/AzureResourceProvisioningMode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace Squadron.AzureCloud
{
/// <summary>
/// Defines ServiceBUs provisioning modes
/// </summary>
public enum AzureResourceProvisioningMode
{
/// <summary>
/// Use an existing Azure resource
/// </summary>
UseExisting,

/// <summary>
/// Provision and delete resource
/// </summary>
CreateAndDelete
}
}
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
using System;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Azure.ServiceBus;
using Xunit;
using Xunit.Abstractions;

namespace Squadron.AzureServiceBus.Tests
{
public class AzureExistingServiceBusResourceTests
: IClassFixture<AzureCloudServiceBusResource<TestExistingNamespaceAzureServiceBusOptions>>
{
private readonly AzureCloudServiceBusResource<TestExistingNamespaceAzureServiceBusOptions> _resource;

public AzureExistingServiceBusResourceTests(
AzureCloudServiceBusResource<TestExistingNamespaceAzureServiceBusOptions> resource,
ITestOutputHelper outputHelper)
{
_resource = resource;
}


[Fact( Skip ="Can not run without Azure credentials")]
public async Task PrepareAzureServiceBusResource_ExistingNamespace_NoError()
{
ITopicClient topicClient = _resource.GetTopicClient("foo");
ISubscriptionClient subscriptionClient =
_resource.GetSubscriptionClient("foo", "test1");

IQueueClient queueClient = _resource.GetQueueClient("bar");

//subscriptionClient.RegisterMessageHandler()

await topicClient.SendAsync(new Message(Encoding.UTF8.GetBytes("Hello")));

ITopicClient newTopic = await _resource.CreateTopicAsync(b => b
.Name("adhoc")
.AddSubscription("test1"));
}
}
}
using System.Text;
using System.Threading.Tasks;
using Microsoft.Azure.ServiceBus;
using Xunit;
using Xunit.Abstractions;
namespace Squadron.AzureServiceBus.Tests
{
public class AzureExistingServiceBusResourceTests
: IClassFixture<AzureCloudServiceBusResource<TestExistingNamespaceAzureServiceBusOptions>>
{
private readonly AzureCloudServiceBusResource<TestExistingNamespaceAzureServiceBusOptions> _resource;
public AzureExistingServiceBusResourceTests(
AzureCloudServiceBusResource<TestExistingNamespaceAzureServiceBusOptions> resource,
ITestOutputHelper outputHelper)
{
_resource = resource;
}
[Fact( Skip ="Can not run without Azure credentials")]
public async Task PrepareAzureServiceBusResource_ExistingNamespace_NoError()
{
ITopicClient topicClient = _resource.GetTopicClient("foo");
ISubscriptionClient subscriptionClient =
_resource.GetSubscriptionClient("foo", "test1");
IQueueClient queueClient = _resource.GetQueueClient("bar");
//subscriptionClient.RegisterMessageHandler()
await topicClient.SendAsync(new Message(Encoding.UTF8.GetBytes("Hello")));
ITopicClient newTopic = await _resource.CreateTopicAsync(b => b
.Name("adhoc")
.AddSubscription("test1"));
}
}
}
43 changes: 21 additions & 22 deletions src/AzureCloudServiceBus.Tests/AzureNewServiceBusResourceTests.cs
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@
using System.Text;
using System.Threading.Tasks;
using Microsoft.Azure.ServiceBus;
using Xunit;

using System.Threading.Tasks;
using Microsoft.Azure.ServiceBus;
using Xunit;
namespace Squadron.AzureServiceBus.Tests
{
public class AzureNewServiceBusResourceTests
public class AzureNewServiceBusResourceTests
: IClassFixture<AzureCloudServiceBusResource<TestNewNamespaceAzureServiceBusOptions>>
{
private readonly AzureCloudServiceBusResource<TestNewNamespaceAzureServiceBusOptions> _resource;

public AzureNewServiceBusResourceTests(
AzureCloudServiceBusResource<TestNewNamespaceAzureServiceBusOptions> resource)
{
_resource = resource;
}


[Fact(Skip = "Can not run without Azure credentials")]
public async Task PrepareAzureServiceBusResource_NewNamespace_NoError()
{
ITopicClient topicClient = _resource.GetTopicClient("foo");
await topicClient.SendAsync(new Message(Encoding.UTF8.GetBytes("Hello")));
IQueueClient queueClient = _resource.GetQueueClient("bar");
}
{
private readonly AzureCloudServiceBusResource<TestNewNamespaceAzureServiceBusOptions> _resource;

public AzureNewServiceBusResourceTests(
AzureCloudServiceBusResource<TestNewNamespaceAzureServiceBusOptions> resource)
{
_resource = resource;
}

[Fact(Skip = "Can not run without Azure credentials")]
public async Task PrepareAzureServiceBusResource_NewNamespace_NoError()
{
ITopicClient topicClient = _resource.GetTopicClient("foo");
await topicClient.SendAsync(new Message(Encoding.UTF8.GetBytes("Hello")));
IQueueClient queueClient = _resource.GetQueueClient("bar");
}
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
using System;

namespace Squadron.AzureServiceBus.Tests
{
public class TestExistingNamespaceAzureServiceBusOptions : AzureCloudServiceBusOptions
{
public override void Configure(ServiceBusOptionsBuilder builder)
{
builder.Namespace("spc-a-squadron-sb01")
.AddTopic("foo")
.AddSubscription("test1", "EventType = 'test1'");
builder.AddQueue("bar");
}
}
}
namespace Squadron.AzureServiceBus.Tests
{
public class TestExistingNamespaceAzureServiceBusOptions : AzureCloudServiceBusOptions
{
public override void Configure(ServiceBusOptionsBuilder builder)
{
builder.Namespace("spc-a-squadron-sb01")
.AddTopic("foo")
.AddSubscription("test1", "EventType = 'test1'");
builder.AddQueue("bar");
}
}
}
27 changes: 13 additions & 14 deletions src/AzureCloudServiceBus/AzureCloudServiceBusOptions.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Extensions.Configuration;
using Squadron.AzureCloud;

namespace Squadron
{
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Extensions.Configuration;
using Squadron.AzureCloud;
namespace Squadron
{
/// <summary>
/// ServiceBus resources options
/// </summary>
/// <seealso cref="Squadron.AzureCloud.AzureResourceOptions" />
public abstract class AzureCloudServiceBusOptions : AzureResourceOptions
{
public abstract class AzureCloudServiceBusOptions : AzureResourceOptions
{
/// <summary>
/// Configures the ServiceBus
/// </summary>
/// <param name="builder">The builder.</param>
public abstract void Configure(ServiceBusOptionsBuilder builder);

}
}
public abstract void Configure(ServiceBusOptionsBuilder builder);
}
}
Loading