Exemple #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);
        }
Exemple #2
0
        public void FinnishWithError()
        {
            var type   = typeof(ErrorTypes.With <int>);
            var errors = ErrorBuilder.Start()
                         .CreateIfNull(type)
                         .Add(TypeMustNotifyError.GetOrCreate(type))
                         .Finnish();

            Assert.AreEqual(type, errors.Type);
            CollectionAssert.AreEqual(new[] { TypeMustNotifyError.GetOrCreate(type) }, errors.Errors);
        }
Exemple #3
0
            public void CheckNotifiesWithInt()
            {
                var settings = PropertiesSettings.GetOrCreate();
                var type     = typeof(ErrorTypes.With <int>);
                var errors   = ErrorBuilder.Start().CheckNotifies(type, settings).Finnish();
                var expected = new[] { TypeMustNotifyError.GetOrCreate(type) };

                CollectionAssert.AreEqual(expected, errors.Errors);
                var stringBuilder = new StringBuilder();
                var message       = stringBuilder.AppendNotSupported(errors)
                                    .ToString();
                var expectedMessage = "The type With<int> does not notify changes.\r\n";

                Assert.AreEqual(expectedMessage, message);

                stringBuilder = new StringBuilder();
                message       = stringBuilder.AppendSuggestExclude(errors)
                                .ToString();
                expectedMessage = string.Empty;
                Assert.AreEqual(expectedMessage, message);
            }