public async void DeleteTask_WhenTaskIsFound_ReturnsNoContent() { var mockTask = new TaskGetResponse { TaskId = 1, Title = "test" }; var mockDataRepository = new Mock <IDataRepository>(); mockDataRepository .Setup(repo => repo.GetTask(1)) .Returns(() => Task.FromResult(mockTask)); var mockTaskCache = new Mock <ITaskCache>(); mockTaskCache .Setup(cashe => cashe.Remove(1)); var tasksController = new TasksController( mockDataRepository.Object, null, mockTaskCache.Object, null); var result = await tasksController.DeleteTask(1); var actionResult = Assert.IsType < NoContentResult >(result); }
public async void GetTask_WhenTaskIsFound_ReturnsTask() { var mockTask = new TaskGetResponse { TaskId = 1, Title = "test" }; var mockDataRepository = new Mock <IDataRepository>(); mockDataRepository .Setup(repo => repo.GetTask(1)) .Returns(() => Task.FromResult(mockTask)); var mockTaskCache = new Mock <ITaskCache>(); mockTaskCache .Setup(cashe => cashe.Get(1)) .Returns(() => mockTask); var tasksController = new TasksController( mockDataRepository.Object, null, mockTaskCache.Object, null); var result = await tasksController.GetTask(1); var actionResult = Assert.IsType < ActionResult <TaskGetResponse> >(result); var taskResult = Assert.IsType <TaskGetResponse>(actionResult.Value); Assert.Equal(1, taskResult.TaskId); }
public TaskGetResponse CreateTaskGetResponse(Task task) { var response = new TaskGetResponse { Data = CreateDto(task) }; return(response); }
//public class StaticWrapper : IStaticWrapper //{ // public Task SendAsync(IClientProxy iClientProxy, string method, object arg1, CancellationToken cancellationToken = default) // { // return ClientProxyExtensions.SendAsync(iClientProxy, method, arg1, cancellationToken); // } //} //public interface IStaticWrapper //{ // Task SendAsync(IClientProxy iClientProxy, string method, object arg1, CancellationToken cancellationToken = default); //} //public class WrapperMethod //{ // readonly IStaticWrapper _wrapper; // public WrapperMethod(IStaticWrapper wrapper) // { // _wrapper = wrapper; // } // public Task SendAsync(IClientProxy iClientProxy, string method, object arg1, CancellationToken cancellationToken = default) // { // var value = _wrapper.SendAsync(iClientProxy, method, arg1, cancellationToken); // return value; // } //} //private class TestWrapper : IStaticWrapper //{ // public Task SendAsync(IClientProxy iClientProxy, string method, object arg1, CancellationToken cancellationToken = default) // { // realisation???; // } //} //[Fact] public async void AddTask_WhenTaskWithTwoParameters_ReturnsCorrectTasks() { var createdAt = DateTime.UtcNow; var mockTaskRequest = new AddTaskRequest { Title = "Test", Content = "Test task", }; var mockTaskFullRequest = new AddTaskFullRequest { Title = "Test", Content = "Test task", CreatedAt = createdAt }; var mockTaskResponse = new TaskGetResponse { TaskId = 1, Title = "Test", Content = "Test task", CreatedAt = createdAt, IsDone = false }; var mockDataRepository = new Mock <IDataRepository>(); mockDataRepository .Setup(repo => repo.AddTask(It.IsAny <AddTaskFullRequest>())) .Returns(() => Task.FromResult(It.IsAny <TaskGetResponse>())); var mockClientProxy = new Mock <IClientProxy>(); var mockHubContext = new Mock <IHubContext <TasksHub> >(); mockHubContext .Setup(hub => hub.Clients.Group(It.IsAny <string>()).SendAsync(It.IsAny <string>(), It.IsAny <Task <TaskGetResponse> >(), It.IsAny <CancellationToken>())) .Returns(It.IsAny <Task>()); var tasksController = new TasksController( mockDataRepository.Object, mockHubContext.Object, null, null); var result = await tasksController.AddTask(mockTaskRequest); var actionResult = Assert.IsType < ActionResult <TaskGetResponse> >(result); var taskResult = Assert.IsType <TaskGetResponse>(actionResult.Value); Assert.Equal(mockTaskResponse, taskResult); }
public void Set(TaskGetResponse task) { var cacheEntryOptions = new MemoryCacheEntryOptions() .SetSize(1); _cache.Set ( GetCacheKey(task.TaskId), task, cacheEntryOptions ); }
public async Task <TaskGetResponse> TaskGet(TaskGetRequest request) { TaskGetResponse response; var board = await _boardRepository.GetAsync(request.BoardId); if (board == null) { response = new TaskGetResponse { Data = null }; response.Failed(_errorService.GetError(ErrorType.ItemNotFound)); return(response); } if (board.CreatedById != request.UserId) { response = new TaskGetResponse { Data = null }; response.Failed(_errorService.GetError(ErrorType.AccessDenied)); return(response); } var task = board.Tasks.Single(t => t.Id == request.Id); if (task == null) { response = new TaskGetResponse { Data = null }; response.Failed(_errorService.GetError(ErrorType.ItemNotFound)); return(response); } response = _taskCreator.CreateTaskGetResponse(task); response.Succeeded(); return(response); }