Ejemplo n.º 1
0
 protected static void AssertEqual(User user, UserModel partial)
 {
     Assert.IsNotNull(partial);
     Assert.AreEqual(user.Id, partial.Id);
     Assert.AreEqual(user.FirstName, partial.FirstName);
     Assert.AreEqual(user.LastName, partial.LastName);
     Assert.AreEqual(default(DateTime), partial.LastModified);
 }
Ejemplo n.º 2
0
 protected static void AssertFirstUser(User user, bool withAddress = false, bool withPostcode = false)
 {
     using (var sourceUsers = GetSqlDataReader())
     {
         Assert.IsTrue(sourceUsers.Read());
         AssertUser(sourceUsers, user, withAddress, withPostcode);
     }
 }
Ejemplo n.º 3
0
 protected static void AssertEqual(User original, User mapped)
 {
     Assert.IsNotNull(mapped);
     Assert.AreEqual(original.Id, mapped.Id);
     Assert.AreEqual(original.FirstName, mapped.FirstName);
     Assert.AreEqual(original.LastName, mapped.LastName);
     Assert.AreEqual(original.DateOfBirth, mapped.DateOfBirth);
 }
Ejemplo n.º 4
0
 protected static void AssertEqual(User user, DifferentCaseUser partial)
 {
     Assert.IsNotNull(partial);
     Assert.AreEqual(user.Id, partial.ID);
     Assert.AreEqual(user.DateOfBirth, partial.Dateofbirth);
     Assert.AreEqual(user.FirstName, partial.Firstname);
     Assert.AreEqual(user.LastName, partial.Lastname);
     Assert.AreEqual(default(DateTime), partial.Lastmodified);
 }
Ejemplo n.º 5
0
 public void PopulateTarget_WithSql_Static()
 {
     User targetUser = new User();
     using (var sourceUsers = GetSqlDataReader())
     {
         sourceUsers.Read();
         DataReaderAutoMap<User>.PopulateTarget(sourceUsers, targetUser);
     }
     AssertFirstUser(targetUser);
 }
Ejemplo n.º 6
0
 public void Populate_WithSql()
 {
     User targetUser = new User();
     using (var sourceUsers = GetSqlDataReader())
     {
         sourceUsers.Read();
         new FullUserFromDataReaderMap().Populate(sourceUsers, targetUser);
     }
     AssertFirstUser(targetUser, true, true);
 }
Ejemplo n.º 7
0
 public void Populate_WithSql_WithExactNameMatching()
 {
     User targetUser = new User();
     using (var sourceUsers = GetSqlDataReader())
     {
         sourceUsers.Read();
         new FullUserFromDataReaderMap()
                 .Matching<ExactNameMatchingStrategy>()
                 .Populate(sourceUsers, targetUser);
     }
     AssertFirstUser(targetUser);
 }
Ejemplo n.º 8
0
 public void Populate_WithSql_WithCache()
 {
     User targetUser = new User();
     using (var sourceUsers = GetSqlDataReader())
     {
         sourceUsers.Read();
         new FullUserFromDataReaderMap()
                 .Cache<DictionaryCachingStrategy>()
                 .Populate(sourceUsers, targetUser);
     }
     AssertFirstUser(targetUser);
 }
Ejemplo n.º 9
0
 protected static void AssertEqualByPropertyOrder(User original, User mapped, bool withAddress = false)
 {
     Assert.IsNotNull(mapped);
     Assert.AreEqual(original.Id, mapped.Id);
     Assert.AreEqual(original.FirstName, mapped.FirstName);
     Assert.AreEqual(original.LastName, mapped.LastName);
     Assert.AreEqual(original.DateOfBirth, mapped.DateOfBirth);
     Assert.AreEqual(original.NationalInsuranceNumber, mapped.NationalInsuranceNumber);
     if (withAddress)
     {
         Assert.IsNotNull(mapped.Address);
         Assert.AreEqual(original.Address.Line1, mapped.Address.Line1);
         Assert.AreEqual(original.Address.Line2, mapped.Address.Line2);
     }
 }
Ejemplo n.º 10
0
 protected static void AssertUser(IDataReader sourceUsers, User user, bool withAddress = false, bool withPostcode = false)
 {
     Assert.IsNotNull(user);
     Assert.AreEqual((string)sourceUsers["FirstName"], user.FirstName);
     Assert.AreEqual((string)sourceUsers["LastName"], user.LastName);
     if (withAddress)
     {
         Assert.IsNotNull(user.Address);
         Assert.AreEqual((string)sourceUsers["Line1"], user.Address.Line1);
         Assert.AreEqual((string)sourceUsers["Line2"], user.Address.Line2);
         if (withPostcode)
         {
             Assert.IsNotNull(user.Address.PostCode);
             Assert.AreEqual((string)sourceUsers["PostCode"], user.Address.PostCode.Code);
         }
     }
 }
Ejemplo n.º 11
0
 protected static User GetFullUser()
 {
     User user = new User
     {
         Id = RandomGuid(),
         FirstName = RandomGuidString(),
         LastName = RandomGuidString(),
         DateOfBirth = RandomDate(),
         EmailAddress = RandomGuidString(),
         NationalInsuranceNumber = RandomGuidString(),
         Address = new Address
         {
             Line1 = RandomGuidString(),
             Line2 = RandomGuidString(),
             PostCode = new PostCode
             {
                 InwardCode = RandomGuidString().Substring(0, 3),
                 OutwardCode = RandomGuidString().Substring(0, 3)
             }
         }
     };
     return user;
 }
Ejemplo n.º 12
0
 protected static void AssertEqual(User user, User otherUser, bool withUpperLastName = true, bool withAddress = false)
 {
     Assert.IsNotNull(otherUser);
     Assert.AreEqual(user.Id, otherUser.Id);
     Assert.AreEqual(user.FirstName, otherUser.FirstName);
     if (withUpperLastName)
     {
         Assert.AreEqual(user.LastName.ToUpper(), otherUser.LastName);
     }
     else
     {
         Assert.AreEqual(user.LastName, otherUser.LastName);
     }
     Assert.AreEqual(user.DateOfBirth, otherUser.DateOfBirth);
     Assert.AreEqual(user.EmailAddress, otherUser.EmailAddress);
     Assert.AreEqual(user.NationalInsuranceNumber, otherUser.NationalInsuranceNumber);
     if (withAddress)
     {
         Assert.AreEqual(user.Address.Line1, otherUser.Address.Line1);
         Assert.AreEqual(user.Address.Line2, otherUser.Address.Line2);
         Assert.AreEqual(user.Address.PostCode.Code, otherUser.Address.PostCode.Code);
     }
 }
 public void FromSqlCe_Manual()
 {
     var stopwatch = Stopwatch.StartNew();
     var count = 0;
     using (var reader = GetSqlDataReader())
     {
         while (reader.Read() && count < PerformanceIterations)
         {
             count++;
             var user = new User();
             user.Id = (Guid)reader["UserId"];
             user.FirstName = (string)reader["FirstName"];
             user.LastName = (string)reader["LastName"];
             var address = new Address();
             address.Line1 = (string)reader["Line1"];
             address.Line2 = (string)reader["Line2"];
             address.PostCode = new PostCode();
             address.PostCode.Code = (string)reader["PostCode"];
             user.Address = address;
             AssertUser(reader, user, true, true);
         }
     }
     Debug.WriteLine("FromSqlCe_Manual -Mapped: {0} objects and asserted 0 failures in: {1}ms", count, stopwatch.ElapsedMilliseconds);
 }
Ejemplo n.º 14
0
 private static void AssertEqual(User user, UserModel partial, bool addressLine1Mapped = true)
 {
     Assert.IsNotNull(partial);
     Assert.AreEqual(user.Id, partial.Id);
     Assert.AreEqual(user.FirstName, partial.FirstName);
     Assert.AreEqual(user.LastName, partial.LastName);
     Assert.AreEqual(user.DateOfBirth, partial.DateOfBirth);
     if (addressLine1Mapped)
     {
         Assert.AreEqual(user.Address.Line1, partial.AddressLine1);
     }
     Assert.AreEqual(default(DateTime), partial.LastModified);
 }
 private static void AssertEqual(User user, UserModel partial)
 {
     Assert.IsNotNull(partial);
     Assert.AreEqual(user.Id, partial.Id);
     Assert.AreEqual(user.FirstName, partial.FirstName);
     Assert.AreEqual(user.LastName, partial.LastName);
     Assert.AreEqual(user.Address.Line1, partial.AddressLine1);
     Assert.AreEqual(user.Address.PostCode.Code, partial.Address.PostCode);
     Assert.AreEqual(user.DateOfBirth, partial.DateOfBirth);
     Assert.AreEqual(default(DateTime), partial.LastModified);
 }
Ejemplo n.º 16
0
 public void CsvToUser_StaticAutoMap_Populate()
 {
     var original = GetFullUser();
     var csvRow = GetCsvRow(original);
     var mapped = new User();
     CsvAutoMap<User>.PopulateTarget(csvRow, mapped);
     AssertEqual(original, mapped);
 }
Ejemplo n.º 17
0
 public void PopulateTarget_Mixed()
 {
     var user = GetFullUser();
     var userXml = GetUserXml(UserMixedXmlFormat, user);
     var source = XDocument.Parse(userXml);
     var mappedUser = new User();
     XDocumentAutoMap<User>.PopulateTarget(source, mappedUser);
     AssertEqual(user, mappedUser, false);
 }
Ejemplo n.º 18
0
 protected string GetPropertyNameOrderedRowWithAddress(User user, char delimiter = ',')
 {
     return string.Format("{0}{1}{2}{1}{3}{1}{4}{1}{5}",
         user.Id, delimiter, user.FirstName, user.LastName, user.DateOfBirth, user.NationalInsuranceNumber, user.Address.Line1, user.Address.Line2);
 }
Ejemplo n.º 19
0
 private static void AssertEqual(User user, LegacyUser partial)
 {
     Assert.IsNotNull(partial);
     Assert.AreEqual(user.Id, partial.ID);
     Assert.AreEqual(user.FirstName, partial.First_Name);
     Assert.AreEqual(user.LastName, partial.Last_Name);
     Assert.AreEqual(user.DateOfBirth, partial.D_O_B);
     Assert.AreEqual(default(DateTime), partial.Last_Modified);
 }
Ejemplo n.º 20
0
 protected static string GetUserXml(string xmlFormat, User user)
 {
     return string.Format(xmlFormat, user.Id, user.FirstName, user.LastName, user.DateOfBirth, user.EmailAddress, user.NationalInsuranceNumber, user.Address.Line1, user.Address.Line2, user.Address.PostCode.Code);
 }
Ejemplo n.º 21
0
 public void Performance_Manual_Sql()
 {
     using (var reader = GetSqlDataReader())
     {
         reader.Read();
         for (int i = 0; i < PerformanceIterations; i++)
         {
             var user = new User();
             user.Id = (Guid)reader["UserId"];
             user.FirstName = (string)reader["FirstName"];
             user.LastName = (string)reader["LastName"];
             user.Address = new Address();
             user.Address.Line1 = (string)reader["Line1"];
             user.Address.Line2 = (string)reader["Line2"];
             user.Address.PostCode.Code = (string)reader["PostCode"];
         }
     }
 }        
Ejemplo n.º 22
0
 private static void AssertNotEqual(User user, DifferentCaseUser partial)
 {
     Assert.IsNotNull(partial);
     Assert.AreNotEqual(user.Id, partial.ID);
     Assert.AreNotEqual(user.FirstName, partial.Firstname);
     Assert.AreNotEqual(user.LastName, partial.Lastname);
     Assert.AreNotEqual(user.DateOfBirth, partial.Dateofbirth);
 }
Ejemplo n.º 23
0
 protected string GetCsvRow(User user, char delimiter = ',')
 {
     return string.Format("{0}{1}{2}{1}{3}{1}{4}{1}{5}{1}{6}",
         user.Id, delimiter, user.FirstName, user.LastName, user.DateOfBirth, user.Address.Line1, user.Address.Line2);
 }