Example #1
0
        public void MapRecordCreateInstanceNotNull()
        {
            CustomDataRecord record = new CustomDataRecord(new List <KeyValuePair <string, object> >());
            Employee         model  = _mapper.MapRecord <Employee>(record);

            Assert.IsNotNull(model);
        }
Example #2
0
        public void MapFullEmployeeModel()
        {
            bool      active       = _faker.Random.Bool();
            int       departmentID = _faker.Random.Int();
            string    phoneNumber  = _faker.Phone.PhoneNumber();
            decimal   salary       = _faker.Random.Decimal();
            Guid      managerID    = _faker.Random.Guid();
            DateTime  hireDate     = _faker.Date.Soon();
            PhoneType phoneType    = _faker.PickRandom <PhoneType>();

            List <KeyValuePair <string, object> > kvp = new List <KeyValuePair <string, object> >()
            {
                new KeyValuePair <string, object>("Earnings", salary),
                new KeyValuePair <string, object>("ManagerID", managerID),
                new KeyValuePair <string, object>("PhoneType", phoneType),
                new KeyValuePair <string, object>("Active", active),
                new KeyValuePair <string, object>("DepartmentID", departmentID),
                new KeyValuePair <string, object>("PhoneNumber", phoneNumber),
                new KeyValuePair <string, object>("HireDate", hireDate)
            };

            CustomDataRecord record = new CustomDataRecord(kvp);
            Employee         model  = _mapper.MapRecord <Employee>(record);

            Assert.AreEqual(active, model.Active);
            Assert.AreEqual(salary, model.Salary);
            Assert.AreEqual(hireDate, model.HireDate);
            Assert.AreEqual(departmentID, model.DepartmentID);
            Assert.AreEqual(managerID, model.ManagerID);
            Assert.AreEqual(phoneNumber, model.PhoneNumber);
            Assert.AreEqual(phoneType, model.PhoneType);
        }
Example #3
0
        public void MapRecordCreateInstance()
        {
            decimal   salary       = _faker.Random.Decimal();
            PhoneType type         = _faker.PickRandom <PhoneType>();
            Guid      id           = _faker.Random.Guid();
            string    title        = _faker.Random.AlphaNumeric(30);
            int       departmentID = _faker.Random.Int();

            List <KeyValuePair <string, object> > kvp = new List <KeyValuePair <string, object> >()
            {
                new KeyValuePair <string, object>("EmployeeID", id),
                new KeyValuePair <string, object>("Title", title),
                new KeyValuePair <string, object>("Salary", salary),
                new KeyValuePair <string, object>("DepartmentID", departmentID),
                new KeyValuePair <string, object>("PhoneType", type)
            };
            CustomDataRecord record = new CustomDataRecord(kvp);
            Employee         model  = _mapper.MapRecord <Employee>(record);

            Assert.AreEqual(salary, model.Salary);
            Assert.AreEqual(title, model.Title);
            Assert.AreEqual(id, model.EmployeeID);
            Assert.AreEqual(departmentID, model.DepartmentID);
            Assert.AreEqual(type, model.PhoneType);
        }
Example #4
0
        public void MapDbFieldNull()
        {
            List <KeyValuePair <string, object> > kvp = new List <KeyValuePair <string, object> >()
            {
                new KeyValuePair <string, object>("EmployeeTitle", DBNull.Value)
            };
            CustomDataRecord record = new CustomDataRecord(kvp);
            Employee         model  = _mapper.MapRecord <Employee>(record);

            Assert.IsTrue(model.Title == "SoftwareDeveloper");
        }
Example #5
0
        public void MapNullableWithNullValue()
        {
            List <KeyValuePair <string, object> > kvp = new List <KeyValuePair <string, object> >()
            {
                new KeyValuePair <string, object>("ManagerID", DBNull.Value)
            };
            CustomDataRecord record = new CustomDataRecord(kvp);
            Employee         model  = _mapper.MapRecord <Employee>(record);

            Assert.IsNull(model.ManagerID);
        }
Example #6
0
        public void MapNullValueNullEnumProperty()
        {
            List <KeyValuePair <string, object> > kvp = new List <KeyValuePair <string, object> >()
            {
                new KeyValuePair <string, object>("PhoneType", DBNull.Value)
            };
            CustomDataRecord record = new CustomDataRecord(kvp);
            Employee         model  = _mapper.MapRecord <Employee>(record);

            Assert.IsNull(model.PhoneType);
        }
Example #7
0
        public void MapNullableWithValue()
        {
            Guid managerID = Guid.NewGuid();
            List <KeyValuePair <string, object> > kvp = new List <KeyValuePair <string, object> >()
            {
                new KeyValuePair <string, object>("ManagerID", managerID)
            };
            CustomDataRecord record = new CustomDataRecord(kvp);
            Employee         model  = _mapper.MapRecord <Employee>(record);

            Assert.AreEqual(managerID, model.ManagerID);
        }
Example #8
0
        public void MapValueNullEnumProperty()
        {
            PhoneType type = _faker.PickRandom <PhoneType>();
            List <KeyValuePair <string, object> > kvp = new List <KeyValuePair <string, object> >()
            {
                new KeyValuePair <string, object>("PhoneType", type)
            };
            CustomDataRecord record = new CustomDataRecord(kvp);
            Employee         model  = _mapper.MapRecord <Employee>(record);

            Assert.AreEqual(type, model.PhoneType);
        }
Example #9
0
        public void MapNormalProperty()
        {
            Guid employeedID = Guid.NewGuid();
            List <KeyValuePair <string, object> > kvp = new List <KeyValuePair <string, object> >()
            {
                new KeyValuePair <string, object>("EmployeeID", employeedID)
            };
            CustomDataRecord record = new CustomDataRecord(kvp);
            Employee         model  = _mapper.MapRecord <Employee>(record);

            Assert.AreEqual(employeedID, model.EmployeeID);
        }
Example #10
0
        public void MapNonExistentProperty()
        {
            decimal wage = _faker.Random.Decimal();

            List <KeyValuePair <string, object> > kvp = new List <KeyValuePair <string, object> >()
            {
                new KeyValuePair <string, object>("Wage", wage)
            };
            CustomDataRecord record = new CustomDataRecord(kvp);
            Employee         model  = _mapper.MapRecord <Employee>(record);

            Assert.IsTrue(model.Salary == default);
        }
Example #11
0
        public void MapDbField()
        {
            decimal earnings = _faker.Random.Decimal();

            List <KeyValuePair <string, object> > kvp = new List <KeyValuePair <string, object> >()
            {
                new KeyValuePair <string, object>("Earnings", earnings)
            };
            CustomDataRecord record = new CustomDataRecord(kvp);
            Employee         model  = _mapper.MapRecord <Employee>(record);

            Assert.IsTrue(model.Salary == earnings);
        }
Example #12
0
        public void MapPropertyColumnNameHasUnderscores()
        {
            DataMapper mapper = new DataMapper(true);
            decimal    salary = _faker.Random.Decimal();

            List <KeyValuePair <string, object> > kvp = new List <KeyValuePair <string, object> >()
            {
                new KeyValuePair <string, object>("S_a_l_a_r_y", salary)
            };
            CustomDataRecord record = new CustomDataRecord(kvp);
            Employee         model  = mapper.MapRecord <Employee>(record);

            Assert.IsTrue(model.Salary == salary);
        }