示例#1
0
        public async Task Insert_Active_Record_Replaces_Existing_Active_Records()
        {
            var serviceConfigurationRecord = new ServiceConfigurationRecord {
                ApplicationName = "Service-a",
                IsActive        = true,
                Name            = "SettingName",
                Type            = ConfigurationItemType.String,
                Value           = "abc"
            };

            _inMemoryStorageAdapter.Db.Add(Constants.AllRecordsKey, new DatabasePage {
                KnownRecords = new List <ServiceConfigurationRecord>()
            });
            _inMemoryStorageAdapter.ServiceConfigurationStorage.Add(serviceConfigurationRecord.ApplicationName.ToLowerInvariant(),
                                                                    new ServiceConfigurationPage {
                Entries = new List <ServiceConfigurationActiveRecord> {
                    new ServiceConfigurationActiveRecord {
                        Name  = serviceConfigurationRecord.Name,
                        Value = "123"
                    }
                }
            });

            await _configurationRepository.InsertAsync(serviceConfigurationRecord, _token);

            _inMemoryStorageAdapter.ServiceConfigurationStorage[serviceConfigurationRecord.ApplicationName.ToLowerInvariant()].Entries.Count.ShouldBe(1);
            _inMemoryStorageAdapter.ServiceConfigurationStorageToUpdate.Entries.Count.ShouldBe(1);
            _inMemoryStorageAdapter.ServiceConfigurationStorageToUpdate.Entries.First().Value.ShouldBe(serviceConfigurationRecord.Value);
        }
示例#2
0
        public async Task Insert_Active_Record_Inserts_Into_Both_Databases()
        {
            var serviceConfigurationRecord = new ServiceConfigurationRecord {
                ApplicationName = "Service-a",
                IsActive        = true,
                Name            = "SettingName",
                Type            = ConfigurationItemType.String,
                Value           = "abc"
            };

            _inMemoryStorageAdapter.Db.Add(Constants.AllRecordsKey, new DatabasePage {
                KnownRecords = new List <ServiceConfigurationRecord>()
            });
            _inMemoryStorageAdapter.ServiceConfigurationStorage.Add(serviceConfigurationRecord.ApplicationName.ToLowerInvariant(),
                                                                    new ServiceConfigurationPage {
                Entries = new List <ServiceConfigurationActiveRecord> {
                    new ServiceConfigurationActiveRecord {
                        Name = "Settings2"
                    }
                }
            });

            await _configurationRepository.InsertAsync(serviceConfigurationRecord, _token);

            _inMemoryStorageAdapter.Db[Constants.AllRecordsKey].KnownRecords.ShouldNotBeEmpty();
            _inMemoryStorageAdapter.DbPageToUpdate.KnownRecords.ShouldNotBeEmpty();

            _inMemoryStorageAdapter.ServiceConfigurationStorage[serviceConfigurationRecord.ApplicationName.ToLowerInvariant()].Entries.Count.ShouldBe(2);
            _inMemoryStorageAdapter.ServiceConfigurationStorageToUpdate.Entries.Count.ShouldBe(2);
        }
示例#3
0
        public async Task Delete_Removes_Record_From_Database()
        {
            var serviceConfigurationRecord = new ServiceConfigurationRecord {
                ApplicationName = "Service-a",
                IsActive        = false,
                Id    = Guid.NewGuid(),
                Name  = "SettingName",
                Type  = ConfigurationItemType.String,
                Value = "abc"
            };

            _inMemoryStorageAdapter.Db.Add(Constants.AllRecordsKey, new DatabasePage {
                KnownRecords = new List <ServiceConfigurationRecord> {
                    serviceConfigurationRecord
                }
            });

            await _configurationRepository.DeleteAsync(serviceConfigurationRecord.Id, _token);

            _inMemoryStorageAdapter.Db[Constants.AllRecordsKey].KnownRecords.ShouldBeEmpty();
            _inMemoryStorageAdapter.DbPageToUpdate.KnownRecords.ShouldBeEmpty();
        }
示例#4
0
        public async Task Delete_ActiveRecord_Removes_Record_From_Both_Databases()
        {
            var serviceConfigurationRecord = new ServiceConfigurationRecord {
                ApplicationName = "Service-a",
                IsActive        = true,
                Id    = Guid.NewGuid(),
                Name  = "SettingName",
                Type  = ConfigurationItemType.String,
                Value = "abc"
            };

            _inMemoryStorageAdapter.Db.Add(Constants.AllRecordsKey, new DatabasePage {
                KnownRecords = new List <ServiceConfigurationRecord> {
                    serviceConfigurationRecord
                }
            });
            _inMemoryStorageAdapter.ServiceConfigurationStorage.Add(serviceConfigurationRecord.ApplicationName.ToLowerInvariant(),
                                                                    new ServiceConfigurationPage {
                Entries = new List <ServiceConfigurationActiveRecord> {
                    new ServiceConfigurationActiveRecord {
                        Name = serviceConfigurationRecord.Name
                    },
                    new ServiceConfigurationActiveRecord {
                        Name = "Settings2"
                    }
                }
            });

            await _configurationRepository.DeleteAsync(serviceConfigurationRecord.Id, _token);

            _inMemoryStorageAdapter.Db[Constants.AllRecordsKey].KnownRecords.ShouldBeEmpty();
            _inMemoryStorageAdapter.DbPageToUpdate.KnownRecords.ShouldBeEmpty();

            _inMemoryStorageAdapter.ServiceConfigurationStorage[serviceConfigurationRecord.ApplicationName.ToLowerInvariant()].Entries.Count.ShouldBe(1);
            _inMemoryStorageAdapter.ServiceConfigurationStorageToUpdate.Entries.Count.ShouldBe(1);
        }
        /// <summary>
        /// Reads the JSON representation of the object.
        /// </summary>
        /// <param name="reader">The <see cref="T:Newtonsoft.Json.JsonReader" /> to read from.</param>
        /// <param name="objectType">Type of the object.</param>
        /// <param name="existingValue">The existing value of object being read.</param>
        /// <param name="serializer">The calling serializer.</param>
        /// <returns>
        /// The object value.
        /// </returns>
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            JObject json;
            ServiceConfigurationRecord record = null;
            string recordType;

            if (reader.TokenType == JsonToken.Null)
            {
                return(null);
            }

            try
            {
                json = JObject.Load(reader);

                if (json.HasValues)
                {
                    recordType = json["recordType"].Value <string>();

                    if (recordType.Equals("cname", StringComparison.CurrentCultureIgnoreCase))
                    {
                        record = new DomainDnsCnameRecord()
                        {
                            CanonicalName = json["canonicalName"].Value <string>()
                        };
                    }
                    else if (recordType.Equals("mx", StringComparison.CurrentCultureIgnoreCase))
                    {
                        record = new DomainDnsMxRecord()
                        {
                            MailExchange = json["mailExchange"].Value <string>(),
                            Preference   = json["preference"].Value <int>()
                        };
                    }
                    else if (recordType.Equals("srv", StringComparison.CurrentCultureIgnoreCase))
                    {
                        record = new DomainDnsSrvRecord()
                        {
                            NameTarget = json["nameTarget"].Value <string>(),
                            Port       = json["port"].Value <int>(),
                            Priority   = json["priority"].Value <int>(),
                            Protocol   = json["protocol"].Value <string>(),
                            Service    = json["service"].Value <string>(),
                            Weight     = json["weight"].Value <int>()
                        };
                    }
                    else if (recordType.Equals("txt", StringComparison.CurrentCultureIgnoreCase))
                    {
                        record = new DomainDnsTxtRecord()
                        {
                            Text = json["text"].Value <string>()
                        };
                    }
                    else
                    {
                        record = new ServiceConfigurationRecord();
                    }

                    record.DnsRecordId      = json["dnsRecordId"].Value <string>();
                    record.IsOptional       = json["isOptional"].Value <bool>();
                    record.Label            = json["label"].Value <string>();
                    record.RecordType       = json["recordType"].Value <string>();
                    record.SupportedService = json["supportedService"].Value <string>();
                    record.Ttl = json["ttl"].Value <int>();
                }

                return(record);
            }
            finally
            {
                json = null;
            }
        }