public async Task UpdateAsyncWhenIdIsCorrectReturnsTopicInstance() { // Arrange var mockUnitOfWork = GetDefaultUnitOfWorkRepositoryInstance(); var mockTopicRepository = GetDefaultTopicRepositoryInstance(); var mockCourseRepository = new Mock <ICourseRepository>(); var mockExpertTopicRepository = new Mock <IExpertTopicRepository>(); var TopicId = 1; var topic = new Topic() { Id = 1, Name = "string", CourseId = 1 }; mockTopicRepository.Setup(r => r.FindById(TopicId)).Returns(Task.FromResult(topic)); mockTopicRepository.Setup(r => r.Update(topic)); var service = new TopicService(mockTopicRepository.Object, mockUnitOfWork.Object, mockCourseRepository.Object, mockExpertTopicRepository.Object); // Act TopicResponse result = await service.UpdateAsync(TopicId, topic); var resource = result.Resource; // Assert resource.Should().Equals(topic); }
public async Task DeleteAsyncWhenInvalidIdReturnsTopicNotFoundResponse() { // Arrange var mockUnitOfWork = GetDefaultUnitOfWorkRepositoryInstance(); var mockTopicRepository = GetDefaultTopicRepositoryInstance(); var mockCourseRepository = new Mock <ICourseRepository>(); var mockExpertTopicRepository = new Mock <IExpertTopicRepository>(); var TopicId = 1; var topic = new Topic() { Id = 1, Name = "string", CourseId = 1 }; mockTopicRepository.Setup(r => r.FindById(TopicId)).Returns(Task.FromResult <Topic>(null)); mockTopicRepository.Setup(r => r.Remove(topic)); var service = new TopicService(mockTopicRepository.Object, mockUnitOfWork.Object, mockCourseRepository.Object, mockExpertTopicRepository.Object); // Act TopicResponse result = await service.DeleteAsync(TopicId); var message = result.Message; // Assert message.Should().Be("Topic not found"); }
public async Task should_set_channel_topic() { // given const string slackKey = "I-is-another-key"; const string channelName = "my-channel"; const string channelTopic = "my topic"; var expectedResponse = new TopicResponse() { Topic = channelTopic }; _httpTest.RespondWithJson(expectedResponse); // when var result = await _channelClient.SetTopic(slackKey, channelName, channelTopic); // then _responseVerifierMock.Verify(x => x.VerifyResponse(Looks.Like(expectedResponse)), Times.Once); _httpTest .ShouldHaveCalled(ClientConstants.SlackApiHost.AppendPathSegment(FlurlChannelClient.CHANNEL_SET_TOPIC_PATH)) .WithQueryParamValue("token", slackKey) .WithQueryParamValue("channel", channelName) .WithQueryParamValue("topic", channelTopic) .Times(1); result.ToExpectedObject().ShouldEqual(expectedResponse.Topic); }
//Implement from Interface ITopicService - Get tất cả Topic for admin public List <TopicResponse> GetAllTopics() { string statusConvert = ""; var rs = _unitOfWork.Repository <Topic>().GetAll().Where(t => t.IsDelete == false).AsQueryable(); List <TopicResponse> listTopicResponse = new List <TopicResponse>(); foreach (var item in rs) { if (item.Status == (int)TopicStatus.Status.New) { statusConvert = "Mới"; } else if (item.Status == (int)TopicStatus.Status.Waiting) { statusConvert = "Đang chờ kích hoạt"; } else if (item.Status == (int)TopicStatus.Status.Active) { statusConvert = "Đang diễn ra"; } else if (item.Status == (int)TopicStatus.Status.Disactive) { statusConvert = "Tạm dừng"; } else if (item.Status == (int)TopicStatus.Status.Closed) { statusConvert = "Đã đóng"; } string topicInRoom = "Chủ đề này chưa được thiết lập phòng"; if (item.RoomId != null) { topicInRoom = "Chủ đề này đang ở phòng: " + item.Room.No; } DateTime createDate = (DateTime)item.CreateDate; DateTime startDate = (DateTime)item.StartDate; TopicResponse topicResponse = new TopicResponse() { Id = item.Id, Name = item.Name, Description = item.Description, NameEng = item.NameEng, DescriptionEng = item.DescriptionEng, Image = item.Image, CreateDate = createDate.Date.ToString("yyyy-MM-dd"), StartDate = startDate.Date.ToString("yyyy-MM-dd"), Rating = (float)item.Rating, Status = statusConvert, isDelete = (bool)item.IsDelete, RoomNo = topicInRoom }; listTopicResponse.Add(topicResponse); } return(listTopicResponse.ToList()); }
public async Task <TopicResponse> GetTopicById(int id) { var topic = _unitOfWork.Repository <Topic>().GetById(id); if (topic == null) { throw new Exception("Can not find Topic!!!"); } string statusConvert = ""; if (topic.Status == (int)TopicStatus.Status.New) { statusConvert = "Mới"; } else if (topic.Status == (int)TopicStatus.Status.Waiting) { statusConvert = "Đang chờ kích hoạt"; } else if (topic.Status == (int)TopicStatus.Status.Active) { statusConvert = "Đang diễn ra"; } else if (topic.Status == (int)TopicStatus.Status.Disactive) { statusConvert = "Tạm dừng"; } else if (topic.Status == (int)TopicStatus.Status.Closed) { statusConvert = "Đã đóng"; } string topicInRoom = "Chủ đề này chưa được thiết lập phòng"; if (topic.RoomId != null) { topicInRoom = "Chủ đề này đang ở phòng: " + topic.RoomId; } DateTime createDate = (DateTime)topic.CreateDate; DateTime startDate = (DateTime)topic.StartDate; TopicResponse topicResponse = new TopicResponse(); topicResponse.Id = topic.Id; topicResponse.Name = topic.Name; topicResponse.Description = topic.Description; topicResponse.NameEng = topic.NameEng; topicResponse.DescriptionEng = topic.DescriptionEng; topicResponse.Image = topic.Image; topicResponse.CreateDate = createDate.Date.ToString("dd/MM/yyyy"); topicResponse.StartDate = startDate.Date.ToString("dd/MM/yyyy"); topicResponse.Rating = (float)topic.Rating; topicResponse.Status = statusConvert; topicResponse.isDelete = (bool)topic.IsDelete; topicResponse.RoomNo = topicInRoom; return(topicResponse); }
List <TopicResponse> SearchTopicByName(string language, string name) { var topic = new List <Topic>(); string vietnamese = "vi"; string english = "en"; if (language == vietnamese) { topic = _unitOfWork.Repository <Topic>().GetAll().Where(t => t.Name.Contains(name) && t.IsDelete == false && t.Status == (int)TopicStatus.Status.Active && DateTime.Now >= t.StartDate).AsQueryable().ToList(); } else if (language == english) { topic = _unitOfWork.Repository <Topic>().GetAll().Where(t => t.NameEng.Contains(name) && t.IsDelete == false && t.Status == (int)TopicStatus.Status.Active && DateTime.Now >= t.StartDate).AsQueryable().ToList(); } List <TopicResponse> listTopic = new List <TopicResponse>(); if (topic != null) { foreach (var item in topic) { int count = 0; var topicInFeedback = _unitOfWork.Repository <Feedback>().GetAll().Where(x => x.TopicId == item.Id); DateTime dt = (DateTime)item.StartDate; if (topicInFeedback != null) { count = topicInFeedback.Count(); } TopicResponse topicObj = new TopicResponse() { Id = item.Id, Name = item.Name, Description = item.Description, NameEng = item.NameEng, DescriptionEng = item.DescriptionEng, Image = item.Image, StartDate = dt.Date.ToString("dd/MM/yyyy"), Rating = (float)item.Rating, TotalFeedback = count }; listTopic.Add(topicObj); } } return(listTopic); }
public void GetTopics() { var randomText = new RandomText(); var request = new TopicRequest(); for (int i = 1; i <= 200; i++) { request.Documents.Add(new TopicDocument() { Id = i.ToString(), Text = randomText.Next() }); } var client = new TopicClient(apiKey); var opeationUrl = client.StartTopicProcessing(request); TopicResponse response = null; var startTime = DateTime.Now; var timeoutTime = startTime.AddMinutes(30); var doneProcessing = false; while (!doneProcessing) { response = client.GetTopicResponse(opeationUrl); if (response.Status == TopicOperationStatus.Cancelled) { Assert.Fail("Operation Cancelled"); } else if (response.Status == TopicOperationStatus.Failed) { Assert.Fail("Operation Failed"); } else if (response.Status == TopicOperationStatus.Succeeded) { doneProcessing = true; } else { if (DateTime.Now >= timeoutTime) { Assert.Fail("Operation Timeout"); } else { Thread.Sleep(60000); } } } Assert.IsTrue(response.OperationProcessingResult.TopicAssignments.Count > 0); Assert.IsTrue(response.OperationProcessingResult.Topics.Count > 0); }
public void StoreArchives(TopicResponse archives, CancellationToken cancelToken) { using (var wrapper = new TransactionWrapper(cancelToken)) { var db = wrapper.Connection; StoreRatings(db, archives.Rating); var arcPosts = mapper.Map <IEnumerable <DbPost> >(archives.Messages); db.Posts.AddOrUpdateRange(arcPosts, p => p.Id); } }
//sort by rating public List <TopicResponse> GetHightLightTopic() { //int highlightRate = 4; var topic = _unitOfWork.Repository <Topic>().GetAll().Where(t => t.Status == (int)TopicStatus.Status.Active && t.IsDelete == false && t.Rating >= 4 && DateTime.Now >= t.StartDate).AsQueryable(); List <TopicResponse> listTopic = new List <TopicResponse>(); foreach (var item in topic) { int count = 0; var topicInFeedback = _unitOfWork.Repository <Feedback>().GetAll().Where(x => x.TopicId == item.Id); DateTime dt = (DateTime)item.StartDate; if (topicInFeedback.Count() > 0) { count = topicInFeedback.Count(); } TopicResponse topicObj = new TopicResponse() { Id = item.Id, Name = item.Name, Description = item.Description, NameEng = item.NameEng, DescriptionEng = item.DescriptionEng, Image = item.Image, StartDate = dt.Date.ToString("dd/MM/yyyy"), Rating = (float)item.Rating, TotalFeedback = count }; /*if (topicObj.Rating >= highlightRate) * {*/ listTopic.Add(topicObj); /*}*/ } listTopic = listTopic.OrderByDescending(response => response.Rating).ToList(); return(listTopic.ToList()); }
public List <TopicResponse> GetAllTopicsForUser() { var rs = _unitOfWork.Repository <Topic>().GetAll().Where(t => t.Status == (int)TopicStatus.Status.Active && t.IsDelete == false && DateTime.Now >= t.StartDate).AsQueryable(); List <TopicResponse> listTopicResponse = new List <TopicResponse>(); foreach (var item in rs) { int count = 0; var evtInFeedback = _unitOfWork.Repository <Feedback>().GetAll().Where(x => x.TopicId == item.Id); if (evtInFeedback.Count() > 0) { count = evtInFeedback.Count(); } DateTime startDate = (DateTime)item.StartDate; TopicResponse topicResponse = new TopicResponse() { Id = item.Id, Name = item.Name, Description = item.Description, NameEng = item.NameEng, DescriptionEng = item.DescriptionEng, Image = item.Image, StartDate = startDate.Date.ToString("dd/MM/yyyy"), Rating = (float)item.Rating, TotalFeedback = count }; listTopicResponse.Add(topicResponse); } return(listTopicResponse.ToList()); }
/// <summary> /// Initializes a new instance of the <see cref="CombinedTopicResponse"/> <see langword="class"/>. /// </summary> /// <param name="byondTopicResponse">The value of <see cref="ByondTopicResponse"/>.</param> /// <param name="interopResponse">The optional value of <see cref="InteropResponse"/>.</param> public CombinedTopicResponse(global::Byond.TopicSender.TopicResponse byondTopicResponse, TopicResponse interopResponse) { ByondTopicResponse = byondTopicResponse ?? throw new ArgumentNullException(nameof(byondTopicResponse)); InteropResponse = interopResponse; }
private async void Detect_Topics(string text) { try { var source = text.Split(new string[] { Environment.NewLine }, StringSplitOptions.None).ToList(); var randomText = new RandomText(source); var request = new TopicRequest(); for (int i = 0; i < 100; i++) { request.Documents.Add(new TopicDocument() { Id = i.ToString(), Text = randomText.Next() }); } MainWindow mainWindow = Window.GetWindow(this) as MainWindow; var client = new TopicClient(mainWindow._scenariosControl.SubscriptionKey); var opeationUrl = await client.StartTopicProcessingAsync(request); TopicResponse response = null; var doneProcessing = false; while (!doneProcessing) { response = await client.GetTopicResponseAsync(opeationUrl); switch (response.Status) { case TopicOperationStatus.Cancelled: Log("Operation Status: Cancelled"); doneProcessing = true; break; case TopicOperationStatus.Failed: Log("Operation Status: Failed"); doneProcessing = true; break; case TopicOperationStatus.NotStarted: Log("Operation Status: Not Started"); Thread.Sleep(100); break; case TopicOperationStatus.Running: Log("Operation Status: Running"); Thread.Sleep(100); break; case TopicOperationStatus.Succeeded: Log("Operation Status: Succeeded"); doneProcessing = true; break; } } foreach (var topic in response.OperationProcessingResult.Topics) { var score = topic.Score * 100; Log(string.Format("{0} ({1}%)", topic.KeyPhrase, score)); } } catch (Exception ex) { Log(ex.Message); } }
static async Task MainAsync() { var apiKey = "YOUR-TEXT-ANALYTICS-API-SUBSCRIPTION-KEY"; var randomText = new RandomText(); var request = new TopicRequest(); for (int i = 1; i <= 200; i++) { request.Documents.Add(new TopicDocument() { Id = i.ToString(), Text = randomText.Next() }); } var client = new TopicClient(apiKey); var operationUrl = await client.StartTopicProcessingAsync(request); TopicResponse response = null; var doneProcessing = false; while (!doneProcessing) { response = await client.GetTopicResponseAsync(operationUrl); switch (response.Status) { case TopicOperationStatus.Cancelled: Console.WriteLine("Status: Operation Cancelled"); doneProcessing = true; break; case TopicOperationStatus.Failed: Console.WriteLine("Status: Operation Failed"); doneProcessing = true; break; case TopicOperationStatus.NotStarted: Console.WriteLine("Status: Operation Not Started"); Thread.Sleep(60000); break; case TopicOperationStatus.Running: Console.WriteLine("Status: Operation Running"); Thread.Sleep(60000); break; case TopicOperationStatus.Succeeded: Console.WriteLine("Status: Operation Succeeded"); doneProcessing = true; break; } } foreach (var topic in response.OperationProcessingResult.Topics) { Console.WriteLine("{0} | {1}", topic.KeyPhrase, topic.Score); } Console.WriteLine("Press any key to exit..."); Console.ReadLine(); }