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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }