Esempio n. 1
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);
        }
Esempio n. 2
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"]);
        }
Esempio n. 3
0
 public static void SetData(this ApplicationSettingsDocument settingsDocument, string data)
 {
     if (string.IsNullOrEmpty(data))
     {
         data = "{}";
     }
     settingsDocument.Data = JsonDocument.Parse(data).RootElement;
 }
        private void WriteXml(string nodeName, XmlWriter writer)
        {
            bool writeContainingNode = false;

            if (!string.IsNullOrEmpty(nodeName))
            {
                writeContainingNode = true;
                writer.WriteStartElement(nodeName);
            }

            writer.WriteElementString("person-id", _personId.ToString());
            writer.WriteElementString("name", Name);

            if (ApplicationSettingsDocument != null)
            {
                writer.WriteRaw(ApplicationSettingsDocument.CreateNavigator().OuterXml);
            }

            if (HasMoreApplicationSettings)
            {
                writer.WriteElementString("more-app-settings", string.Empty);
            }

            if (_selectedRecordId != Guid.Empty)
            {
                writer.WriteElementString(
                    "selected-record-id",
                    _selectedRecordId.ToString());
            }

            foreach (HealthRecordInfo record in AuthorizedRecords.Values)
            {
                record.WriteXml("record", writer);
            }

            if (HasMoreRecords)
            {
                writer.WriteElementString("more-records", string.Empty);
            }

            if (!string.IsNullOrEmpty(PreferredCulture))
            {
                WriteCulture("preferred-culture", writer, PreferredCulture);
            }

            if (!string.IsNullOrEmpty(PreferredUICulture))
            {
                WriteCulture("preferred-uiculture", writer, PreferredUICulture);
            }

            Location?.WriteXml(writer, "location");

            if (writeContainingNode)
            {
                writer.WriteEndElement();
            }
        }
 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());
     }
 }