public DbPost Convert(Post post) { return new DbPost { Id = post.Id, ItemId = post.ItemId, PhotoUrl = post.PhotoUrl, Text = post.Text, Timestamp = post.TimeStamp, UserId = post.User.Id }; }
public JsonPostResponse Convert(Post post, string username) { return new JsonPostResponse { C10 = post.ItemId, CreationTime = post.TimeStamp, Description = post.Text, Liked = post.LikeUserEnumerable.Any(user => user.UserName == username), NumLikes = post.LikeUserEnumerable.Count, PhotoUrl = post.PhotoUrl, PostId = post.Id, UserName = post.User.UserName }; }
public void TestConvertPost() { var creationDateTime = DateTime.Now; var user = new User{UserName = "******"}; var requesterUsername = "******"; var input = new Post { Id = 0, ItemId = "itemId", PhotoUrl = "photoUrl", Text = "description", TimeStamp = creationDateTime, User = user}; var expectedResult = new PostResponse { IdPost = 0, CreationDateTime = creationDateTime, Description = "Description", Liked = true, LikeNumber = 1, PhotoUrl = "photoUrl", UserName = "******", ItemId = "itemId" }; var output = _sut.Convert(input, requesterUsername); Assert.AreEqual(expectedResult,output); }
protected bool Equals(Post other) { return Id == other.Id && Equals(User, other.User) && string.Equals(Text, other.Text) && string.Equals(ItemId, other.ItemId) && string.Equals(PhotoUrl, other.PhotoUrl) && LikeUserEnumerable.SetEquals(other.LikeUserEnumerable); }
public long Save(Post post) { var dbPost = _mapper.Convert(post); var result = _connection.posts.Insert(item_id: dbPost.ItemId, text: dbPost.Text, user_id: dbPost.UserId, photo_url: dbPost.PhotoUrl); return result; }
public void TestReadDbPost() { var likeUserSet = new HashSet<User> { new User{ City = "city1", UserName = "******", DateOfBirth = DateTime.Parse("1990-01-01").Date, Email = "*****@*****.**", FirstName = "firstName1", Gender = User.Sex.Male, Id = 2, LastName = "lastName1", PictureUrl = "pictureUrl1" }, new User{ City = "city2", UserName = "******", DateOfBirth = DateTime.Parse("1990-01-01").Date, Email = "*****@*****.**", FirstName = "firstName2", Gender = User.Sex.Male, Id = 3, LastName = "lastName2", PictureUrl = "pictureUrl2" } }; var user = new User { City = "city", UserName = "******", DateOfBirth = DateTime.Parse("1990-01-01").Date, Email = "*****@*****.**", FirstName = "firstName", Gender = User.Sex.Male, Id = 1, LastName = "lastName", PictureUrl = "pictureUrl" }; var expectedPost = new Post { Id = 1, ItemId = "itemId", PhotoUrl = "photoUrl", Text = "text", TimeStamp = DateTime.Now, User = user, LikeUserEnumerable = likeUserSet }; const int postId = 1; var actual = _sut.Read(postId); Assert.AreEqual(expectedPost, actual); }
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)); }
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)); }