Exemple #1
0
        public void Delegate_funtion_that_updates_member_ordered_after_member_configs_does_not_change_values()
        {
            var people = new List <TestPerson> {
                new TestPerson {
                    PublicProperty = "Hello"
                }
            };

            Translator.AddProfile <StrangeDelegatesProfile>();
            Translator.ApplyUpdates();
            var table = Translator.Translate <StrangeDelegatesProfile, TestPerson>(people, "After");

            Assert.AreEqual("Hello", table.Rows[0][0]);
        }
        public void Get_all_profiles_returns_all_profiles()
        {
            var basicProfile  = new BasicProfile();
            var basicProfile2 = new BasicProfile2();
            var spyProfile    = new SpyProfile();

            Translator.AddProfile(basicProfile);
            Translator.AddProfile(basicProfile2);
            Translator.AddProfile(spyProfile);

            var profiles = Translator.GetAllProfiles().ToList();

            CollectionAssert.Contains(profiles, basicProfile);
            CollectionAssert.Contains(profiles, basicProfile2);
            CollectionAssert.Contains(profiles, spyProfile);
        }
        public void Translate_to_DT_values()
        {
            Translator.AddProfile <BasicProfile>();
            Translator.ApplyUpdates();
            var rows = Translator.Translate <BasicProfile, TestPerson>(people, "Translation1").Rows;

            Assert.AreEqual("Chris", rows[0][0]);
            Assert.AreEqual(27, (int)rows[0][1]);
            Assert.AreEqual(108, (int)rows[0][2]);
            Assert.AreEqual(999, (int)rows[0][3]);

            Assert.AreEqual("Aubrey", rows[1][0]);
            Assert.AreEqual(27, (int)rows[1][1]);
            Assert.AreEqual(109, (int)rows[1][2]);
            Assert.AreEqual(999, (int)rows[0][3]);

            Assert.AreEqual("John", rows[2][0]);
            Assert.AreEqual(27, (int)rows[2][1]);
            Assert.AreEqual(110, (int)rows[2][2]);
            Assert.AreEqual(999, (int)rows[0][3]);
        }
        public void Translation_for_model_with_multiple_generic()
        {
            var threeGenerics = new List <Generics.ThreeGenerics <int, DateTime, string> >
            {
                new Generics.ThreeGenerics <int, DateTime, string> {
                    TData = 1, KData = DateTime.Now, JData = "J1"
                },
                new Generics.ThreeGenerics <int, DateTime, string> {
                    TData = 2, KData = DateTime.Now, JData = "J2"
                },
                new Generics.ThreeGenerics <int, DateTime, string> {
                    TData = 3, KData = DateTime.Now, JData = "J3"
                }
            };

            Translator.AddProfile <GenericsProfile>();
            Translator.ApplyUpdates();
            var dt = new DataTable();

            Assert.DoesNotThrow(() => dt = Translator.Translate <GenericsProfile, Generics.ThreeGenerics <int, DateTime, string> >(threeGenerics));
            Assert.AreEqual(3, dt.Rows.Count);
        }
        public void Translation_for_model_with_one_generic()
        {
            var oneGenerics = new List <Generics.OneGeneric <int> >
            {
                new Generics.OneGeneric <int> {
                    TData = 1
                },
                new Generics.OneGeneric <int> {
                    TData = 2
                },
                new Generics.OneGeneric <int> {
                    TData = 3
                }
            };

            Translator.AddProfile <GenericsProfile>();
            Translator.ApplyUpdates();
            var dt = new DataTable();

            Assert.DoesNotThrow(() => dt = Translator.Translate <GenericsProfile, Generics.OneGeneric <int> >(oneGenerics, "IntGeneric"));
            Assert.AreEqual(3, dt.Rows.Count);
        }
Exemple #6
0
        static void Main(string[] args)
        {
            // add our example profile
            Translator.AddProfile <ExampleProfile>();

            // initialize the translator
            Translator.Initialize();

            // translate data using the various translations in our profile
            PrintTranslationHeader("Miscellaneous");
            Translator.Translate <ExampleProfile, Person>(_people, "Miscellaneous").PrintToConsole();

            PrintTranslationHeader("AllMembers");
            Translator.Translate <ExampleProfile, Person>(_people, "AllMembers").PrintToConsole();

            PrintTranslationHeader("AllMembersWithPredicate");
            Translator.Translate <ExampleProfile, Person>(_people, "AllMembersWithPredicate").PrintToConsole();

            PrintTranslationHeader("AllMembersWithOrderer");
            Translator.Translate <ExampleProfile, Person>(_people, "AllMembersWithOrderer").PrintToConsole();

            PrintTranslationHeader("AllMembersWithBindingFlags");
            Translator.Translate <ExampleProfile, Person>(_people, "AllMembersWithBindingFlags").PrintToConsole();

            PrintTranslationHeader("VariousOptionalSettings");
            Translator.Translate <ExampleProfile, Person>(_people, "VariousOptionalSettings").PrintToConsole();

            PrintTranslationHeader("ForAStruct");
            Translator.Translate <ExampleProfile, int>(new List <int> {
                1, 2, 3
            }, "ForAStruct").PrintToConsole();

            // NOTE: The same translation can translate a list to a DataTable and/or DbParameter
            PrintTranslationHeader("Miscellaneous (as a DbParameter)");
            Translator.TranslateToDbParameter <ExampleProfile, Person>(_people,
                                                                       new DbParameterSettings("myParameterName", "myDatabaseObjName"), "Miscellaneous").PrintToConsole();

            Console.ReadLine();
        }
Exemple #7
0
 public void Seeded_with_non_long_parseable_type_throws_TableTranslatorConfigurationException()
 {
     Translator.AddProfile <BadTypeSeededIdentityProfile>();
     Assert.Throws <TableTranslatorConfigurationException>(() => Translator.ApplyUpdates());
 }
Exemple #8
0
 public void Seeded_with_custom_increment_of_zero_throws_TableTranslatorConfigurationException()
 {
     Translator.AddProfile <ZeroIncrementSeededIdentityProfile>();
     Assert.Throws <TableTranslatorConfigurationException>(() => Translator.ApplyUpdates());
 }
 public void DataType_and_return_type_of_get_value_throws_exception_when_not_the_same()
 {
     Translator.AddProfile <WrongTypeIdentityProfile>();
     Assert.Throws <TableTranslatorConfigurationException>(() => Translator.ApplyUpdates());
 }
 public void Null_profile_passed_to_add_profile_throws_TableTranslationException()
 {
     Assert.Throws <ArgumentNullException>(() => Translator.AddProfile(null));
 }
 public void Null_non_expression_column_config_does_not_throw_exception()
 {
     Translator.AddProfile <NullNonExpressionProfile>();
     Assert.DoesNotThrow(() => Translator.ApplyUpdates());
 }
 public void String_reverse_non_expression_column_config_does_not_throw_exception()
 {
     Translator.AddProfile <StringReverseProfile>();
     Assert.DoesNotThrow(() => Translator.ApplyUpdates());
 }
 public void Explicit_column_name_matching_default_column_name_for_non_member_config_throws_TableTranslatorConfigurationException()
 {
     Translator.AddProfile <DupeExplicitNonMemberColumnNameProfile>();
     Assert.Throws <TableTranslatorConfigurationException>(() => Translator.ApplyUpdates());
 }
 public void Adding_profiles_with_same_name_throws_TableTranslationConfigurationException()
 {
     Translator.AddProfile <DupeProfile1>();
     Assert.Throws <TableTranslatorConfigurationException>(Translator.AddProfile <DupeProfile2>);
 }
 public void Adding_duplicate_profiles_throws_TableTranslationConfigurationException()
 {
     Translator.AddProfile <DefaultNameProfile>();
     Assert.Throws <TableTranslatorConfigurationException>(Translator.AddProfile <DefaultNameProfile>);
 }
Exemple #16
0
 public void Translate_to_DT_throws_TableTranslatorException_when_more_than_one_matching_translation_is_found()
 {
     Translator.AddProfile <BasicProfile>();
     Translator.ApplyUpdates();
     Assert.Throws <TableTranslatorException>(() => Translator.Translate <BasicProfile, TestPerson>(this.people));
 }
 public void Null_db_parameter_settings_throws_ArgumentNullException()
 {
     Translator.AddProfile <BasicProfile>();
     Translator.ApplyUpdates();
     Assert.Throws <ArgumentNullException>(() => Translator.TranslateToDbParameter <BasicProfile, TestPerson>(new List <TestPerson>(), null, "Translation1"));
 }