public void AddTeamCorrect() { var teamDTO = new TeamDTO { Id = 1, Naam = "Team A" }; var response = new Response <TeamDTO> { DTO = teamDTO }; //Arrange var mockService = new Mock <ITeamService>(); mockService.Setup(x => x.AddTeam(It.IsAny <TeamDTO>())).Returns(response); var controller = new TeamController(mockService.Object); //Act var teamViewModel = new TeamViewModelRequest { //Id = 1, Naam = "Team A" }; var addTeam = controller.Create(teamViewModel) as ObjectResult; var entity = addTeam.Value as TeamViewModelResponse; //Assert Assert.DoesNotThrow(() => controller.Create(teamViewModel)); Assert.That(entity.Id, Is.EqualTo(teamDTO.Id)); Assert.That(entity.Naam, Is.EqualTo(teamDTO.Naam)); }
public async Task Create_ShouldReturnOkAndCreatedId_IfNoError() { mockTeamService.Setup(x => x.Create(It.IsAny <Team>())).ReturnsAsync(123); var result = await TeamController.Create(new Team()); var typedResult = Assert.IsType <OkObjectResult>(result); Assert.Equal(123, typedResult.Value); }
public void Create_MissingRequiredFieldLocation_DoesNotCallCreateTeam() { sut.ModelState.AddModelError("", "Location field is required"); var viewModel = new TeamViewModel { TeamId = TeamId, Name = "Test", Division = "Western", Conference = "Madeup" }; sut.Create(viewModel); _teamService.DidNotReceive().CreateTeam(Arg.Any <DbTeam>()); }
public void Create_Team_Request_Should_Return_Create_Team_View() { var controller = new TeamController(); ViewResult actualResult = controller.Create() as ViewResult; Assert.IsNotNull(actualResult); }
public async Task Test_Create_Creates_Team() { var team = new Team { Name = "Middlesbrough" }; await controller.Create(team); context.MockTeams.Verify(x => x.Add(It.Is <Team>(t => t == team))); }
public void Teams_AddNewTeam_IsBeingAdded() { // Arrange // Act var x = MockController.Create(testModel); // Assert Assert.IsNotNull(x); }
private List <Team> CreateTeams() { TeamController tc = new TeamController(); var tnw = tc.Create("writer team", testContext.users[0]); tc.AddAdmin(tnw.Id, testContext.users[3].Id, testContext.users[0]); tc.AddReader(tnw.Id, testContext.users[4].Id, testContext.users[0]); var tnr = tc.Create("reader team", testContext.users[0]); tc.AddAdmin(tnr.Id, testContext.users[5].Id, testContext.users[0]); tc.AddReader(tnr.Id, testContext.users[6].Id, testContext.users[0]); var teams = new List <Team>(); teams.Add(tnw); teams.Add(tnr); return(teams); }
private Team CreateNestedTeam() { var team = controller.Create("team", testContext.users[0]); controller.AddAdmin(team.Id, testContext.users[1].Id, testContext.users[0]); controller.AddReader(team.Id, testContext.users[2].Id, testContext.users[0]); var tnw = controller.Create("nested writer", testContext.users[0]); controller.AddAdmin(tnw.Id, testContext.users[3].Id, testContext.users[0]); controller.AddReader(tnw.Id, testContext.users[4].Id, testContext.users[0]); controller.AddAdmin(team.Id, tnw.Id, testContext.users[0]); var tnr = controller.Create("nested reader", testContext.users[0]); controller.AddAdmin(tnr.Id, testContext.users[5].Id, testContext.users[0]); controller.AddReader(tnr.Id, testContext.users[6].Id, testContext.users[0]); controller.AddReader(team.Id, tnr.Id, testContext.users[0]); return(team); }
public void TeamPostGet() { Team team = new Team { Access = true, Name = "Work together!" }; TeamController controller = new TeamController(new MockDatabase()); controller.Create(1, team); var result = controller.Get(1) as OkNegotiatedContentResult <Team>; Assert.IsNotNull(result); Assert.AreEqual("Work together!", result.Content.Name); Assert.AreEqual(true, result.Content.Access); }
public async void Create_Errors() { TeamControllerMockFacade mock = new TeamControllerMockFacade(); var mockResponse = new Mock <CreateResponse <ApiTeamResponseModel> >(new FluentValidation.Results.ValidationResult()); var mockRecord = new ApiTeamResponseModel(); mockResponse.SetupGet(x => x.Success).Returns(false); mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiTeamRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiTeamResponseModel> >(mockResponse.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.Create(new ApiTeamRequestModel()); response.Should().BeOfType <ObjectResult>(); (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity); mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiTeamRequestModel>())); }
public void AddTeamNull() { var teamDTO = new TeamDTO { Id = 1, Naam = "Team A" }; var response = new Response <TeamDTO> { DTO = teamDTO }; //Arrange var mockService = new Mock <ITeamService>(); mockService.Setup(x => x.AddTeam(It.IsAny <TeamDTO>())).Returns(response); var controller = new TeamController(mockService.Object); //Assert Assert.IsInstanceOf <BadRequestObjectResult>(controller.Create(null)); }
public async void Create_No_Errors() { TeamControllerMockFacade mock = new TeamControllerMockFacade(); var mockResponse = new CreateResponse <ApiTeamResponseModel>(new FluentValidation.Results.ValidationResult()); mockResponse.SetRecord(new ApiTeamResponseModel()); mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiTeamRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiTeamResponseModel> >(mockResponse)); 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.Create(new ApiTeamRequestModel()); response.Should().BeOfType <CreatedResult>(); (response as CreatedResult).StatusCode.Should().Be((int)HttpStatusCode.Created); var createResponse = (response as CreatedResult).Value as CreateResponse <ApiTeamResponseModel>; createResponse.Record.Should().NotBeNull(); mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiTeamRequestModel>())); }
public void TeamPostPutGet() { Team team = new Team { Access = true, Name = "Work together!" }; TeamController controller = new TeamController(new MockDatabase()); team = (controller.Create(1, team) as OkNegotiatedContentResult <Team>).Content; team.Access = false; team.Name = "Nah"; var result = controller.Get(team.Id) as OkNegotiatedContentResult <Team>; Assert.IsNotNull(result); Assert.AreEqual("Nah", result.Content.Name); Assert.AreEqual(false, result.Content.Access); }