public void TestReadUser()
        {
            var expectedUser = 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"
            };

            const int userId = 1;
            var actual = _sut.Read(userId);
            Assert.AreEqual(expectedUser.City, actual.City);
            Assert.AreEqual(expectedUser.DateOfBirth.Date, actual.DateOfBirth.Date);
            Assert.AreEqual(expectedUser.Email, actual.Email);
            Assert.AreEqual(expectedUser.FirstName, actual.FirstName);
            Assert.AreEqual(expectedUser.LastName, actual.LastName);
            Assert.AreEqual(expectedUser.PictureUrl, actual.PictureUrl);
            Assert.AreEqual(expectedUser.Gender, actual.Gender);
            Assert.AreEqual(expectedUser.UserName, actual.UserName);
        }
Esempio n. 2
0
 public static string Sex(User.Sex sexEnum)
 {
     var sex = "m";
     if (User.Sex.Female == sexEnum)
         sex = "f";
     else if (User.Sex.NoGender == sexEnum)
         sex = "n";
     return sex;
 }
Esempio n. 3
0
        public long Save(User user)
        {
            var dbUser = _mapper.Convert(user);

            var result = _connection.users.Insert(user_name: dbUser.UserName, first_name: dbUser.FirstName,
                last_name: dbUser.LastName, sex: dbUser.Sex,
                email: dbUser.Email, date_of_birth: dbUser.DateOfBirth,
                city: dbUser.City, picture_url: dbUser.PictureUrl);
            return result.id;
        }
Esempio n. 4
0
        public DbUser Convert(User user)
        {
            var sex = Utils.Sex(user.Gender);

            return new DbUser
            {
                City = user.City,
                DateOfBirth = user.DateOfBirth,
                Email = user.Email,
                FirstName = user.FirstName,
                Id = user.Id,
                LastName = user.LastName,
                PictureUrl = user.PictureUrl,
                Sex = sex,
                UserName = user.UserName
            };
        }
Esempio n. 5
0
        public void TestConvertDbUserToUser()
        {
            var Id = 1;
            var UserName = "******";
            var FirstName = "FirstName";
            var LastName = "LastName";
            var Sex = "m";
            var Email = "user@email";
            var City = "Bologna";
            var DateOfBirth = DateTime.Now;
            var PictureUrl = "picture01";

            var input = new DbUser
            {
                Id = Id,
                UserName = UserName,
                FirstName = FirstName,
                LastName = LastName,
                Sex = Sex,
                Email = Email,
                City = City,
                DateOfBirth = DateOfBirth,
                PictureUrl = PictureUrl
            };

            var expected = new User
            {
                Id = Id,
                UserName = UserName,
                FirstName = FirstName,
                LastName = LastName,
                Gender = User.Sex.Male,
                Email = Email,
                City = City,
                DateOfBirth = DateOfBirth,
                PictureUrl = PictureUrl
            };

            var actual = _sut.Convert(input);

            Assert.AreEqual(expected, actual);
        }
        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);
        }
Esempio n. 7
0
 public IList<Post> GetPostAtPage(int page, User.Sex sex)
 {
     return _postRepository.GetDbPostsByPage(page, Utils.Sex(sex));
 }
        public void TestReadDbPostByPageBySex()
        {
            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 expectedPostList = new List<Post>
            {
                new Post
                {
                    Id = 1,
                    ItemId = "itemId",
                    PhotoUrl = "photoUrl",
                    Text = "text",
                    TimeStamp = DateTime.Now,
                    User = user,
                    LikeUserEnumerable = likeUserSet
                }
            };

            const int pageNumber = 1;
            var actual = _sut.GetDbPostsByPage(pageNumber, "m");
            Assert.AreEqual(expectedPostList, actual);
        }
Esempio n. 9
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));
        }
Esempio n. 10
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));
        }
Esempio n. 11
0
 protected bool Equals(User other)
 {
     return Id == other.Id && string.Equals(UserName, other.UserName) && string.Equals(FirstName, other.FirstName) && string.Equals(LastName, other.LastName) && Gender == other.Gender && string.Equals(Email, other.Email) && string.Equals(City, other.City) && DateOfBirth.Equals(other.DateOfBirth) && string.Equals(PictureUrl, other.PictureUrl);
 }