Skip to content
This repository was archived by the owner on Jul 30, 2024. It is now read-only.
/ NuGet.Jobs Public archive

Commit

Permalink
Merge pull request #132 from NuGet/dev
Browse files Browse the repository at this point in the history
Merge dev to master
  • Loading branch information
cristinamanum authored Mar 2, 2017
2 parents c384ad0 + 2eebd82 commit d1a3946
Show file tree
Hide file tree
Showing 7 changed files with 185 additions and 9 deletions.
2 changes: 2 additions & 0 deletions src/Catalog/Persistence/AzureStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,15 @@ protected override async Task OnSave(Uri resourceUri, StorageContent content, Ca

destinationStream.Seek(0, SeekOrigin.Begin);
await blob.UploadFromStreamAsync(destinationStream, cancellationToken);
Trace.WriteLine(String.Format("Saved compressed blob {0} to container {1}", blob.Uri.ToString(), _directory.Container.Name));
}
}
else
{
using (Stream stream = content.GetContentStream())
{
await blob.UploadFromStreamAsync(stream, cancellationToken);
Trace.WriteLine(String.Format("Saved uncompressed blob {0} to container {1}", blob.Uri.ToString(), _directory.Container.Name));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Ng/Arguments.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Ng
{
static class Arguments
public static class Arguments
{

#region Shared
Expand Down
14 changes: 9 additions & 5 deletions src/Ng/CommandHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public static StorageFactory CreateStorageFactory(IDictionary<string, string> ar
{ Arguments.StoragePath, Arguments.StoragePath }
};

return CreateStorageFactoryImpl(arguments, names, verbose);
return CreateStorageFactoryImpl(arguments, names, verbose, compressed: false);
}

public static StorageFactory CreateCompressedStorageFactory(IDictionary<string, string> arguments, bool verbose)
Expand All @@ -105,7 +105,7 @@ public static StorageFactory CreateCompressedStorageFactory(IDictionary<string,
{ Arguments.StoragePath, Arguments.CompressedStoragePath }
};

return CreateStorageFactoryImpl(arguments, names, verbose);
return CreateStorageFactoryImpl(arguments, names, verbose, compressed: true);
}

public static StorageFactory CreateSuffixedStorageFactory(string suffix, IDictionary<string, string> arguments, bool verbose)
Expand All @@ -124,10 +124,13 @@ public static StorageFactory CreateSuffixedStorageFactory(string suffix, IDictio
{ Arguments.StoragePath, Arguments.StoragePath + suffix }
};

return CreateStorageFactoryImpl(arguments, names, verbose);
return CreateStorageFactoryImpl(arguments, names, verbose, compressed: false);
}

private static StorageFactory CreateStorageFactoryImpl(IDictionary<string, string> arguments, IDictionary<string, string> argumentNameMap, bool verbose)
private static StorageFactory CreateStorageFactoryImpl(IDictionary<string, string> arguments,
IDictionary<string, string> argumentNameMap,
bool verbose,
bool compressed)
{
Uri storageBaseAddress = null;
var storageBaseAddressStr = arguments.GetOrDefault<string>(argumentNameMap[Arguments.StorageBaseAddress]);
Expand Down Expand Up @@ -162,7 +165,8 @@ private static StorageFactory CreateStorageFactoryImpl(IDictionary<string, strin

var credentials = new StorageCredentials(storageAccountName, storageKeyValue);
var account = new CloudStorageAccount(credentials, true);
return new AzureStorageFactory(account, storageContainer, storagePath, storageBaseAddress) { Verbose = verbose };
return new AzureStorageFactory(account, storageContainer, storagePath, storageBaseAddress)
{ Verbose = verbose, CompressContent = compressed };
}

throw new ArgumentException($"Unrecognized storageType \"{storageType}\"");
Expand Down
56 changes: 56 additions & 0 deletions tests/NgTests/NgTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,45 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Hyak.Common, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\packages\Hyak.Common.1.0.2\lib\net45\Hyak.Common.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Azure.Common, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.Azure.Common.2.0.4\lib\net45\Microsoft.Azure.Common.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Azure.Common.NetFramework, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.Azure.Common.2.0.4\lib\net45\Microsoft.Azure.Common.NetFramework.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Azure.KeyVault, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.Azure.KeyVault.1.0.0\lib\net45\Microsoft.Azure.KeyVault.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Extensions.Configuration, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.Extensions.Configuration.1.0.0\lib\netstandard1.1\Microsoft.Extensions.Configuration.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Extensions.Configuration.Abstractions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.Extensions.Configuration.Abstractions.1.0.0\lib\netstandard1.0\Microsoft.Extensions.Configuration.Abstractions.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Extensions.Configuration.FileExtensions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.Extensions.Configuration.FileExtensions.1.0.0\lib\net451\Microsoft.Extensions.Configuration.FileExtensions.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Extensions.Configuration.Json, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.Extensions.Configuration.Json.1.0.0\lib\net451\Microsoft.Extensions.Configuration.Json.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Extensions.DependencyInjection.Abstractions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.Extensions.DependencyInjection.Abstractions.1.0.0\lib\netstandard1.0\Microsoft.Extensions.DependencyInjection.Abstractions.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Extensions.FileProviders.Abstractions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.Extensions.FileProviders.Abstractions.1.0.0\lib\netstandard1.0\Microsoft.Extensions.FileProviders.Abstractions.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Extensions.FileProviders.Physical, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.Extensions.FileProviders.Physical.1.0.0\lib\net451\Microsoft.Extensions.FileProviders.Physical.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Extensions.FileSystemGlobbing, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.Extensions.FileSystemGlobbing.1.0.0\lib\net451\Microsoft.Extensions.FileSystemGlobbing.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Extensions.Logging, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.Extensions.Logging.1.0.0\lib\netstandard1.1\Microsoft.Extensions.Logging.dll</HintPath>
<Private>True</Private>
Expand All @@ -46,6 +81,15 @@
<HintPath>..\..\packages\Microsoft.Extensions.Logging.Abstractions.1.0.0\lib\netstandard1.1\Microsoft.Extensions.Logging.Abstractions.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Extensions.Primitives, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.Extensions.Primitives.1.0.0\lib\netstandard1.0\Microsoft.Extensions.Primitives.dll</HintPath>
</Reference>
<Reference Include="Microsoft.IdentityModel.Clients.ActiveDirectory, Version=3.13.5.907, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.3.13.5\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.dll</HintPath>
</Reference>
<Reference Include="Microsoft.IdentityModel.Clients.ActiveDirectory.Platform, Version=3.13.5.907, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.3.13.5\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.Platform.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Threading.Tasks, Version=1.0.12.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.dll</HintPath>
<Private>True</Private>
Expand All @@ -58,7 +102,18 @@
<HintPath>..\..\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.Extensions.Desktop.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="NuGet.Services.Configuration, Version=1.0.75.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\NuGet.Services.Configuration.1.0.75-r-develop\lib\net452\NuGet.Services.Configuration.dll</HintPath>
</Reference>
<Reference Include="NuGet.Services.KeyVault, Version=1.0.75.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\NuGet.Services.KeyVault.1.0.75-r-develop\lib\net45\NuGet.Services.KeyVault.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.ComponentModel.Composition" />
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System.Core" />
<Reference Include="System.Net" />
<Reference Include="System.Net.Http.Extensions, Version=2.2.29.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
Expand Down Expand Up @@ -113,6 +168,7 @@
<Compile Include="Infrastructure\ODataPackage.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="RegistrationCollectorTests.cs" />
<Compile Include="StorageFactoryTests.cs" />
<Compile Include="TestableFeed2CatalogJob.cs" />
<Compile Include="Data\TestCatalogEntries.Designer.cs">
<AutoGen>True</AutoGen>
Expand Down
95 changes: 95 additions & 0 deletions tests/NgTests/StorageFactoryTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System.Collections.Generic;
using System.ComponentModel;
using Ng;
using NuGet.Services.Metadata.Catalog.Persistence;
using Xunit;

namespace NgTests
{
public class StorageFactoryTests
{
[Theory]
[Description("The azure commpressed factory should compress the content.")]
[InlineData("http://localhost/reg", "testAccount", "ZiWrbTMNTApZxLeWB7a0yN52gJj+ZlGE0ipRi9PaTcn9AU4epwvsngE5rLSMk9TwpazxUtzeyBnFeWFAhfkGpw==", "testContainer", "testStoragePath", "azure")]
public void AzureCommpressedFactory(string storageBaseAddress,
string storageAccountName,
string storageKeyValue,
string storageContainer,
string storagePath,
string storageType)
{
Dictionary<string, string> arguments = new Dictionary<string, string>()
{
{ Arguments.CompressedStorageBaseAddress, storageBaseAddress },
{ Arguments.CompressedStorageAccountName, storageAccountName },
{ Arguments.CompressedStorageKeyValue, storageKeyValue },
{ Arguments.CompressedStorageContainer, storageContainer },
{ Arguments.CompressedStoragePath, storagePath },
{ Arguments.StorageType, storageType},
{ Arguments.UseCompressedStorage, "true"}
};

StorageFactory factory = CommandHelpers.CreateCompressedStorageFactory(arguments, true);
AzureStorageFactory azureFactory = factory as AzureStorageFactory;
// Assert
Assert.True(azureFactory!=null, "The CreateCompressedStorageFactory should return an AzureStorageFactory.");
Assert.True(azureFactory.CompressContent, "The compressed storage factory should compress the content.");
}

[Theory]
[Description("The azure commpressed factory will be null if the UseCompressedStorage is false.")]
[InlineData("http://localhost/reg", "testAccount", "ZiWrbTMNTApZxLeWB7a0yN52gJj+ZlGE0ipRi9PaTcn9AU4epwvsngE5rLSMk9TwpazxUtzeyBnFeWFAhfkGpw==", "testContainer", "testStoragePath", "azure")]
public void AzureCommpressedFactoryNull(string storageBaseAddress,
string storageAccountName,
string storageKeyValue,
string storageContainer,
string storagePath,
string storageType)
{
Dictionary<string, string> arguments = new Dictionary<string, string>()
{
{ Arguments.CompressedStorageBaseAddress, storageBaseAddress },
{ Arguments.CompressedStorageAccountName, storageAccountName },
{ Arguments.CompressedStorageKeyValue, storageKeyValue },
{ Arguments.CompressedStorageContainer, storageContainer },
{ Arguments.CompressedStoragePath, storagePath },
{ Arguments.StorageType, storageType},
{ Arguments.UseCompressedStorage, "false"}
};

StorageFactory factory = CommandHelpers.CreateCompressedStorageFactory(arguments, true);
// Assert
Assert.True(factory == null, "The CompressedStorageFactory should be null when the UseCompressedStorage is false.");
}

[Theory]
[Description("The regular azure factory should not compress the content if.")]
[InlineData("http://localhost/reg", "testAccount", "ZiWrbTMNTApZxLeWB7a0yN52gJj+ZlGE0ipRi9PaTcn9AU4epwvsngE5rLSMk9TwpazxUtzeyBnFeWFAhfkGpw==", "testContainer", "testStoragePath", "azure")]
public void AzureFactory(string storageBaseAddress,
string storageAccountName,
string storageKeyValue,
string storageContainer,
string storagePath,
string storageType)
{
Dictionary<string, string> arguments = new Dictionary<string, string>()
{
{ Arguments.StorageBaseAddress, storageBaseAddress },
{ Arguments.StorageAccountName, storageAccountName },
{ Arguments.StorageKeyValue, storageKeyValue },
{ Arguments.StorageContainer, storageContainer },
{ Arguments.StoragePath, storagePath },
{ Arguments.StorageType, storageType}
};

StorageFactory factory = CommandHelpers.CreateStorageFactory(arguments, true);
AzureStorageFactory azureFactory = factory as AzureStorageFactory;
// Assert
Assert.True(azureFactory != null, "The CreateCompressedStorageFactory should return an AzureStorageFactory type.");
Assert.False(azureFactory.CompressContent, "The azure storage factory should not compress the content.");
}
}
}
7 changes: 4 additions & 3 deletions tests/NgTests/app.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
Expand All @@ -8,6 +8,7 @@
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Data.Edm" publicKeyToken="31bf3856ad364e35" culture="neutral"/>

<bindingRedirect oldVersion="0.0.0.0-5.6.4.0" newVersion="5.6.4.0"/>
</dependentAssembly>
<dependentAssembly>
Expand Down Expand Up @@ -59,8 +60,8 @@
<bindingRedirect oldVersion="0.0.0.0-3.5.0.0" newVersion="3.5.0.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="xunit.core" publicKeyToken="8d05b1bb7a6fdb6c" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-2.1.0.3179" newVersion="2.1.0.3179"/>
<assemblyIdentity name="xunit.core" publicKeyToken="8d05b1bb7a6fdb6c" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.1.0.3179" newVersion="2.1.0.3179" />
</dependentAssembly>
</assemblyBinding>
</runtime>
Expand Down
Loading

0 comments on commit d1a3946

Please sign in to comment.