|
| 1 | +// Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | +// Licensed under the MIT License. |
| 3 | + |
| 4 | +using System.Collections.Generic; |
| 5 | +using Azure.ResourceManager.Automation.Models; |
| 6 | +using Azure.ResourceManager.Models; |
| 7 | +using Azure.ResourceManager.Resources.Models; |
| 8 | +using NUnit.Framework; |
| 9 | +using Azure.Core; |
| 10 | +using System; |
| 11 | +using System.Text; |
| 12 | +using Azure.ResourceManager.Resources; |
| 13 | +using System.Threading.Tasks; |
| 14 | +using NUnit.Framework.Internal; |
| 15 | +using System.IO; |
| 16 | + |
| 17 | +namespace Azure.ResourceManager.Automation.Tests.Helpers |
| 18 | +{ |
| 19 | + public static class ResourceDataHelpers |
| 20 | + { |
| 21 | + public static IDictionary<string, string> ReplaceWith(this IDictionary<string, string> dest, IDictionary<string, string> src) |
| 22 | + { |
| 23 | + dest.Clear(); |
| 24 | + foreach (var kv in src) |
| 25 | + { |
| 26 | + dest.Add(kv); |
| 27 | + } |
| 28 | + |
| 29 | + return dest; |
| 30 | + } |
| 31 | + |
| 32 | + public static void AssertResource(ResourceData r1, ResourceData r2) |
| 33 | + { |
| 34 | + Assert.AreEqual(r1.Name, r2.Name); |
| 35 | + Assert.AreEqual(r1.Id, r2.Id); |
| 36 | + Assert.AreEqual(r1.ResourceType, r2.ResourceType); |
| 37 | + } |
| 38 | + |
| 39 | + #region Credential |
| 40 | + public static void AssertCredential(AutomationCredentialData data1, AutomationCredentialData data2) |
| 41 | + { |
| 42 | + AssertResource(data1, data2); |
| 43 | + Assert.AreEqual(data1.UserName, data2.UserName); |
| 44 | + Assert.AreEqual(data1.Description, data2.Description); |
| 45 | + } |
| 46 | + |
| 47 | + public static AutomationCredentialCreateOrUpdateContent GetCredentialData(string name) |
| 48 | + { |
| 49 | + var data = new AutomationCredentialCreateOrUpdateContent(name, "userName1", "pwd1") |
| 50 | + { |
| 51 | + Description = "description of credential" |
| 52 | + }; |
| 53 | + return data; |
| 54 | + } |
| 55 | + #endregion |
| 56 | + |
| 57 | + #region DscConfigurationData |
| 58 | + public static void AssertDscConfiguration(DscConfigurationData data1, DscConfigurationData data2) |
| 59 | + { |
| 60 | + AssertResource(data1, data2); |
| 61 | + Assert.AreEqual(data1.Location, data2.Location); |
| 62 | + Assert.AreEqual(data1.Description, data2.Description); |
| 63 | + Assert.AreEqual(data1.State, data2.State); |
| 64 | + Assert.AreEqual(data1.JobCount, data2.JobCount); |
| 65 | + } |
| 66 | + |
| 67 | + public static DscConfigurationCreateOrUpdateContent GetDscConfigurationData(string name) |
| 68 | + { |
| 69 | + var data = new DscConfigurationCreateOrUpdateContent(new AutomationContentSource() |
| 70 | + { |
| 71 | + Hash = new AutomationContentHash("sha256", "A9E5DB56BA21513F61E0B3868816FDC6D4DF5131F5617D7FF0D769674BD5072F"), |
| 72 | + Value = "Configuration "+name+@" { Node SampleConfiguration.localhost { WindowsFeature IIS { Name = ""Web - Server""; Ensure = ""Present""; }}}", |
| 73 | + SourceType = AutomationContentSourceType.EmbeddedContent, |
| 74 | + Version = "1.0.0" |
| 75 | + }) |
| 76 | + { |
| 77 | + Description= "new sample configuration test", |
| 78 | + Location = AzureLocation.EastUS, |
| 79 | + }; |
| 80 | + return data; |
| 81 | + } |
| 82 | + #endregion |
| 83 | + |
| 84 | + #region DscNodeConfigurationData |
| 85 | + public static void AssertDscNodeConfiguration(DscNodeConfigurationData data1, DscNodeConfigurationData data2) |
| 86 | + { |
| 87 | + AssertResource(data1, data2); |
| 88 | + Assert.AreEqual(data1.ConfigurationName, data2.ConfigurationName); |
| 89 | + Assert.AreEqual(data1.Source, data2.Source); |
| 90 | + Assert.AreEqual(data1.NodeCount, data2.NodeCount); |
| 91 | + } |
| 92 | + |
| 93 | + public static DscNodeConfigurationCreateOrUpdateContent GetDscNodeConfigurationData(string dscconfigurationName) |
| 94 | + { |
| 95 | + var data = new DscNodeConfigurationCreateOrUpdateContent() |
| 96 | + { |
| 97 | + Name = "SampleConfiguration.localhost", |
| 98 | + Source = new AutomationContentSource() |
| 99 | + { |
| 100 | + Hash = new AutomationContentHash("sha256", "6DE256A57F01BFA29B88696D5E77A383D6E61484C7686E8DB955FA10ACE9FFE5"), |
| 101 | + Value = @"instance of MSFT_RoleResource as $MSFT_RoleResource1ref { ResourceID = ""[WindowsFeature]IIS""; Ensure = ""Present""; SourceInfo = ""::3::32::WindowsFeature""; Name = ""Web-Server""; ModuleName = ""PsDesiredStateConfiguration""; ModuleVersion = ""1.0""; ConfigurationName = ""SampleConfiguration""; }; instance of OMI_ConfigurationDocument { Version=""2.0.0""; MinimumCompatibleVersion = ""1.0.0""; CompatibleVersionAdditionalProperties= {""Omi_BaseResource:ConfigurationName""}; Author=""vameru""; GenerationDate=""03/30/2017 13:40:25""; GenerationHost=""VAMERU-BACKEND""; Name=""SampleConfiguration""; };", |
| 102 | + SourceType = AutomationContentSourceType.EmbeddedContent, |
| 103 | + Version = "1.0" |
| 104 | + }, |
| 105 | + ConfigurationName = "SampleConfiguration", |
| 106 | + IsIncrementNodeConfigurationBuildRequired = false |
| 107 | + }; |
| 108 | + return data; |
| 109 | + } |
| 110 | + #endregion |
| 111 | + |
| 112 | + #region Runbook |
| 113 | + |
| 114 | + public static AutomationRunbookCreateOrUpdateContent GetRunbookData() |
| 115 | + { |
| 116 | + var data = new AutomationRunbookCreateOrUpdateContent(AutomationRunbookType.Script) |
| 117 | + { |
| 118 | + Location = AzureLocation.EastUS |
| 119 | + }; |
| 120 | + return data; |
| 121 | + } |
| 122 | + |
| 123 | + public static void AssertRunbook(AutomationRunbookData data1, AutomationRunbookData data2) |
| 124 | + { |
| 125 | + AssertResource(data1, data2); |
| 126 | + Assert.AreEqual(data1.Location, data2.Location); |
| 127 | + Assert.AreEqual(data1.State, data2.State); |
| 128 | + Assert.AreEqual(data1.Description, data2.Description); |
| 129 | + Assert.AreEqual(data1.JobCount, data2.JobCount); |
| 130 | + } |
| 131 | + #endregion |
| 132 | + |
| 133 | + #region SourceControl |
| 134 | + public static AutomationSourceControlCreateOrUpdateContent GetSourceControlData() |
| 135 | + { |
| 136 | + var data = new AutomationSourceControlCreateOrUpdateContent() |
| 137 | + { |
| 138 | + RepoUri = new Uri("https://dev.azure.com/vinkumar0563/_git/VinKumar-AzureAutomation"), |
| 139 | + Branch = "sdktest", |
| 140 | + FolderPath = "/Runbooks/PowershellScripts", |
| 141 | + IsAutoSyncEnabled = false, |
| 142 | + IsAutoPublishRunbookEnabled = true, |
| 143 | + SourceType = SourceControlSourceType.VsoGit, |
| 144 | + SecurityToken = new SourceControlSecurityTokenProperties() |
| 145 | + { |
| 146 | + AccessToken = "stringfortoken", |
| 147 | + TokenType = SourceControlTokenType.PersonalAccessToken |
| 148 | + }, |
| 149 | + Description = "test creating a Source Control", |
| 150 | + }; |
| 151 | + return data; |
| 152 | + } |
| 153 | + |
| 154 | + public static void AssertSourceControl(AutomationSourceControlData data1, AutomationSourceControlData data2) |
| 155 | + { |
| 156 | + AssertResource(data1, data2); |
| 157 | + Assert.AreEqual(data1.Description, data2.Description); |
| 158 | + Assert.AreEqual(data1.Branch, data2.Branch); |
| 159 | + Assert.AreEqual(data1.RepoUri, data2.RepoUri); |
| 160 | + Assert.AreEqual(data1.FolderPath, data2.FolderPath); |
| 161 | + } |
| 162 | + #endregion |
| 163 | + |
| 164 | + #region Variable |
| 165 | + public static AutomationVariableCreateOrUpdateContent GetVariableData(string name) |
| 166 | + { |
| 167 | + var data = new AutomationVariableCreateOrUpdateContent(name) |
| 168 | + { |
| 169 | + Value = "10", |
| 170 | + IsEncrypted = false, |
| 171 | + }; |
| 172 | + return data; |
| 173 | + } |
| 174 | + |
| 175 | + public static void AssertVariable(AutomationVariableData data1, AutomationVariableData data2) |
| 176 | + { |
| 177 | + AssertResource(data1, data2); |
| 178 | + Assert.AreEqual(data1.Value, data2.Value); |
| 179 | + Assert.AreEqual(data1.IsEncrypted, data2.IsEncrypted); |
| 180 | + Assert.AreEqual(data1.CreatedOn, data2.CreatedOn); |
| 181 | + Assert.AreEqual(data1.LastModifiedOn, data2.LastModifiedOn); |
| 182 | + Assert.AreEqual(data1.Description, data2.Description); |
| 183 | + } |
| 184 | + #endregion |
| 185 | + |
| 186 | + #region Schedule |
| 187 | + public static AutomationScheduleCreateOrUpdateContent GetScheduleData(string name) |
| 188 | + { |
| 189 | + var data = new AutomationScheduleCreateOrUpdateContent(name, DateTime.Today.AddDays(1), AutomationScheduleFrequency.Hour) |
| 190 | + { |
| 191 | + Interval = BinaryData.FromString("1"), |
| 192 | + }; |
| 193 | + return data; |
| 194 | + } |
| 195 | + |
| 196 | + public static void AssertSchedule(AutomationScheduleData data1, AutomationScheduleData data2) |
| 197 | + { |
| 198 | + AssertResource(data1, data2); |
| 199 | + Assert.AreEqual(data1.Frequency, data2.Frequency); |
| 200 | + Assert.AreEqual(data1.Description, data2.Description); |
| 201 | + } |
| 202 | + #endregion |
| 203 | + |
| 204 | + #region Account |
| 205 | + public static AutomationAccountCreateOrUpdateContent GetAccountData() |
| 206 | + { |
| 207 | + var data = new AutomationAccountCreateOrUpdateContent() |
| 208 | + { |
| 209 | + Sku = new AutomationSku("Basic"), |
| 210 | + Location = AzureLocation.EastUS |
| 211 | + }; |
| 212 | + return data; |
| 213 | + } |
| 214 | + |
| 215 | + public static void AssertAccount(AutomationAccountData data1, AutomationAccountData data2) |
| 216 | + { |
| 217 | + AssertResource(data1, data2); |
| 218 | + Assert.AreEqual(data1.Location, data2.Location); |
| 219 | + Assert.AreEqual(data1.Description, data2.Description); |
| 220 | + } |
| 221 | + #endregion |
| 222 | + } |
| 223 | +} |
0 commit comments