Exemplo n.º 1
0
        public async Task TestLoadDocumentSettingsOnChangeAsync_WithTagDocument_ShouldSuccess()
        {
            //Arrange
            var provider = _autoFixture.Create <FirestoreProvider>();

            var appSettings         = _autoFixture.Create <TestSettings>();
            var appSettingsDocument = new ApplicationSettingsDocument();

            appSettingsDocument.SetData(JsonSerializer.Serialize(appSettings));

            var stageSettings         = _autoFixture.Create <TestSettings>();
            var stageSettingsDocument = new ApplicationSettingsDocument();

            stageSettingsDocument.SetData(JsonSerializer.Serialize(stageSettings));

            var machineSettings         = _autoFixture.Create <TestSettings>();
            var machineSettingsDocument = new ApplicationSettingsDocument();

            machineSettingsDocument.SetData(JsonSerializer.Serialize(machineSettings));

            var tagSettings         = _autoFixture.Create <TestSettings>();
            var tagSettingsDocument = new ApplicationSettingsDocument();

            tagSettingsDocument.SetData(JsonSerializer.Serialize(tagSettings));

            var connectionMock = _autoFixture.Freeze <Mock <IFirestoreConnectionManager> >();

            connectionMock
            .Setup(mock => mock.GetConfigurationDocumentLevels())
            .Returns(new List <ConfigurationLevels>()
            {
                { ConfigurationLevels.Application }, { ConfigurationLevels.Stage }, { ConfigurationLevels.Tag }
            });
            connectionMock
            .Setup(mock => mock.GetDocumentFieldsAsync(It.Is <ConfigurationLevels>(param => param == ConfigurationLevels.Application)))
            .ReturnsAsync(appSettingsDocument.Data.ToDictionary());
            connectionMock
            .Setup(mock => mock.GetDocumentFieldsAsync(It.Is <ConfigurationLevels>(param => param == ConfigurationLevels.Stage)))
            .ReturnsAsync(stageSettingsDocument.Data.ToDictionary());
            connectionMock
            .Setup(mock => mock.GetDocumentFieldsAsync(It.Is <ConfigurationLevels>(param => param == ConfigurationLevels.Tag)))
            .ReturnsAsync(tagSettingsDocument.Data.ToDictionary());

            //Act
            var sut = _autoFixture.Create <ApplicationSettingsManager>();

            sut.CreateListeners(provider.JsonSettingsToDictionary, provider.ReloadSettings);
            await sut.LoadDocumentSettingsOnChangeAsync(ConfigurationLevels.Tag, "snapshotId");

            //Assert
            Assert.NotEmpty(sut.ConfigData);
            Assert.NotEqual(appSettings.Id, int.Parse(sut.ConfigData["id"]));
            Assert.NotEqual(appSettings.Name, sut.ConfigData["name"]);
            Assert.NotEqual(stageSettings.Id, int.Parse(sut.ConfigData["id"]));
            Assert.NotEqual(stageSettings.Name, sut.ConfigData["name"]);
            Assert.NotEqual(machineSettings.Id, int.Parse(sut.ConfigData["id"]));
            Assert.NotEqual(machineSettings.Name, sut.ConfigData["name"]);
            Assert.Equal(tagSettings.Id, int.Parse(sut.ConfigData["id"]));
            Assert.Equal(tagSettings.Name, sut.ConfigData["name"]);
        }
Exemplo n.º 2
0
        public async Task TestLoadDocumentSettingsOnChangeAsync_WithAppDocumentOnly_ShouldSuccess()
        {
            //Arrange
            var provider            = _autoFixture.Create <FirestoreConfigurationProvider>();
            var appSettings         = _autoFixture.Create <TestSettings>();
            var appSettingsDocument = new ApplicationSettingsDocument();
            var appSettingsJson     = JsonSerializer.Serialize(appSettings);

            _outputHelper.WriteLine(appSettingsJson);
            appSettingsDocument.SetData(appSettingsJson);

            var connectionMock = _autoFixture.Freeze <Mock <IFirestoreConnectionManager> >();

            connectionMock
            .Setup(mock => mock.GetConfigurationDocumentLevels())
            .Returns(new List <ConfigurationLevels>()
            {
                { ConfigurationLevels.Application }
            });
            connectionMock
            .Setup(mock => mock.GetDocumentFieldsAsync(It.IsAny <ConfigurationLevels>()))
            .ReturnsAsync(appSettingsDocument.Data.ToDictionary());

            //Act
            var sut = _autoFixture.Create <ApplicationSettingsManager>();

            sut.CreateListeners(provider.JsonSettingsToDictionary, provider.ReloadSettings);
            await sut.LoadDocumentSettingsOnChangeAsync(ConfigurationLevels.Application, "snapshotId");

            //Assert
            Assert.NotEmpty(sut.ConfigData);
        }
 private async Task CreateAppSettingsDocument()
 {
     if (await _connectionManager.IsDocumentEmptyAsync(_options.GetApplicationDocumentPath()))
     {
         _logger.LogDebug($"Creating setting from {_options.SettingsFilePath}{_options.SettingsFileName}");
         var remoteSettingsDocument = new ApplicationSettingsDocument();
         remoteSettingsDocument.SetData(_fileManager.GetFileContent($"{_options.SettingsFilePath}{_options.SettingsFileName}"));
         await _connectionManager.SaveAsync(_options.GetApplicationDocumentPath(), remoteSettingsDocument.Data.ToDictionary());
     }
 }