mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-14 01:25:40 -05:00
* Enabled backup to and restore from URL * Created RPC, but when process tries to load Microsoft.Azure.Storage.Blob.dll, it crashes * Added create shared access token * Code refactor * Minor changes * Changed RPC path * Moved createSas RPC to the newly created BlobService, fixed PR comments * Added sas expiration date parameter to the RPC * Added copyright headers * Removed ConnectionInstance property from BlobService * Removed unhelpful comment * Removed unused using statements * Changed copy/paste comments * Disposable objects fix * Small formatting fix * Changed backup to/restore from url supported device types * Added backup to url integration test * Created restore integration test. Test are now getting azure blob params from env variables instead of file. * Culture invariant epiration date param, fixed comment, and typo * Updated headers * PR comments fix * Changed supported device type logic * string localization fix * String formatting fix * build failure fix * Typo * Updated supported restore device types
42 lines
1.9 KiB
C#
42 lines
1.9 KiB
C#
//
|
|
// Copyright (c) Microsoft. All rights reserved.
|
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
//
|
|
|
|
using System;
|
|
using Moq;
|
|
using NUnit.Framework;
|
|
using Azure.Storage.Blobs;
|
|
using Microsoft.SqlTools.ServiceLayer.AzureBlob;
|
|
using Microsoft.SqlServer.Management.Smo;
|
|
using Azure.Storage.Sas;
|
|
|
|
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.DisasterRecovery
|
|
{
|
|
class SharedAccessSignatureCreatorTests
|
|
{
|
|
[Test]
|
|
public void GetServiceSasUriForContainerReturnsNullWhenCannotGenerateSasUri()
|
|
{
|
|
var mockBlobContainerClient = new Mock<BlobContainerClient>();
|
|
mockBlobContainerClient.Setup(x => x.CanGenerateSasUri).Returns(false);
|
|
var mockServer = new Server();
|
|
SharedAccessSignatureCreator sharedAccessSignatureCreator = new SharedAccessSignatureCreator(mockServer);
|
|
Assert.Throws<FailedOperationException>(() => sharedAccessSignatureCreator.GetServiceSasUriForContainer(mockBlobContainerClient.Object));
|
|
}
|
|
|
|
[Test]
|
|
public void GetServiceSasUriForContainerReturnsSasUri()
|
|
{
|
|
Uri sharedAccessSignatureUriMock = new Uri("https://azureblob/mocked-shared-access-signature");
|
|
var mockBlobContainerClient = new Mock<BlobContainerClient>();
|
|
mockBlobContainerClient.Setup(x => x.CanGenerateSasUri).Returns(true);
|
|
mockBlobContainerClient.Setup(x => x.GenerateSasUri(It.IsAny<BlobSasBuilder>())).Returns(sharedAccessSignatureUriMock);
|
|
var mockServer = new Server();
|
|
SharedAccessSignatureCreator sharedAccessSignatureCreator = new SharedAccessSignatureCreator(mockServer);
|
|
Uri result = sharedAccessSignatureCreator.GetServiceSasUriForContainer(mockBlobContainerClient.Object);
|
|
Assert.AreEqual(result, sharedAccessSignatureUriMock);
|
|
}
|
|
}
|
|
}
|