public async Task Activities_controller_post_should_return_accepted() { var busClientMock = new Mock <IBusClient>(); var activityRepositoryMock = new Mock <IActivityRepository>(); var controller = new ActivitiesController(busClientMock.Object, activityRepositoryMock.Object); Guid userId = Guid.NewGuid(); controller.ControllerContext = new ControllerContext { HttpContext = new DefaultHttpContext { User = new ClaimsPrincipal(new ClaimsIdentity( new Claim[] { new Claim(ClaimTypes.Name, userId.ToString()) } , "test")) } }; var command = new CreateActivity { Id = Guid.NewGuid(), UserId = userId }; var result = await controller.Post(command); var contentResult = result as AcceptedResult; contentResult.Should().NotBeNull(); contentResult.Location.Should().BeEquivalentTo($"Activities/{command.Id}"); }
public void Post_Statistical_Valid_API() { //Arrange activityServiceMock.Setup(x => x.GetAll()).Returns(items); activityServiceMock.Setup(x => x.IsOk(checkpoints[2], users[0])).Returns(-1); checkpointServiceMock.Setup(x => x.GetByIP("192.168.0.25")).Returns(checkpoints[2]); identityServiceMock.Setup(x => x.GetByGUID(id.ToString())).Returns(users[0]); ActivityAPIModel item = new ActivityAPIModel { GUID = "1", CheckpointIP = "192.168.0.25" }; //Act var actionResult = controllerAPI.Post(item); var createdResult = actionResult as OkResult; //Assert Assert.IsNotNull(createdResult); }
public async Task ActivitiesController_Post_Should_Return_Accepted_StatusCode() { //arrange var busClient = new Mock <IBusClient>(); var activityRepository = new Mock <IActivityRepository>(); var userId = Guid.NewGuid(); var command = new CreateActivityCommandModel { Id = Guid.NewGuid(), Name = "Test", Category = "TestCategory", Description = "Description Category" }; var sut = new ActivitiesController(busClient.Object, activityRepository.Object); sut.ControllerContext = new ControllerContext { HttpContext = new DefaultHttpContext { User = new ClaimsPrincipal( new ClaimsIdentity ( new Claim[] { new Claim(ClaimTypes.Name, userId.ToString()) }, "test" ) ) } }; var routeValues = new Dictionary <string, object> { { "id", command.Id } }; //act var result = await sut.Post(command) as AcceptedAtRouteResult; //assert result.Should().NotBeNull(); result.StatusCode?.Should().Be(StatusCodes.Status202Accepted); result.RouteName.Should().Be("Get"); result.RouteValues.Should().BeEquivalentTo(routeValues); }