public async Task ShouldDeserializeInheritors() { //Arrange var json = "{" + "\"Status\": {" + "\"$type\": \"UnitTests.ResponseProcessingBehavior+InheritaceModels+Status, UnitTests\"," + "\"Consumes\": {" + "\"async-proc-test:queue:6cb845c0f9564644b8b2bbc627536930\": {" + "\"LastTime\": \"2020-11-10T03:19:47.7876725+03:00\"" + "}" + "}" + "}" + "}"; var httpContent = new StringContent(json, Encoding.UTF8, "application/json"); //Act var res = await ResponseProcessing.DeserializeContent <InheritaceModels.Root>(httpContent, HttpStatusCode.OK); var status = res?.Status as InheritaceModels.Status; //Assert Assert.NotNull(status); Assert.NotNull(status.Consumes); Assert.True(status.Consumes.ContainsKey("async-proc-test:queue:6cb845c0f9564644b8b2bbc627536930")); Assert.Equal(10, status.Consumes["async-proc-test:queue:6cb845c0f9564644b8b2bbc627536930"].LastTime.Day); }
public JsonResult GetInfoCard(int id) { InfoCard infoCard = infoCardRepository.GetById(id); if (infoCard != null) { InfoCardDTO response = new InfoCardDTO { Id = infoCard.ID, Adress = infoCard.Adress, BirthDay = infoCard.BirthDay.HasValue ? infoCard.BirthDay.Value : DateTime.MinValue, CompanyId = infoCard.CompanyId, Email = infoCard.Email, GetJobDate = infoCard.GetJobDate.HasValue ? infoCard.GetJobDate.Value : DateTime.MinValue, Name = infoCard.Name, Patronymic = infoCard.Patronymic, Phone = infoCard.Phone, Post = infoCard.Post, Surname = infoCard.Surname, UserId = infoCard.UserId, CompanyName = companyRepository.GetById(infoCard.CompanyId).CompanyName, DivisionId = infoCard.DivisionId.HasValue ? infoCard.DivisionId.Value : 0, AvatarUrl = infoCard.AvatarUrl }; return(Json(ResponseProcessing.Success(response))); } else { return(Json(ResponseProcessing.Error("Невозможно извлечь данные о сотруднике. Обновите страницу и повторите попытку."))); } }
public async Task ShouldDeserializeContent(string strContent, string mediaType) { //Arrange var httpContent = new StringContent(strContent, Encoding.UTF8, mediaType); //Act var res = await ResponseProcessing.DeserializeContent <TestModel>(httpContent, HttpStatusCode.OK); //Assert Assert.Equal("foo", res.TestValue); }
public async Task ShouldDeserializeSimpleContent(Type targetType, string strContent, object expected) { //Arrange var httpContent = new StringContent(strContent); //Act var res = await ResponseProcessing.DeserializeContent(targetType, httpContent, HttpStatusCode.OK); //Assert Assert.Equal(expected, res); }
public JsonResult GetProject(int id) { Project project = projectRepository.GetById(id); List <ProjectDocument> documents = projectDocumentRepository.GetProjectDocuments(id).ToList(); List <ProjectDocumentDTO> documentsDTO = new List <ProjectDocumentDTO>(); foreach (ProjectDocument pd in documents) { documentsDTO.Add(new ProjectDocumentDTO { DocumentPath = pd.DocumentPath, DocumentTitle = pd.DocumentTitle, Id = pd.ID, ProjectId = pd.ProjectId.HasValue ? pd.ProjectId.Value : 0, UploadDate = pd.UploadDate }); } ProjectDTO projectTransferObj = new ProjectDTO { Id = project.ID, CompanyId = infoCardRepository.GetUserInfoCard(brioContext.CurrentUser.ID).CompanyId, CreateDate = DateTime.Now, Description = project.Description, EndDate = project.EndDate.HasValue ? project.EndDate.Value : DateTime.MinValue, ResponsibleUserId = project.ResponsibleUserId, StartDate = project.StartDate.HasValue ? project.StartDate.Value : DateTime.MinValue, Tile = project.Tile, Documents = documentsDTO }; if (project != null) { return(Json(ResponseProcessing.Success(projectTransferObj, "Проект успешно извлечен."))); } else { return(Json(ResponseProcessing.Error(String.Format("Проекта с идентификатором {0} не существует.", id)))); } }
public JsonResult GetProjectStep(int id) { ProjectStep projectSteps = projectStepRepository.GetById(id); if (projectSteps != null) { ProjectStepDTO projectStepsDTO = new ProjectStepDTO { Id = projectSteps.ID, Description = projectSteps.Description, Title = projectSteps.Title, ProjectId = projectSteps.ProjectId }; return(Json(ResponseProcessing.Success(projectStepsDTO, "Проект успешно извлечен."))); } else { return(Json(ResponseProcessing.Error(String.Format("У проекта с идентификатором {0} этапов не существует.", id)))); } }
public JsonResult GetNews(int id) { News news = newsRepository.GetById(id); if (news != null) { NewsDTO response = new NewsDTO { AuthorUserId = news.AuthorUserId, CompanyId = news.CompanyId, CreateDate = news.CreateDate, Id = news.ID, Text = news.Text, Title = news.Title, PhotoPath = news.PhotoPath }; return(Json(ResponseProcessing.Success(response))); } else { return(Json(ResponseProcessing.Error("Невозможно извлечь новость. Обновите страницу и повторите попытку."))); } }