Ejemplo n.º 1
0
        public void GetIDAccessor_ClassWithNoDetectableID()
        {
            var ex = Assert.Throws <InvalidOperationException>(()
                                                               => ChildMapperTestingHelper.GetIDAccessor(typeof(TestClasses.ClassWithInsufficientData)));

            Assert.That(ex.Message, Is.StringStarting("Cannot find a way to get the ID from"));
        }
Ejemplo n.º 2
0
        public void GetIDAccessor_ByName()
        {
            //-----------------test single fields-----------------
            var result = ChildMapperTestingHelper.GetIDAccessor(typeof(TestClasses.ClassWithPlainID), "ID");

            Assert.AreEqual(1, result.Count());
            Assert.AreEqual("ID", result.ElementAt(0));

            result = ChildMapperTestingHelper.GetIDAccessor(typeof(TestClasses.ClassWithPlainID), "AnotherID");
            Assert.AreEqual(1, result.Count());
            Assert.AreEqual("AnotherID", result.ElementAt(0));

            //-----------------test multiple fields-----------------
            result = ChildMapperTestingHelper.GetIDAccessor(typeof(TestClasses.ClassWithPlainID), "ID, AnotherID");
            Assert.AreEqual(2, result.Count());
            Assert.AreEqual("ID", result.ElementAt(0));
            Assert.AreEqual("AnotherID", result.ElementAt(1));

            // take out the spaces
            result = ChildMapperTestingHelper.GetIDAccessor(typeof(TestClasses.ClassWithPlainID), "ID,AnotherID");
            Assert.AreEqual(2, result.Count());
            Assert.AreEqual("ID", result.ElementAt(0));
            Assert.AreEqual("AnotherID", result.ElementAt(1));

            // reverse the order
            result = ChildMapperTestingHelper.GetIDAccessor(typeof(TestClasses.ClassWithPlainID), "AnotherID, ID");
            Assert.AreEqual(2, result.Count());
            Assert.AreEqual("AnotherID", result.ElementAt(0));
            Assert.AreEqual("ID", result.ElementAt(1));
        }
Ejemplo n.º 3
0
        public void GetIDAccessor_ByAttribute()
        {
            var result = ChildMapperTestingHelper.GetIDAccessor(typeof(TestClasses.InvoiceLineWithAttributes));

            Assert.AreEqual(1, result.Count());
            Assert.AreEqual("InvoiceLine_id", result.ElementAt(0));
        }
Ejemplo n.º 4
0
        public void GetIDAccessor_ClassNamePlusUnderscoreID()
        {
            var result = ChildMapperTestingHelper.GetIDAccessor(typeof(TestClasses.ClassWithSuffixedUnderscore));

            Assert.AreEqual(1, result.Count());
            Assert.AreEqual("ClassWithSuffixedUnderscore_ID", result.ElementAt(0));
        }
Ejemplo n.º 5
0
        public void GetIDAccessor_ClassNamePlusId_WithOtherIdFields()
        {
            var result = ChildMapperTestingHelper.GetIDAccessor(typeof(TestClasses.ClassWithSuffixed));

            Assert.AreEqual(1, result.Count());
            Assert.AreEqual("ClassWithSuffixedId", result.ElementAt(0));
        }
Ejemplo n.º 6
0
        public void GetIDAccessor_ClassNamePlusUnderscoreID_MultipleOptions()
        {
            var result = ChildMapperTestingHelper.GetIDAccessor(typeof(TestClasses.InvoiceLine));

            Assert.AreEqual(1, result.Count());
            Assert.AreEqual("InvoiceLine_id", result.ElementAt(0));
        }
Ejemplo n.º 7
0
        public void GetIDAccessor_PlainID()
        {
            var result = ChildMapperTestingHelper.GetIDAccessor(typeof(TestClasses.ClassWithPlainID));

            Assert.AreEqual(1, result.Count());
            Assert.AreEqual("ID", result.ElementAt(0));
        }
Ejemplo n.º 8
0
        public void GetIDAccessor_ByName_BadName()
        {
            var ex = Assert.Throws <InvalidOperationException>(()
                                                               => ChildMapperTestingHelper.GetIDAccessor(typeof(TestClasses.ClassWithSuffixedUnderscore), "foo123"));

            Assert.That(ex.Message, Is.StringContaining("foo123"));

            ex = Assert.Throws <InvalidOperationException>(()
                                                           => ChildMapperTestingHelper.GetIDAccessor(typeof(TestClasses.ClassWithSuffixedUnderscore), "ClassWithSuffixedUnderscore_ID, foo123"));
            Assert.That(ex.Message, Is.StringContaining("foo123"));

            ex = Assert.Throws <InvalidOperationException>(()
                                                           => ChildMapperTestingHelper.GetIDAccessor(typeof(TestClasses.ClassWithSuffixedUnderscore), "foo123, ClassWithSuffixedUnderscore_ID"));
            Assert.That(ex.Message, Is.StringContaining("foo123"));

            // we could clean up trailing commas, but this test verifies current behavior
            ex = Assert.Throws <InvalidOperationException>(()
                                                           => ChildMapperTestingHelper.GetIDAccessor(typeof(TestClasses.ClassWithSuffixedUnderscore), "ID, "));
        }