public IContentType BuildEntity(DocumentTypeDto dto) { var contentType = new ContentType(dto.ContentTypeDto.NodeDto.ParentId) { Id = dto.ContentTypeDto.NodeDto.NodeId, Key = dto.ContentTypeDto.NodeDto.UniqueId, Alias = dto.ContentTypeDto.Alias, Name = dto.ContentTypeDto.NodeDto.Text, Icon = dto.ContentTypeDto.Icon, Thumbnail = dto.ContentTypeDto.Thumbnail, SortOrder = dto.ContentTypeDto.NodeDto.SortOrder, Description = dto.ContentTypeDto.Description, CreateDate = dto.ContentTypeDto.NodeDto.CreateDate, Path = dto.ContentTypeDto.NodeDto.Path, Level = dto.ContentTypeDto.NodeDto.Level, CreatorId = dto.ContentTypeDto.NodeDto.UserId.Value, AllowedAsRoot = dto.ContentTypeDto.AllowAtRoot, IsContainer = dto.ContentTypeDto.IsContainer, Trashed = dto.ContentTypeDto.NodeDto.Trashed, DefaultTemplateId = dto.TemplateNodeId }; //on initial construction we don't want to have dirty properties tracked // http://issues.umbraco.org/issue/U4-1946 contentType.ResetDirtyProperties(false); return contentType; }
public void UpdateDocumentType_Successfult_Test() { var documentTypeRepoMock = new Mock <IDocumentTypeRepository>(); documentTypeRepoMock .Setup(x => x.SearchMatching(It.IsAny <Expression <Func <DocumentTypeEntity, bool> > >())) .Returns(new List <DocumentTypeEntity> { new DocumentTypeEntity { DocumentTypeId = Guid.NewGuid() } }); documentTypeRepoMock .Setup(x => x.Update(It.IsAny <DocumentTypeEntity>())) .Returns(() => { return(true); }); var service = new ServiceCollection(); service.AddTransient(_ => documentTypeRepoMock.Object); service.ConfigurePeopleManagementService(new DbSettings()); var provider = service.BuildServiceProvider(); var documentTypeSvc = provider.GetRequiredService <IDocumentTypeService>(); var newArea = new DocumentTypeDto { DocumentTypeId = Guid.NewGuid(), DocumentType = "Fake area" }; var response = documentTypeSvc.UpdateDocumentType(newArea); Assert.NotEqual(default, response);
/// <summary> /// Método para obtener la lista de los registros de la tabla DocumentType /// </summary> /// <returns> Objecto transacción con el resultado de la consulta </returns> public TransactionDto <List <DocumentTypeDto> > GetListDocumentType() { TransactionDto <List <DocumentTypeDto> > transaction = new TransactionDto <List <DocumentTypeDto> >(); transaction.Data = new List <DocumentTypeDto>(); try { var getListDocumentType = _documentTypeRepository.GetListDocumentType(); if (getListDocumentType.Count == 0) { transaction.Message = "No existen registros."; return(transaction); } foreach (var item in getListDocumentType) { DocumentTypeDto documentType = new DocumentTypeDto(); documentType.Id = item.Id; documentType.Name = item.Name; documentType.Code = item.Code; transaction.Data.Add(documentType); } transaction.Message = "Datos consultados correctamente."; transaction.Status = Status.Success; } catch (ArgumentException ex) { transaction.Message = ex.Message; } return(transaction); }
public async Task <BaseEntity> SaveAndReturnEntityAsync(DocumentTypeDto entityDto) { var entity = _mapper.Map <DocumentType>(entityDto); var result = await _repository.SaveAndReturnEntityAsync(entity); return(result); }
public async Task AddDocumentType_Successfult_Test() { var documentTypeRepoMock = new Mock <IDocumentTypeRepository>(); documentTypeRepoMock .Setup(x => x.Insert(It.IsAny <DocumentTypeEntity>())) .Returns(() => { return(Task.FromResult(new DocumentTypeEntity { DocumentTypeId = Guid.NewGuid(), DocumentType = "Fake area" })); }); var service = new ServiceCollection(); service.AddTransient(_ => documentTypeRepoMock.Object); service.ConfigurePeopleManagementService(new DbSettings()); var provider = service.BuildServiceProvider(); var documentTypeSvc = provider.GetRequiredService <IDocumentTypeService>(); var newDocumentType = new DocumentTypeDto { DocumentTypeId = Guid.NewGuid(), DocumentType = "Fake area", }; var responseAdd = await documentTypeSvc.AddDocumentType(newDocumentType).ConfigureAwait(false); Assert.NotNull(responseAdd); Assert.NotEqual(default, responseAdd);
public IActionResult Edit(int id, DocumentTypeDto documentTypeDto) { log.Info(nameof(DocumentTypesController.Edit)); if (id != documentTypeDto.Id) { log.Warn(nameof(DocumentTypesController.Edit) + " id is not equal to documentTypeDto.Id"); return(NotFound()); } if (ModelState.IsValid) { try { documentTypeService.Update(documentTypeDto); } catch (Exception e) { log.Error(e); return(BadRequest()); } return(RedirectToAction(nameof(Index))); } return(View(documentTypeDto)); }
private static void ValidateRequireDocumentype(DocumentTypeDto request) { if (request.DocumentTypeId == Guid.Empty) { throw new DocumentTypeIdNotDefinedException(); } }
public async Task <DocumentTypeDto> PutDocumentType(int id, DocumentTypeDto model) { var url = CRMApiUri + "/DocumentType/" + id; var result = await PutRequestToApi(url, model); return(result); }
public async Task <DocumentTypeDto> PostDocumentType(DocumentTypeDto model) { var url = CRMApiUri + "/DocumentType"; var result = await PostRequestToApi(url, model); return(result); }
public async Task <IHttpActionResult> PostDocumentType(DocumentTypeDto documentTypeDto) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } //DocumentType documentType = _mapper.Map<DocumentTypeDto, DocumentType>(documentTypeDto); var documentType = new DocumentType { DocumentTypeName = documentTypeDto.DocumentType, Remark = documentTypeDto.Remark, Description = documentTypeDto.Description, }; documentType = _documentTypeService.Add(documentType); await _documentTypeService.CommitAsync(); //documentTypeDto = _mapper.Map(documentType, documentTypeDto); documentTypeDto = new DocumentTypeDto { Id = documentType.Id, CreatedBy = documentType.CreatedBy, CreatedDate = documentType.CreatedDate, DocumentType = documentType.DocumentTypeName, Remark = documentType.Remark, Description = documentType.Description, }; return(Ok(documentTypeDto)); }
public DocumentTypeDto UpdateDocumentType(DocumentTypeDto dto) { var entity = AutoMapper.Mapper.Map <DocumentType>(dto); _docTypeRepository.Update(entity); return(AutoMapper.Mapper.Map <DocumentTypeDto>(entity)); }
public async Task <IActionResult> Post([FromBody] DocumentTypeDto documentType) { if (documentType.Id != 0) { return(StatusCode(StatusCodes.Status400BadRequest, "Identity insert is not permitted.")); } return(await SaveAndReturnEntityAsync(async() => await _documentTypeService.SaveAndReturnEntityAsync(documentType))); }
public async Task <IActionResult> Put(int id, [FromBody] DocumentTypeDto documentType) { if (id == 0 || documentType.Id == 0) { return(StatusCode(StatusCodes.Status400BadRequest, "Id needs to be greater than 0.")); } return(await SaveAndReturnEntityAsync(async() => await _documentTypeService.SaveAndReturnEntityAsync(documentType))); }
private void ValidateDocumentTypeIdExist(DocumentTypeDto request) { var documentTypeIdExist = _repoDocumentType .SearchMatching <DocumentTypeEntity>(dt => dt.DocumentTypeId == request.DocumentTypeId); if (!documentTypeIdExist.Any()) { throw new DontExistIdException(); } }
public async Task <Guid?> AddDocumentType(DocumentTypeDto request) { if (string.IsNullOrEmpty(request.DocumentType)) { throw new DocumentTypeNotDefinedException(); } var response = await _repoDocumentType.Insert(_mapper.Map <DocumentTypeEntity>(request)).ConfigureAwait(false); return(response.DocumentTypeId); }
public void Update(DocumentTypeDto documentTypeDto) { if (!documentTypeValidator.Validate(documentTypeDto).IsValid) { throw new ArgumentException(documentTypeValidator.Validate(documentTypeDto).Errors.First().ErrorMessage); } var documentType = mapper.Map <DocumentTypeDto, DocumentType>(documentTypeDto); unitOfWork.DocumentTypes.Create(documentType); unitOfWork.Save(); }
public DocumentTypeDto BuildDto(IContentType entity) { var documentTypeDto = new DocumentTypeDto {ContentTypeDto = BuildContentTypeDto(entity), ContentTypeNodeId = entity.Id}; var contentType = entity as ContentType; if(contentType != null) { documentTypeDto.TemplateNodeId = contentType.DefaultTemplateId; documentTypeDto.IsDefault = true; } return documentTypeDto; }
public async void PostDocumentTypeModelStateErrorReturnsBadRequest() { using (var context = DbTestContext.GenerateContextWithData()) using (var controller = new DocumentTypesController(context, _mapper)) { controller.ModelState.AddModelError("an error", "some error"); DocumentTypeDto p11 = GetTestDocumentTypeDto(11); var result = await controller.PostDocumentType(p11); Assert.IsType <BadRequestObjectResult>(result); } }
public async void PostDocumentTypeCorrectDataCreatesDocumentType() { using (var context = DbTestContext.GenerateContextWithData()) using (var controller = new DocumentTypesController(context, _mapper)) { DocumentTypeDto p11 = GetTestDocumentTypeDto(11); var result = await controller.PostDocumentType(p11); Assert.NotNull(result); var resultValue = Assert.IsType <CreatedAtActionResult>(result); } }
public async Task <IActionResult> PostDocumentType([FromBody] DocumentTypeDto documentType) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } DocumentType documentTypeReversed = _mapper.Map <DocumentType>(documentType); _context.DocumentTypes.Add(documentTypeReversed); await _context.SaveChangesAsync(); return(CreatedAtAction("GetDocumentType", new { id = documentTypeReversed.Id }, _mapper.Map <DocumentTypeDto>(documentTypeReversed))); }
public async void DeleteDocumentTypeIdDeletesDocumentType() { using (var context = DbTestContext.GenerateContextWithData()) using (var controller = new DocumentTypesController(context, _mapper)) { var result = await controller.DeleteDocumentType(3); DocumentTypeDto p3 = GetTestDocumentTypeDto(3); Assert.NotNull(result); var okObjectResult = Assert.IsType <OkObjectResult>(result); var resultValue = okObjectResult.Value; Assert.Equal(p3, resultValue); } }
public DocumentSubTypeDto[] GetForDocumentType(long documentTypeId) { var documentType = new DocumentTypeDto() { Id = documentTypeId }; var documentSubTypes = new List<DocumentSubTypeDto>() { new DocumentSubTypeDto() { Id = 1, DocumentType = documentType } }; return documentSubTypes.ToArray(); }
public bool UpdateDocumentType(DocumentTypeDto request) { ValidateRequireDocumentype(request); var documentTypeIdExist = _repoDocumentType .SearchMatching <DocumentTypeEntity>(dt => dt.DocumentTypeId == request.DocumentTypeId); if (!documentTypeIdExist.Any()) { throw new DontExistIdException(); } var entityUpdate = documentTypeIdExist.FirstOrDefault(); entityUpdate.DocumentType = request.DocumentType; return(_repoDocumentType.Update(entityUpdate)); }
public async Task <IHttpActionResult> PutDocumentType(Guid id, DocumentTypeDto documentTypeDto) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != documentTypeDto.Id) { return(BadRequest()); } try { var documentType = await _documentTypeService.GetByIdAsync(id); if (documentType != null) { documentType.DocumentTypeName = documentTypeDto.DocumentType; documentType.Remark = documentTypeDto.Remark; documentType.Description = documentTypeDto.Description; _documentTypeService.Update(documentType); await _documentTypeService.CommitAsync(); return(Ok(documentTypeDto)); } else { return(StatusCode(HttpStatusCode.NoContent)); } } catch (DbUpdateConcurrencyException) { if (!DocumentTypeExists(id)) { return(NotFound()); } else { throw; } } }
public async void GetDocumentTypeByIdReturnsSingleDocumentType() { using (var context = DbTestContext.GenerateContextWithData()) using (var controller = new DocumentTypesController(context, _mapper)) { var result = await controller.GetDocumentType(3); var okObjectResult = Assert.IsType <OkObjectResult>(result); var resultValue = okObjectResult.Value; DocumentTypeDto p3 = GetTestDocumentTypeDto(3); Assert.NotNull(resultValue); Assert.IsType <DocumentTypeDto>(resultValue); DocumentTypeDto p = (DocumentTypeDto)resultValue; Assert.True(p.Equals(p3)); Assert.True(p.Equals(p3, true)); } }
public IActionResult Create(DocumentTypeDto documentTypeDto) { log.Info(nameof(DocumentTypesController.Create)); if (ModelState.IsValid) { try { documentTypeService.Create(documentTypeDto); return(RedirectToAction(nameof(Index))); } catch (Exception e) { log.Error(e); return(BadRequest()); } } return(View(documentTypeDto)); }
public void Throw_DontExistIdException_when_id_it_isnt() { var documentTypeRepoMock = new Mock <IDocumentTypeRepository>(); documentTypeRepoMock .Setup(x => x.SearchMatching(It.IsAny <Expression <Func <DocumentTypeEntity, bool> > >())) .Returns(new List <DocumentTypeEntity>()); var service = new ServiceCollection(); service.AddTransient(_ => documentTypeRepoMock.Object); service.ConfigurePeopleManagementService(new DbSettings()); var provider = service.BuildServiceProvider(); var documentTypeSvc = provider.GetRequiredService <IDocumentTypeService>(); var newDocumentType = new DocumentTypeDto { DocumentTypeId = Guid.NewGuid(), DocumentType = "Fake area" }; Assert.Throws <DontExistIdException>(() => documentTypeSvc.UpdateDocumentType(newDocumentType)); }
public void DocumentTypeDtoEqualsRetursCorrectValues() { DocumentTypeDto d1 = new DocumentTypeDto { Id = 1, FullName = "Doc Type 1", ShortName = "DT1", DocumentCategory = DocumentCategory.FunctionalDocumentation }; DocumentTypeDto d2 = new DocumentTypeDto { Id = 1, FullName = "Doc Type 1", ShortName = "DT1", DocumentCategory = DocumentCategory.FunctionalDocumentation }; DocumentTypeDto d3 = new DocumentTypeDto { Id = 3, FullName = "Doc Type 1", ShortName = "DT1", DocumentCategory = DocumentCategory.FunctionalDocumentation }; DocumentTypeDto d4 = new DocumentTypeDto { Id = 1, FullName = "Doc Type 4", ShortName = "DT4", DocumentCategory = DocumentCategory.ReleaseNotes }; Assert.True(d1.Equals(d2)); Assert.True(d1.Equals(d2, true)); Assert.False(d1.Equals(d3)); Assert.False(d1.Equals(d3, true)); Assert.True(d1.Equals(d4)); Assert.False(d1.Equals(d4, true)); }
public DocumentTypesServiceTests() { var mockRepository = new Mock <IRepository <DocumentType, int> >(); var mockUnitOfWork = new Mock <IUnitOfWork>(); fakeDocumentTypes = new List <DocumentType> { new DocumentType { Id = 5, Name = "Test1" }, new DocumentType { Id = 7, Name = "Test2" }, new DocumentType { Id = int.MaxValue, Name = "Test2" } }; documentTypesDto = new DocumentTypeDto { Id = 3, Name = "TestDTO" }; mockRepository.Setup(m => m.GetAll()).Returns(fakeDocumentTypes.AsQueryable); mockRepository.Setup(m => m.Get(It.IsAny <int>())) .Returns <int>(id => fakeDocumentTypes.Single(t => t.Id == id)); mockRepository.Setup(r => r.Create(It.IsAny <DocumentType>())) .Callback <DocumentType>(t => fakeDocumentTypes.Add(documentType = t)); mockRepository.Setup(r => r.Update(It.IsAny <DocumentType>())) .Callback <DocumentType>(t => documentType = t); mockRepository.Setup(x => x.Delete(It.IsAny <int>())) .Callback <int>(id => fakeDocumentTypes.Remove(fakeDocumentTypes.Single(t => t.Id == id))); mockUnitOfWork.Setup(m => m.DocumentTypes).Returns(mockRepository.Object); documentTypesService = new DocumentTypesService(mockUnitOfWork.Object); }
public DocumentSubTypeDto[] GetByDepartmentId(long departmentId) { var documentType = new DocumentTypeDto() { Department = new DepartmentDto() { Id = departmentId } }; var documentSubTypes = new List<DocumentSubTypeDto>() { new DocumentSubTypeDto() { Id = 1, DocumentType = documentType, }, new DocumentSubTypeDto() { Id = 1, DocumentType = new DocumentTypeDto() { Id = 124, Department = new DepartmentDto() }, Title = "Fake Sub Type" } }; return documentSubTypes.ToArray(); }
public void GetDocumentTypesReturnsListOfDocumentTypes() { using (var context = DbTestContext.GenerateContextWithData()) using (var controller = new DocumentTypesController(context, _mapper)) { var result = controller.GetDocumentTypes(); DocumentTypeDto p3 = GetTestDocumentTypeDto(3); Assert.NotNull(result); var okObjectResult = Assert.IsType <OkObjectResult>(result); var resultValue = okObjectResult.Value; Assert.IsAssignableFrom <IEnumerable <DocumentTypeDto> >(resultValue); Assert.NotEmpty((IEnumerable <DocumentTypeDto>)resultValue); IEnumerable <DocumentTypeDto> resultValueList = (IEnumerable <DocumentTypeDto>)resultValue; Assert.Equal(10, resultValueList.Count()); DocumentTypeDto p = (DocumentTypeDto)resultValueList.Where(r => r.Id == 3).FirstOrDefault(); Assert.True(p.Equals(p3)); Assert.True(p.Equals(p3, true)); } }
public IHttpActionResult GetDocumentType(Guid id) { var documentType = _documentTypeService.GetByIdQuerableAsync(id).FirstOrDefault(); if (documentType == null) { return(NotFound()); } //DocumentTypeDto documentTypeDto = _mapper.Map<DocumentType, DocumentTypeDto>(documentType); DocumentTypeDto documentTypeDto = new DocumentTypeDto { Id = documentType.Id, CreatedBy = documentType.CreatedBy, CreatedDate = documentType.CreatedDate, DocumentType = documentType.DocumentTypeName, Remark = documentType.Remark, Description = documentType.Description, }; return(Ok(documentTypeDto)); }
private void LoadDocuments() { var documentTypeA = new DocumentTypeDto() { Id = 124, Title = "Type A" }; var documentTypeB = new DocumentTypeDto() { Id = 126, Title = "Type B" }; var documentTypeC = new DocumentTypeDto() { Id = 136, Title = "Type C" }; var documentTypeD = new DocumentTypeDto() { Id = 137, Title = "Type D" }; var documentSubTypeA = new DocumentSubTypeDto() { Id = 1, Title = "Sub Type A" }; var documentSubTypeB = new DocumentSubTypeDto() { Id = 2, Title = "Sub Type B" }; var documentSubTypeC = new DocumentSubTypeDto() { Id = 3, Title = "Sub Type C" }; var documentSubTypeD = new DocumentSubTypeDto() { Id = 4, Title = "Sub Type D" }; _documents.Add(new ClientDocumentDto() { Id = 1, DocumentType = documentTypeA, DocumentSubType = documentSubTypeA, Title = "Test Title 1", Description = "Test Description 1", CreatedOn = DateTime.Now }); _documents.Add(new ClientDocumentDto() { Id = 1, DocumentType = documentTypeB, DocumentSubType = documentSubTypeB, Title = "Test Title 2", Description = "Test Description 2", CreatedOn = DateTime.Now }); _documents.Add(new ClientDocumentDto() { Id = 1, DocumentType = documentTypeC, DocumentSubType = documentSubTypeC, Title = "Test Title 3", Description = "Test Description 3", CreatedOn = DateTime.Now }); _documents.Add(new ClientDocumentDto() { Id = 1, DocumentType = documentTypeD, DocumentSubType = documentSubTypeD, Title = "Test Title 4", Description = "Test Description 4", CreatedOn = DateTime.Now }); }