コード例 #1
0
        public async Task CanGetAzureSettings()
        {
            var fullPath = Path.GetFullPath($"./{nameof(CanGetAzureSettings)}");
            var envMock  = GetEnvMock(fullPath, false);

            var model = new UserSettings.Model {
                Azure = new AzureSettings {
                    SubscriptionId = Guid.NewGuid().ToString("N")
                }
            };
            var json     = JsonConvert.SerializeObject(model, JsonUtil.CreateSettings());
            var fileMock = new Mock <IFileUtil>(MockBehavior.Strict);

            fileMock.Setup(m => m.ReadAllText(It.IsAny <string>())).ReturnsAsync(json);

            var settings   = new UserSettings(fileMock.Object, envMock.Object);
            var azSettings = await settings.GetAzureSettings();

            Assert.Equal(model.Azure.SubscriptionId, azSettings.SubscriptionId);

            model = new UserSettings.Model();
            json  = JsonConvert.SerializeObject(model, JsonUtil.CreateSettings());
            fileMock.Setup(m => m.ReadAllText(It.IsAny <string>())).ReturnsAsync(json);
            azSettings = await settings.GetAzureSettings();

            Assert.NotNull(azSettings);
            Assert.Equal(default, azSettings.SubscriptionId);
コード例 #2
0
        public async Task CanGetServer()
        {
            var uri        = new Uri("http://acme.d/d");
            var fullPath   = Path.GetFullPath($"./{nameof(CanGetServer)}");
            var configPath = Path.Combine(fullPath, ".certes", "certes.json");
            var envMock    = GetEnvMock(fullPath);

            var fileMock = new Mock <IFileUtil>(MockBehavior.Strict);

            fileMock.Setup(m => m.ReadAllText(It.IsAny <string>())).ReturnsAsync((string)null);

            var settings = new UserSettings(fileMock.Object, envMock.Object);

            Assert.Equal(WellKnownServers.LetsEncryptV2, await settings.GetDefaultServer());
            fileMock.Verify(m => m.ReadAllText(configPath), Times.Once);

            fileMock.ResetCalls();
            var model = new UserSettings.Model {
                DefaultServer = uri, Servers = new AcmeSettings[0]
            };

            fileMock.Setup(m => m.ReadAllText(It.IsAny <string>()))
            .ReturnsAsync(JsonConvert.SerializeObject(model, JsonUtil.CreateSettings()));

            Assert.Equal(uri, await settings.GetDefaultServer());

            fileMock.Verify(m => m.ReadAllText(configPath), Times.Once);
        }