public void MisspelledPropertyName()
        {
            bool excCaught = false;

            // add a resource that has a bad mapping
            string        resource = "NHibernate.Test.MappingExceptions.A.PropertyNotFound.hbm.xml";
            Configuration cfg      = new Configuration();

            try
            {
                cfg.AddResource(resource, GetType().Assembly);
                cfg.BuildSessionFactory();
            }
            catch (MappingException me)
            {
                PropertyNotFoundException found = null;
                Exception find = me;
                while (find != null)
                {
                    found = find as PropertyNotFoundException;
                    find  = find.InnerException;
                }
                Assert.IsNotNull(found, "The PropertyNotFoundException is not present in the Exception tree.");
                Assert.AreEqual("Naame", found.PropertyName, "should contain name of missing property 'Naame' in exception");
                Assert.AreEqual(typeof(A), found.TargetType, "should contain name of class that is missing the property");
                excCaught = true;
            }

            Assert.IsTrue(excCaught, "Should have caught the MappingException that contains the property not found exception.");
        }
Exemple #2
0
        public void ConstructorAssignsPropertyName()
        {
            var target = new PropertyNotFoundException(typeof(firstparam), "propertyName", new List <string> {
                "first", "second"
            }, "caller");

            Assert.AreEqual(target.PropertyName, "propertyName");
        }
Exemple #3
0
        public void ConstructorAssignsAvailableProperties()
        {
            var target = new PropertyNotFoundException(typeof(firstparam), "propertyName", new List <string> {
                "first", "second"
            }, "caller");

            Assert.IsNotEmpty(target.AvailableProperties);
        }
Exemple #4
0
        public void ConstructorSetsMessage()
        {
            var target = new PropertyNotFoundException(typeof(firstparam), "propertyName", new List <string> {
                "first", "second"
            }, "caller");

            Assert.IsFalse(string.IsNullOrEmpty(target.Message));
        }
Exemple #5
0
        protected string RenderPropertyValue(PSObject inputObject,
                                             string propertyName,
                                             ColorString formatString,
                                             bool dontGroupMultipleResults,
                                             bool allowMultipleLines)
        {
            PSPropertyInfo pi = inputObject.Properties[propertyName];

            if (null == pi)
            {
                var val = sm_PropNotFoundFmt.ToString(DbgProvider.HostSupportsColor);
                val = Util.Sprintf(val, propertyName);
                var e = new PropertyNotFoundException(Util.Sprintf("Property not found: {0}", propertyName));
                try { throw e; } catch (Exception) { };  // give it a stack
                ErrorRecord er = new ErrorRecord(e, "MissingProperty", ErrorCategory.InvalidData, inputObject);
                AddToError(er);
                return(val);
            }

            try
            {
                var         obj        = pi.Value;
                IEnumerable enumerable = obj as IEnumerable;
                if ((null != enumerable) && _ShouldUnroll(enumerable))
                {
                    return(ObjectsToMarkedUpString(enumerable,
                                                   formatString,
                                                   null,
                                                   dontGroupMultipleResults).ToString());
                }

                // If a formatString was specified, let /it/ control the display, instead of FormatSingleLine.
                if (null == formatString)
                {
                    return(ObjectToMarkedUpString(FormatSingleLine(pi.Value, allowMultipleLines),
                                                  formatString).ToString());
                }
                else
                {
                    return(ObjectToMarkedUpString(pi.Value, formatString).ToString());
                }
            }
            catch (RuntimeException rte)
            {
                AddToError(Util.FixErrorRecord(rte.ErrorRecord, rte));

                return(new ColorString(ConsoleColor.Red,
                                       Util.Sprintf("<Error: {0}>",
                                                    Util.GetExceptionMessages(rte)))
                       .ToString(DbgProvider.HostSupportsColor));
            }
        } // end RenderPropertyValue()
Exemple #6
0
        public void When_InstantiatingPropertyNotFoundExceptionWithPropertyNameAndType_Expect_PropertyNameAndTypeInMessage()
        {
            // Arrange
            string propertyName = Guid.NewGuid().ToString();
            string type         = Guid.NewGuid().ToString();
            PropertyNotFoundException exception;

            // Act
            exception = new PropertyNotFoundException(propertyName, type);

            // Assert
            Assert.Equal($"\"{propertyName}\" is not a property of \"{type}\".", exception.Message);
        }
        private static T GetPropertyAttribute <T>(string propertyName)
            where T : Attribute
        {
            var propertyInfo = _itemRowType.GetProperty(propertyName);

            if (propertyInfo == null)
            {
                var ex = new PropertyNotFoundException(propertyName, _itemRowType);
                ex.Trace("Unable to find attribute by property.");
                throw ex;
            }

            T attribute = propertyInfo.GetCustomAttribute <T>();

            return(attribute);
        }
Exemple #8
0
        private static T GetPropertyAttribute <T>(string propertyName)
            where T : Attribute
        {
            var propertyInfo = _itemRowType.GetProperty(propertyName);

            if (propertyInfo == null)
            {
                var ex = new PropertyNotFoundException(propertyName, _itemRowType);
                LogManager.ForContext(typeof(ColumnsManager)).Error(ex, "Failed to load data for property {PropertyName}.", propertyName);
                throw ex;
            }

            T attribute = propertyInfo.GetCustomAttribute <T>();

            return(attribute);
        }
Exemple #9
0
 private void DoTest(string name)
 {
     try
     {
         ISessionFactory factory =
             new Configuration().AddResource("NHibernate.Test.NHSpecificTest.NH642." + name + ".hbm.xml",
                                             typeof(Fixture).Assembly).BuildSessionFactory();
         factory.Close();
     }
     catch (MappingException me)
     {
         PropertyNotFoundException found = null;
         Exception find = me;
         while (find != null)
         {
             found = find as PropertyNotFoundException;
             find  = find.InnerException;
         }
         Assert.IsNotNull(found, "The PropertyNotFoundException is not present in the Exception tree.");
     }
 }
Exemple #10
0
 private async Task DoTestAsync(string name, CancellationToken cancellationToken = default(CancellationToken))
 {
     try
     {
         ISessionFactory factory =
             new Configuration().AddResource("NHibernate.Test.NHSpecificTest.NH642." + name + ".hbm.xml",
                                             typeof(FixtureAsync).Assembly).BuildSessionFactory();
         await(factory.CloseAsync(cancellationToken));
     }
     catch (MappingException me)
     {
         PropertyNotFoundException found = null;
         Exception find = me;
         while (find != null)
         {
             found = find as PropertyNotFoundException;
             find  = find.InnerException;
         }
         Assert.IsNotNull(found, "The PropertyNotFoundException is not present in the Exception tree.");
     }
 }
Exemple #11
0
        public void When_DeserializingPropertyNotFoundException_Expect_SerializedPropertyNotFoundException()
        {
            // Arrange
            PropertyNotFoundException exception = new PropertyNotFoundException(Guid.NewGuid().ToString(), Guid.NewGuid().ToString());

            PropertyNotFoundException result;

            // Act
            using (Stream stream = new MemoryStream())
            {
                BinaryFormatter formatter = new BinaryFormatter();
                formatter.Serialize(stream, exception);
                stream.Position = 0;
                result          = (PropertyNotFoundException)formatter.Deserialize(stream);
            }

            // Assert
            Assert.Equal(exception.Message, result.Message);
            Assert.Equal(exception.InnerException, result.InnerException);
            Assert.Null(result.InnerException);
        }
        public void TestConstructor()
        {
            var exception = new PropertyNotFoundException("PropertyName");

            Assert.AreEqual("PropertyName", exception.PropertyName);
        }
        public void TestToString()
        {
            var exception = new PropertyNotFoundException("TrainSimulator2019");

            Assert.AreEqual("The following required property was not found: TrainSimulator2019", exception.ToString());
        }