| | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | 2 | | // Licensed under the MIT License. |
| | 3 | |
|
| | 4 | | using System; |
| | 5 | | using System.ComponentModel; |
| | 6 | |
|
| | 7 | | namespace Azure.Security.KeyVault.Certificates |
| | 8 | | { |
| | 9 | | /// <summary> |
| | 10 | | /// Model factory that enables mocking for the Key Vault Certificates library. |
| | 11 | | /// </summary> |
| | 12 | | public static class CertificateModelFactory |
| | 13 | | { |
| | 14 | | /// <summary> |
| | 15 | | /// Initializes a new instance of the <see cref="Certificates.IssuerProperties"/> for mocking purposes. |
| | 16 | | /// </summary> |
| | 17 | | /// <param name="id">Sets the <see cref="Certificates.IssuerProperties.Id"/> property.</param> |
| | 18 | | /// <param name="name">Sets the <see cref="Certificates.IssuerProperties.Name"/> property.</param> |
| | 19 | | /// <returns>A new instance of the <see cref="Certificates.IssuerProperties"/> for mocking purposes.</returns> |
| | 20 | | public static IssuerProperties IssuerProperties( |
| | 21 | | Uri id = default, |
| 0 | 22 | | string name = default) => new IssuerProperties |
| 0 | 23 | | { |
| 0 | 24 | | Id = id, |
| 0 | 25 | | Name = name, |
| 0 | 26 | | }; |
| | 27 | |
|
| | 28 | | /// <summary> |
| | 29 | | /// Initializes a new instance of the <see cref="Certificates.CertificateIssuer"/> for mocking purposes. |
| | 30 | | /// </summary> |
| | 31 | | /// <param name="properties">Sets the <see cref="Certificates.CertificateIssuer.Id"/>, <see cref="Certificates.C |
| | 32 | | /// <param name="createdOn">Sets the <see cref="Certificates.CertificateIssuer.CreatedOn"/> property.</param> |
| | 33 | | /// <param name="updatedOn">Sets the <see cref="Certificates.CertificateIssuer.UpdatedOn"/> property.</param> |
| | 34 | | /// <returns>A new instance of the <see cref="Certificates.CertificateIssuer"/> for mocking purposes.</returns> |
| | 35 | | public static CertificateIssuer CertificateIssuer( |
| | 36 | | IssuerProperties properties, |
| | 37 | | DateTimeOffset? createdOn = default, |
| 0 | 38 | | DateTimeOffset? updatedOn = default) => new CertificateIssuer(properties) |
| 0 | 39 | | { |
| 0 | 40 | | CreatedOn = createdOn, |
| 0 | 41 | | UpdatedOn = updatedOn, |
| 0 | 42 | | }; |
| | 43 | |
|
| | 44 | | // TODO: How should we support CertificateOperation? |
| | 45 | |
|
| | 46 | | /// <summary> |
| | 47 | | /// Initializes a new instance of the <see cref="Certificates.CertificateOperationError"/> for mocking purposes. |
| | 48 | | /// </summary> |
| | 49 | | /// <param name="code">Sets the <see cref="Certificates.CertificateOperationError.Code"/> property.</param> |
| | 50 | | /// <param name="message">Sets the <see cref="Certificates.CertificateOperationError.Message"/> property.</param |
| | 51 | | /// <param name="innerError">Sets the <see cref="Certificates.CertificateOperationError.InnerError"/> property.< |
| | 52 | | /// <returns>A new instance of the <see cref="Certificates.CertificateOperationError"/> for mocking purposes.</r |
| | 53 | | public static CertificateOperationError CertificateOperationError( |
| | 54 | | string code = default, |
| | 55 | | string message = default, |
| 0 | 56 | | CertificateOperationError innerError = default) => new CertificateOperationError |
| 0 | 57 | | { |
| 0 | 58 | | Code = code, |
| 0 | 59 | | Message = message, |
| 0 | 60 | | InnerError = innerError, |
| 0 | 61 | | }; |
| | 62 | |
|
| | 63 | | /// <summary> |
| | 64 | | /// Initializes a new instance of the <see cref="Certificates.CertificateOperationProperties"/> for mocking purp |
| | 65 | | /// </summary> |
| | 66 | | /// <param name="id">Sets the <see cref="Certificates.CertificateOperationProperties.Id"/> property.</param> |
| | 67 | | /// <param name="name">Sets the <see cref="Certificates.CertificateOperationProperties.Name"/> property.</param> |
| | 68 | | /// <param name="vaultUri">Sets the <see cref="Certificates.CertificateOperationProperties.VaultUri"/> property. |
| | 69 | | /// <param name="issuerName">Sets the <see cref="Certificates.CertificateOperationProperties.IssuerName"/> prope |
| | 70 | | /// <param name="certificateType">Sets the <see cref="Certificates.CertificateOperationProperties.CertificateTyp |
| | 71 | | /// <param name="certificateTransparency">Sets the <see cref="Certificates.CertificateOperationProperties.Certif |
| | 72 | | /// <param name="csr">Sets the <see cref="Certificates.CertificateOperationProperties.Csr"/> property.</param> |
| | 73 | | /// <param name="cancellationRequested">Sets the <see cref="Certificates.CertificateOperationProperties.Cancella |
| | 74 | | /// <param name="requestId">Sets the <see cref="Certificates.CertificateOperationProperties.RequestId"/> propert |
| | 75 | | /// <param name="status">Sets the <see cref="Certificates.CertificateOperationProperties.Status"/> property.</pa |
| | 76 | | /// <param name="statusDetails">Sets the <see cref="Certificates.CertificateOperationProperties.StatusDetails"/> |
| | 77 | | /// <param name="target">Sets the <see cref="Certificates.CertificateOperationProperties.Target"/> property.</pa |
| | 78 | | /// <param name="error">Sets the <see cref="Certificates.CertificateOperationProperties.Error"/> property.</para |
| | 79 | | /// <returns>A new instance of the <see cref="Certificates.CertificateOperationProperties"/> for mocking purpose |
| | 80 | | public static CertificateOperationProperties CertificateOperationProperties( |
| | 81 | | Uri id = default, |
| | 82 | | string name = default, |
| | 83 | | Uri vaultUri = default, |
| | 84 | | string issuerName = default, |
| | 85 | | string certificateType = default, |
| | 86 | | bool? certificateTransparency = default, |
| | 87 | | byte[] csr = default, |
| | 88 | | bool cancellationRequested = default, |
| | 89 | | string requestId = default, |
| | 90 | | string status = default, |
| | 91 | | string statusDetails = default, |
| | 92 | | string target = default, |
| 0 | 93 | | CertificateOperationError error = default) => new CertificateOperationProperties |
| 0 | 94 | | { |
| 0 | 95 | | Id = id, |
| 0 | 96 | | Name = name, |
| 0 | 97 | | VaultUri = vaultUri, |
| 0 | 98 | | IssuerName = issuerName, |
| 0 | 99 | | CertificateType = certificateType, |
| 0 | 100 | | CertificateTransparency = certificateTransparency, |
| 0 | 101 | | Csr = csr, |
| 0 | 102 | | CancellationRequested = cancellationRequested, |
| 0 | 103 | | RequestId = requestId, |
| 0 | 104 | | Status = status, |
| 0 | 105 | | StatusDetails = statusDetails, |
| 0 | 106 | | Target = target, |
| 0 | 107 | | Error = error, |
| 0 | 108 | | }; |
| | 109 | |
|
| | 110 | | /// <summary> |
| | 111 | | /// Initializes a new instance of the <see cref="Certificates.CertificatePolicy"/> for mocking purposes. |
| | 112 | | /// </summary> |
| | 113 | | /// <param name="subject">Sets the <see cref="Certificates.CertificatePolicy.Subject"/> property.</param> |
| | 114 | | /// <param name="subjectAlternativeNames">Sets the <see cref="Certificates.CertificatePolicy.SubjectAlternativeN |
| | 115 | | /// <param name="issuerName">Sets the <see cref="Certificates.CertificatePolicy.IssuerName"/> property.</param> |
| | 116 | | /// <param name="createdOn">Sets the <see cref="Certificates.CertificatePolicy.CreatedOn"/> property.</param> |
| | 117 | | /// <param name="updatedOn">Sets the <see cref="Certificates.CertificatePolicy.UpdatedOn"/> property.</param> |
| | 118 | | /// <returns>A new instance of the <see cref="Certificates.CertificatePolicy"/> for mocking purposes.</returns> |
| | 119 | | public static CertificatePolicy CertificatePolicy( |
| | 120 | | string subject = default, |
| | 121 | | SubjectAlternativeNames subjectAlternativeNames = default, |
| | 122 | | string issuerName = default, |
| | 123 | | DateTimeOffset? createdOn = default, |
| 0 | 124 | | DateTimeOffset? updatedOn = default) => new CertificatePolicy |
| 0 | 125 | | { |
| 0 | 126 | | Subject = subject, |
| 0 | 127 | | SubjectAlternativeNames = subjectAlternativeNames, |
| 0 | 128 | | IssuerName = issuerName, |
| 0 | 129 | | CreatedOn = createdOn, |
| 0 | 130 | | UpdatedOn = updatedOn, |
| 0 | 131 | | }; |
| | 132 | |
|
| | 133 | | /// <summary> |
| | 134 | | /// Initializes a new instance of the <see cref="Certificates.CertificateProperties"/> for mocking purposes. |
| | 135 | | /// </summary> |
| | 136 | | /// <param name="id">Sets the <see cref="Certificates.CertificateProperties.Id"/> property.</param> |
| | 137 | | /// <param name="name">Sets the <see cref="Certificates.CertificateProperties.Name"/> property.</param> |
| | 138 | | /// <param name="vaultUri">Sets the <see cref="Certificates.CertificateProperties.VaultUri"/> property.</param> |
| | 139 | | /// <param name="version">Sets the <see cref="Certificates.CertificateProperties.Version"/> property.</param> |
| | 140 | | /// <param name="x509thumbprint">Sets the <see cref="Certificates.CertificateProperties.X509Thumbprint"/> proper |
| | 141 | | /// <param name="notBefore">Sets the <see cref="Certificates.CertificateProperties.NotBefore"/> property.</param |
| | 142 | | /// <param name="expiresOn">Sets the <see cref="Certificates.CertificateProperties.ExpiresOn"/> property.</param |
| | 143 | | /// <param name="createdOn">Sets the <see cref="Certificates.CertificateProperties.CreatedOn"/> property.</param |
| | 144 | | /// <param name="updatedOn">Sets the <see cref="Certificates.CertificateProperties.UpdatedOn"/> property.</param |
| | 145 | | /// <param name="recoveryLevel">Sets the <see cref="Certificates.CertificateProperties.RecoveryLevel"/> property |
| | 146 | | /// <returns>A new instance of the <see cref="Certificates.CertificateProperties"/> for mocking purposes.</retur |
| | 147 | | [EditorBrowsable(EditorBrowsableState.Never)] |
| | 148 | | public static CertificateProperties CertificateProperties( |
| | 149 | | Uri id, |
| | 150 | | string name, |
| | 151 | | Uri vaultUri, |
| | 152 | | string version, |
| | 153 | | byte[] x509thumbprint, |
| | 154 | | DateTimeOffset? notBefore, |
| | 155 | | DateTimeOffset? expiresOn, |
| | 156 | | DateTimeOffset? createdOn, |
| | 157 | | DateTimeOffset? updatedOn, |
| 0 | 158 | | string recoveryLevel) => CertificateProperties( |
| 0 | 159 | | id, |
| 0 | 160 | | name, |
| 0 | 161 | | vaultUri, |
| 0 | 162 | | version, |
| 0 | 163 | | x509thumbprint, |
| 0 | 164 | | notBefore, |
| 0 | 165 | | expiresOn, |
| 0 | 166 | | createdOn, |
| 0 | 167 | | updatedOn, |
| 0 | 168 | | recoveryLevel, |
| 0 | 169 | | default); |
| | 170 | |
|
| | 171 | | /// <summary> |
| | 172 | | /// Initializes a new instance of the <see cref="Certificates.CertificateProperties"/> for mocking purposes. |
| | 173 | | /// </summary> |
| | 174 | | /// <param name="id">Sets the <see cref="Certificates.CertificateProperties.Id"/> property.</param> |
| | 175 | | /// <param name="name">Sets the <see cref="Certificates.CertificateProperties.Name"/> property.</param> |
| | 176 | | /// <param name="vaultUri">Sets the <see cref="Certificates.CertificateProperties.VaultUri"/> property.</param> |
| | 177 | | /// <param name="version">Sets the <see cref="Certificates.CertificateProperties.Version"/> property.</param> |
| | 178 | | /// <param name="x509thumbprint">Sets the <see cref="Certificates.CertificateProperties.X509Thumbprint"/> proper |
| | 179 | | /// <param name="notBefore">Sets the <see cref="Certificates.CertificateProperties.NotBefore"/> property.</param |
| | 180 | | /// <param name="expiresOn">Sets the <see cref="Certificates.CertificateProperties.ExpiresOn"/> property.</param |
| | 181 | | /// <param name="createdOn">Sets the <see cref="Certificates.CertificateProperties.CreatedOn"/> property.</param |
| | 182 | | /// <param name="updatedOn">Sets the <see cref="Certificates.CertificateProperties.UpdatedOn"/> property.</param |
| | 183 | | /// <param name="recoveryLevel">Sets the <see cref="Certificates.CertificateProperties.RecoveryLevel"/> property |
| | 184 | | /// <param name="recoverableDays">Sets the <see cref="Certificates.CertificateProperties.RecoverableDays"/> prop |
| | 185 | | /// <returns>A new instance of the <see cref="Certificates.CertificateProperties"/> for mocking purposes.</retur |
| | 186 | | public static CertificateProperties CertificateProperties( |
| | 187 | | Uri id = default, |
| | 188 | | string name = default, |
| | 189 | | Uri vaultUri = default, |
| | 190 | | string version = default, |
| | 191 | | byte[] x509thumbprint = default, |
| | 192 | | DateTimeOffset? notBefore = default, |
| | 193 | | DateTimeOffset? expiresOn = default, |
| | 194 | | DateTimeOffset? createdOn = default, |
| | 195 | | DateTimeOffset? updatedOn = default, |
| | 196 | | string recoveryLevel = default, |
| 0 | 197 | | int? recoverableDays = default) => new CertificateProperties |
| 0 | 198 | | { |
| 0 | 199 | | Id = id, |
| 0 | 200 | | Name = name, |
| 0 | 201 | | VaultUri = vaultUri, |
| 0 | 202 | | Version = version, |
| 0 | 203 | | X509Thumbprint = x509thumbprint, |
| 0 | 204 | | NotBefore = notBefore, |
| 0 | 205 | | ExpiresOn = expiresOn, |
| 0 | 206 | | CreatedOn = createdOn, |
| 0 | 207 | | UpdatedOn = updatedOn, |
| 0 | 208 | | RecoveryLevel = recoveryLevel, |
| 0 | 209 | | RecoverableDays = recoverableDays, |
| 0 | 210 | | }; |
| | 211 | |
|
| | 212 | | /// <summary> |
| | 213 | | /// Initializes a new instance of the <see cref="Certificates.DeletedCertificate"/> for mocking purposes. |
| | 214 | | /// </summary> |
| | 215 | | /// <param name="properties">Sets the <see cref="Certificates.KeyVaultCertificate.Properties"/> property.</param |
| | 216 | | /// <param name="keyId">Sets the <see cref="Certificates.KeyVaultCertificate.KeyId"/> property.</param> |
| | 217 | | /// <param name="secretId">Sets the <see cref="Certificates.KeyVaultCertificate.SecretId"/> property.</param> |
| | 218 | | /// <param name="cer">Sets the <see cref="Certificates.KeyVaultCertificate.Cer"/> property.</param> |
| | 219 | | /// <param name="policy">Sets the <see cref="Certificates.KeyVaultCertificateWithPolicy.Policy"/> property.</par |
| | 220 | | /// <param name="recoveryId">Sets the <see cref="Certificates.DeletedCertificate.RecoveryId"/> property.</param> |
| | 221 | | /// <param name="deletedOn">Sets the <see cref="Certificates.DeletedCertificate.DeletedOn"/> property.</param> |
| | 222 | | /// <param name="scheduledPurgeDate">Sets the <see cref="Certificates.DeletedCertificate.ScheduledPurgeDate"/> p |
| | 223 | | /// <returns>A new instance of the <see cref="Certificates.DeletedCertificate"/> for mocking purposes.</returns> |
| | 224 | | public static DeletedCertificate DeletedCertificate( |
| | 225 | | CertificateProperties properties, |
| | 226 | | Uri keyId = default, |
| | 227 | | Uri secretId = default, |
| | 228 | | byte[] cer = default, |
| | 229 | | CertificatePolicy policy = default, |
| | 230 | | Uri recoveryId = default, |
| | 231 | | DateTimeOffset? deletedOn = default, |
| 0 | 232 | | DateTimeOffset? scheduledPurgeDate = default) => new DeletedCertificate(properties) |
| 0 | 233 | | { |
| 0 | 234 | | KeyId = keyId, |
| 0 | 235 | | SecretId = secretId, |
| 0 | 236 | | Cer = cer, |
| 0 | 237 | | Policy = policy, |
| 0 | 238 | | RecoveryId = recoveryId, |
| 0 | 239 | | DeletedOn = deletedOn, |
| 0 | 240 | | ScheduledPurgeDate = scheduledPurgeDate, |
| 0 | 241 | | }; |
| | 242 | |
|
| | 243 | | /// <summary> |
| | 244 | | /// Initializes a new instance of the <see cref="Certificates.KeyVaultCertificate"/> for mocking purposes. |
| | 245 | | /// </summary> |
| | 246 | | /// <param name="properties">Sets the <see cref="Certificates.KeyVaultCertificate.Properties"/> property.</param |
| | 247 | | /// <param name="keyId">Sets the <see cref="Certificates.KeyVaultCertificate.KeyId"/> property.</param> |
| | 248 | | /// <param name="secretId">Sets the <see cref="Certificates.KeyVaultCertificate.SecretId"/> property.</param> |
| | 249 | | /// <param name="cer">Sets the <see cref="Certificates.KeyVaultCertificate.Cer"/> property.</param> |
| | 250 | | /// <returns>A new instance of the <see cref="Certificates.KeyVaultCertificate"/> for mocking purposes.</returns |
| | 251 | | public static KeyVaultCertificate KeyVaultCertificate( |
| | 252 | | CertificateProperties properties, |
| | 253 | | Uri keyId = default, |
| | 254 | | Uri secretId = default, |
| 0 | 255 | | byte[] cer = default) => new KeyVaultCertificate(properties) |
| 0 | 256 | | { |
| 0 | 257 | | KeyId = keyId, |
| 0 | 258 | | SecretId = secretId, |
| 0 | 259 | | Cer = cer, |
| 0 | 260 | | }; |
| | 261 | |
|
| | 262 | | /// <summary> |
| | 263 | | /// Initializes a new instance of the <see cref="Certificates.KeyVaultCertificateWithPolicy"/> for mocking purpo |
| | 264 | | /// </summary> |
| | 265 | | /// <param name="properties">Sets the <see cref="Certificates.KeyVaultCertificate.Properties"/> property.</param |
| | 266 | | /// <param name="keyId">Sets the <see cref="Certificates.KeyVaultCertificate.KeyId"/> property.</param> |
| | 267 | | /// <param name="secretId">Sets the <see cref="Certificates.KeyVaultCertificate.SecretId"/> property.</param> |
| | 268 | | /// <param name="cer">Sets the <see cref="Certificates.KeyVaultCertificate.Cer"/> property.</param> |
| | 269 | | /// <param name="policy">Sets the <see cref="Certificates.KeyVaultCertificateWithPolicy.Policy"/> property.</par |
| | 270 | | /// <returns>A new instance of the <see cref="Certificates.KeyVaultCertificateWithPolicy"/> for mocking purposes |
| | 271 | | public static KeyVaultCertificateWithPolicy KeyVaultCertificateWithPolicy( |
| | 272 | | CertificateProperties properties, |
| | 273 | | Uri keyId = default, |
| | 274 | | Uri secretId = default, |
| | 275 | | byte[] cer = default, |
| 0 | 276 | | CertificatePolicy policy = default) => new KeyVaultCertificateWithPolicy(properties) |
| 0 | 277 | | { |
| 0 | 278 | | KeyId = keyId, |
| 0 | 279 | | SecretId = secretId, |
| 0 | 280 | | Cer = cer, |
| 0 | 281 | | Policy = policy, |
| 0 | 282 | | }; |
| | 283 | | } |
| | 284 | | } |