From 9a7fa786ccfdadbe17db1a711f9cdd7352adb4b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magnus=20M=C3=A5rtensson?= Date: Fri, 5 Apr 2013 16:04:25 +0200 Subject: [PATCH] Fleshed out some more parameters and added an extension for friendlier create storage account. --- Elastacloud.FluentExamples.Tests/App.config | 5 + .../Elastacloud.FluentExamples.Tests.csproj | 128 + Elastacloud.FluentExamples.Tests/NLog.config | 25 + Elastacloud.FluentExamples.Tests/NLog.xsd | 2585 +++++++++++++++++ .../Properties/AssemblyInfo.cs | 36 + .../StorageClientTests.cs | 64 + .../packages.config | 8 + Elastacloud.FluentExamples.sln | 6 + .../BuildVirtualMachine.cs | 152 +- .../Elastacloud.FluentExamples.csproj | 33 + Elastacloud.FluentExamples/Program.cs | 50 +- .../StorageClientExtensions.cs | 65 + 12 files changed, 3066 insertions(+), 91 deletions(-) create mode 100644 Elastacloud.FluentExamples.Tests/App.config create mode 100644 Elastacloud.FluentExamples.Tests/Elastacloud.FluentExamples.Tests.csproj create mode 100644 Elastacloud.FluentExamples.Tests/NLog.config create mode 100644 Elastacloud.FluentExamples.Tests/NLog.xsd create mode 100644 Elastacloud.FluentExamples.Tests/Properties/AssemblyInfo.cs create mode 100644 Elastacloud.FluentExamples.Tests/StorageClientTests.cs create mode 100644 Elastacloud.FluentExamples.Tests/packages.config create mode 100644 Elastacloud.FluentExamples/StorageClientExtensions.cs diff --git a/Elastacloud.FluentExamples.Tests/App.config b/Elastacloud.FluentExamples.Tests/App.config new file mode 100644 index 0000000..9fc988c --- /dev/null +++ b/Elastacloud.FluentExamples.Tests/App.config @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/Elastacloud.FluentExamples.Tests/Elastacloud.FluentExamples.Tests.csproj b/Elastacloud.FluentExamples.Tests/Elastacloud.FluentExamples.Tests.csproj new file mode 100644 index 0000000..e016f66 --- /dev/null +++ b/Elastacloud.FluentExamples.Tests/Elastacloud.FluentExamples.Tests.csproj @@ -0,0 +1,128 @@ + + + + Debug + AnyCPU + {039FF870-897E-4C78-809B-9322CC548621} + Library + Properties + Elastacloud.FluentExamples.Tests + Elastacloud.FluentExamples.Tests + v4.5 + 512 + {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 10.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages + False + UnitTest + ..\ + true + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\BouncyCastle.1.7.0\lib\Net40-Client\BouncyCastle.Crypto.dll + + + ..\packages\Elastacloud.AzureManagement.Fluent.0.4.4.8\lib\Elastacloud.AzureManagement.Fluent.dll + + + True + ..\packages\Elastacloud.AzureManagement.Fluent.0.4.4.8\lib\Microsoft.SqlServer.ConnectionInfo.dll + + + True + ..\packages\Elastacloud.AzureManagement.Fluent.0.4.4.8\lib\Microsoft.SqlServer.Management.Sdk.Sfc.dll + + + True + ..\packages\Elastacloud.AzureManagement.Fluent.0.4.4.8\lib\Microsoft.SqlServer.Smo.dll + + + ..\packages\Newtonsoft.Json.4.5.11\lib\net40\Newtonsoft.Json.dll + + + ..\packages\NLog.2.0.0.2000\lib\net40\NLog.dll + + + + + + + + + + + + + + + + + + + + + + + + Always + + + + Designer + + + + + + {2accfe36-b097-4658-90c0-79498bff6eea} + Elastacloud.FluentExamples + + + + + + + False + + + False + + + False + + + False + + + + + + + + + \ No newline at end of file diff --git a/Elastacloud.FluentExamples.Tests/NLog.config b/Elastacloud.FluentExamples.Tests/NLog.config new file mode 100644 index 0000000..d2e19fd --- /dev/null +++ b/Elastacloud.FluentExamples.Tests/NLog.config @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Elastacloud.FluentExamples.Tests/NLog.xsd b/Elastacloud.FluentExamples.Tests/NLog.xsd new file mode 100644 index 0000000..2203f4e --- /dev/null +++ b/Elastacloud.FluentExamples.Tests/NLog.xsd @@ -0,0 +1,2585 @@ + + + + + + + + + + + + + + Watch config file for changes and reload automatically. + + + + + Print internal NLog messages to the console. Default value is: false + + + + + Print internal NLog messages to the console error output. Default value is: false + + + + + Write internal NLog messages to the specified file. + + + + + Log level threshold for internal log messages. Default value is: Info. + + + + + Global log level threshold for application log messages. Messages below this level won't be logged.. + + + + + Pass NLog internal exceptions to the application. Default value is: false. + + + + + + + + + + + + + + Make all targets within this section asynchronous (creates additional threads but the calling thread isn't blocked by any target writes). + + + + + + + + + + + + + + + + + Prefix for targets/layout renderers/filters/conditions loaded from this assembly. + + + + + Load NLog extensions from the specified file (*.dll) + + + + + Load NLog extensions from the specified assembly. Assembly name should be fully qualified. + + + + + + + + + + Name of the logger. May include '*' character which acts like a wildcard. Allowed forms are: *, Name, *Name, Name* and *Name* + + + + + Comma separated list of levels that this rule matches. + + + + + Minimum level that this rule matches. + + + + + Maximum level that this rule matches. + + + + + Level that this rule matches. + + + + + Comma separated list of target names. + + + + + Ignore further rules if this one matches. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Name of the file to be included. The name is relative to the name of the current config file. + + + + + Ignore any errors in the include file. + + + + + + + Variable name. + + + + + Variable value. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Limit on the number of requests in the lazy writer thread request queue. + + + + + Time in milliseconds to sleep between batches. + + + + + Number of log events that should be processed in a batch by the lazy writer thread. + + + + + Action to be taken when the lazy writer thread request queue count exceeds the set limit. + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + + + + + + + + + + + + + Name of the target. + + + + + Indicates whether to use sliding timeout. + + + + + Number of log events to be buffered. + + + + + Timeout (in milliseconds) after which the contents of buffer will be flushed if there's no write in the specified period of time. Use -1 to disable timed flushes. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Indicates whether to append newline at the end of log message. + + + + + Instance of that is used to format log messages. + + + + + Action that should be taken if the message is larger than maxMessageSize. + + + + + Maximum message size in bytes. + + + + + Encoding to be used. + + + + + Size of the connection cache (number of connections which are kept alive). + + + + + Network address. + + + + + Indicates whether to keep connection open whenever possible. + + + + + Indicates whether to include source info (file name and line number) in the information sent over the network. + + + + + Indicates whether to include call site (class and method name) in the information sent over the network. + + + + + AppInfo field. By default it's the friendly name of the current AppDomain. + + + + + NDC item separator. + + + + + Indicates whether to include stack contents. + + + + + Indicates whether to include NLog-specific extensions to log4j schema. + + + + + Indicates whether to include dictionary contents. + + + + + + + + + + + + + + + + + + + + Layout that should be use to calcuate the value for the parameter. + + + + + Viewer parameter name. + + + + + + + + + + + + + + + + Name of the target. + + + + + Text to be rendered. + + + + + Footer. + + + + + Header. + + + + + Indicates whether to send the log messages to the standard error instead of the standard output. + + + + + + + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Database user name. If the ConnectionString is not provided this value will be used to construct the "User ID=" part of the connection string. + + + + + Name of the database provider. + + + + + Indicates whether to use database transactions. Some data providers require this. + + + + + Name of the connection string (as specified in <connectionStrings> configuration section. + + + + + Connection string. When provided, it overrides the values specified in DBHost, DBUserName, DBPassword, DBDatabase. + + + + + Indicates whether to keep the database connection open between the log events. + + + + + Database name. If the ConnectionString is not provided this value will be used to construct the "Database=" part of the connection string. + + + + + Database password. If the ConnectionString is not provided this value will be used to construct the "Password=" part of the connection string. + + + + + Database host name. If the ConnectionString is not provided this value will be used to construct the "Server=" part of the connection string. + + + + + Connection string using for installation and uninstallation. If not provided, regular ConnectionString is being used. + + + + + Text of the SQL command to be run on each log level. + + + + + + + + + + + + + + + + + + + + + + + Type of the command. + + + + + Connection string to run the command against. If not provided, connection string from the target is used. + + + + + Indicates whether to ignore failures. + + + + + Command text. + + + + + + + + + + + + + + Layout that should be use to calcuate the value for the parameter. + + + + + Database parameter name. + + + + + Database parameter precision. + + + + + Database parameter scale. + + + + + Database parameter size. + + + + + + + + + + + + + Name of the target. + + + + + Layout used to format log messages. + + + + + + + + + + + + + + + Name of the target. + + + + + Indicates whether to return to the first target after any successful write. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Text to be rendered. + + + + + Header. + + + + + Footer. + + + + + File encoding. + + + + + Line ending mode. + + + + + Size in bytes above which log files will be automatically archived. + + + + + Maximum number of archive files that should be kept. + + + + + Name of the file to be used for an archive. + + + + + Way file archives are numbered. + + + + + Indicates whether to automatically archive log files every time the specified time passes. + + + + + Indicates whether to replace file contents on each write instead of appending log message at the end. + + + + + File attributes (Windows only). + + + + + Name of the file to write to. + + + + + Indicates whether to delete old log file on startup. + + + + + Indicates whether to enable log file(s) to be deleted. + + + + + Indicates whether to create directories if they don't exist. + + + + + Indicates whether concurrent writes to the log file by multiple processes on the same host. + + + + + Maximum number of seconds that files are kept open. If this number is negative the files are not automatically closed after a period of inactivity. + + + + + Number of files to be kept open. Setting this to a higher value may improve performance in a situation where a single File target is writing to many files (such as splitting by level or by logger). + + + + + Indicates whether concurrent writes to the log file by multiple processes on different network hosts. + + + + + Delay in milliseconds to wait before attempting to write to the file again. + + + + + Number of times the write is appended on the file before NLog discards the log message. + + + + + Log file buffer size in bytes. + + + + + Indicates whether to automatically flush the file buffers after each log message. + + + + + Indicates whether to keep log file open instead of opening and closing it on each logging event. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Condition expression. Log events who meet this condition will be forwarded to the wrapped target. + + + + + + + + + + + + + + + Name of the target. + + + + + Layout used to format log messages. + + + + + + + + + + + + + + + + Name of the target. + + + + + Layout used to format log messages. + + + + + Message box title. + + + + + + + + + + + + + + + + + Name of the target. + + + + + Method name. The method must be public and static. + + + + + Class name. + + + + + + + + + + + + + + Layout that should be use to calcuate the value for the parameter. + + + + + Name of the parameter. + + + + + Type of the parameter. + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Action that should be taken if the message is larger than maxMessageSize. + + + + + Indicates whether to append newline at the end of log message. + + + + + Layout used to format log messages. + + + + + Maximum message size in bytes. + + + + + Encoding to be used. + + + + + Size of the connection cache (number of connections which are kept alive). + + + + + Indicates whether to keep connection open whenever possible. + + + + + Network address. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Indicates whether to append newline at the end of log message. + + + + + Instance of that is used to format log messages. + + + + + Action that should be taken if the message is larger than maxMessageSize. + + + + + Maximum message size in bytes. + + + + + Encoding to be used. + + + + + Size of the connection cache (number of connections which are kept alive). + + + + + Network address. + + + + + Indicates whether to keep connection open whenever possible. + + + + + Indicates whether to include source info (file name and line number) in the information sent over the network. + + + + + Indicates whether to include call site (class and method name) in the information sent over the network. + + + + + AppInfo field. By default it's the friendly name of the current AppDomain. + + + + + NDC item separator. + + + + + Indicates whether to include stack contents. + + + + + Indicates whether to include NLog-specific extensions to log4j schema. + + + + + Indicates whether to include dictionary contents. + + + + + + + + + + + + + + + + Name of the target. + + + + + Indicates whether to perform layout calculation. + + + + + Layout used to format log messages. + + + + + + + + + + + + + + + Name of the target. + + + + + Layout used to format log messages. + + + + + + + + + + + + + + + + Name of the target. + + + + + Default filter to be applied when no specific rule matches. + + + + + + + + + + + + + Condition to be tested. + + + + + Resulting filter to be applied when the condition matches. + + + + + + + + + + + + Name of the target. + + + + + + + + + + + + + + + Name of the target. + + + + + Number of times to repeat each log message. + + + + + + + + + + + + + + + + Name of the target. + + + + + Time to wait between retries in milliseconds. + + + + + Number of retries that should be attempted on the wrapped target in case of a failure. + + + + + + + + + + + + + + Name of the target. + + + + + + + + + + + + + + Name of the target. + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Web service URL. + + + + + Encoding. + + + + + Protocol to be used when calling web service. + + + + + Web service namespace. + + + + + Web service method name. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Body layout (can be repeated multiple times). + + + + + Footer layout. + + + + + Header layout. + + + + + Quoting mode. + + + + + Quote Character. + + + + + Indicates whether CVS should include header. + + + + + Custom column delimiter value (valid when ColumnDelimiter is set to 'Custom'). + + + + + Column delimiter. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Layout of the column. + + + + + Name of the column. + + + + + + + + + + + + Layout text. + + + + + + + + + + + + + + + + Body layout (can be repeated multiple times). + + + + + Header layout. + + + + + Footer layout. + + + + + + + + + + + + + + + + + + + + + + Condition expression. + + + + + Action to be taken when filter matches. + + + + + + + + + + + + + + + + + + + + + + + + + + Layout to be used to filter log messages. + + + + + Substring to be matched. + + + + + Action to be taken when filter matches. + + + + + Indicates whether to ignore case when comparing strings. + + + + + + + + + + + + + + + + + Indicates whether to ignore case when comparing strings. + + + + + Layout to be used to filter log messages. + + + + + Action to be taken when filter matches. + + + + + String to compare the layout to. + + + + + + + + + + + + + + + + + Layout to be used to filter log messages. + + + + + Substring to be matched. + + + + + Action to be taken when filter matches. + + + + + Indicates whether to ignore case when comparing strings. + + + + + + + + + + + + + + + + + Indicates whether to ignore case when comparing strings. + + + + + Layout to be used to filter log messages. + + + + + Action to be taken when filter matches. + + + + + String to compare the layout to. + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Indicates whether to use the XML format when serializing message. + + + + + Encoding to be used when writing text to the queue. + + + + + Layout used to format log messages. + + + + + Indicates whether to use recoverable messages (with guaranteed delivery). + + + + + Indicates whether to create the queue if it doesn't exists. + + + + + Label to associate with each message. + + + + + Name of the queue to write to. + + + + + + + + + + + + + + + + + Name of the target. + + + + + Maximum number of log events that the buffer can keep. + + + + + Indicates whether buffer should grow as needed. + + + + + Number of log events to be buffered. + + + + + + + + + + + + + + + Name of the target. + + + + + Layout used to format log messages. + + + + + + + + + + + + + + + + Name of the target. + + + + + Indicates whether to add <!-- --> comments around all written texts. + + + + + Layout used to format log messages. + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Text to be rendered. + + + + + Header. + + + + + Footer. + + + + + Indicates whether to use default row highlighting rules. + + + + + Indicates whether the error stream (stderr) should be used instead of the output stream (stdout). + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Background color. + + + + + Condition that must be met in order to set the specified foreground and background color. + + + + + Foreground color. + + + + + + + + + + + + + + + Background color. + + + + + Foreground color. + + + + + Indicates whether to ignore case when comparing texts. + + + + + Regular expression to be matched. You must specify either text or regex. + + + + + Text to be matched. You must specify either text or regex. + + + + + Indicates whether to match whole words only. + + + + + + + + + + + + + + + Name of the target. + + + + + Footer. + + + + + Text to be rendered. + + + + + Header. + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Layout used to format log messages. + + + + + Name of the machine on which Event Log service is running. + + + + + Value to be used as the event Source. + + + + + Layout that renders event Category. + + + + + Layout that renders event ID. + + + + + Name of the Event Log to write to. This can be System, Application or any user-defined name. + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Layout used to format log messages. + + + + + Indicates whether log text should be appended to the text of the control instead of overwriting it. + + + + + Name of control to which NLog will log write log text. + + + + + Name of the Form on which the control is located. + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Username to change context to. + + + + + User account password. + + + + + Indicates whether to revert to the credentials of the process instead of impersonating another user. + + + + + Required impersonation level. + + + + + Windows domain name to change context to. + + + + + Logon Type. + + + + + Type of the logon provider. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Header. + + + + + Footer. + + + + + Text to be rendered. + + + + + Indicates whether to send message as HTML instead of plain text. + + + + + Indicates whether to add new lines between log entries. + + + + + Encoding to be used for sending e-mail. + + + + + Mail subject. + + + + + Recipients' email addresses separated by semicolons (e.g. john@domain.com;jane@domain.com). + + + + + BCC email addresses separated by semicolons (e.g. john@domain.com;jane@domain.com). + + + + + CC email addresses separated by semicolons (e.g. john@domain.com;jane@domain.com). + + + + + Sender's email address (e.g. joe@domain.com). + + + + + Mail message body (repeated for each log message send in one mail). + + + + + Username used to connect to SMTP server (used when SmtpAuthentication is set to "basic"). + + + + + Indicates whether SSL (secure sockets layer) should be used when communicating with SMTP server. + + + + + Password used to authenticate against SMTP server (used when SmtpAuthentication is set to "basic"). + + + + + SMTP Authentication mode. + + + + + SMTP Server to be used for sending. + + + + + Port number that SMTP Server is listening on. + + + + + + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Performance counter instance name. + + + + + Counter help text. + + + + + Performance counter type. + + + + + Indicates whether performance counter should be automatically created. + + + + + Name of the performance counter category. + + + + + Name of the performance counter. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Layout used to format log messages. + + + + + Initial height of the form with rich text box. + + + + + Indicates whether scroll bar will be moved automatically to show most recent log entries. + + + + + Maximum number of lines the rich text box will store (or 0 to disable this feature). + + + + + Indicates whether the created form will be initially minimized. + + + + + Indicates whether the created window will be a tool window. + + + + + Name of RichTextBox to which Nlog will write. + + + + + Name of the Form on which the control is located. If there is no open form of a specified name than NLog will create a new one. + + + + + Initial width of the form with rich text box. + + + + + Indicates whether to use default coloring rules. + + + + + + + + + + + + + + + + + + + + + + + + + + + Background color. Names are identical with KnownColor enum extended with Empty value which means that background color won't be changed. + + + + + Font color. Names are identical with KnownColor enum extended with Empty value which means that font color won't be changed. + + + + + Indicates whether to ignore case when comparing texts. + + + + + Regular expression to be matched. You must specify either text or regex. + + + + + Font style of matched text. Possible values are the same as in FontStyle enum in System.Drawing. + + + + + Text to be matched. You must specify either text or regex. + + + + + Indicates whether to match whole words only. + + + + + + + + + + + + + Background color. + + + + + Condition that must be met in order to set the specified font color. + + + + + Font color. + + + + + Font style of matched text. + + + + + + + + + + + + + Name of the target. + + + + + Layout used to format log messages. + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Name of the endpoint configuration in WCF configuration file. + + + + + Endpoint address. + + + + + Indicates whether to use binary message encoding. + + + + + Client ID. + + + + + Indicates whether to include per-event properties in the payload sent to the server. + + + + + + \ No newline at end of file diff --git a/Elastacloud.FluentExamples.Tests/Properties/AssemblyInfo.cs b/Elastacloud.FluentExamples.Tests/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..a0c6255 --- /dev/null +++ b/Elastacloud.FluentExamples.Tests/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Elastacloud.FluentExamples.Tests")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Elastacloud.FluentExamples.Tests")] +[assembly: AssemblyCopyright("Copyright © 2013")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("56881b8c-1d29-4544-9c51-fee375878493")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Elastacloud.FluentExamples.Tests/StorageClientTests.cs b/Elastacloud.FluentExamples.Tests/StorageClientTests.cs new file mode 100644 index 0000000..392bef3 --- /dev/null +++ b/Elastacloud.FluentExamples.Tests/StorageClientTests.cs @@ -0,0 +1,64 @@ +using System.Configuration; +using System.Security.Cryptography.X509Certificates; +using Elastacloud.AzureManagement.Fluent.Clients; +using Elastacloud.AzureManagement.Fluent.Helpers.PublishSettings; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace Elastacloud.FluentExamples.Tests +{ + [TestClass] + public class StorageClientTests + { + static string publishSettingsFile = @"F:\Code\Fluent Management Examples Forked\noopman.publishsettings"; + static string subscriptionId = "b951dbc2-b9f2-415d-baeb-fdd1ee98f85e"; + const string storageAccountName = "apicatest"; + + static PublishSettingsExtractor settings; + static X509Certificate2 certificate; + + StorageClient storageClient; + + [ClassInitialize] + public static void ReadConfig(TestContext context) + { + publishSettingsFile = ConfigurationManager.AppSettings["Publish Settings File"]; + Assert.IsNotNull(publishSettingsFile); + + subscriptionId = ConfigurationManager.AppSettings["Subscription ID"]; + Assert.IsNotNull(subscriptionId); + + settings = PublishSettingsExtractor.GetFromFile(publishSettingsFile); + Assert.IsNotNull(settings); + + certificate = settings.AddPublishSettingsToPersonalMachineStore(); + Assert.IsNotNull(certificate); + } + + [TestInitialize] + public void CreateStorageClient() + { + storageClient = new StorageClient(subscriptionId, certificate); + + Assert.IsNotNull(storageClient); + } + + [TestMethod] + public void GetStorageAccountList() + { + var storageAccountList = storageClient.GetStorageAccountList(); + Assert.IsNotNull(storageAccountList); + } + + [TestMethod] + public void CreateNewStorageAccountIfNotExists() + { + storageClient.CreateNewStorageAccountIfNotExists(storageAccountName); + } + + [TestMethod] + public void TryCreateNewStorageAccountIfNotExists() + { + Assert.IsFalse(storageClient.TryCreateNewStorageAccount(storageAccountName)); + } + } +} \ No newline at end of file diff --git a/Elastacloud.FluentExamples.Tests/packages.config b/Elastacloud.FluentExamples.Tests/packages.config new file mode 100644 index 0000000..9cf8dc2 --- /dev/null +++ b/Elastacloud.FluentExamples.Tests/packages.config @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/Elastacloud.FluentExamples.sln b/Elastacloud.FluentExamples.sln index aa544be..4dcce61 100644 --- a/Elastacloud.FluentExamples.sln +++ b/Elastacloud.FluentExamples.sln @@ -10,6 +10,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{F408B8 .nuget\NuGet.targets = .nuget\NuGet.targets EndProjectSection EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Elastacloud.FluentExamples.Tests", "Elastacloud.FluentExamples.Tests\Elastacloud.FluentExamples.Tests.csproj", "{039FF870-897E-4C78-809B-9322CC548621}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -20,6 +22,10 @@ Global {2ACCFE36-B097-4658-90C0-79498BFF6EEA}.Debug|Any CPU.Build.0 = Debug|Any CPU {2ACCFE36-B097-4658-90C0-79498BFF6EEA}.Release|Any CPU.ActiveCfg = Release|Any CPU {2ACCFE36-B097-4658-90C0-79498BFF6EEA}.Release|Any CPU.Build.0 = Release|Any CPU + {039FF870-897E-4C78-809B-9322CC548621}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {039FF870-897E-4C78-809B-9322CC548621}.Debug|Any CPU.Build.0 = Debug|Any CPU + {039FF870-897E-4C78-809B-9322CC548621}.Release|Any CPU.ActiveCfg = Release|Any CPU + {039FF870-897E-4C78-809B-9322CC548621}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Elastacloud.FluentExamples/BuildVirtualMachine.cs b/Elastacloud.FluentExamples/BuildVirtualMachine.cs index 2d19481..e940c42 100644 --- a/Elastacloud.FluentExamples/BuildVirtualMachine.cs +++ b/Elastacloud.FluentExamples/BuildVirtualMachine.cs @@ -1,9 +1,6 @@ using System; using System.Collections.Generic; -using System.Linq; using System.Security.Cryptography.X509Certificates; -using System.Text; -using System.Threading.Tasks; using Elastacloud.AzureManagement.Fluent.Clients; using Elastacloud.AzureManagement.Fluent.Commands.VirtualMachines; using Elastacloud.AzureManagement.Fluent.Helpers; @@ -14,83 +11,86 @@ namespace Elastacloud.FluentExamples { - public class BuildVirtualMachine : IBuilder - { - private readonly WindowsVirtualMachineProperties _properties; - private readonly X509Certificate2 _certificate; - private readonly string _subscriptionId; - private readonly string _rdpFile; + public class BuildVirtualMachine : IBuilder + { + private readonly WindowsVirtualMachineProperties _properties; + private readonly X509Certificate2 _certificate; + private readonly string _subscriptionId; + private readonly string _rdpFile; + private readonly string _storageAccountName; + private readonly string _storageLocationName; - public BuildVirtualMachine(string subscriptionId, string publishSettingsFile, string rdpFile) - { - var settings = PublishSettingsExtractor.GetFromFile(publishSettingsFile); - _certificate = settings.AddPublishSettingsToPersonalMachineStore(); - _subscriptionId = subscriptionId; - _rdpFile = rdpFile; - _properties = new WindowsVirtualMachineProperties() - { - AdministratorPassword = "Password101!", - RoleName = "stackedliverpool", - DeploymentName = "stackedliverpool", - Certificate = _certificate, - Location = LocationConstants.NorthEurope, - UseExistingCloudService = false, - SubscriptionId = subscriptionId, - CloudServiceName = "stackedliverpool", - PublicEndpoints = new List(new[] - { - new InputEndpoint() - { - EndpointName = "web", - LocalPort = 80, - Port = 80, - Protocol = Protocol.TCP - } - }), - VirtualMachineType = VirtualMachineTemplates.WindowsServer2012, - VmSize = VmSize.Medium, - StorageAccountName = "stackedstorage", - DataDisks = new List(new[] { - new DataVirtualHardDisk(){LogicalDiskSizeInGB = 100} - }) - }; - } + public BuildVirtualMachine(string subscriptionId, string publishSettingsFile, string rdpFile, string storageAccountName, string storageLocationName, string cloudServiceName, string deploymentName, string roleName, string administratorPassWord) + { + var settings = PublishSettingsExtractor.GetFromFile(publishSettingsFile); + _certificate = settings.AddPublishSettingsToPersonalMachineStore(); + _subscriptionId = subscriptionId; + _rdpFile = rdpFile; + _storageAccountName = storageAccountName; + _storageLocationName = storageLocationName; + _properties = new WindowsVirtualMachineProperties + { + AdministratorPassword = administratorPassWord, + RoleName = roleName, + DeploymentName = deploymentName, + Certificate = _certificate, + Location = LocationConstants.NorthEurope, + UseExistingCloudService = false, + SubscriptionId = subscriptionId, + CloudServiceName = cloudServiceName, + PublicEndpoints = new List(new[] + { + new InputEndpoint + { + EndpointName = "web", + LocalPort = 80, + Port = 80, + Protocol = Protocol.TCP + } + }), + VirtualMachineType = VirtualMachineTemplates.WindowsServer2012, + VmSize = VmSize.Medium, + StorageAccountName = _storageAccountName, + DataDisks = new List(new[] + { + new DataVirtualHardDisk + { + LogicalDiskSizeInGB = 100 + } + }) + }; + } - void IBuilder.SpinUp() - { - var storageClient = new StorageClient(_subscriptionId, _certificate); - storageClient.CreateNewStorageAccount("stackedstorage"); - var client = new WindowsVirtualMachineClient(_subscriptionId, _certificate); - var newClient = client.CreateNewVirtualMachineFromTemplateGallery(_properties); - Console.WriteLine("Virtual machine now created - with diskname {0}", - newClient.VirtualMachine.OSHardDisk.DiskName); - Console.WriteLine("Getting and saving RD file"); - client.SaveRemoteDesktopFile(_rdpFile); - } + void IBuilder.SpinUp() + { + var storageClient = new StorageClient(_subscriptionId, _certificate); + storageClient.CreateNewStorageAccountIfNotExists(_storageAccountName, _storageLocationName); + var client = new WindowsVirtualMachineClient(_subscriptionId, _certificate); + var newClient = client.CreateNewVirtualMachineFromTemplateGallery(_properties); + Console.WriteLine("Virtual machine now created - with diskname {0}", newClient.VirtualMachine.OSHardDisk.DiskName); + Console.WriteLine("Getting and saving RD file"); + client.SaveRemoteDesktopFile(_rdpFile); + } - void IBuilder.TearDown() - { - var client = new WindowsVirtualMachineClient(_properties); - string ipAddress = client.VirtualMachine.NetworkConfigurationSet.InputEndpoints[0].Vip; - - Console.WriteLine("The VIP is {0}", ipAddress); - - client.DeleteVirtualMachine(); - Console.WriteLine("Virtual machine has been deleted, with cloud service and storage"); - } - - X509Certificate2 IBuilder.ManagementCertificate - { - get { return _certificate; } - } - - string IBuilder.SubscriptionId - { - get { return _subscriptionId; } - } - } -} + void IBuilder.TearDown() + { + var client = new WindowsVirtualMachineClient(_properties); + string ipAddress = client.VirtualMachine.NetworkConfigurationSet.InputEndpoints[0].Vip; + Console.WriteLine("The VIP is {0}", ipAddress); + client.DeleteVirtualMachine(); + Console.WriteLine("Virtual machine has been deleted, with cloud service and storage"); + } + X509Certificate2 IBuilder.ManagementCertificate + { + get { return _certificate; } + } + string IBuilder.SubscriptionId + { + get { return _subscriptionId; } + } + } +} \ No newline at end of file diff --git a/Elastacloud.FluentExamples/Elastacloud.FluentExamples.csproj b/Elastacloud.FluentExamples/Elastacloud.FluentExamples.csproj index 01a42d7..2d95292 100644 --- a/Elastacloud.FluentExamples/Elastacloud.FluentExamples.csproj +++ b/Elastacloud.FluentExamples/Elastacloud.FluentExamples.csproj @@ -13,6 +13,21 @@ 512 ..\ true + publish\ + true + Disk + false + Foreground + 7 + Days + false + false + true + 0 + 1.0.0.%2a + false + false + true AnyCPU @@ -77,6 +92,7 @@ + @@ -88,6 +104,23 @@ + + + False + Microsoft .NET Framework 4.5 %28x86 and x64%29 + true + + + False + .NET Framework 3.5 SP1 Client Profile + false + + + False + .NET Framework 3.5 SP1 + false + +