예제 #1
0
        public void RefLoopAndMemberErrors()
        {
            var rootType       = typeof(ErrorTypes.With <ErrorTypes.Parent>);
            var valueProperty  = rootType.GetProperty(nameof(ErrorTypes.With <ErrorTypes.Parent> .Value));
            var parentType     = typeof(ErrorTypes.Parent);
            var childProperty  = parentType.GetProperty(nameof(ErrorTypes.Parent.Child));
            var parentProperty = typeof(ErrorTypes.Child).GetProperty(nameof(ErrorTypes.Child.Parent));
            var path           = new MemberPath(rootType)
                                 .WithProperty(valueProperty);

            var loopPath = path.WithProperty(childProperty)
                           .WithProperty(parentProperty)
                           .WithProperty(childProperty);
            var referenceLoop = new ReferenceLoop(loopPath);
            var refLoopErrors = ErrorBuilder.Start()
                                .CreateIfNull(rootType)
                                .Add(referenceLoop)
                                .Finnish();
            var typeMustNotifyError = TypeMustNotifyError.GetOrCreate(parentType);
            var typeErrors          = new TypeErrors(parentType, typeMustNotifyError);
            var memberErrors        = new MemberErrors(path, typeErrors);
            var notifyErrors        = ErrorBuilder.Start()
                                      .CreateIfNull(rootType)
                                      .Add(memberErrors)
                                      .Finnish();
            var merged = ErrorBuilder.Merge(refLoopErrors, notifyErrors);

            Assert.AreEqual(2, merged.Errors.Count);
            Assert.AreEqual(8, merged.AllErrors.Count);
        }
예제 #2
0
        public void RefLoopAndMemberErrors()
        {
            var rootType = typeof(ErrorTypes.With<ErrorTypes.Parent>);
            var valueProperty = rootType.GetProperty(nameof(ErrorTypes.With<ErrorTypes.Parent>.Value));
            var parentType = typeof(ErrorTypes.Parent);
            var childProperty = parentType.GetProperty(nameof(ErrorTypes.Parent.Child));
            var parentProperty = typeof(ErrorTypes.Child).GetProperty(nameof(ErrorTypes.Child.Parent));
            var path = new MemberPath(rootType)
                            .WithProperty(valueProperty);

            var loopPath = path.WithProperty(childProperty)
                               .WithProperty(parentProperty)
                               .WithProperty(childProperty);
            var referenceLoop = new ReferenceLoop(loopPath);
            var refLoopErrors = ErrorBuilder.Start()
                                     .CreateIfNull(rootType)
                                     .Add(referenceLoop)
                                     .Finnish();
            var typeMustNotifyError = TypeMustNotifyError.GetOrCreate(parentType);
            var typeErrors = new TypeErrors( parentType, typeMustNotifyError);
            var memberErrors = new MemberErrors(path, typeErrors);
            var notifyErrors = ErrorBuilder.Start()
                                           .CreateIfNull(rootType)
                                           .Add(memberErrors)
                                           .Finnish();
            var merged = ErrorBuilder.Merge(refLoopErrors, notifyErrors);
            Assert.AreEqual(2, merged.Errors.Count);
            Assert.AreEqual(8, merged.AllErrors.Count);
        }