public void NewBatchTaskParametersTest() { // Setup cmdlet without the required parameters BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys(); cmdlet.BatchContext = context; Assert.Throws<ArgumentNullException>(() => cmdlet.ExecuteCmdlet()); cmdlet.WorkItemName = "testWorkItem"; cmdlet.JobName = "job-0000000001"; Assert.Throws<ArgumentNullException>(() => cmdlet.ExecuteCmdlet()); cmdlet.Name = "testTask"; // Don't go to the service on an AddWorkItem call YieldInjectionInterceptor interceptor = new YieldInjectionInterceptor((opContext, request) => { if (request is AddTaskRequest) { AddTaskResponse response = new AddTaskResponse(); Task<object> task = Task<object>.Factory.StartNew(() => { return response; }); return task; } return null; }); cmdlet.AdditionalBehaviors = new List<BatchClientBehavior>() { interceptor }; // Verify no exceptions when required parameters are set cmdlet.ExecuteCmdlet(); }
public AddTaskResponse AddTask(AddTaskRequest request) { using (var client = new SqlConnection("Data Source=db-mssql;Initial Catalog=s18730;Integrated Security=True")) using (var com = new SqlCommand()) { client.Open(); var transaction = client.BeginTransaction("AddAnimal"); try { com.Connection = client; com.Transaction = transaction; Debug.WriteLine(request.TaskType.name); com.CommandText = "SELECT * FROM TaskType WHERE idTaskType = @idType"; com.Parameters.AddWithValue("idType", request.TaskType.idTaskType); var dr = com.ExecuteReader(); if (!dr.Read()) { dr.Close(); com.CommandText = "INSERT INTO TaskType VALUES (@idType, @typeName)"; com.Parameters.AddWithValue("typeName", request.TaskType.name); } com.CommandText = "INSERT INTO Task VALUES (@name, @description, @deadline, @idTeam, @TaskType, @idAssignedTo, @idCreator)"; com.Parameters.AddWithValue("name", request.name); com.Parameters.AddWithValue("description", request.description); com.Parameters.AddWithValue("deadline", request.deadline); com.Parameters.AddWithValue("idTeam", request.IdTeam); com.Parameters.AddWithValue("TaskType", request.TaskType.idTaskType); com.Parameters.AddWithValue("idAssignedTo", request.IdAssignedTo); com.Parameters.AddWithValue("idCreator", request.IdCreator); //wyrzuca do catcha na lini niżej. Nie wiem czemu i nie mam czasu na poprawienie com.ExecuteNonQuery(); transaction.Commit(); var response = new AddTaskResponse() { name = request.name, description = request.description, deadline = request.deadline }; return(response); } catch (SqlException exception) { transaction.Rollback(); throw new ArgumentException("Parameter is null", "original"); } } }
private static string Add(string description, string dueDate) { IAddTaskUseCase addTaskUseCase = null; AddTaskResponse addTaskResponse = addTaskUseCase.Add(new AddTaskRequest() { Description = description, DueDate = DateTime.Parse(dueDate) } ); return(addTaskResponse.Result); }
public void NewBatchTaskParametersTest() { // Setup cmdlet without the required parameters BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys(); cmdlet.BatchContext = context; Assert.Throws <ArgumentNullException>(() => cmdlet.ExecuteCmdlet()); cmdlet.WorkItemName = "testWorkItem"; cmdlet.JobName = "job-0000000001"; Assert.Throws <ArgumentNullException>(() => cmdlet.ExecuteCmdlet()); cmdlet.Name = "testTask"; // Don't go to the service on an AddWorkItem call YieldInjectionInterceptor interceptor = new YieldInjectionInterceptor((opContext, request) => { if (request is AddTaskRequest) { AddTaskResponse response = new AddTaskResponse(); Task <object> task = Task <object> .Factory.StartNew(() => { return(response); }); return(task); } return(null); }); cmdlet.AdditionalBehaviors = new List <BatchClientBehavior>() { interceptor }; // Verify no exceptions when required parameters are set cmdlet.ExecuteCmdlet(); }
public ActionResult <AddTaskResponse> Post(AddTask request) { AddTaskResponse ret = new AddTaskResponse(); DateTime now = DateTime.Now; foreach (var it in request.Actions) { if (it.Object.Id == 0) { UInt64 dId = it.Object.DeviceId; int ot = it.Object.ObjectType; string ln = it.Object.LogicalName; it.Object = host.Connection.SingleOrDefault <GXObject>(GXSelectArgs.Select <GXObject>(null, q => q.DeviceId == dId && q.ObjectType == ot && q.LogicalName == ln)); if (it.Object == null) { return(BadRequest(string.Format("Invalid target {0}:{1} DeviceID {2}.", ot, ln, dId))); } } it.Generation = now; host.Connection.Insert(GXInsertArgs.Insert(it)); } host.SetChange(TargetType.Tasks, DateTime.Now); return(ret); }