Beispiel #1
0
        public void Builtin_Cummulative_Functions_Min_Max_Test()
        {
            UserDTO dto = m_assembler.AssembleFrom(m_user);

            Assert.AreEqual(1, dto.MinTaskDuration);
            Assert.AreEqual(6, dto.MaxTaskDuration);
        }
        public void Null_value_replacement()
        {
            SetUpDefaults();
            m_user.UserName = null;
            AttributedUserDTO dto = m_asm.AssembleFrom(m_user);

            Assert.AreEqual("[unknown]", dto.UserName);
        }
Beispiel #3
0
        public void TestXmlGenerics()
        {
            IAssembler <XmlGenericEntityDTO, GenericEntity <int> > asm = CreateXmlAssembler();

            XmlGenericEntityDTO xmlDto = asm.AssembleFrom(m_source);

            Assert.That(xmlDto.Id, Is.EqualTo(1));
            Assert.That(xmlDto.NullableProperty, Is.EqualTo(2));

            // test nullables
            m_source.NullableProperty = null;
            xmlDto = asm.AssembleFrom(m_source);
            Assert.That(xmlDto.NullableProperty, Is.Null);
        }
        public void Formatting_Is_Applied_To_String_Members()
        {
            m_user.BirthDay = new DateTime(1973, 10, 22);

            CultureInfo culture = Thread.CurrentThread.CurrentCulture;

            Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");

            UserDTO dto = m_assembler.AssembleFrom(m_user);

            Assert.AreEqual("Monday, October 22, 1973", dto.BirthDay);

            Thread.CurrentThread.CurrentCulture = culture;
        }
Beispiel #5
0
        public void TestAttributedGenerics()
        {
            IAssembler <AttributedGenericEntityDTO, GenericEntity <int> > asm = CreateAttributedAssembler();

            AttributedGenericEntityDTO dto = asm.AssembleFrom(m_source);

            Assert.That(dto.Id, Is.EqualTo(1));
            Assert.That(dto.NullableProperty, Is.EqualTo(2));

            // test nullables
            m_source.NullableProperty = null;
            dto = asm.AssembleFrom(m_source);
            Assert.That(dto.NullableProperty, Is.Null);
        }
Beispiel #6
0
        public void Preparer_Is_Called_Before_Transformation()
        {
            IAssembler <MappingPreparerDTO_CheckOrder, User> asm = ConfigureType <MappingPreparerDTO_CheckOrder>();
            MappingPreparerDTO_CheckOrder dto = asm.AssembleFrom(m_user);

            Assert.AreEqual(77, dto.Id);              // check it is not -1
        }
Beispiel #7
0
        public void Helper_Is_Called_After_Transformation()
        {
            IAssembler <MappingHelperDTO_CheckOrder, User> asm = ConfigureType <MappingHelperDTO_CheckOrder>();
            MappingHelperDTO_CheckOrder dto = asm.AssembleFrom(m_user);

            Assert.AreEqual(-100, dto.Id);              // check it is not -1
        }
        public void Configure_From_Type()
        {
            Configuration cfg = new Configuration();

            cfg.AddType(typeof(AttributedUserDTO));

            IAssembler <AttributedUserDTO, User> asm = cfg.GetAssembler <AttributedUserDTO, User>();
            AttributedUserDTO dto = asm.AssembleFrom(m_user);

            Assert.AreEqual(dto.Id, m_user.Id);
            Assert.AreEqual(dto.Age, m_user.Age);
            Assert.AreEqual(dto.UserName, m_user.UserName.ToUpper());
            Assert.AreEqual(dto.ProjectCount, m_user.Projects.Count);
            Assert.AreEqual(dto.FullName, m_user.FirstName + " " + m_user.LastName);
            Assert.AreEqual(dto.Gender, Gender.Male);
            Assert.AreEqual(dto.GenderCode, "M");


            AttributedUserDTO dto2 = new AttributedUserDTO();

            asm.Assemble(ref dto2, ref m_user);

            Assert.AreEqual(dto2.Id, m_user.Id);
            Assert.AreEqual(dto2.Age, m_user.Age);
            Assert.AreEqual(dto2.UserName, m_user.UserName.ToUpper());
            Assert.AreEqual(dto2.ProjectCount, m_user.Projects.Count);
        }
Beispiel #9
0
        public void Static_Preparer()
        {
            IAssembler <MappingPreparerDTO_StaticPreparer, User> asm = ConfigureType <MappingPreparerDTO_StaticPreparer>();
            MappingPreparerDTO_StaticPreparer dto = asm.AssembleFrom(m_user);

            Assert.AreEqual(77, dto.Id);
            Assert.AreEqual("custom_mapping_StaticPreparer", dto.FullName);
        }
Beispiel #10
0
        public void Non_Static_Helper()
        {
            IAssembler <MappingHelperDTO_InstanceHelper, User> asm = ConfigureType <MappingHelperDTO_InstanceHelper>();
            MappingHelperDTO_InstanceHelper dto = asm.AssembleFrom(m_user);

            Assert.AreEqual(77, dto.Id);
            Assert.AreEqual("custom_mapping_InstanceHelper", dto.FullName);
        }
        public void ProjectionTest()
        {
            Configuration cfg = new Configuration();

            cfg.AddType(typeof(AttributedUserDTO));
            IAssembler <AttributedUserDTO, User> asm = cfg.GetAssembler <AttributedUserDTO, User>();
            AttributedUserDTO dto = asm.AssembleFrom(m_user);

            Assert.AreEqual(dto.Gender, Gender.Male);
            Assert.AreEqual(dto.GenderCode, "M");

            m_user.UserGender = "W";
            dto = asm.AssembleFrom(m_user);

            Assert.AreEqual(dto.Gender, Gender.Female);
            Assert.AreEqual(dto.GenderCode, "W");
        }
        public void TestInheritanceXml()
        {
            IAssembler <DerivedXmlUserDTO, DerivedUser> asm = CreateXmlAssembler();
            DerivedXmlUserDTO userDto = asm.AssembleFrom(m_source);

            Assert.That(userDto.FullName, Is.EqualTo(m_source.FirstName + " " + m_source.LastName));
            Assert.That(userDto.Age, Is.EqualTo(m_source.Age));
            Assert.That(userDto.DerivedProperty, Is.EqualTo(m_source.DerivedProperty));
        }
        public void Formatting_Works_For_User_Aggregates_Not_Derived_From_SimpleFunctionBase()
        {
            Configuration cfg = new Configuration();

            cfg.RegisterFunction <MedianFn>("median");
            cfg.AddType(typeof(Dummy2));
            IAssembler <Dummy2, User> asm = cfg.GetAssembler <Dummy2, User>();
            Dummy2 dummy = asm.AssembleFrom(Helpers.CreateComplexUser());

            Assert.AreEqual("Median document length: 4.00 characters", dummy.MedianDocumentNameLengthInfo);
        }
        public void Formatting_Works_For_Aggregate_Expressions()
        {
            Configuration cfg = new Configuration();

            cfg.AddType(typeof(Dummy));
            IAssembler <Dummy, User> asm = cfg.GetAssembler <Dummy, User>();
            Dummy dummy = asm.AssembleFrom(Helpers.CreateComplexUser());

            Assert.AreEqual("2 documents", dummy.DocumentInfo);
            Assert.AreEqual("Avg document length: 4.00 characters", dummy.AvgDocumentNameLengthInfo);
        }
        private void TestXmlConfiguration(Configuration cfg)
        {
            IAssembler <XmlUserDTO, User> asm = cfg.GetAssembler <XmlUserDTO, User>();
            XmlUserDTO dto = asm.AssembleFrom(m_user);

            Assert.AreEqual(dto.Id, m_user.Id);
            Assert.AreEqual(dto.Age, m_user.Age);
            Assert.AreEqual(dto.UserName, m_user.UserName.ToUpper());
            Assert.AreEqual(dto.ProjectCount, m_user.Projects.Count);
            Assert.AreEqual(dto.FullName, m_user.FirstName + " " + m_user.LastName);
        }
Beispiel #16
0
        public void Aggregate_Functions_Understand_Complex_Path_Items()
        {
            Configuration cfg;

            cfg = new Configuration();
            cfg.AddType <ComplexUserDTO>();
            cfg.BuildAssemblers();

            IAssembler <ComplexUserDTO, User> assembler = cfg.GetAssembler <ComplexUserDTO, User>();
            ComplexUserDTO dto = assembler.AssembleFrom(m_user);

            Assert.AreEqual(4, dto.AvgDocumentNameLength);
        }
Beispiel #17
0
        public void User_Defined_Aggregate_Functions()
        {
            Configuration cfg;

            cfg = new Configuration();
            cfg.AddType <SimpleUserDTO>();
            cfg.RegisterFunction("median", typeof(MedianFn));
            cfg.BuildAssemblers();

            IAssembler <SimpleUserDTO, User> assembler = cfg.GetAssembler <SimpleUserDTO, User>();
            SimpleUserDTO dto = assembler.AssembleFrom(m_user);

            Assert.AreEqual(4, dto.MedianTaskDuration);
            Assert.AreEqual(4, dto.MedianDocumentNameLength);
        }