Skip to content

Commit

Permalink
Merge pull request #85 from faesel/build-fix
Browse files Browse the repository at this point in the history
added code to override location of connection collection
  • Loading branch information
faesel committed Dec 17, 2020
2 parents 3605d2f + 51ffc16 commit c4bfa62
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
5 changes: 2 additions & 3 deletions az-lazy.test/BlobTest/Blob.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System.ComponentModel.DataAnnotations;
using System;
using System.IO;
using System.Reflection;
Expand Down Expand Up @@ -34,7 +33,7 @@ public async Task CanUploadNewBlob()
}
catch (Exception)
{
//Suppress, its most likely becuase the container doesnt exist
//Suppress, its most likely because the container doesnt exist
}
await LocalStorageFixture.AzureContainerManager.CreateContainer(DevStorageConnectionString, PublicAccessType.None, containerName).ConfigureAwait(false);

Expand All @@ -60,7 +59,7 @@ public async Task CanDeleteBlob()
}
catch (Exception)
{
//Suppress, its most likely becuase the container doesnt exist
//Suppress, its most likely because the container doesnt exist
}
await LocalStorageFixture.AzureContainerManager.CreateContainer(DevStorageConnectionString, PublicAccessType.None, containerName).ConfigureAwait(false);

Expand Down
6 changes: 6 additions & 0 deletions az-lazy.test/LocalStorageFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
using az_lazy.Manager;
using az_lazy.Startup;
using Microsoft.Extensions.DependencyInjection;
using System.IO;
using System.Reflection;

namespace az_lazy.test
{
Expand Down Expand Up @@ -37,6 +39,10 @@ public LocalStorageFixture()

//Add development connection to connect to azure storage emulator
LocalStorageManager = ServiceProvider.GetService<ILocalStorageManager>();

string collectionLocation = @$"{Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)}\connections.db";

LocalStorageManager.OverrideCollectionLocation(collectionLocation);
LocalStorageManager.AddDevelopmentConnection();

AzureQueueManager = ServiceProvider.GetService<IAzureQueueManager>();
Expand Down
22 changes: 14 additions & 8 deletions az-lazy/Manager/LocalStorageManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public interface ILocalStorageManager
{
void AddConnection(string connectionName, string connectionString, bool selectConnection = false);
void AddDevelopmentConnection();
void OverrideCollectionLocation(string location);
bool SelectConnection(string connectionName);
bool RemoveConnection(string connectionName);
bool RemoveAllConnections(string connectionName);
Expand All @@ -24,11 +25,16 @@ public class LocalStorageManager : ILocalStorageManager
{
private const string DevConnectionName = "devStorage";
private const string DevConnectionString = "UseDevelopmentStorage=true";
private readonly string ConnectionCollection = @$"{Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)}\.dotnet\tools\.store\az-lazy\connections.db";
private string CollectionLocation = @$"{Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)}\.dotnet\tools\.store\az-lazy\connections.db";

public void OverrideCollectionLocation(string location)
{
CollectionLocation = location;
}

public void AddConnection(string connectionName, string connectionString, bool selectConnection = false)
{
using var db = new LiteDatabase(ConnectionCollection);
using var db = new LiteDatabase(CollectionLocation);
var collection = db.GetCollection<Connection>(nameof(ModelNames.Connection));
var connection = new Connection(connectionName, connectionString);

Expand All @@ -48,7 +54,7 @@ public void AddDevelopmentConnection()
developmentStorage.SetSelected();
developmentStorage.SetDevelopmentStorage();

using var db = new LiteDatabase(ConnectionCollection);
using var db = new LiteDatabase(CollectionLocation);
var collection = db.GetCollection<Connection>(nameof(ModelNames.Connection));

var hasDevelopmentStorage = collection.Query()
Expand All @@ -63,7 +69,7 @@ public void AddDevelopmentConnection()

public List<Connection> GetConnections()
{
using var db = new LiteDatabase(ConnectionCollection);
using var db = new LiteDatabase(CollectionLocation);
var collection = db.GetCollection<Connection>(nameof(ModelNames.Connection));

return collection.Query()
Expand All @@ -72,15 +78,15 @@ public List<Connection> GetConnections()

public Connection GetSelectedConnection()
{
using var db = new LiteDatabase(ConnectionCollection);
using var db = new LiteDatabase(CollectionLocation);
var collection = db.GetCollection<Connection>(nameof(ModelNames.Connection));

return collection.FindOne(x => x.IsSelected);
}

public bool SelectConnection(string connectionName)
{
using var db = new LiteDatabase(ConnectionCollection);
using var db = new LiteDatabase(CollectionLocation);
var collection = db.GetCollection<Connection>(nameof(ModelNames.Connection));

var connectionToSelect = collection.FindOne(x => x.ConnectionName.Equals(connectionName, StringComparison.InvariantCultureIgnoreCase));
Expand All @@ -106,7 +112,7 @@ public bool SelectConnection(string connectionName)

public bool RemoveConnection(string connectionName)
{
using var db = new LiteDatabase(ConnectionCollection);
using var db = new LiteDatabase(CollectionLocation);
var collection = db.GetCollection<Connection>(nameof(ModelNames.Connection));

var connectionToRemove = collection.FindOne(x => x.ConnectionName.Equals(connectionName, StringComparison.InvariantCultureIgnoreCase));
Expand All @@ -123,7 +129,7 @@ public bool RemoveConnection(string connectionName)

public bool RemoveAllConnections(string connectionName)
{
using var db = new LiteDatabase(ConnectionCollection);
using var db = new LiteDatabase(CollectionLocation);
var collection = db.GetCollection<Connection>(nameof(ModelNames.Connection));

var connectionToRemove = collection
Expand Down

0 comments on commit c4bfa62

Please sign in to comment.