public async Task AddUserProjectShouldAddUserProject() { var userProject = new UserProject(); _projectBLMock.Setup(x => x.AddUserProjectAsync(It.IsAny <UserProject>())).Returns(Task.FromResult <UserProject>(userProject)); var userProjectController = new UserProjectController(_projectBLMock.Object); var result = await userProjectController.AddUserProjectAsync(new UserProject()); Assert.IsAssignableFrom <CreatedAtActionResult>(result); _projectBLMock.Verify(x => x.AddUserProjectAsync((It.IsAny <UserProject>()))); }
public async Task AddUserProjectAsync_ShouldReturnStatusCode400_WhenUserProjectIsInvalid() { //arrange var projectBLMock = new Mock <IProjectBL>(); UserProject userProject = null; projectBLMock.Setup(i => i.AddUserProjectAsync(userProject)).Throws(new Exception()); UserProjectController userProjectController = new UserProjectController(projectBLMock.Object); //act var result = await userProjectController.AddUserProjectAsync(userProject); //assert Assert.IsType <StatusCodeResult>(result); Assert.Equal(400, ((StatusCodeResult)result).StatusCode); }