コード例 #1
0
		public void KeyOfErrorsAreGivenIndexedByKey() {
			var req = new Mock<AbstractRequirement<int>> { CallBase = true };
			req.Setup(t => t.Check(It.IsAny<int>()))
				.Returns(new[] { new ValidationError { Key = "", Message = "Error" } });
			var list = new DictionaryRequirementList<T, string, int>(t => t.V);
			list.Add(req.Object);
			var errors = list.Check(new T { V = new Dictionary<string, int> { { "a", 0 } } });
			Assert.Equal("V[0]", errors.First().Key);
		}
コード例 #2
0
		public void CanUseLambdaToFormatKey() {
			var req = new Mock<AbstractRequirement<int>> { CallBase = true };
			req.Setup(t => t.Check(It.IsAny<int>()))
				.Returns(new[] { new ValidationError { Key = "", Message = "Error" } });
			var list = new DictionaryRequirementList<T, string, int>(t => t.V);
			list.Add(req.Object);
			list.FormatIndexerUsing((ix, key) => "["+ix+","+key+"]");
			var errors = list.Check(new T { V = new Dictionary<string, int> { { "a", 0 } } });
			Assert.Equal("V[0,a]", errors.First().Key);
		}
コード例 #3
0
        public void KeyOfErrorsAreGivenIndexedByKey()
        {
            var req = new Mock <AbstractRequirement <int> > {
                CallBase = true
            };

            req.Setup(t => t.Check(It.IsAny <int>()))
            .Returns(new[] { new ValidationError {
                                 Key = "", Message = "Error"
                             } });
            var list = new DictionaryRequirementList <T, string, int>(t => t.V);

            list.Add(req.Object);
            var errors = list.Check(new T {
                V = new Dictionary <string, int> {
                    { "a", 0 }
                }
            });

            Assert.Equal("V[0]", errors.First().Key);
        }
コード例 #4
0
        public void CanUseLambdaToFormatKey()
        {
            var req = new Mock <AbstractRequirement <int> > {
                CallBase = true
            };

            req.Setup(t => t.Check(It.IsAny <int>()))
            .Returns(new[] { new ValidationError {
                                 Key = "", Message = "Error"
                             } });
            var list = new DictionaryRequirementList <T, string, int>(t => t.V);

            list.Add(req.Object);
            list.FormatIndexerUsing((ix, key) => "[" + ix + "," + key + "]");
            var errors = list.Check(new T {
                V = new Dictionary <string, int> {
                    { "a", 0 }
                }
            });

            Assert.Equal("V[0,a]", errors.First().Key);
        }