예제 #1
0
파일: TopicTests.cs 프로젝트: Jazaret/Nancy
        public async Task AssertGetTopicsCallsGetTopicsRepoAsync()
        {
            //Given

            //When
            var result = await _topicService.GetAllTopics();

            //Then
            _mockRepo.Verify(m => m.GetTopics());
        }
        private void SetupTopicList()
        {
            TopicService topicService = new TopicService(Ioc.GetInstance <ITopicRepository>());

            var topics = topicService.GetAllTopics().OrderByDescending(x => x.CreatedDate);

            foreach (var topic in topics)
            {
                ddlTopics.Items.Add(new ListItem(topic.TopicName, topic.TopicId.ToString()));
            }

            ListItem item = new ListItem("Please select a Topic", "-1");

            ddlTopics.Items.Insert(0, item);

            item.Selected = true;
        }
예제 #3
0
        private IEnumerable <MinimalTopic> GetAllTopics(bool refreshAll = false)
        {
            var topics = new List <MinimalTopic>();

            if (System.IO.File.Exists(JsonPath) && refreshAll == false)
            {
                var jsonData = System.IO.File.ReadAllText(JsonPath);
                topics = JsonConvert.DeserializeObject <List <MinimalTopic> >(jsonData);
            }
            else
            {
                var topicService = new TopicService(DatabaseContext);

                //var currentCulture = CultureInfo.CurrentCulture;
                var topicData = topicService.GetAllTopics();
                foreach (var topic in topicData)
                {
                    var minimalTopic = new MinimalTopic
                    {
                        Id      = topic.Id,
                        Created = topic.Created,
                        Replies = topic.Replies,
                        Answer  = topic.Answer
                    };
                    topics.Add(minimalTopic);
                }

                // Serialize the data to raw JSON
                var rawJson = JsonConvert.SerializeObject(topics, Formatting.Indented);

                // Save the JSON to disk
                System.IO.File.WriteAllText(JsonPath, rawJson, Encoding.UTF8);
            }

            return(topics);
        }