public void GetActivities() { var ActivitiesRepo = new Mock <IActivitiesRepository>(); var ActivitiesControl = new ActivitiesController(ActivitiesRepo.Object); Assert.IsAssignableFrom <IEnumerable <ActivitiesAC> >(ActivitiesControl.GetActivities()); }
public void GetActivity_NotFound() { var ActivitiesRepo = new Mock <IActivitiesRepository>(); var ActivitiesControl = new ActivitiesController(ActivitiesRepo.Object); var result = ActivitiesControl.GetActivities(0); Assert.IsType <NotFoundResult>(result.Result); }
public void ApiGetActivities() { var acc = Mock.Of <IActivityService>(a => a.GetActivities() == _manyActivities); var uow = Mock.Of <IUnitOfWork>(u => u.ActivityService == acc); ActivitiesController controller = new ActivitiesController(uow); var activities = controller.GetActivities(); Assert.IsTrue(activities.EqualValues(_manyActivities)); }
public async Task ActivityController_GetAllActivities() { // Arrange Activity activity1 = new Activity { Id = 1, Amount = 10, DateTime = DateTime.Now, Description = "Test-1", Status = "Completed" }; Activity activity2 = new Activity { Id = 2, Amount = 20, DateTime = DateTime.Now, Description = "Test-2", Status = "Cancelled" }; Activity activity3 = new Activity { Id = 3, Amount = 30, DateTime = DateTime.Now, Description = "Test-3", Status = "Pending" }; List <Activity> activities = new List <Activity>(); activities.Add(activity1); activities.Add(activity2); activities.Add(activity3); var mockActivityService = new MockActivityService().MockGetActivities(activities); var controller = new ActivitiesController(mockActivityService.Object, AutoMapperSingleton.Mapper); // Act var actionResult = await controller.GetActivities(); var resultObject = Utils.GetObjectResultContent <IEnumerable <Activity> >(actionResult); // Assert Assert.IsType <OkObjectResult>(actionResult.Result); Assert.Collection(resultObject, elem1 => { Assert.Equal(1, elem1.Id); Assert.Equal(10, elem1.Amount); Assert.Equal("Test-1", elem1.Description); Assert.Equal("Completed", elem1.Status); }, elem2 => { Assert.Equal(2, elem2.Id); Assert.Equal(20, elem2.Amount); Assert.Equal("Test-2", elem2.Description); Assert.Equal("Cancelled", elem2.Status); }, elem3 => { Assert.Equal(3, elem3.Id); Assert.Equal(30, elem3.Amount); Assert.Equal("Test-3", elem3.Description); Assert.Equal("Pending", elem3.Status); } ); }