public void test_copy() { Task t1 = new Task(Guid.NewGuid(), "Some current task"), t2 = new Task(Guid.NewGuid(), "Some former task"); TaskDomain foo = new TaskDomain(), bar; foo.add_task(t1); Guid rem_guid = foo.add_task(t2); foo.remove_task(rem_guid); bar = foo.copy(); Assert.IsFalse(ReferenceEquals(foo, bar)); Assert.IsFalse(ReferenceEquals(foo.tasks, bar.tasks)); Assert.AreEqual(foo.tasks.Count, bar.tasks.Count); foreach (Guid task in foo.tasks.Keys) { Assert.IsTrue(bar.tasks.ContainsKey(task)); Assert.IsFalse(ReferenceEquals(foo.tasks[task], bar.tasks[task])); Assert.AreEqual(foo.tasks[task].name, bar.tasks[task].name); } Assert.IsFalse(ReferenceEquals(foo.active_tasks, bar.active_tasks)); Assert.AreEqual(foo.active_tasks.Count, bar.active_tasks.Count); foreach (Guid task in foo.active_tasks) { Assert.IsTrue(bar.active_tasks.Contains(task)); } }
public Task AddAsync(TaskDomain toAdd) { var dbTask = CreateDbTask(toAdd); _taskRepository.Add(dbTask); return(Task.CompletedTask); }
public void test_serialization() { Task t1 = new Task(Guid.NewGuid(), "Some current task"), t2 = new Task(Guid.NewGuid(), "Some former task"); TaskDomain foo = new TaskDomain(), bar; foo.add_task(t1); Guid rem_guid = foo.add_task(t2); foo.remove_task(rem_guid); DataContractSerializer fmt = new DataContractSerializer(typeof(TaskDomain)); using (System.IO.MemoryStream ms = new System.IO.MemoryStream()) { fmt.WriteObject(ms, foo); ms.Seek(0, System.IO.SeekOrigin.Begin); System.Xml.XmlDictionaryReader xr = System.Xml.XmlDictionaryReader.CreateTextReader(ms, new System.Xml.XmlDictionaryReaderQuotas()); bar = (TaskDomain)(fmt.ReadObject(xr, true)); } Assert.AreEqual(foo.tasks.Count, bar.tasks.Count); foreach (Guid task in foo.tasks.Keys) { Assert.IsTrue(bar.tasks.ContainsKey(task)); Assert.AreEqual(foo.tasks[task].name, bar.tasks[task].name); } Assert.AreEqual(foo.active_tasks.Count, bar.active_tasks.Count); foreach (Guid task in foo.active_tasks) { Assert.IsTrue(bar.active_tasks.Contains(task)); } }
private void MapTaskToDb(DbTask dbTask, TaskDomain taskDomain) { dbTask.State = taskDomain.State; dbTask.DueDate = taskDomain.DueDate; dbTask.Priority = taskDomain.Priority; dbTask.Description = taskDomain.Description; }
public HttpResponseMessage getByTaskId(decimal id) { try { return(response(HttpStatusCode.OK, true, "ready", TaskDomain.fetchById(id))); } catch (Exception e) { return(response(HttpStatusCode.OK, false, e)); } }
public void Complete_WithInvalidValues_ShouldThrowException(TaskDomain taskDomain, string message) { // Arrange && Act Action act = () => taskDomain.Validate(); // Assert act.Should().Throw <Exception>().WithMessage($"*{message}*"); }
public void test_restore_task_active() { TaskDomain domain = new TaskDomain(); Task task = new Task(Guid.NewGuid(), "Some task"); Guid task_guid = domain.add_task(task); domain.restore_task(task_guid); }
public HttpResponseMessage getRejectionTasksByCreator(decimal id) { try { return(response(HttpStatusCode.OK, true, "ready", TaskDomain.getRejectionTasksByCreator(id))); } catch (Exception e) { return(response(HttpStatusCode.OK, false, e)); } }
public void test_add_task_duplicate_task() { TaskDomain domain = new TaskDomain(); Task task = new Task(Guid.NewGuid(), "Some task"); domain.add_task(task); domain.add_task(task); }
public HttpResponseMessage assignTask(Task task) { try { TaskDomain.assignTask(task.id, task.assingId); return(response(HttpStatusCode.OK, true, "ready")); } catch (Exception e) { return(response(HttpStatusCode.OK, false, e)); } }
public void test_add_task_duplicate_guid() { TaskDomain domain = new TaskDomain(); Task task1 = new Task(Guid.NewGuid(), "Some task"), task2 = new Task(Guid.NewGuid(), "Some other task"); Guid task_guid = domain.add_task(task1); domain.add_task(task2, task_guid); }
public HttpResponseMessage refuseTask(Task task) { try { TaskDomain.refuseTask(task.id, task.description, task.creatorUserId); return(response(HttpStatusCode.OK, true, "ready")); } catch (Exception e) { return(response(HttpStatusCode.OK, false, e)); } }
public HttpResponseMessage createTask(Task task) { try { TaskDomain.createTask(task); return(response(HttpStatusCode.OK, true, "ready")); } catch (Exception e) { return(response(HttpStatusCode.OK, false, e)); } }
public void Complete_WithValidValues_ShouldNotThrowException() { // Arrange var taskDomain = new TaskDomain(Guid.NewGuid(), "test", Priority.High, false); // Act Action act = () => taskDomain.Validate(); // Assert act.Should().NotThrow <Exception>(); }
public async Task CompleteAsync(Guid id) { TaskDomain task = await GetAndValidateAsync(id); task.Complete(); _repository.Update(task); await _repository.SaveChangesAsync(); await _twitterClient.PostTweetAsync("Task completed! \r \n #TechTalkIntegrationTest"); }
public void Complete_ShouldCompleteTask() { // Arrange var taskDomain = new TaskDomain(Guid.NewGuid(), "", 0, false); // Act taskDomain.Complete(); // Assert taskDomain.Completed.Should().BeTrue(); }
private DbTask CreateDbTask(TaskDomain task) { var dbTask = new DbTask { Id = _guidFactory.Create(), AddedDate = _dateTimeProvider.Now }; MapTaskToDb(dbTask, task); return(dbTask); }
public void test_remove_task() { TaskDomain domain = new TaskDomain(); Task task = new Task(Guid.NewGuid(), "Some task"); Guid task_guid = domain.add_task(task); domain.remove_task(task_guid); Assert.AreEqual(domain.tasks.Count, 1); Assert.IsTrue(domain.tasks.ContainsKey(task_guid)); Assert.AreEqual(domain.tasks[task_guid], task); Assert.AreEqual(domain.active_tasks.Count, 0); }
public async Task <Guid> CreateAsync(TaskForCreationDto taskForCreation) { var taskDomain = new TaskDomain(Guid.NewGuid(), taskForCreation.Description, (Priority)taskForCreation.Priority, taskForCreation.Completed); taskDomain.Validate(); var id = await _repository.CreateAsync(taskDomain); await _repository.SaveChangesAsync(); return(id); }
public Task <Result> Handle(UpdateTaskCommand request, CancellationToken cancellationToken) { if (this._tasksRepoByAccount.TaskExists(this.GetCurrentUserId(), request.Id)) { TaskDomain taskInDb = _tasksRepoByAccount.GetTask(this.GetCurrentUserId(), request.Id); _mapper.Map(request.Task, taskInDb); return(Task.FromResult(_tasksRepoByAccount.SaveModifications())); } else { return(Task.FromResult(Results.Fail( new CustomError(ErrorsCodesContants.TASK_ID_NOT_FOUND, ErrorsMessagesConstants.TASK_ID_NOT_FOUND, 404)))); } }
public HttpResponseMessage getReportProcess(decimal id) { if (checkToken(Request)) { try { return(response(HttpStatusCode.OK, true, "ready", TaskDomain.getReportProcess(id))); } catch (Exception e) { return(response(HttpStatusCode.InternalServerError, false, e)); } } else { return(response(HttpStatusCode.Unauthorized, false, "invalid token")); } }
public void SetDomain() { domain = new TaskDomain(); unitOfWork = new Mock <IUnitOfWork>(); domain.unitOfWork = unitOfWork.Object; task = new Task(); task.Description = "Teste"; task.Hours = 4; task.ProjectId = 3; task.SprintId = 2; task.TaskId = 1; task.Tracking = 5; task.UserId = 6; unitOfWork.Setup(x => x.Tasks.Get(1)).Returns(task); }
public HttpResponseMessage getAllByUnit(string unit_id) { if (checkToken(Request)) { try { return(response(HttpStatusCode.OK, true, "ready", TaskDomain.fetchByUnit(decimal.Parse(unit_id)))); } catch (Exception e) { return(response(HttpStatusCode.InternalServerError, false, e)); } } else { return(response(HttpStatusCode.Unauthorized, false, "invalid token")); } }
public void Constructor_ShouldCreateAnActiveTask() { // Arrange var id = Guid.NewGuid(); var description = "test"; var completed = false; var priority = Priority.High; // Act var taskDomain = new TaskDomain(id, description, priority, completed); // Assert taskDomain.Id.Should().Be(id); taskDomain.Description.Should().Be(description); taskDomain.Priority.Should().Be(priority); taskDomain.Completed.Should().Be(completed); taskDomain.Active.Should().BeTrue(); }
public Result CreateTask(int accountId, TaskDomain task) { Account account = _dbContext.Accounts.FirstOrDefault(a => a.Id == accountId); if (account != null) { task.Account = account; task.AccountId = accountId; _dbContext.Tasks.Add(task); return(Results.Ok()); } else { return(Results.Fail(new CustomError( ErrorsCodesContants.USER_ID_NOT_FOUND, ErrorsMessagesConstants.USER_ID_NOT_FOUND, 404))); } }
public async Task Handle_HappyFlow() { // Arrange TaskQuery request = new TaskQuery { Id = ConstantsTasksTest.Id }; TaskDomain tasktoReturn = ConstantsTasksTest.taskDomain; _tasksRepoByAccountMock.Setup(x => x.TaskExists(ConstantsTasksTest.taskDomain.AccountId, ConstantsTasksTest.Id)).Returns(true); _tasksRepoByAccountMock.Setup(x => x.GetTask(ConstantsTasksTest.taskDomain.AccountId, ConstantsTasksTest.Id)).Returns(tasktoReturn); // Act Result <TaskDomain> result = await _taskQueryHandler.Handle(request, CancellationToken.None); // Assert result.IsSuccess.Should().BeTrue(); result.Value.Should().Be(tasktoReturn); }
public async Task <IActionResult> CreateTask([FromBody] TaskToBeCreatedDto taskDto) { TaskDomain taskToBeCreated = _mapper.Map <TaskDomain>(taskDto); Result opResult = await _mediator.Send( new CreateTaskCommand { Task = taskToBeCreated }); if (opResult.IsSuccess) { var taskCreated = _mapper.Map <TaskToGetDto>(taskToBeCreated); return(CreatedAtRoute("GetTask", new { id = taskCreated.Id }, taskCreated)); } else { return(_errorResponseCreator.CreateResponse(opResult.Errors)); } }
public void Update_ShouldUpdateValues() { // Arrange var id = Guid.NewGuid(); var taskDomain = new TaskDomain(id, "old description", 0, false); var newDescription = "test"; var newCompleted = true; var newPriority = Priority.High; // Act taskDomain.Update(newDescription, newCompleted, newPriority); // Assert taskDomain.Id.Should().Be(id); taskDomain.Description.Should().Be(newDescription); taskDomain.Priority.Should().Be(newPriority); taskDomain.Completed.Should().Be(newCompleted); taskDomain.Active.Should().BeTrue(); }
public async Task Handle_UpdateExistingTask_HappyFlow() { // Arrange _tasksRepoByAccountMock.Setup(x => x.TaskExists(ConstantsAccountsCQTest.Id, _request.Id)).Returns(true); TaskDomain taskInDBMock = new TaskDomain(); _tasksRepoByAccountMock.Setup(X => X.GetTask(ConstantsAccountsCQTest.Id, _request.Id)).Returns(taskInDBMock); _mapperMock.Setup(x => x.Map(_request.Task, taskInDBMock)); Result succesSaveModifications = Results.Ok(); _tasksRepoByAccountMock.Setup(x => x.SaveModifications()).Returns(succesSaveModifications); // Act Result result = await _handler.Handle(_request, CancellationToken.None); // Assert result.IsSuccess.Should().BeTrue(); result.Should().Be(succesSaveModifications); }
public async void GetAsync_ReturnsTask() { var newGuid = _fixture.Create <Guid>(); var dbTask = _fixture.Create <DbTask>(); var expected = new TaskDomain { Priority = dbTask.Priority, State = dbTask.State, AddedDate = dbTask.AddedDate, DueDate = dbTask.DueDate, Description = dbTask.Description, Id = dbTask.Id }; _dbRepository.Setup(x => x.GetByIdAsync(newGuid)).Returns(Task.FromResult(dbTask)).Verifiable(); var actual = await _tasksRepository.GetAsync(newGuid); actual.Should().BeEquivalentTo(expected); _dbRepository.VerifyAll(); }