Ejemplo n.º 1
0
        public async void CloneProject_ReturnsCreatedProject()
        {
            _projectService
            .Setup(s => s.CloneProject(It.IsAny <int>(), It.IsAny <string>(), It.IsAny <int>(),
                                       It.IsAny <bool>(), It.IsAny <bool>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync((int id, string newProjectName, int ownerUserId, bool includeMembers,
                           bool includeJobDefinitions, CancellationToken cancellationToken) =>
                          new Project
            {
                Id   = 2,
                Name = newProjectName
            });

            var httpContext = new DefaultHttpContext()
            {
                User = new ClaimsPrincipal(new[]
                {
                    new ClaimsIdentity(new[] { new Claim(ClaimTypes.NameIdentifier, "1") })
                })
            };

            var controller = new ProjectController(_projectService.Object, _mapper, _logger.Object)
            {
                ControllerContext = new ControllerContext {
                    HttpContext = httpContext
                }
            };

            var dto = new CloneProjectOptionDto
            {
                NewProjectName = "Project02"
            };
            var result = await controller.CloneProject(1, dto);

            var createAtRouteActionResult = Assert.IsType <CreatedAtRouteResult>(result);
            var returnValue = Assert.IsType <ProjectDto>(createAtRouteActionResult.Value);

            Assert.Equal(2, returnValue.Id);
            Assert.Equal("Project02", returnValue.Name);
        }