|
| 1 | +// |
| 2 | +// Copyright (c) Microsoft. All rights reserved. |
| 3 | +// Licensed under the MIT license. See LICENSE file in the project root for full license information. |
| 4 | +// |
| 5 | + |
| 6 | +using Moq; |
| 7 | +using Xunit; |
| 8 | +using Microsoft.Azure.Functions.PowerShellWorker.Utility; |
| 9 | +using System.Collections.Generic; |
| 10 | + |
| 11 | +namespace Microsoft.Azure.Functions.PowerShellWorker.Test |
| 12 | +{ |
| 13 | + public class FunctionsEnvironmentReloaderTests |
| 14 | + { |
| 15 | + private readonly Mock<ILogger> _mockLogger = new Mock<ILogger>(); |
| 16 | + |
| 17 | + [Fact] |
| 18 | + public void SetsEnvironmentVariables() |
| 19 | + { |
| 20 | + var actualEnvironmentVariables = new List<KeyValuePair<string, string>>(); |
| 21 | + |
| 22 | + var reloader = new FunctionsEnvironmentReloader( |
| 23 | + logger: _mockLogger.Object, |
| 24 | + setEnvironmentVariable: (name, value) => { actualEnvironmentVariables.Add(new KeyValuePair<string, string>(name, value)); }, |
| 25 | + setCurrentDirectory: directory => { }); |
| 26 | + |
| 27 | + var requestedEnvironmentVariables = new[] { |
| 28 | + new KeyValuePair<string, string>( "name1", "valueA" ), |
| 29 | + new KeyValuePair<string, string>( "name2", "valueB" ), |
| 30 | + new KeyValuePair<string, string>( "name3", "valueC" ), |
| 31 | + }; |
| 32 | + |
| 33 | + reloader.ReloadEnvironment(requestedEnvironmentVariables, functionAppDirectory: null); |
| 34 | + |
| 35 | + Assert.Equal(requestedEnvironmentVariables, actualEnvironmentVariables); |
| 36 | + } |
| 37 | + |
| 38 | + [Fact] |
| 39 | + public void SetsFunctionAppDirectoryIfRequested() |
| 40 | + { |
| 41 | + const string RequestedNewDirectory = "new app directory"; |
| 42 | + string actualNewDirectory = null; |
| 43 | + |
| 44 | + var reloader = new FunctionsEnvironmentReloader( |
| 45 | + logger: _mockLogger.Object, |
| 46 | + setEnvironmentVariable: (name, value) => { }, |
| 47 | + setCurrentDirectory: directory => { actualNewDirectory = directory; }); |
| 48 | + |
| 49 | + reloader.ReloadEnvironment(new List<KeyValuePair<string, string>>(), RequestedNewDirectory); |
| 50 | + |
| 51 | + Assert.Equal(RequestedNewDirectory, actualNewDirectory); |
| 52 | + } |
| 53 | + |
| 54 | + [Fact] |
| 55 | + public void DoesNotSetFunctionAppDirectoryIfNotRequested() |
| 56 | + { |
| 57 | + var reloader = new FunctionsEnvironmentReloader( |
| 58 | + logger: _mockLogger.Object, |
| 59 | + setEnvironmentVariable: (name, value) => { }, |
| 60 | + setCurrentDirectory: directory => { Assert.True(false, "Unexpected invocation"); }); |
| 61 | + |
| 62 | + reloader.ReloadEnvironment(new List<KeyValuePair<string, string>>(), functionAppDirectory: null); |
| 63 | + } |
| 64 | + } |
| 65 | +} |
0 commit comments