public async Task Delete_ShouldReturnNoContent_IfNoError() { mockTeamService.Setup(x => x.Delete(It.IsAny <int>())); var result = await TeamController.Delete(1); Assert.IsType <NoContentResult>(result); }
public void DeleteTeamCorrect() { var teamDTO = new TeamDTO { Id = 1, Naam = "Team A" }; var response = new Response <int> { DTO = 1 }; //Arrange var mockService = new Mock <ITeamService>(); mockService.Setup(x => x.Delete(1)).Returns(response); var controller = new TeamController(mockService.Object); //Act var teamViewModel = new TeamViewModelResponse { Id = 1, Naam = "Team A" }; var deleteTeam = controller.Delete(teamViewModel.Id) as ObjectResult; //Assert Assert.DoesNotThrow(() => controller.Delete(teamViewModel.Id)); }
public void DeleteTeamTest() { string teamName = "New Team"; var team = controller.Create(teamName, testContext.users[0]); var fetchedTeam = controller.Get(team.Id, testContext.users[0]); Assert.NotNull(fetchedTeam); long count = controller.Delete(team.Id, testContext.users[0]); Assert.Equal(1, count); Assert.Throws <NotAuthorized>(() => fetchedTeam = controller.Get(team.Id, testContext.users[0])); }
public void DeleteFailureTeamInTheRepo() { var mock = new Mock <ITeamRepository>(MockBehavior.Strict); // Creating the rules for mock, always send true in this case mock.As <ICRUDRepository <Team, int, TeamFilter> >().Setup(m => m.Remove(It.IsAny <int>())) .Returns(Task.FromResult(false)); mock.As <ITeamRepository>().Setup(m => m.HasMatches(It.IsAny <int>())).Returns(Task.FromResult(false)); var mockCountryRepo = new Mock <ICountryRepository>(MockBehavior.Strict); mockCountryRepo.As <ICRUDRepository <Country, int, TeamFilter> >().Setup(m => m.Get(It.IsAny <int>())) .Returns <int>(id => Task.FromResult(new Country())); // Creating the controller which we want to create TeamController controller = new TeamController(mock.Object, mockCountryRepo.Object); // configuring the context for the controler fakeContext(controller); HttpResponseMessage response = controller.Delete(0).Result; // the result should say "HttpStatusCode.NotFound" Assert.AreEqual(response.StatusCode, HttpStatusCode.NotFound); }
public void TeamController_DeleteTeam_ShouldReturnCorrectInt() { _mockService.CallCount = 1; var result = _controller.Delete(1); Assert.AreEqual(2, _mockService.CallCount); Assert.IsInstanceOfType(result, typeof(OkResult)); }
public void Test_Delete_Return_OkResult() { //Arrange var controller = new TeamController(TeamService); var request = 1; //Act var data = controller.Delete(request); //Assert Assert.IsType <OkObjectResult>(data); }
public async Task Delete_CallsDeleteMethod_WhenIdIsValid() { var userId = Guid.NewGuid(); var teamId = Guid.NewGuid(); SetupRequestHeader(_sut, userId); _teamServiceMock .Setup(teamService => teamService.GetAsync(userId, teamId)) .ReturnsAsync(new TeamDto { Owner = new UserDto { Id = userId } }); await _sut.Delete(teamId); _teamServiceMock.Verify(teamService => teamService.DeleteAsync(userId, teamId), Times.Once); }
public async void Delete_Errors() { TeamControllerMockFacade mock = new TeamControllerMockFacade(); var mockResult = new Mock <ActionResponse>(); mockResult.SetupGet(x => x.Success).Returns(false); mock.ServiceMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.FromResult <ActionResponse>(mockResult.Object)); TeamController controller = new TeamController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object); controller.ControllerContext = new ControllerContext(); controller.ControllerContext.HttpContext = new DefaultHttpContext(); IActionResult response = await controller.Delete(default(int)); response.Should().BeOfType <ObjectResult>(); (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity); mock.ServiceMock.Verify(x => x.Delete(It.IsAny <int>())); }
public void Teams() { ILogger <TeamController> _testlogger = null; using (var context = new AppDbContext(options, null)) { var controller = new TeamController(context, _testlogger); // Get all var result = controller.Get(); // Assert var okResult = Assert.IsAssignableFrom <IEnumerable <Team> >(result); var pgcount = okResult.ToList().Count; Assert.Equal(2, pgcount); // Get by ID var result1 = controller.Get(1); var okResult1 = Assert.IsAssignableFrom <Team>(result1); Assert.Equal("team 1", okResult1.TeamName); // test update var pg1 = new Team { TeamID = 1, TeamName = "team 1 upd" }; controller.UpdateEntry(pg1); var result3 = controller.Get(1); Assert.NotEqual("team 1", result3.TeamName); Assert.Equal("team 1 upd", result3.TeamName); // test delete var result4 = controller.Get(2); Assert.Equal("team 2", result4.TeamName); IActionResult result5 = controller.Delete(2); var viewResult = Assert.IsType <Microsoft.AspNetCore.Mvc.OkResult>(result5); var result6 = controller.Get(2); Assert.Null(result6); } }
public void DeleteTest() { Team team1 = new Team(); team1.Name = "Barcelona"; team1.TeamId = 1; team1.Password = "******"; team1.Mail = "*****@*****.**"; Team team2 = new Team() { Name = "New", Mail = "*****@*****.**" }; team2.TeamId = 2; List <Team> lst = new List <Team>() { team1, team2 }; Player player = new Player(); player.Name = "Messi"; player.PlayerId = 1; player.Born = new DateTime(1987, 12, 23); player.Position = "Middle Attacker"; player.Surname = "Lionel"; player.TeamId = 1; Reward reward = new Reward(); reward.Name = "Reward"; reward.Date = "1987-01-23"; reward.TeamId = 1; // Arrange var mockHighService = new Mock <IHighLevelSoccerManagerService>(); var mockLowService = new Mock <ILowLevelSoccerManagmentService>(); mockHighService.Setup(service => service.GetAllTeam()).Returns(lst); mockHighService.Setup(ser => ser.RemoveTeam(It.IsAny <int>())).Callback(() => lst.RemoveAt(0)); mockLowService.Setup(service => service.GetAllPlayers()).Returns(new List <Player>() { player }); mockLowService.Setup(service => service.GetAllRewards()).Returns(new List <Reward>() { reward }); var store = new Mock <IUserStore <User> >(); var mockUserStore = new Mock <IUserStore <User> >(); var mockUserRoleStore = mockUserStore.As <IUserRoleStore <User> >(); var userManager = new Mock <UserManager <User> >(mockUserStore.Object, null, null, null, null, null, null, null, null); userManager.Setup(u => u.GetUserAsync(It.IsAny <ClaimsPrincipal>())).ReturnsAsync( new User() { UserName = "******", UserId = 1 }); TeamController controller = new TeamController(mockHighService.Object, mockLowService.Object, userManager.Object); controller.ControllerContext = new ControllerContext { HttpContext = new DefaultHttpContext { User = new ClaimsPrincipal(new ClaimsIdentity(new Claim[] { new Claim(ClaimTypes.Name, "Test") })) } }; controller.ModelState.AddModelError("Name", "Required"); // Act RedirectToActionResult result = (RedirectToActionResult)controller.Delete().Result; // Assert var viewResult = Assert.IsType <RedirectToActionResult>(result); }