Example #1
0
        /// <summary>
        /// Retrieves the foreign key in this mapping and all its children
        /// </summary>
        /// <returns></returns>
        public IEnumerable <ForeignKeyMappingInfo> GetForeignKeys()
        {
            var thisLevelFks   = SimpleProperties.OfType <ForeignKeyMappingInfo>();
            var lowerLevelsFks = CollectionProperties.SelectMany(e => e.GetForeignKeys());

            return(thisLevelFks.Concat(lowerLevelsFks));
        }
        public void known_string_key_assigned()
        {
            var demo = new SimpleProperties();

            Structure.Start(demo, TestOptions <SimpleProperties>($@"[ {KV("/keystring", "valuestring")} ]"));
            demo.KeyString.ShouldBe("valuestring");
        }
        public async Task key_is_assigned_repeatedly()
        {
            var config      = new SimpleProperties();
            var testOptions = TestOptions <SimpleProperties>(
                async r =>
            {
                var idxValue = r.Request.Query["index"];
                var idx      = string.IsNullOrEmpty(idxValue) ? 0 : int.Parse(idxValue);
                idx++;
                await Task.Delay(TimeSpan.FromSeconds(1));
                await r.Response(200, idx, $"[ {KV("/keystring", $"http{idx}")} ]");
            });

            Structure updater     = null;
            int       assignments = 0;

            testOptions.Events.KeyValueAssigned = (path, value) =>
            {
                if (++assignments >= 2)
                {
                    updater.Stop();
                    KeyAssigned.SetResult(true);
                }
            };

            updater = Structure.Start(config, testOptions);
            var result = await Task.WhenAny(KeyAssigned.Task, Task.Delay(TimeSpan.FromMinutes(1)));

            assignments.ShouldBe(2);
            result.ShouldBe(KeyAssigned.Task, "Assignment timed out");
            config.KeyString.ShouldBe("http2");
            await updater.Stop();
        }
        public void property_discovered()
        {
            var demo = new SimpleProperties();

            Structure.Start(demo, TestOptions <SimpleProperties>("[]"));
            DiscoveredKeys.ShouldContainKey("keystring");
        }
        public void unknown_key_is_ignored()
        {
            var demo = new SimpleProperties();

            Structure.Start(demo, TestOptions <SimpleProperties>($@"[ {KV("/unknown", "valuestring")} ]"));
            IgnoredKeys.ShouldContainKey("/unknown");
        }
        public void when_serializing_simple_properties_as_array()
        {
            var simpleObject = new SimpleProperties();
            var serialized   = JsonConvert.SerializeObject(simpleObject);

            Assert.AreEqual("[false,0]", serialized);
        }
        public async Task known_string_key_assigned()
        {
            var demo = new SimpleProperties();
            var s    = Structure.Start(demo, TestOptions <SimpleProperties>($@"[ {Http.KV("keystring", "valuestring")} ]"));

            demo.KeyString.ShouldBe("valuestring");
            KeyValuesIgnored.Count.ShouldBe(0);
            await s.Stop();
        }
        public async Task unknown_key_is_ignored()
        {
            var demo = new SimpleProperties();
            var s    = Structure.Start(demo, TestOptions <SimpleProperties>($@"[ {Http.KV("unknown", "valuestring")} ]"));

            IgnoredKeys.ShouldContainKey("unknown");
            KeyValuesAssigned.Count.ShouldBe(0);
            await s.Stop();
        }
        public void known_int_key_assigned()
        {
            var demo = new SimpleProperties();

            Structure.Start(demo, TestOptions <SimpleProperties>($@"[ {KV("/keyint32", "1")} ]"));
            demo.KeyInt32.ShouldBe(1);
            Structure.Start(demo, TestOptions <SimpleProperties>($@"[ {KV("/keyint32", "0")} ]"));
            demo.KeyInt32.ShouldBe(0);
        }
        public void known_bool_key_assigned()
        {
            var demo = new SimpleProperties();

            Structure.Start(demo, TestOptions <SimpleProperties>($@"[ {KV("/keybool", "true")} ]"));
            demo.KeyBool.ShouldBe(true);
            Structure.Start(demo, TestOptions <SimpleProperties>($@"[ {KV("/keybool", "false")} ]"));
            demo.KeyBool.ShouldBe(false);
        }
Example #11
0
        private IEnumerable <T> Enumerable <T>(IEnumerable <T> e) => e; // To keep C# compiler happy

        /// <summary>
        /// Returns all the simple properties with the given name (e.g. "PostingDate")
        /// </summary>
        public IEnumerable <PropertyMappingInfo> SimplePropertiesByName(string name)
        {
            _simplePropsDic ??= SimpleProperties
            .GroupBy(e => e.Metadata.Descriptor.Name)
            .ToDictionary(g => g.Key, g => Enumerable(g));

            _simplePropsDic.TryGetValue(name, out IEnumerable <PropertyMappingInfo> result);
            return(result);
        }
        public async Task known_bool_key_assigned()
        {
            var demo = new SimpleProperties();
            var s    = Structure.Start(demo, TestOptions <SimpleProperties>($@"[ {Http.KV("keybool", "true")} ]"));

            demo.KeyBool.ShouldBe(true);
            Structure.Start(demo, TestOptions <SimpleProperties>($@"[ {Http.KV("keybool", "false")} ]"));
            demo.KeyBool.ShouldBe(false);
            await s.Stop();
        }
Example #13
0
        public async Task key_is_assigned_once()
        {
            var config  = new SimpleProperties();
            var updater = Structure.Start(config, TestOptions());

            ConsulKvSimulator.PutKey("keystring", "http");
            await KeyValuesAssigned.Dequeue();

            config.KeyString.ShouldBe("http");
            await updater.Stop();
        }
Example #14
0
        private int MaxIndex()
        {
            int maxIndex = SimpleProperties.Max(prop => prop.Index);

            foreach (var prop in CollectionProperties)
            {
                maxIndex = Math.Max(maxIndex, prop.MaxIndex());
            }

            return(maxIndex);
        }
        public async Task known_int_key_assigned()
        {
            var demo = new SimpleProperties();
            var s    = Structure.Start(demo, TestOptions <SimpleProperties>($@"[ {Http.KV("keyint32", "1")} ]"));

            demo.KeyInt32.ShouldBe(1);
            await s.Stop();

            s = Structure.Start(demo, TestOptions <SimpleProperties>($@"[ {Http.KV("keyint32", "0")} ]"));
            demo.KeyInt32.ShouldBe(0);
            await s.Stop();
        }
        public async Task key_is_assigned_once()
        {
            var config  = new SimpleProperties();
            var updater = Structure.Start(config, TestOptions <SimpleProperties>(
                                              r => r.Response(200, 1, $"[ {KV("/keystring", "http")} ]")
                                              ));
            var result = await Task.WhenAny(KeyAssigned.Task, Task.Delay(TimeSpan.FromMinutes(1)));

            result.ShouldBe(KeyAssigned.Task, "Assignment timed out");
            config.KeyString.ShouldBe("http");
            await updater.Stop();
        }
Example #17
0
        public async Task same_index_understood_as_no_change()
        {
            var config  = new SimpleProperties();
            var updater = Structure.Start(config, TestOptions(next => env => env.Response(200, 0)));

            await HttpSuccesses.Dequeue();

            HttpErrors.Count.ShouldBe(0);
            KeyValuesAssigned.Count.ShouldBe(0);

            await updater.Stop();
        }
Example #18
0
        public async Task mutliple_key_changes_get_correct_value()
        {
            var config = new SimpleProperties();

            ConsulKvSimulator.PutKey("keystring", "first");
            ConsulKvSimulator.PutKey("keystring", "second");

            var updater = Structure.Start(config, TestOptions());

            var lastResult = await KeyValuesAssigned.Dequeue();

            lastResult.Last().Value.ShouldBe("second");

            config.KeyString.ShouldBe("second");
            await updater.Stop();
        }
Example #19
0
        public async Task http_events_published()
        {
            var config  = new SimpleProperties();
            var updater = Structure.Start(config, TestOptions());

            ConsulKvSimulator.PutKey("keystring", "http");
            var result = await HttpSuccesses.Dequeue();

            result.Item1.RequestUri.AbsolutePath.ShouldStartWith("/v1/kv/");

            result.Item2.StatusCode.ShouldBe(HttpStatusCode.OK);

            result.Item3.ShouldBeGreaterThan(TimeSpan.Zero);

            await updater.Stop();
        }
Example #20
0
        void IDisposable.Dispose()
        {
            if (TokenProperties != null)
            {
                TokenProperties.Clear();
            }
            if (SimpleProperties != null)
            {
                SimpleProperties.Clear();
            }
            if (Model != null)
            {
                Model = null;
            }

            GC.SuppressFinalize(this);
        }
Example #21
0
        public async Task key_is_assigned_repeatedly()
        {
            var config  = new SimpleProperties();
            var updater = Structure.Start(config, TestOptions());

            ConsulKvSimulator.PutKey("keystring", "first");
            await KeyValuesAssigned.Dequeue();

            config.KeyString.ShouldBe("first");

            await Task.WhenAll(
                ConsulKvSimulator.PutKeyWithDelay("keystring", "second", TimeSpan.FromSeconds(3)),
                KeyValuesAssigned.Dequeue());

            config.KeyString.ShouldBe("second");
            await updater.Stop();
        }
Example #22
0
 public IEnumerable <PropertyMappingInfo> AllPropertyMappings() => SimpleProperties
 .Concat(CollectionProperties.SelectMany(p => p.AllPropertyMappings()));