Ejemplo n.º 1
0
        //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);
        }
Ejemplo n.º 2
0
        public async Task <TaskGetResponse> AddTask(AddTaskFullRequest task)
        {
            using (var connection = new SqlConnection(_connectionString))
            {
                await connection.OpenAsync();

                var taskId = await connection.QueryFirstAsync <int>
                             (
                    @"EXEC dbo.Add_Task
                    @Title = @Title, @Content = @Content,
                    @CreatedAt = @CreatedAt",
                    task
                             );

                return(await GetTask(taskId));
            }
        }