diff --git a/NuGet.Config b/NuGet.Config index 7254bc10808fe..74f5935bb8363 100644 --- a/NuGet.Config +++ b/NuGet.Config @@ -5,6 +5,7 @@ + diff --git a/samples/SmokeTest/.gitignore b/samples/SmokeTest/.gitignore new file mode 100644 index 0000000000000..8392c905c61ea --- /dev/null +++ b/samples/SmokeTest/.gitignore @@ -0,0 +1 @@ +launchSettings.json \ No newline at end of file diff --git a/samples/SmokeTest/SmokeTest.sln b/samples/SmokeTest/SmokeTest.sln new file mode 100644 index 0000000000000..2d6ea2d812daf --- /dev/null +++ b/samples/SmokeTest/SmokeTest.sln @@ -0,0 +1,29 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.28922.388 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SmokeTest", "SmokeTest\SmokeTest.csproj", "{F406BDFE-913D-4ED1-8C97-928128DA0F7D}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {F406BDFE-913D-4ED1-8C97-928128DA0F7D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F406BDFE-913D-4ED1-8C97-928128DA0F7D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F406BDFE-913D-4ED1-8C97-928128DA0F7D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F406BDFE-913D-4ED1-8C97-928128DA0F7D}.Release|Any CPU.Build.0 = Release|Any CPU + {89D7E7D6-0C87-4E12-87AC-B51EC63F7C22}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {89D7E7D6-0C87-4E12-87AC-B51EC63F7C22}.Debug|Any CPU.Build.0 = Debug|Any CPU + {89D7E7D6-0C87-4E12-87AC-B51EC63F7C22}.Release|Any CPU.ActiveCfg = Release|Any CPU + {89D7E7D6-0C87-4E12-87AC-B51EC63F7C22}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {6755A3D3-5AB2-487B-87FF-64D0E637E35A} + EndGlobalSection +EndGlobal diff --git a/samples/SmokeTest/SmokeTest/BlobStorageTest.cs b/samples/SmokeTest/SmokeTest/BlobStorageTest.cs new file mode 100644 index 0000000000000..e9bb585226733 --- /dev/null +++ b/samples/SmokeTest/SmokeTest/BlobStorageTest.cs @@ -0,0 +1,57 @@ +using Azure.Storage.Blobs; +using System; +using System.IO; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices.ComTypes; +using System.Text; +using System.Threading.Tasks; + +namespace SmokeTest +{ + class BlobStorageTest + { + private static BlobServiceClient serviceClient; + private static BlockBlobClient blobClient; + + /// + /// Test the Storage Blobs SDK + /// + public static async Task RunTests() + { + Console.WriteLine("\n---------------------------------"); + Console.WriteLine("STORAGE"); + Console.WriteLine("---------------------------------"); + Console.WriteLine("Functionalities to test: 2:"); + Console.WriteLine("1.- Upload Blob Block"); + Console.WriteLine("2.- Delete that Blob Block" + '\n'); + + string connectionString = Environment.GetEnvironmentVariable("BLOB_CONNECTION_STRING"); + string containerName = "mycontainer"; //The container must exists, this sample is not creating it. + string blobName = "netSmokeTestBlob"; + serviceClient = new BlobServiceClient(connectionString); + blobClient = serviceClient.GetBlobContainerClient(containerName).GetBlockBlobClient(blobName); + + await UploadBlob(); + await DeleteBlob(); + } + + private static async Task UploadBlob() + { + Console.Write("Uploading blob... "); + + const string content = "This is the content for the sample blob"; + byte[] byteArray = Encoding.UTF8.GetBytes(content); + MemoryStream stream = new MemoryStream(byteArray); + await blobClient.UploadAsync(stream); + + Console.WriteLine("\tdone"); + } + + private static async Task DeleteBlob() + { + Console.Write("Deleting blob..."); + await blobClient.DeleteAsync(); + Console.WriteLine("\tdone"); + } + } +} \ No newline at end of file diff --git a/samples/SmokeTest/SmokeTest/CosmosDBTest.cs b/samples/SmokeTest/SmokeTest/CosmosDBTest.cs new file mode 100644 index 0000000000000..890b63c376be4 --- /dev/null +++ b/samples/SmokeTest/SmokeTest/CosmosDBTest.cs @@ -0,0 +1,168 @@ +using Azure.Storage.Blobs.Models; +using Microsoft.Azure.Documents; +using Microsoft.Azure.Documents.Client; +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Numerics; +using System.Reflection.Metadata; +using System.Runtime.ConstrainedExecution; +using System.Text; +using System.Threading.Tasks; + +namespace SmokeTest +{ + public class Planet + { + [JsonProperty(PropertyName = "id")] + public string Id { get; set; } + public bool HasRings { get; set; } + public int Radius { get; set; } + public Moon[] Moons { get; set; } + public override string ToString() + { + return JsonConvert.SerializeObject(this); + } + } + + public class Moon + { + public string Name { get; set; } + } + + class CosmosDBTest + { + private static DocumentClient client; + private const string DataBaseName = "netSolarSystemDB"; + private const string CollectionName = "PlanetsCollection"; + private static List planets = new List(); + + /// + /// Test the Cosmos DB SDK by creating an example Database called {DataBaseName} and a PlanetsCollection with planets on it. + /// + public static async Task RunTests() + { + Console.WriteLine("\n---------------------------------"); + Console.WriteLine("COSMOS DB"); + Console.WriteLine("---------------------------------"); + Console.WriteLine("Functionalities to test: 5:"); + Console.WriteLine("1.- Create a Database"); + Console.WriteLine("2.- Create a Collection in the DB"); + Console.WriteLine("3.- Create 2 JSON Documents (Items) in the collection"); + Console.WriteLine("4.- Excecute simple query to the collection"); + Console.WriteLine("5.- Clean up the resource (Delete DB)\n"); + + string endpoint = Environment.GetEnvironmentVariable("COSMOS_URI"); + string authKey = Environment.GetEnvironmentVariable("COSMOS_AUTH_KEY"); + client = new DocumentClient(new Uri(endpoint), authKey); + + //Delete the database to ensure that the test environment is clean. + try + { + await DeleteDatabase(); + } + catch + { } + + await CreateDatabase(); + await CreateCollection(); + await CreateDocuments(); + await ExecuteSimpleQuery(); + await DeleteDatabase(); + } + + private static async Task CreateDatabase() + { + Console.Write("Creating Database '" + DataBaseName + "'..."); + await client.CreateDatabaseIfNotExistsAsync(new Database { Id = DataBaseName }); + Console.WriteLine("\tdone"); + } + + private static async Task CreateCollection() + { + Console.Write("Creating collection '" + CollectionName + "'..."); + await client.CreateDocumentCollectionIfNotExistsAsync(UriFactory.CreateDatabaseUri(DataBaseName), new DocumentCollection { Id = CollectionName }); + Console.WriteLine("\tdone"); + } + + private static async Task CreateDocuments() + { + planets.Add(new Planet + { + Id = "Earth", + HasRings = false, + Radius = 3959, + Moons = new Moon[] + { + new Moon + { + Name = "Moon" + } + } + }); + planets.Add(new Planet + { + Id = "Mars", + HasRings = false, + Radius = 2106, + Moons = new Moon[] + { + new Moon + { + Name = "Phobos" + }, + new Moon + { + Name = "Deimos" + } + } + }); + + //The items must NOT exists in the collection + foreach (Planet planet in planets) + { + Console.Write("Inserting '"+planet.Id+"' document..."); + await client.CreateDocumentAsync(UriFactory.CreateDocumentCollectionUri(DataBaseName, CollectionName), planet); + Console.WriteLine("\tdone"); + } + } + + /// + /// The query retrieve all planets, this is going to verify that planets match + /// + private static async Task ExecuteSimpleQuery(){ + Console.Write("Querying... "); + IQueryable planetarySqlQuery = client.CreateDocumentQuery(UriFactory.CreateDocumentCollectionUri(DataBaseName, CollectionName), "SELECT * FROM c"); + + var planetsSet = new HashSet(planets.Count); + foreach(Planet planet in planets) + { + planetsSet.Add(planet.ToString()); + } + + int i = 0; + foreach (Planet planet in planetarySqlQuery) + { + var serializedPlanet = planet.ToString(); + if (planetsSet.Contains(serializedPlanet)) + { + i++; + } + } + + if(i != planets.Count) + { + throw new Exception("Error, values do not match."); + } + Console.WriteLine("\tdone"); + } + + private static async Task DeleteDatabase() + { + Console.Write("Cleaning up the resource..."); + await client.DeleteDatabaseAsync(UriFactory.CreateDatabaseUri(DataBaseName)); + Console.WriteLine("\tdone"); + } + } +} \ No newline at end of file diff --git a/samples/SmokeTest/SmokeTest/EventHubsTest.cs b/samples/SmokeTest/SmokeTest/EventHubsTest.cs new file mode 100644 index 0000000000000..115398337a702 --- /dev/null +++ b/samples/SmokeTest/SmokeTest/EventHubsTest.cs @@ -0,0 +1,116 @@ +using Azure; +using Azure.Messaging.EventHubs; +using Microsoft.Azure.Amqp.Framing; +using System; +using System.Collections.Generic; +using System.Data; +using System.Linq; +using System.Net.Http; +using System.Reflection.Metadata.Ecma335; +using System.Runtime.InteropServices.ComTypes; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace SmokeTest +{ + class EventHubsTest + { + private static EventHubClient client; + private static EventSender sender; + private static EventReceiver receiver; + + /// + /// Test the Event Hubs SDK by sending and receiving events + /// + public static async Task RunTests() + { + Console.WriteLine("\n---------------------------------"); + Console.WriteLine("EVENT HUBS"); + Console.WriteLine("---------------------------------"); + Console.WriteLine("Functionalities to test: 2:"); + Console.WriteLine("1.- Send an Event batch"); + Console.WriteLine("2.- Recieve those events\n"); + + var connectionString = Environment.GetEnvironmentVariable("EVENT_HUBS_CONNECTION_STRING"); + client = new EventHubClient(connectionString); + + await CreateSenderAndReceiver(); + await SendAndReceiveEvents(); + } + + private static async Task CreateSenderAndReceiver() + { + Console.Write("Creating the Sender and Receivers... "); + var partition = (await client.GetPartitionIdsAsync()).First(); + var senderOptions = new EventSenderOptions + { + PartitionId = partition + }; + var receiverOptions = new EventReceiverOptions + { + BeginReceivingAt = EventPosition.NewEventsOnly + }; + sender = client.CreateSender(senderOptions); + receiver = client.CreateReceiver(partition, receiverOptions); + Console.WriteLine("\tdone"); + } + + private static async Task SendAndReceiveEvents() + { + var eventBatch = new[] + { + new EventData(Encoding.UTF8.GetBytes("First event data")), + new EventData(Encoding.UTF8.GetBytes("Second event data")), + new EventData(Encoding.UTF8.GetBytes("Third event data")) + }; + var index = 0; + var receivedEvents = new List(); + + //Before sending any event, start the receiver + await receiver.ReceiveAsync(1, TimeSpan.Zero); + + Console.Write("Ready to send a batch of " + eventBatch.Count().ToString() + " events... "); + await sender.SendAsync(eventBatch); + Console.Write("Sent\n"); + + Console.Write("Receiving events... "); + while ((receivedEvents.Count < eventBatch.Length) && (++index < 3)) + { + receivedEvents.AddRange(await receiver.ReceiveAsync(eventBatch.Length + 10, TimeSpan.FromMilliseconds(25))); + } + index = 0; + + //Check if at least one event was received in order to start validation + if (receivedEvents.Count == 0) + { + throw new Exception(String.Format("Error, No events received.")); + } + Console.Write(receivedEvents.Count() + " events received.\n"); + + Console.WriteLine("Beginning validation..."); + foreach (var receivedEvent in receivedEvents) + { + var receivedEventMessage = Encoding.UTF8.GetString(receivedEvent.Body.ToArray()); + var sentEventMessage = Encoding.UTF8.GetString(eventBatch[index].Body.ToArray()); + + if (receivedEventMessage == sentEventMessage) + { + Console.WriteLine("\tEvent '" + receivedEventMessage + "' correctly validated."); + } + else + { + throw new Exception(String.Format("Error, Event: '" + receivedEventMessage + "' was not expected.")); + } + index++; + } + + if (index < eventBatch.Count()) + { + throw new Exception(String.Format("Error, expecting " + eventBatch.Count().ToString() + " events, but only got " + index.ToString() + ".")); + } + + Console.WriteLine("done"); + } + } +} \ No newline at end of file diff --git a/samples/SmokeTest/SmokeTest/KeyVaultTest.cs b/samples/SmokeTest/SmokeTest/KeyVaultTest.cs new file mode 100644 index 0000000000000..824e85423d004 --- /dev/null +++ b/samples/SmokeTest/SmokeTest/KeyVaultTest.cs @@ -0,0 +1,66 @@ +using Azure.Identity; +using Azure.Security.KeyVault.Secrets; +using System; +using System.Threading.Tasks; + +namespace SmokeTest +{ + class KeyVaultTest + { + private const string SecretName = "SmokeTestSecret"; + private const string SecretValue = "smokeTestValue"; + private static SecretClient client; + + /// + /// Validates the Key Vault SDK + /// + public static async Task RunTests() + { + Console.WriteLine("\n---------------------------------"); + Console.WriteLine("KEY VAULT"); + Console.WriteLine("---------------------------------"); + Console.WriteLine("Functionalities to test: 3:"); + Console.WriteLine("1.- Set a Secret"); + Console.WriteLine("2.- Get that Secret"); + Console.WriteLine("3.- Delete that Secret (Clean up)\n"); + + string tenantID = Environment.GetEnvironmentVariable("DIR_TENANT_ID"); + string clientID = Environment.GetEnvironmentVariable("APP_CLIENT_ID"); + string clientSecret = Environment.GetEnvironmentVariable("CLIENT_SECRET"); + string keyVaultUri = Environment.GetEnvironmentVariable("KEY_VAULT_URI"); + client = new SecretClient(new Uri(keyVaultUri), new ClientSecretCredential(tenantID, clientID, clientSecret)); + + await SetNewSecret(); + await GetSecret(); + await CleanUp(); + } + + private static async Task SetNewSecret() + { + Console.Write("Setting a secret..."); + var newSecret = new Secret(SecretName, SecretValue); + await client.SetAsync(newSecret); + Console.WriteLine("\tdone"); + } + + private static async Task GetSecret() + { + Console.Write("Getting that secret..."); + Azure.Response secret; + secret = await client.GetAsync(SecretName); + //Verify that the secret received is the one that was set previously + if (secret.Value.Value != SecretValue) + { + throw new Exception(String.Format("Secret retreived, but not the one previously created: '" + secret.Value.Value)); + } + Console.WriteLine("\tdone"); + } + + private static async Task CleanUp() + { + Console.Write("Cleaning up the resource..."); + await client.DeleteAsync(SecretName); + Console.WriteLine("\tdone"); + } + } +} \ No newline at end of file diff --git a/samples/SmokeTest/SmokeTest/Program.cs b/samples/SmokeTest/SmokeTest/Program.cs new file mode 100644 index 0000000000000..9663c6fd9058e --- /dev/null +++ b/samples/SmokeTest/SmokeTest/Program.cs @@ -0,0 +1,22 @@ +using Azure.Messaging.EventHubs; +using System; +using System.Reflection.Metadata; +using System.Threading.Tasks; + +namespace SmokeTest +{ + class Program + { + static async Task Main(string[] args) + { + Console.WriteLine("SMOKE TEST FOR TRACK 2 LIBRARIES"); + + await KeyVaultTest.RunTests(); + await BlobStorageTest.RunTests(); + await EventHubsTest.RunTests(); + await CosmosDBTest.RunTests(); + + return 0; + } + } +} diff --git a/samples/SmokeTest/SmokeTest/Properties/Resources.Designer.cs b/samples/SmokeTest/SmokeTest/Properties/Resources.Designer.cs new file mode 100644 index 0000000000000..ebf480105cfde --- /dev/null +++ b/samples/SmokeTest/SmokeTest/Properties/Resources.Designer.cs @@ -0,0 +1,63 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace SmokeTest.Properties { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("SmokeTest.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + } +} diff --git a/samples/SmokeTest/SmokeTest/Properties/Resources.resx b/samples/SmokeTest/SmokeTest/Properties/Resources.resx new file mode 100644 index 0000000000000..2f96abecd49c6 --- /dev/null +++ b/samples/SmokeTest/SmokeTest/Properties/Resources.resx @@ -0,0 +1,121 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + \ No newline at end of file diff --git a/samples/SmokeTest/SmokeTest/SmokeTest.csproj b/samples/SmokeTest/SmokeTest/SmokeTest.csproj new file mode 100644 index 0000000000000..257f3424ce7ee --- /dev/null +++ b/samples/SmokeTest/SmokeTest/SmokeTest.csproj @@ -0,0 +1,32 @@ + + + + Exe + netcoreapp2.1 + + + + + + + + + + + + + + True + True + Resources.resx + + + + + + ResXFileCodeGenerator + Resources.Designer.cs + + + +