Exemplo n.º 1
0
        public void Register_WithDummyUsersAndRoles_ShouldRegisterUserWithCorrectData()
        {
            var context = DotaAppContextInitializer.InitializeContext();

            this.SeedUsers(context);
            this.SeedRoles(context);

            var options = this.GetOptions();

            this.userService = new UserService(context, options);

            var userDto = new UserDto
            {
                FirstName = "Pesho2",
                LastName  = "Peshov2",
                Email     = "*****@*****.**",
                Username  = "******",
                Password  = "******"
            };

            var expectedRegisteredUser = this.userService.Register(userDto);

            var expectedUsersLength = 4;
            var actualUsers         = context.Users.ToList();

            Assert.Equal(expectedUsersLength, actualUsers.Count);

            var actualRegisteredUser = context.Users.Last();

            Assert.Equal(expectedRegisteredUser.Username, actualRegisteredUser.Username);
        }
Exemplo n.º 2
0
        public void AddComment_WithDummy_ShouldAddComment()
        {
            var context = DotaAppContextInitializer.InitializeContext();

            this.SeedItems(context);

            this.commentService = new CommentService(context);

            var addCommentDto = new AddCommentDto
            {
                ItemId   = 2,
                Comment  = "New comment from test",
                Username = "******"
            };

            int expectedId = 4;
            int actualId   = this.commentService.AddComment(addCommentDto);

            Assert.Equal(expectedId, actualId);

            int expectedCommentsCount = 4;
            var actualComments        = context.Comments
                                        .Where(c => c.ItemId == 2)
                                        .ToList();

            Assert.Equal(expectedCommentsCount, actualComments.Count);
        }
Exemplo n.º 3
0
        public void GetById_WithDummyItems_ShouldThrowExceptionWhenItemNotFound()
        {
            var context = DotaAppContextInitializer.InitializeContext();

            this.SeedItems(context);

            this.itemService = new ItemService(context);

            int           itemId    = 123;
            DotaException exception = Assert.Throws <DotaException>(() => this.itemService.GetById(itemId));

            Assert.Equal(Constants.InvalidOperation, exception.Message);
        }
Exemplo n.º 4
0
        public void GetById_WithDummyHeroes_ShouldThrowExceptionWhenItemNotFound()
        {
            var context = DotaAppContextInitializer.InitializeContext();

            this.SeedHeroes(context);

            this.heroService = new HeroService(context);

            int           heroId    = 777;
            DotaException exception = Assert.Throws <DotaException>(() => this.heroService.GetById(heroId));

            Assert.Equal(Constants.InvalidOperation, exception.Message);
        }
Exemplo n.º 5
0
        public void All_WithDummyTeams_ShoudlReturnCorrectResults()
        {
            var context = DotaAppContextInitializer.InitializeContext();

            this.SeedTeams(context, this.GetDummyTeams());

            this.teamsService = new TeamService(context);

            var expectedTeams = context.Teams.ToList();
            var actualTeams   = this.teamsService.All();

            Assert.Equal(expectedTeams.Count, actualTeams.Count);
        }
Exemplo n.º 6
0
        public void GetAll_WithDummyHeroes_ShouldReturnCorrectResults()
        {
            var context = DotaAppContextInitializer.InitializeContext();

            this.SeedHeroes(context);

            this.heroService = new HeroService(context);

            var expectedHeroes = context.Heroes.ToList();
            var actualHeroes   = this.heroService.GetAll();

            Assert.Equal(expectedHeroes.Count, actualHeroes.Count);
        }
Exemplo n.º 7
0
        public void GetAll_WithDummyItems_ShoudlReturnCorrectResults()
        {
            var context = DotaAppContextInitializer.InitializeContext();

            this.SeedItems(context);

            this.itemService = new ItemService(context);

            var expectedItems = context.Items.ToList();
            var actualItems   = this.itemService.GetAll();

            Assert.Equal(expectedItems.Count, actualItems.Count);
        }
Exemplo n.º 8
0
        public void Approve_WithDummyComments_ShouldThrowExceptionWhenCommentNotFound()
        {
            var context = DotaAppContextInitializer.InitializeContext();

            this.SeedComments(context);

            this.adminService = new AdminService(context);

            int commentId = 123;

            DotaException exception = Assert.Throws <DotaException>(() => this.adminService.Approve(commentId));

            Assert.Equal(Constants.InvalidOperation, exception.Message);
        }
Exemplo n.º 9
0
        public void Review_WithDummyComments_ShouldReturnCorrectResults()
        {
            var context = DotaAppContextInitializer.InitializeContext();

            this.SeedComments(context);

            this.adminService = new AdminService(context);

            var expectedComments = context.Comments
                                   .Where(c => !c.IsApproved && c.IsPending)
                                   .ToList();

            var actualComments = this.adminService.Review();

            Assert.Equal(expectedComments.Count, actualComments.Count);
        }
Exemplo n.º 10
0
        public void All_WithDummyComments_ShouldReturnCorrectResults(int itemId)
        {
            var context = DotaAppContextInitializer.InitializeContext();

            this.SeedComments(context);

            this.commentService = new CommentService(context);

            var expectedComments = context.Comments
                                   .Where(c => c.ItemId == itemId && !c.IsPending && c.IsApproved)
                                   .ToList();

            var actualComments = this.commentService.All(itemId);

            Assert.Equal(expectedComments.Count, actualComments.Count);
        }
Exemplo n.º 11
0
        public void All_WithDummyData_ShouldBeOrderedByRatingCorrectly()
        {
            var context = DotaAppContextInitializer.InitializeContext();

            this.SeedTeams(context, this.GetDummyTeams());

            this.teamsService = new TeamService(context);

            var expectedTeams = context.Teams
                                .OrderByDescending(t => t.Rating)
                                .ToList();

            var actualTeams = this.teamsService.All();

            Assert.Equal(expectedTeams.First().Name, actualTeams.First().Name);
        }
Exemplo n.º 12
0
        public void DeleteCommentById_WithDummyComments_ShouldDeleteCommentWhenValidIdIsPassed()
        {
            var context = DotaAppContextInitializer.InitializeContext();

            this.SeedComments(context);

            this.adminService = new AdminService(context);

            int commentId = 4;

            this.adminService.DeleteCommentById(commentId);

            var expectedCommentsCount = 3;
            var actualComments        = context.Comments.ToList();

            Assert.Equal(expectedCommentsCount, actualComments.Count);
        }
Exemplo n.º 13
0
        public void All_WithDummyTeamsWithEmptyNameAndLogoUrl_ShouldReturnCorrectResults()
        {
            var context = DotaAppContextInitializer.InitializeContext();

            this.SeedTeams(context, this.GetDummyTeamsWithEmptyNameAndLogoUrl());

            this.teamsService = new TeamService(context);

            var expectedTeams = context.Teams
                                .Where(t => !string.IsNullOrEmpty(t.Name) && !string.IsNullOrEmpty(t.LogoUrl))
                                .ToList();


            var actualTeams = this.teamsService.All();

            Assert.Equal(expectedTeams.Count, actualTeams.Count);
        }
Exemplo n.º 14
0
        public void GetById_WithDummyItems_ShouldReturnCorrectResults()
        {
            var context = DotaAppContextInitializer.InitializeContext();

            this.SeedItems(context);

            this.itemService = new ItemService(context);

            int itemId = 2;

            var expectedItem = context.Items
                               .First(i => i.Id == itemId);

            var actualItem = this.itemService.GetById(itemId);

            Assert.Equal(expectedItem.Id, actualItem.Id);
            Assert.Equal(expectedItem.Name, actualItem.Name);
        }
Exemplo n.º 15
0
        public void Reject_WithDummyComments_ShouldRejectTheCorrectComment()
        {
            var context = DotaAppContextInitializer.InitializeContext();

            this.SeedComments(context);

            this.adminService = new AdminService(context);

            int commentId = 1;

            this.adminService.Reject(commentId);

            var actualComment = context.Comments
                                .First(c => c.Id == commentId);

            Assert.False(actualComment.IsPending);
            Assert.False(actualComment.IsApproved);
        }
Exemplo n.º 16
0
        public void GetById_WithDummyHeroes_ShouldReturnCorrectResults()
        {
            var context = DotaAppContextInitializer.InitializeContext();

            this.SeedHeroes(context);

            this.heroService = new HeroService(context);

            int heroId = 1;

            var expectedHero = context.Heroes
                               .First(h => h.Id == heroId);

            var actualItem = this.heroService.GetById(heroId);

            Assert.Equal(expectedHero.Id, actualItem.Id);
            Assert.Equal(expectedHero.Name, actualItem.Name);
        }
Exemplo n.º 17
0
        public void AddComment_WithDummy_ShouldThrowExceptionWhenItemNotFound()
        {
            var context = DotaAppContextInitializer.InitializeContext();

            this.SeedComments(context);

            this.commentService = new CommentService(context);

            var addCommentDto = new AddCommentDto
            {
                ItemId   = 777,
                Comment  = "New comment from test",
                Username = "******"
            };

            DotaException exception = Assert.Throws <DotaException>(() => this.commentService.AddComment(addCommentDto));

            Assert.Equal(Constants.InvalidOperation, exception.Message);
        }
Exemplo n.º 18
0
        public void Authenticate_WithDummyUsers_ShouldThrowErrorIfUserWithThatUsernameIsNotFound()
        {
            var context = DotaAppContextInitializer.InitializeContext();

            this.SeedUsers(context);

            var options = this.GetOptions();

            this.userService = new UserService(context, options);

            var usernamePasswordDto = new UsernamePasswordDto
            {
                Username = "******"
            };

            DotaException exception = Assert.Throws <DotaException>(() => this.userService.Authenticate(usernamePasswordDto));

            Assert.Equal(Constants.IncorrectUsernamePassword, exception.Message);
        }
Exemplo n.º 19
0
        public void Update_WithDummyUses_ShouldThrowErrorIfUserWithThatUsernameDoesNotExist()
        {
            var context = DotaAppContextInitializer.InitializeContext();

            this.SeedUsers(context);

            var options = this.GetOptions();

            this.userService = new UserService(context, options);

            var updateUserDto = new UpdateUserDto
            {
                Username = "******"
            };

            DotaException exception = Assert.Throws <DotaException>(() => this.userService.Update(updateUserDto));

            Assert.Equal(Constants.UserNotFound, exception.Message);
        }
Exemplo n.º 20
0
        public void Register_WithDummyUsers_ShouldThrowErrorIfUsernameIsTaken()
        {
            var context = DotaAppContextInitializer.InitializeContext();

            this.SeedUsers(context);

            var options = this.GetOptions();

            this.userService = new UserService(context, options);

            var userDto = new UserDto
            {
                FirstName = "Pesho",
                LastName  = "Peshov",
                Email     = "*****@*****.**",
                Username  = "******"
            };

            DotaException exception = Assert.Throws <DotaException>(() => this.userService.Register(userDto));

            Assert.Equal(Constants.UsernameTaken, exception.Message);
        }