public async Task GetManager_WhenCalled_ReturnManagerFromDb() { const int id = 1; var expectedManager = new Manager { Id = id, }; _managerService.Setup(p => p.GetDetailByIdAsync(id)).ReturnsAsync(expectedManager); var result = await _managersController.GetManager(id); var okObjectResult = result as OkObjectResult; var okObjectResultValue = okObjectResult.Value as ManagerDetailDto; Assert.That(result, Is.TypeOf <OkObjectResult>()); Assert.That(okObjectResultValue, Is.Not.Null); Assert.That(okObjectResultValue.Id, Is.EqualTo(id)); }
public void GetManagerIdShouldNot() { // Arrange int id = 1000; ManagersController controller = new ManagersController(); // Act IHttpActionResult actionResult = controller.GetManager(id); var contentResult = actionResult as NotFoundResult; // Assert Assert.IsType <NotFoundResult>(actionResult); }
public async Task TestGetManagerAsync() { var dbContext = DbContextMocker.GetContext(nameof(this.TestGetManagerAsync)); var managersRepository = new ManagersRepository(dbContext, AutoMapperConfiguration.ConfigureForWeb().CreateMapper()); var managersService = new ManagersService(managersRepository, null); var controller = new ManagersController(managersService, AutoMapperConfiguration.ConfigureForWeb().CreateMapper()); var response = await controller.GetManager(2); var value = response.Value; dbContext.Dispose(); Assert.Equal("Test", value.FirstName); }
public void GetManagerShould() { // Arrange DBEntities db = new DBEntities(); ManagersController controller = new ManagersController(); // Act IQueryable <Manager> expected = db.Manager; IQueryable <Manager> actual = controller.GetManager(); // Assert Assert.True(actual != null); Assert.Equal(expected.Count(), actual.Count()); }
public void GetManagerIdShould() { // Arrange int id = 3; ManagersController controller = new ManagersController(); // Act IHttpActionResult actionResult = controller.GetManager(id); var contentResult = actionResult as OkNegotiatedContentResult <Manager>; // Assert Assert.NotNull(contentResult); Assert.NotNull(contentResult.Content); Assert.Equal(id, contentResult.Content.ID); }