|
| 1 | +using System; |
| 2 | +using System.Linq; |
| 3 | +using System.Threading.Tasks; |
| 4 | +using Microsoft.Azure.WebJobs.Script.Models; |
| 5 | +using Microsoft.Azure.WebJobs.Script.Workers.Rpc; |
| 6 | +using Microsoft.Extensions.DependencyInjection; |
| 7 | +using Microsoft.WindowsAzure.Storage.Queue; |
| 8 | +using Xunit; |
| 9 | + |
| 10 | +namespace Microsoft.Azure.WebJobs.Script.Tests.Integration.Storage |
| 11 | +{ |
| 12 | + public class StorageEndToEndTests : IClassFixture<StorageEndToEndTests.StorageTestFixture> |
| 13 | + { |
| 14 | + private StorageTestFixture _fixture; |
| 15 | + |
| 16 | + public StorageEndToEndTests(StorageTestFixture fixture) |
| 17 | + { |
| 18 | + _fixture = fixture; |
| 19 | + } |
| 20 | + |
| 21 | + [Fact] |
| 22 | + public async Task QueueTriggerToBlobRich() |
| 23 | + { |
| 24 | + var logs = _fixture.Host.GetScriptHostLogMessages(); |
| 25 | + |
| 26 | + string id = Guid.NewGuid().ToString(); |
| 27 | + string messageContent = string.Format("{{ \"id\": \"{0}\" }}", id); |
| 28 | + CloudQueueMessage message = new CloudQueueMessage(messageContent); |
| 29 | + |
| 30 | + await _fixture.TestQueue.AddMessageAsync(message); |
| 31 | + |
| 32 | + var resultBlob = _fixture.TestOutputContainer.GetBlockBlobReference(id); |
| 33 | + string result = await TestHelpers.WaitForBlobAndGetStringAsync(resultBlob); |
| 34 | + Assert.Equal(TestHelpers.RemoveByteOrderMarkAndWhitespace(messageContent), TestHelpers.RemoveByteOrderMarkAndWhitespace(result)); |
| 35 | + } |
| 36 | + |
| 37 | + public class StorageTestFixture : EndToEndTestFixture |
| 38 | + { |
| 39 | + public StorageTestFixture() : base(@"TestScripts\CSharp", "csharp", RpcWorkerConstants.DotNetLanguageWorkerName) |
| 40 | + { |
| 41 | + } |
| 42 | + |
| 43 | + protected override ExtensionPackageReference[] GetExtensionsToInstall() |
| 44 | + { |
| 45 | + // This test fixture should use the most recent major version of the storage extension, so update this as required. |
| 46 | + return new ExtensionPackageReference[] |
| 47 | + { |
| 48 | + new ExtensionPackageReference |
| 49 | + { |
| 50 | + Id = "Microsoft.Azure.WebJobs.Extensions.Storage", |
| 51 | + Version = "3.0.10" |
| 52 | + } |
| 53 | + }; |
| 54 | + } |
| 55 | + |
| 56 | + public override void ConfigureScriptHost(IWebJobsBuilder webJobsBuilder) |
| 57 | + { |
| 58 | + webJobsBuilder.Services.Configure<ScriptJobHostOptions>(o => |
| 59 | + { |
| 60 | + o.Functions = new[] |
| 61 | + { |
| 62 | + "QueueTriggerToBlobRichTypes", |
| 63 | + }; |
| 64 | + }); |
| 65 | + } |
| 66 | + } |
| 67 | + } |
| 68 | + |
| 69 | + |
| 70 | + public class StorageV9EndToEndTests : IClassFixture<StorageV9EndToEndTests.StorageReferenceTestFixture> |
| 71 | + { |
| 72 | + private EndToEndTestFixture _fixture; |
| 73 | + |
| 74 | + public StorageV9EndToEndTests(StorageReferenceTestFixture fixture) |
| 75 | + { |
| 76 | + _fixture = fixture; |
| 77 | + } |
| 78 | + |
| 79 | + [Fact] |
| 80 | + public async Task CanUseStorageV9Types() |
| 81 | + { |
| 82 | + // The point of this test is to verify back compat behavior that a user can still #r and use storage v9 types in CSX, |
| 83 | + // regardless of whether the storage extension installed (and of what version) |
| 84 | + |
| 85 | + string testData = Guid.NewGuid().ToString(); |
| 86 | + |
| 87 | + await _fixture.Host.BeginFunctionAsync("StorageReferenceV9", testData); |
| 88 | + |
| 89 | + await TestHelpers.Await(() => |
| 90 | + { |
| 91 | + // make sure the function executed successfully |
| 92 | + var logs = _fixture.Host.GetScriptHostLogMessages(); |
| 93 | + return logs.Any(p => p.FormattedMessage != null && p.FormattedMessage.Contains(testData)); |
| 94 | + }, userMessageCallback: _fixture.Host.GetLog); |
| 95 | + } |
| 96 | + |
| 97 | + public class StorageReferenceTestFixture : EndToEndTestFixture |
| 98 | + { |
| 99 | + public StorageReferenceTestFixture() : base(@"TestScripts\CSharp", "csharp", RpcWorkerConstants.DotNetLanguageWorkerName) |
| 100 | + { |
| 101 | + } |
| 102 | + |
| 103 | + protected override ExtensionPackageReference[] GetExtensionsToInstall() |
| 104 | + { |
| 105 | + // It is explicitly intended that this scenario has no package references |
| 106 | + return new ExtensionPackageReference[] |
| 107 | + { |
| 108 | + }; |
| 109 | + } |
| 110 | + |
| 111 | + public override void ConfigureScriptHost(IWebJobsBuilder webJobsBuilder) |
| 112 | + { |
| 113 | + webJobsBuilder.Services.Configure<ScriptJobHostOptions>(o => |
| 114 | + { |
| 115 | + o.Functions = new[] |
| 116 | + { |
| 117 | + "StorageReferenceV9", |
| 118 | + }; |
| 119 | + }); |
| 120 | + } |
| 121 | + } |
| 122 | + } |
| 123 | +} |
0 commit comments