Exemple #1
0
        public void ForDictionaryWithElementsShouldIterate()
        {
            var keys   = new[] { "key1", "key2" };
            var values = new[] { "value1", "value2" };

            var errors = new ResultErrorsDictionary
            {
                { keys[0], values[0] },
                { keys[1], values[1] }
            };

            var iteratedKeys   = new List <string>();
            var iteratedValues = new List <string>();

            foreach (var error in errors)
            {
                iteratedKeys.Add(error.Key);
                iteratedValues.Add(error.Value.First());
            }

            iteratedKeys.Sort();
            iteratedValues.Sort();

            iteratedKeys.Should().BeEquivalentTo(keys);
            iteratedValues.Should().BeEquivalentTo(values);
        }
Exemple #2
0
        public void ForNoKeyInDictionaryTryGetShouldNotReturnValue()
        {
            var errors = new ResultErrorsDictionary();
            var result = errors.TryGetValue("key", out var value);

            new { result, value }.Should().BeEquivalentTo(new { result = false, value = new string[0] });
        }
Exemple #3
0
        public void ForKeyInDictionaryShouldHaveCount()
        {
            var errors = new ResultErrorsDictionary {
                { "key", "value" }
            };

            errors.Count.Should().Be(1);
        }
Exemple #4
0
        public void ForKeyInDictionaryIndexerShouldReturnValue()
        {
            var errors = new ResultErrorsDictionary {
                { "key", "value" }
            };

            errors["key"].Should().BeEquivalentTo("value");
        }
Exemple #5
0
        public void ForKeyInDictionaryContainsKeyShouldReturnTrue()
        {
            var errors = new ResultErrorsDictionary {
                { "key", "value" }
            };

            errors.ContainsKey("key").Should().BeTrue();
        }
Exemple #6
0
        public void ForKeyFromNestedCollectionsWithIndexersShouldAddNewErrorWithProperName()
        {
            var errors = new ResultErrorsDictionary();

            errors.Add <Model>(m => m.CollectionA[0].CollectionB[0].PropertyD, "value");
            errors.Should().BeEquivalentTo(new Dictionary <string, string[]> {
                [$"Model.{nameof(Model.CollectionA)}.{nameof(Model.PropertyB.CollectionB)}.{nameof(Model.PropertyB.PropertyC.PropertyD)}"] = new[] { "value" }
            });
        }
Exemple #7
0
        public void ForKeyFromNestedClassMixedWithStructsPropertyShouldAddNewErrorWithProperName()
        {
            var errors = new ResultErrorsDictionary();

            errors.Add <Model>(m => m.PropertyB.PropertyC.PropertyD, "value");
            errors.Should().BeEquivalentTo(new Dictionary <string, string[]> {
                [$"Model.{nameof(Model.PropertyB)}.{nameof(Model.PropertyB.PropertyC)}.{nameof(Model.PropertyB.PropertyC.PropertyD)}"] = new[] { "value" }
            });
        }
Exemple #8
0
        public void ForKeyFromClassPropertyShouldAddNewErrorWithProperName()
        {
            var errors = new ResultErrorsDictionary();

            errors.Add <Model>(m => m.PropertyA, "value");
            errors.Should().BeEquivalentTo(new Dictionary <string, string[]> {
                [$"Model.{nameof(Model.PropertyA)}"] = new[] { "value" }
            });
        }
Exemple #9
0
        public void ForKeyInDictionaryTryGetShouldReturnValue()
        {
            var errors = new ResultErrorsDictionary {
                { "key", "value" }
            };
            var result = errors.TryGetValue("key", out var value);

            new { result, value }.Should().BeEquivalentTo(new { result = true, value = new List <string> {
                                                                    "value"
                                                                } });
        }
Exemple #10
0
        public void ForNewStringKeyShouldAddNewError()
        {
            var errors = new ResultErrorsDictionary
            {
                { "key", "value" }
            };

            errors.Should().BeEquivalentTo(new Dictionary <string, string[]> {
                ["key"] = new[] { "value" }
            });
        }
Exemple #11
0
        public void ForAlreadyExistingStringKeyShouldAddNewErrorMessage()
        {
            var errors = new ResultErrorsDictionary
            {
                { "key", "value" },
                { "key", "value2" }
            };

            errors.Should().BeEquivalentTo(new Dictionary <string, string[]> {
                ["key"] = new[] { "value", "value2" }
            });
        }
Exemple #12
0
        public void ForNoKeyInDictionaryContainsKeyShouldReturnFalse()
        {
            var errors = new ResultErrorsDictionary();

            errors.ContainsKey("key").Should().BeFalse();
        }