Пример #1
0
 public ActionResult <UserListModel> GetLessDetailUserById(int id)
 {
     try
     {
         return(_mapper.DetailModelToListModel(_repository.GetById(id)));
     }
     catch (Exception e)
     {
         return(null);
     }
 }
Пример #2
0
 public List <TeamListModel> GetAllTeamsForUser(int id)
 {
     using (var dbContext = dbContextFactory.CreateDbContext())
     {
         var userMapper     = new UserMapper();
         var teamMapper     = new TeamMapper();
         var teamEntityList = GetAllDetail();
         var userTeamList   = new List <TeamListModel>();
         var repository     = new UserRepository(dbContextFactory);
         var user           = userMapper.DetailModelToListModel(repository.GetById(id));
         foreach (var team in teamEntityList)
         {
             if (team.Members.Contains(user))
             {
                 userTeamList.Add(teamMapper.DetailModelToListModel(team));
             }
         }
         return(userTeamList);
     }
 }
Пример #3
0
        public void PostEntityModelTest()
        {
            var postMapper = new PostMapper();
            var userMapper = new UserMapper();

            Assert.Null(postMapper.EntityToModel(null));
            Assert.Null(postMapper.ModelToEntity(null));

            var UserEntityObject = new UserEntity()
            {
                Id       = 4,
                Name     = "Anton",
                Password = "******",
                Email    = "*****@*****.**",
            };

            var TeamEntityObject = new TeamEntity()
            {
                Id      = 2,
                Leader  = UserEntityObject.Id,
                Members = new Collection <TeamUserEntity>(),
                Name    = "Team1"
            };

            var PostEntityObject = new PostEntity()
            {
                Id         = 4,
                Author     = UserEntityObject.Id,
                AuthorName = UserEntityObject.Name,
                Date       = new DateTime(2019, 4, 1),
                Team       = TeamEntityObject.Id,
                Text       = "Toto je testovaci prispevok",
                Title      = "Titulok"
            };

            var CommentEntity1 = new CommentEntity()
            {
                Author     = UserEntityObject.Id,
                AuthorName = UserEntityObject.Name,
                Date       = new DateTime(2019, 1, 4),
                Id         = 1,
                Text       = "Testovaci koment"
            };
            var CommentEntity2 = new CommentEntity()
            {
                Author     = UserEntityObject.Id,
                AuthorName = UserEntityObject.Name,
                Date       = new DateTime(2019, 1, 4),
                Id         = 1,
                Text       = "Testovaci koment cislo 2"
            };



            var UserModelObject = new UserDetailModel()
            {
                Id       = 4,
                Name     = "Anton",
                Password = "******",
                Email    = "*****@*****.**",
            };

            var TeamModelObject = new TeamDetailModel()
            {
                Id      = 2,
                Leader  = UserModelObject.Id,
                Members = new Collection <UserListModel>(),
                Name    = "Team1"
            };

            var PostModelObject = new PostModel()
            {
                Id         = 4,
                Author     = UserModelObject.Id,
                AuthorName = UserModelObject.Name,
                Comments   = new Collection <CommentModel>(),
                Date       = new DateTime(2019, 4, 1),
                Team       = TeamModelObject.Id,
                Text       = "Toto je testovaci prispevok",
                Title      = "Titulok"
            };

            Assert.Equal(PostModelObject, postMapper.EntityToModel(PostEntityObject));

            PostEntityObject.Comments = new Collection <CommentEntity>();

            var Comment1 = new CommentModel()
            {
                Author     = UserModelObject.Id,
                AuthorName = UserModelObject.Name,
                Date       = new DateTime(2019, 1, 4),
                Id         = 1,
                Text       = "Testovaci koment"
            };
            var Comment2 = new CommentModel()
            {
                Author     = UserModelObject.Id,
                AuthorName = UserModelObject.Name,
                Date       = new DateTime(2019, 1, 4),
                Id         = 1,
                Text       = "Testovaci koment cislo 2"
            };

            PostModelObject.Comments = null;

            Assert.Equal(PostEntityObject, postMapper.ModelToEntity(PostModelObject));

            PostModelObject.Comments = new Collection <CommentModel>();

            TeamEntityObject.Members.Add(new TeamUserEntity()
            {
                UserId = UserEntityObject.Id, UserName = UserEntityObject.Name
            });
            PostEntityObject.Comments.Add(CommentEntity1);
            PostEntityObject.Comments.Add(CommentEntity2);
            TeamModelObject.Members.Add(userMapper.DetailModelToListModel(UserModelObject));
            PostModelObject.Comments.Add(Comment1);
            PostModelObject.Comments.Add(Comment2);

            Assert.Equal(PostModelObject, postMapper.EntityToModel(PostEntityObject));
            Assert.Equal(PostEntityObject, postMapper.ModelToEntity(PostModelObject));
        }
Пример #4
0
        public void TeamEntityModelTest()
        {
            var teamMapper = new TeamMapper();
            var userMapper = new UserMapper();

            Assert.Null(teamMapper.EntityToDetailModel(null));
            Assert.Null(teamMapper.DetailModelToEntity(null));

            var UserEntityObject = new UserEntity()
            {
                Id       = 4,
                Name     = "Anton",
                Password = "******",
                Email    = "*****@*****.**",
                Comments = new Collection <CommentEntity>(),
                Posts    = new Collection <PostEntity>()
            };

            var TeamEntityObject = new TeamEntity()
            {
                Id     = 2,
                Leader = UserEntityObject.Id,
                Name   = "Team1"
            };


            var UserModelObject = new UserDetailModel()
            {
                Id       = 4,
                Name     = "Anton",
                Password = "******",
                Email    = "*****@*****.**",
                Comments = new Collection <CommentModel>(),
                Posts    = new Collection <PostModel>()
            };

            var TeamModelObject = new TeamDetailModel()
            {
                Id      = 2,
                Leader  = UserModelObject.Id,
                Members = new Collection <UserListModel>(),
                Name    = "Team1"
            };

            Assert.Equal(TeamModelObject, teamMapper.EntityToDetailModel(TeamEntityObject));

            TeamEntityObject.Members = new Collection <TeamUserEntity>();

            TeamModelObject.Members = null;

            Assert.Equal(TeamEntityObject, teamMapper.DetailModelToEntity(TeamModelObject));

            TeamModelObject.Members = new Collection <UserListModel>();

            TeamEntityObject.Members.Add(new TeamUserEntity()
            {
                UserId = UserEntityObject.Id, UserName = UserEntityObject.Name
            });
            TeamModelObject.Members.Add(userMapper.DetailModelToListModel(UserModelObject));

            Assert.Equal(TeamModelObject, teamMapper.EntityToDetailModel(TeamEntityObject));
            Assert.Equal(TeamEntityObject, teamMapper.DetailModelToEntity(TeamModelObject));
        }
Пример #5
0
        public void TeamRepozitoryTest()
        {
            var dbContextFactory = new InMemoryDbContextFactory();
            var Repository       = new TeamRepository(dbContextFactory);
            var UserRepository   = new UserRepository(dbContextFactory);

            Assert.Throws <System.InvalidOperationException>(() => Repository.GetById(0));

            var Post = new PostModel()
            {
                Id       = 1,
                Author   = 4,
                Comments = new Collection <CommentModel>(),
                Date     = new DateTime(2019, 1, 4),
                Team     = 2,
                Text     = "No pozrite sa na tie komenty",
                Title    = "Lol"
            };
            var Comment1 = new CommentModel()
            {
                Author = 2,
                Date   = new DateTime(2019, 1, 4),
                Id     = 11,
                Text   = "Testovaci koment",
                Post   = 1
            };

            var Comment2 = new CommentModel()
            {
                Author = 1,
                Date   = new DateTime(2019, 1, 5),
                Id     = 20,
                Text   = "Testovaci koment cislo 2",
                Post   = 1
            };

            Post.Comments.Add(Comment1);
            Post.Comments.Add(Comment2);

            var User1 = new UserDetailModel()
            {
                Id       = 4,
                Name     = "Anton",
                Comments = new Collection <CommentModel>(),
                Email    = "*****@*****.**",
                Password = "******",
                Posts    = new Collection <PostModel>()
            };

            var User2 = new UserDetailModel()
            {
                Id       = 2,
                Name     = "Tomas",
                Email    = "*****@*****.**",
                Password = "******",
                Comments = new Collection <CommentModel>(),
                Posts    = new Collection <PostModel>()
            };
            var User3 = new UserDetailModel()
            {
                Id       = 3,
                Name     = "Sergej",
                Email    = "*****@*****.**",
                Password = "******",
                Comments = new Collection <CommentModel>(),
                Posts    = new Collection <PostModel>()
            };

            var Team1 = new TeamDetailModel()
            {
                Id      = 2,
                Leader  = User2.Id,
                Members = new Collection <UserListModel>(),
                Name    = "Team1",
            };
            var Team2 = new TeamDetailModel()
            {
                Id      = 3,
                Leader  = User3.Id,
                Members = new Collection <UserListModel>(),
                Name    = "Team2",
            };

            UserRepository.Create(User1);
            UserRepository.Create(User2);
            UserRepository.Create(User3);

            var userMapper = new UserMapper();

            Team1.Members.Add(userMapper.DetailModelToListModel(User1));
            Team1.Members.Add(userMapper.DetailModelToListModel(User2));

            Team2.Members.Add(userMapper.DetailModelToListModel(User2));
            Team2.Members.Add(userMapper.DetailModelToListModel(User3));

            Repository.Create(Team1);
            Repository.Create(Team2);

            var ReceivedTeam = Repository.GetById(2);

            Assert.Equal(Team1, ReceivedTeam);

            ReceivedTeam = Repository.GetById(3);

            Assert.Equal(Team2, ReceivedTeam);

            var AllTeams               = new List <TeamListModel>();
            var AllTeamsDetail         = new List <TeamDetailModel>();
            var ReceivedAllTeams       = Repository.GetAll();
            var ReceivedAllTeamsDetail = Repository.GetAllDetail();

            var teamMapper = new TeamMapper();

            AllTeams.Add(teamMapper.DetailModelToListModel(Team1));
            AllTeams.Add(teamMapper.DetailModelToListModel(Team2));
            AllTeamsDetail.Add(Team1);
            AllTeamsDetail.Add(Team2);

            var Comparer = new CollectionComparer <TeamListModel>();

            Assert.True(Comparer.Equals(AllTeams, ReceivedAllTeams));

            var DetailComparer = new CollectionComparer <TeamDetailModel>();

            Assert.True(DetailComparer.Equals(AllTeamsDetail, ReceivedAllTeamsDetail));

            var AllTeamsForUser1 = new List <TeamListModel>();

            AllTeamsForUser1.Add(teamMapper.DetailModelToListModel(Team1));

            var ReceivedAllTeamsForUser1 = Repository.GetAllTeamsForUser(User1.Id);

            Assert.True(Comparer.Equals(AllTeamsForUser1, ReceivedAllTeamsForUser1));

            Team1.Name = "Zmenene meno";

            Repository.Update(Team1);
            Assert.Equal(Team1, Repository.GetById(Team1.Id));

            Repository.Delete(3);

            Assert.Throws <System.InvalidOperationException>(() => Repository.GetById(0));

            ReceivedTeam = Repository.GetById(2);

            Assert.Equal(Team1, ReceivedTeam);
        }
Пример #6
0
        public void UserRepozitoryTest()
        {
            var factory    = new InMemoryDbContextFactory();
            var Repository = new UserRepository(factory);



            using (var dbContext = factory.CreateDbContext())
            {
                dbContext.Database.EnsureDeleted();
            }

            Assert.Throws <System.InvalidOperationException>(() => Repository.GetById(1));

            var User1 = new UserDetailModel()

            {
                Id       = 4,
                Name     = "Anton",
                Password = "******",
                Email    = "*****@*****.**",
            };

            var User2 = new UserDetailModel()
            {
                Id       = 2,
                Name     = "Anton",
                Password = "******",
                Email    = "*****@*****.**",
            };

            Repository.Create(User1);
            Repository.Create(User2);

            var ReceivedUser = Repository.GetById(4);

            Assert.Equal(User1, ReceivedUser);

            var userMapper = new UserMapper();

            var AllUsers = new List <UserListModel>();

            AllUsers.Add(userMapper.DetailModelToListModel(User1));
            AllUsers.Add(userMapper.DetailModelToListModel(User2));
            var ReceivedAllUsers = Repository.GetAll();

            var Comparer = new CollectionComparer <UserListModel>();

            Assert.True(Comparer.Equals(AllUsers, ReceivedAllUsers));

            User1.Name = "Antonko";

            Repository.Update(User1);
            ReceivedUser = Repository.GetById(4);

            Assert.Equal(User1, ReceivedUser);

            Repository.Delete(4);

            Assert.Throws <System.InvalidOperationException>(() => Repository.GetById(4));
        }