예제 #1
0
 public Post Convert(DbPost dbPost, DbUser dbUser, IEnumerable<DbUser> dbLikeUsers)
 {
     var user = _userMapper.Convert(dbUser);
     var likeUsers = _userMapper.Convert(dbLikeUsers);
     return new Post
     {
         Id = dbPost.Id,
         ItemId = dbPost.ItemId,
         PhotoUrl = dbPost.PhotoUrl,
         Text = dbPost.Text,
         TimeStamp = dbPost.Timestamp,
         User = user,
         LikeUserEnumerable = likeUsers
     };
 }
예제 #2
0
        public void TestConvertDbPostAndDbUserToPost()
        {
            var now = DateTime.Now;

            User user = new User
            {
                City = "city",
                DateOfBirth = now,
                Email = "email",
                FirstName = "firstName",
                Gender = User.Sex.Male,
                Id = 1,
                LastName = "lastName",
                PictureUrl = "pictureUrl",
                UserName = "******"
            };

            var userSet = new HashSet<User>
            {
                new User
                {
                    City = "city1",
                    DateOfBirth = now,
                    Email = "email1",
                    FirstName = "firstName1",
                    Gender = User.Sex.Male,
                    Id = 2,
                    LastName = "lastName1",
                    PictureUrl = "pictureUrl1",
                    UserName = "******"
                },
                new User
                {
                    City = "city2",
                    DateOfBirth = now,
                    Email = "email2",
                    FirstName = "firstName2",
                    Gender = User.Sex.Male,
                    Id = 3,
                    LastName = "lastName2",
                    PictureUrl = "pictureUrl2",
                    UserName = "******"
                }
            };

            Post expectedResult = new Post
            {
                Id = 1,
                ItemId = "itemId",
                PhotoUrl = "photoUrl",
                Text = "text",
                TimeStamp = now,
                User = user,
                LikeUserEnumerable = userSet
            };

            var inputDbUser = new DbUser
            {
                Id = 1,
                City = "city",
                DateOfBirth = now,
                Email = "email",
                FirstName = "firstName",
                LastName = "lastName",
                PictureUrl = "pictureUrl",
                Sex = "m",
                UserName = "******"
            };

            var inputdbPost = new DbPost
            {
                Id = 1,
                ItemId = "itemId",
                PhotoUrl = "photoUrl",
                Text = "text",
                Timestamp = now,
                UserId = 1
            };

            var inputDbUserList = new List<DbUser>
            {
                new DbUser
                {
                    Id = 2,
                    City = "city1",
                    DateOfBirth = now,
                    Email = "email1",
                    FirstName = "firstName1",
                    LastName = "lastName1",
                    PictureUrl = "pictureUrl1",
                    Sex = "m",
                    UserName = "******"
                },
                new DbUser
                {
                    Id = 3,
                    City = "city2",
                    DateOfBirth = now,
                    Email = "email2",
                    FirstName = "firstName2",
                    LastName = "lastName2",
                    PictureUrl = "pictureUrl2",
                    Sex = "m",
                    UserName = "******"
                }
            };

            Assert.AreEqual(expectedResult,_sut.Convert(inputdbPost,inputDbUser,inputDbUserList));
        }
예제 #3
0
        public void TestConvertPostToDbPost()
        {
            var now = DateTime.Now;

            User user = new User
            {
                City = "city",
                DateOfBirth = now,
                Email = "email",
                FirstName = "firstName",
                Gender = User.Sex.Male,
                Id = 1,
                LastName = "lastName",
                PictureUrl = "pictureUrl",
                UserName = "******"
            };

            Post input = new Post
            {
                Id = 1,
                ItemId = "itemId",
                PhotoUrl = "photoUrl",
                Text = "text",
                TimeStamp = now,
                User = user
            };

            var expectedResult = new DbPost
            {
                Id = 1,
                ItemId = "itemId",
                PhotoUrl = "photoUrl",
                Text = "text",
                Timestamp = now,
                UserId = 1
            };

            Assert.AreEqual(expectedResult, _sut.Convert(input));
        }
예제 #4
0
 protected bool Equals(DbPost other)
 {
     return Id == other.Id && string.Equals(ItemId, other.ItemId) && UserId == other.UserId && Timestamp.Equals(other.Timestamp);
 }