public void ConvertToDTOTest() { var user = new Domain.User.User { Id = Guid.NewGuid(), FirstName = "test", LastName = "test", Address = new Address { Country = "UK" } }; var task = new Domain.Task.Task { Id = Guid.NewGuid(), Name = "test", Time = DateTime.Now, User = user }; var mapper = new TaskDtoMapper(); var result = mapper.ConvertToDTO(task); Assert.AreEqual(task.Id, result.Id); Assert.AreEqual(task.Name, result.Name); Assert.AreEqual(task.Time, result.Time); Assert.AreEqual(user.Id, result.UserId); Assert.AreEqual(user.FirstName, result.UserFirstName); Assert.AreEqual(user.LastName, result.UserLastName); }
public void ConvertToDatabaseTypeTest() { var domainUser = new Domain.User.User { Id = Guid.NewGuid(), FirstName = "test", LastName = "test", Address = new Address { Country = "UK", City = "London", Street = "Baker street", HouseNumber = "221B" } }; var domainTask = new Domain.Task.Task { Id = Guid.NewGuid(), Name = "test", Time = DateTime.Now, User = domainUser }; var userMapper = new Mock <IUserDatabaseMapper>(); var mapper = new TaskDatabaseMapper(userMapper.Object); var result = mapper.ConvertToDatabaseType(domainTask); Assert.AreEqual(domainTask.Id, result.Id); Assert.AreEqual(domainTask.Name, result.Name); Assert.AreEqual(domainTask.Time, result.Time); Assert.AreEqual(domainTask.User.Id, result.UserId); }
public void UpdateTaskInvalidTest() { var testGuid = Guid.NewGuid(); var taskRequest = new UpdateTaskRequest(testGuid) { TaskProperties = new TaskEditDTO { Name = null, Time = DateTime.Now, UserId = Guid.NewGuid() } }; var expectedTask = new Domain.Task.Task { Id = testGuid, Name = "test", Time = taskRequest.TaskProperties.Time, User = new Domain.User.User { Id = taskRequest.TaskProperties.UserId, FirstName = "test", LastName = "test", Address = new Address { Country = "UK" } } }; var expectedUpdatedTask = expectedTask; expectedUpdatedTask.Name = taskRequest.TaskProperties.Name; var mockUow = new Mock <IUnitOfWork>(); var mockRepo = new Mock <ITaskRepository>(); mockRepo.Setup(x => x.Update(expectedTask)); mockRepo.Setup(x => x.FindBy(taskRequest.Id)).Returns(expectedTask); var mockMapper = new Mock <ITaskDtoMapper>(); mockMapper.Setup(x => x.PopulateDomainObject(expectedTask, taskRequest.TaskProperties)) .Returns(expectedUpdatedTask); var mockValidator = new Mock <IValidator <Domain.Task.Task> >(); mockValidator.Setup(x => x.GetBrokenRules(expectedTask)).Returns(new List <BusinessRule> { TaskBusinessRules.TaskNameRequired }); var service = new TaskService(mockUow.Object, mockRepo.Object, mockMapper.Object, mockValidator.Object); var response = service.UpdateTask(taskRequest); Assert.IsFalse(response.Result); Assert.IsNotNull(response.Exception); Assert.AreEqual(typeof(ValidationException), response.Exception.GetType()); mockRepo.Verify(x => x.Insert(expectedTask), Times.Never); mockUow.Verify(x => x.Commit(), Times.Never); }
public TaskOutput(Domain.Task.Task task) { Id = task.Id; Name = task.Name; CreatedAt = task.CreatedAt; DoneAt = task.DoneAt; Done = task.Done; }
public void ConvertToDTOMutipleTest() { var user = new Domain.User.User { Id = Guid.NewGuid(), FirstName = "test", LastName = "test", Address = new Address { Country = "UK" } }; var task1 = new Domain.Task.Task { Id = Guid.NewGuid(), Name = "test", Time = DateTime.Now, User = user }; var task2 = new Domain.Task.Task { Id = Guid.NewGuid(), Name = "test2", Time = DateTime.Now, User = user }; var tasks = new List <Domain.Task.Task> { task1, task2 }; var mapper = new TaskDtoMapper(); var results = mapper.ConvertToDTO(tasks); Assert.AreEqual(2, results.Count()); var firstDto = results.First(); Assert.AreEqual(task1.Name, firstDto.Name); Assert.AreEqual(task1.Time, firstDto.Time); Assert.AreEqual(task1.User.Id, firstDto.UserId); Assert.AreEqual(task1.User.FirstName, firstDto.UserFirstName); Assert.AreEqual(task1.User.LastName, firstDto.UserLastName); var lastDto = results.Last(); Assert.AreEqual(task2.Name, lastDto.Name); Assert.AreEqual(task2.Time, lastDto.Time); Assert.AreEqual(task2.User.Id, lastDto.UserId); Assert.AreEqual(task2.User.FirstName, lastDto.UserFirstName); Assert.AreEqual(task2.User.LastName, lastDto.UserLastName); }
private void ThrowExceptionIfTaskIsInvalid(Domain.Task.Task newTask) { var brokenRules = new BusinessRuleCollection(_taskValidator.GetBrokenRules(newTask)); if (brokenRules.HasRules()) { throw new ValidationException(brokenRules.GetRulesSummary()); } }
public DbModels.Task ConvertToDatabaseType(Domain.Task.Task domainType) { return(new DbModels.Task { Id = domainType.Id, Name = domainType.Name, Time = domainType.Time, UserId = domainType.User.Id }); }
public async Task <SaveResponseDto> Update(Domain.Task.Task entity) { var response = await _taskRepository.UpdateAsync(entity, entity.Id); return(new SaveResponseDto { SaveSuccessful = response != null, SavedEntityId = entity.Id }); }
public TaskDTO ConvertToDTO(Domain.Task.Task task) { return(new TaskDTO { Id = task.Id, Name = task.Name, Time = task.Time, UserId = task.User.Id, UserFirstName = task.User?.FirstName, UserLastName = task.User?.LastName }); }
private async Task DeleteFiles(List <string> filesToDelete, Domain.Task.Task task) { task.DeleteEvidencesUrls = new List <string>(); foreach (var fe in filesToDelete) { var fileToDelete = new Evidence(); fileToDelete.FileName = fe; fileToDelete.Url = await _azureStorageRepository.DeleteFileAzureStorage(fileToDelete, _azureStorageSettings.ContainerTaskName); task.DeleteEvidencesUrls.Add(fileToDelete.Url); } }
public void GetBrokenRulesValidInputTest() { var task = new Domain.Task.Task { Id = Guid.NewGuid(), Name = "test", Time = DateTime.Now }; var spec = new TaskNameRequired(); var broken = spec.GetBrokenRules(task); Assert.IsTrue(!broken.Any()); }
public Domain.Task.Task PopulateDomainObject(Domain.Task.Task entity, TaskEditDTO dto) { entity.Name = dto.Name; entity.Time = dto.Time; if (entity.User == null) { entity.User = new Domain.User.User(); } entity.User.Id = dto.UserId; return(entity); }
public void GetBrokenRulesMissingNameTest() { var task = new Domain.Task.Task { Id = Guid.NewGuid(), Name = null, Time = DateTime.Now }; var spec = new TaskNameRequired(); var broken = spec.GetBrokenRules(task); Assert.IsTrue(broken.Any()); Assert.AreEqual(1, broken.Count()); Assert.AreEqual(TaskBusinessRules.TaskNameRequired.Description, broken.First().Description); }
public async System.Threading.Tasks.Task UpdateTask(int id, Domain.Task.Task task) { var taskDto = await _taskRepository.FindAsync(x => x.Id == id); if (taskDto != null) { taskDto.Description = task.Description; taskDto.TaskStatusId = task.TaskStatusId; taskDto.TaskPriorityId = task.TaskPriorityId; taskDto.Name = task.Name; taskDto.ModifiedDate = DateTime.Now; taskDto.StartDate = task.StartDate; taskDto.DueDate = task.DueDate; } await _taskRepository.UpdateAsync(taskDto, task.Id); }
public void GetTaskTest() { var testGuid = Guid.NewGuid(); var taskRequest = new GetTaskRequest(testGuid); var expectedTask = new Domain.Task.Task { Id = testGuid, Name = "test", Time = DateTime.Now, User = new Domain.User.User { Id = Guid.NewGuid(), FirstName = "test", LastName = "test", Address = new Address { Country = "UK" } } }; var mockUow = new Mock <IUnitOfWork>(); var mockRepo = new Mock <ITaskRepository>(); mockRepo.Setup(x => x.FindBy(testGuid)).Returns(expectedTask); var mockMapper = new Mock <ITaskDtoMapper>(); mockMapper.Setup(x => x.ConvertToDTO(expectedTask)).Returns(new TaskDTO { Id = expectedTask.Id, Name = expectedTask.Name, Time = expectedTask.Time, UserId = expectedTask.User.Id, UserFirstName = expectedTask.User.FirstName, UserLastName = expectedTask.User.LastName }); var mockValidator = new Mock <IValidator <Domain.Task.Task> >(); var service = new TaskService(mockUow.Object, mockRepo.Object, mockMapper.Object, mockValidator.Object); var response = service.GetTask(taskRequest); Assert.IsNull(response.Exception); Assert.IsNotNull(response.Result); Assert.AreEqual(expectedTask.Id, response.Result.Id); Assert.AreEqual(expectedTask.User.Id, response.Result.UserId); }
public void InsertTaskTest() { var taskRequest = new InsertTaskRequest { TaskProperties = new TaskEditDTO { Name = "test", Time = DateTime.Now, UserId = Guid.NewGuid() } }; var expectedTask = new Domain.Task.Task { Id = Guid.NewGuid(), Name = taskRequest.TaskProperties.Name, Time = taskRequest.TaskProperties.Time, User = new Domain.User.User { Id = taskRequest.TaskProperties.UserId, FirstName = "test", LastName = "test", Address = new Address { Country = "UK" } } }; var mockUow = new Mock <IUnitOfWork>(); var mockRepo = new Mock <ITaskRepository>(); mockRepo.Setup(x => x.Insert(expectedTask)); var mockMapper = new Mock <ITaskDtoMapper>(); mockMapper.Setup(x => x.ConvertToDomainObject(taskRequest.TaskProperties)).Returns(expectedTask); var mockValidator = new Mock <IValidator <Domain.Task.Task> >(); mockValidator.Setup(x => x.GetBrokenRules(expectedTask)).Returns(new List <BusinessRule>()); var service = new TaskService(mockUow.Object, mockRepo.Object, mockMapper.Object, mockValidator.Object); var response = service.InsertTask(taskRequest); Assert.IsTrue(response.Result); Assert.IsNull(response.Exception); mockRepo.Verify(x => x.Insert(expectedTask), Times.Once); mockUow.Verify(x => x.Commit(), Times.Once); }
public void GetBrokenRulesBlankUserTest() { var task = new Domain.Task.Task { Id = Guid.NewGuid(), Name = "test", Time = DateTime.Now, User = new Domain.User.User() }; var spec = new TaskUserRequired(); var broken = spec.GetBrokenRules(task); Assert.IsTrue(broken.Any()); Assert.AreEqual(1, broken.Count()); Assert.AreEqual(TaskBusinessRules.TaskUserRequired.Description, broken.First().Description); }
public void PopulateDomainObjectTest() { var task = new Domain.Task.Task(); var dto = new TaskEditDTO { Name = "test", Time = DateTime.Now, UserId = Guid.NewGuid() }; var mapper = new TaskDtoMapper(); var result = mapper.PopulateDomainObject(task, dto); Assert.AreEqual(dto.Name, result.Name); Assert.AreEqual(dto.Time, result.Time); Assert.AreEqual(dto.UserId, result.User.Id); }
public Domain.Task.Task ConvertToDomainType(DbModels.Task databaseType, IDataContext context) { var result = new Domain.Task.Task { Id = databaseType.Id, Name = databaseType.Name, Time = databaseType.Time, User = new Domain.User.User { Id = databaseType.UserId } }; if (context.IsLoaded(databaseType, x => x.User)) { result.User = _userMapper.ConvertToDomainType(databaseType.User, context); } return(result); }
private async Task InsertFiles(IFormFile[] taskEvidence, Domain.Task.Task task) { task.NewEvidencesUrls = new List <string>(); foreach (var fe in taskEvidence) { var fileToAdd = new Evidence(); using (var memoryStream = new MemoryStream()) { await fe.CopyToAsync(memoryStream); fileToAdd.Bytes = memoryStream.ToArray(); } fileToAdd.FileName = fe.FileName; fileToAdd.IsInsert = true; fileToAdd.IsDelete = false; fileToAdd.Url = await _azureStorageRepository.InsertFileAzureStorage(fileToAdd, TypeData.Byte, _azureStorageSettings.ContainerTaskName); task.NewEvidencesUrls.Add(fileToAdd.Url); } }
public async System.Threading.Tasks.Task AddTask(Domain.Task.Task task) { task.DataId = DataIdGenerationService.GenerateDataId(_taskRepository.GetLast().Id, "TA"); await _taskRepository.AddAsync(task); }
public Task <SaveResponseDto> Insert(Domain.Task.Task entity) { throw new NotImplementedException(); }
public void GetTasksTest() { var tasksRequest = new GetTasksRequest(); var task1 = new Domain.Task.Task { Id = Guid.NewGuid(), Name = "test", Time = DateTime.Now, User = new Domain.User.User { Id = Guid.NewGuid(), FirstName = "test", LastName = "test", Address = new Address { Country = "UK" } } }; var task2 = new Domain.Task.Task { Id = Guid.NewGuid(), Name = "test2", Time = DateTime.Now, User = new Domain.User.User { Id = Guid.NewGuid(), FirstName = "test2", LastName = "test2", Address = new Address { Country = "UK" } } }; var tasks = new List <Domain.Task.Task> { task1, task2 }; var mockUow = new Mock <IUnitOfWork>(); var mockRepo = new Mock <ITaskRepository>(); mockRepo.Setup(x => x.Find(It.IsAny <TaskQueryParam>())).Returns(tasks); var mockMapper = new Mock <ITaskDtoMapper>(); mockMapper.Setup(x => x.ConvertToDTO(tasks)).Returns(new List <TaskDTO> { new TaskDTO { Id = task1.Id, Name = task1.Name, Time = task1.Time, UserId = task1.User.Id, UserFirstName = task1.User.FirstName, UserLastName = task1.User.LastName }, new TaskDTO { Id = task2.Id, Name = task2.Name, Time = task2.Time, UserId = task2.User.Id, UserFirstName = task2.User.FirstName, UserLastName = task2.User.LastName } }); var mockValidator = new Mock <IValidator <Domain.Task.Task> >(); var service = new TaskService(mockUow.Object, mockRepo.Object, mockMapper.Object, mockValidator.Object); var response = service.GetTasks(tasksRequest); Assert.IsNull(response.Exception); Assert.IsNotNull(response.Result); Assert.AreEqual(2, response.Result.Count()); var firstDto = response.Result.First(); Assert.AreEqual(task1.Id, firstDto.Id); Assert.AreEqual(task1.User.Id, firstDto.UserId); var lastDto = response.Result.Last(); Assert.AreEqual(task2.Id, lastDto.Id); Assert.AreEqual(task2.User.Id, lastDto.UserId); }