public ChatHistoryImporterSpecs(TestDiscussionWebApp app)
        {
            var urlHelper = new Mock <IUrlHelper>();

            urlHelper.Setup(url => url.Action(It.IsAny <UrlActionContext>())).Returns("http://mock-url/");

            var httpClient = StubHttpClient.Create().When(req =>
            {
                var ms = new MemoryStream();
                ms.Write(Encoding.UTF8.GetBytes("This is file content"));
                ms.Seek(0, SeekOrigin.Begin);

                return(new HttpResponseMessage(HttpStatusCode.OK)
                {
                    Content = new StreamContent(ms)
                    {
                        Headers =
                        {
                            ContentType = new MediaTypeHeaderValue("application/octet-stream")
                        }
                    }
                });
            });

            var currentUser = new Mock <ICurrentUser>();

            currentUser.SetupGet(u => u.DiscussionUser).Returns(new User {
                Id = 42
            });

            var options = new ChatyOptions
            {
                ServiceBaseUrl = "http://chaty/"
            };
            var optionsMock = new Mock <IOptions <ChatyOptions> >();

            optionsMock.SetupGet(o => o.Value).Returns(options);

            _fileRepo          = app.GetService <IRepository <FileRecord> >();
            _weChatAccountRepo = app.GetService <IRepository <WeChatAccount> >();
            _importer          = new DefaultChatHistoryImporter(app.GetService <IClock>(),
                                                                httpClient,
                                                                urlHelper.Object,
                                                                _fileRepo,
                                                                _weChatAccountRepo,
                                                                app.GetService <IFileSystem>(),
                                                                currentUser.Object,
                                                                optionsMock.Object);

            app.DeleteAll <FileRecord>();
            app.DeleteAll <WeChatAccount>();
        }
Example #2
0
 public TopicController(IRepository <Topic> topicRepo,
                        ITopicService topicService,
                        ILogger <TopicController> logger,
                        IOptions <ChatyOptions> chatyOptions, IChatHistoryImporter chatHistoryImporter, HttpMessageInvoker httpClient, IRepository <Reply> replyRepo, IRepository <WeChatAccount> wechatAccountRepo)
 {
     _topicRepo           = topicRepo;
     _topicService        = topicService;
     _logger              = logger;
     _chatyOptions        = chatyOptions?.Value;
     _chatHistoryImporter = chatHistoryImporter;
     _httpClient          = httpClient;
     _replyRepo           = replyRepo;
     _wechatAccountRepo   = wechatAccountRepo;
 }