public async Task ThenIfATaskIsCompletedTheItemsDueCounterShouldBeDecremented()
        {
            //We represent multiple tasks of the same type and owner as a counter rather than multiple tasks entries

            //Arrange
            Query.TaskCompleted = true;

            var existingTask = new DasTask
            {
                Id = Guid.NewGuid(),
                EmployerAccountId = "123",
                Type          = TaskType.AgreementToSign,
                ItemsDueCount = 3
            };

            var expectedItemsDueCount = (ushort)(existingTask.ItemsDueCount - 1);

            _repository.Setup(x => x.GetTask(Query.EmployerAccountId, Query.Type)).ReturnsAsync(existingTask);

            //Act
            await RequestHandler.Handle(Query);

            //Assert
            _repository.Verify(x => x.GetTask(Query.EmployerAccountId, Query.Type), Times.Once);
            _repository.Verify(x => x.SaveTask(It.Is <DasTask>(t => t.Id.Equals(existingTask.Id) &&
                                                               t.EmployerAccountId.Equals(existingTask.EmployerAccountId) &&
                                                               t.Type.Equals(existingTask.Type) &&
                                                               t.ItemsDueCount.Equals(expectedItemsDueCount))), Times.Once);
        }
        public async Task SaveTask(DasTask task)
        {
            await WithConnection(async c =>
            {
                var parameters = new DynamicParameters();
                parameters.Add("@Id", task.Id, DbType.Guid);
                parameters.Add("@employerAccountId", task.EmployerAccountId, DbType.String);
                parameters.Add("@type", task.Type, DbType.String);
                parameters.Add("@itemsDueCount", (int)task.ItemsDueCount, DbType.Int32);

                return(await c.ExecuteAsync(
                           sql: "[tasks].[UpsertTask]",
                           param: parameters,
                           commandType: CommandType.StoredProcedure));
            });
        }
        public void Arrange()
        {
            base.SetUp();

            _task       = new DasTask();
            _repository = new Mock <ITaskRepository>();

            RequestHandler = new GetTaskRequestHandler(_repository.Object, RequestValidator.Object);
            Query          = new GetTaskRequest
            {
                EmployerAccountId = "123",
                Type = TaskType.AgreementToSign
            };

            _repository.Setup(x => x.GetTask(It.IsAny <string>(), It.IsAny <TaskType>()))
            .ReturnsAsync(_task);
        }
        public async Task ThenIShouldBeAbleToCompleteAllTasks()
        {
            //Arrange
            var existingTask = new DasTask
            {
                Id = Guid.NewGuid(),
                EmployerAccountId = "123",
                Type          = TaskType.AgreementToSign,
                ItemsDueCount = 3
            };

            Query.CompleteAllTasks = true;

            _repository.Setup(x => x.GetTask(Query.EmployerAccountId, Query.Type)).ReturnsAsync(existingTask);

            //Act
            await RequestHandler.Handle(Query);

            //Assert
            _repository.Verify(x => x.GetTask(Query.EmployerAccountId, Query.Type), Times.Once);
            _repository.Verify(x => x.SaveTask(It.Is <DasTask>(t => t.ItemsDueCount.Equals(0))), Times.Once);
        }