Example #1
0
 public UserController(UserManager <User> userManager, IUserService userService, ILogger <UserController> logger,
                       IRepository <WeChatAccount> wechatAccountRepo, ChatyApiService chatyApiService)
 {
     _userManager       = userManager;
     _userService       = userService;
     _wechatAccountRepo = wechatAccountRepo;
     _chatyApiService   = chatyApiService;
     _logger            = logger;
 }
Example #2
0
 public UserController(UserManager <User> userManager, IUserService userService, ILogger <UserController> logger,
                       IRepository <WeChatAccount> wechatAccountRepo, ChatyApiService chatyApiService, IOptions <ExternalIdentityServiceOptions> idpOptions)
 {
     _userManager       = userManager;
     _userService       = userService;
     _wechatAccountRepo = wechatAccountRepo;
     _chatyApiService   = chatyApiService;
     _idpOptions        = idpOptions?.Value;
     _logger            = logger;
 }
        public void should_check_support_as_true_when_allowed_users_not_configured()
        {
            var optionsWithoutAllowedUsers = new Mock <IOptions <ChatyOptions> >();

            optionsWithoutAllowedUsers.SetupGet(op => op.Value).Returns(new ChatyOptions()
            {
                ServiceBaseUrl = "http://abcd",
                AllowedUsers   = null
            });

            var chatyApiService = new ChatyApiService(optionsWithoutAllowedUsers.Object, null, null);

            Assert.True(chatyApiService.IsChatySupported(StringUtility.Random(6)));
        }
Example #4
0
 public TopicController(IRepository <Topic> topicRepo,
                        ITopicService topicService,
                        ILogger <TopicController> logger, IChatHistoryImporter chatHistoryImporter,
                        IRepository <Reply> replyRepo, IRepository <WeChatAccount> wechatAccountRepo,
                        ChatyApiService chatyApiService)
 {
     _topicRepo           = topicRepo;
     _topicService        = topicService;
     _logger              = logger;
     _chatHistoryImporter = chatHistoryImporter;
     _replyRepo           = replyRepo;
     _wechatAccountRepo   = wechatAccountRepo;
     _chatyApiService     = chatyApiService;
 }
        private TopicController CreateControllerWithChatyApiService(ChatyApiService chatyApiService)
        {
            var mockUrlHelper       = CreateMockUrlHelper("http://dotnetclub/download/file");
            var chatHistoryImporter = new DefaultChatHistoryImporter(new SystemClock(),
                                                                     mockUrlHelper,
                                                                     _app.GetService <IRepository <FileRecord> >(),
                                                                     _app.GetService <IRepository <WeChatAccount> >(),
                                                                     _app.GetService <IFileSystem>(),
                                                                     _app.GetService <ICurrentUser>(),
                                                                     chatyApiService);

            var httpContext = new DefaultHttpContext
            {
                User = _app.User, RequestServices = _app.ApplicationServices
            };
            var topicController = new TopicController(
                _app.GetService <IRepository <Topic> >(),
                _app.GetService <ITopicService>(),
                _app.GetService <ILogger <TopicController> >(),
                chatHistoryImporter,
                _app.GetService <IRepository <Reply> >(),
                _app.GetService <IRepository <WeChatAccount> >(),
                chatyApiService)
                                  .WithHttpContext(httpContext);

            topicController.Url = mockUrlHelper;

            _app.GetService <IHttpContextAccessor>().HttpContext = httpContext;
            return(topicController);


            IUrlHelper CreateMockUrlHelper(string fileLink)
            {
                var urlHelper = new Mock <IUrlHelper>();

                urlHelper.Setup(url => url.Action(It.IsAny <UrlActionContext>())).Returns(fileLink);
                return(urlHelper.Object);
            }
        }
        public ChatyApiServiceSpecs()
        {
            _httpClient = StubHttpClient.Create()
                          .Json("/chat/list/some_wx_id", new[] { "1556867244", "1556867241" })
                          .Json("/chat/detail/some_wx_id/1556867244", new[] {
                new ChatMessage
                {
                    SourceName      = "someone",
                    SourceTime      = "2018/12/02 12:00:08",
                    SourceTimestamp = 1547552931,
                    SourceWxId      = "Wx_879LJJKJGS",
                    Content         = new TextChatMessageContent()
                    {
                        Text = "text1"
                    }
                },
                new ChatMessage
                {
                    SourceName      = "Another one",
                    SourceTime      = "2018/12/02 12:00:09",
                    SourceTimestamp = 1547552932,
                    SourceWxId      = "Wx_879LKJGSJJ",
                    Content         = new TextChatMessageContent()
                    {
                        Text = "text2"
                    }
                }
            })
                          .Json("/chat/detail/some_wx_id/1556867241", new[] {
                new ChatMessage
                {
                    SourceName      = "someone",
                    SourceTime      = "2018/12/02 12:00:08",
                    SourceTimestamp = 1547552933,
                    SourceWxId      = "Wx_879LJJKJGS",
                    Content         = new FileChatMessageContent()
                    {
                        FileId   = "89257293",
                        FileName = "SomeFile.jpg"
                    }
                },
                new ChatMessage
                {
                    SourceName      = "Another one",
                    SourceTime      = "2018/12/02 12:00:09",
                    SourceTimestamp = 1547552934,
                    SourceWxId      = "Wx_879LKJGSJJ",
                    Content         = new UrlChatMessageContent()
                    {
                        Link = "http://dotnetclub"
                    }
                }
            })
                          .Json("/bot/info", new ChatyBotInfoViewModel
            {
                Name    = "Someone",
                QrCode  = "https://weixin.com/2o3kl3z",
                Weixin  = "wx_l09d",
                ChatyId = "34kds"
            }).Json("/bot/pair", new ChatyVerifyResultViewModel
            {
                Name = "Someone",
                Id   = "wx_l09d"
            }).When(req =>
            {
                if (req.RequestUri.PathAndQuery.StartsWith("/chat/file/"))
                {
                    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")
                            }
                        }
                    });
                }

                return(null);
            });

            var chatyOptions = new Mock <IOptions <ChatyOptions> >();

            chatyOptions.SetupGet(op => op.Value).Returns(new ChatyOptions
            {
                ServiceBaseUrl = "http://localhost:3000",
                AllowedUsers   = string.Format("{0},someone_else", _userAllowedToUseChaty)
            });
            _normalChatyApiService = new ChatyApiService(chatyOptions.Object, _httpClient, NullLogger <ChatyApiService> .Instance);
        }
 public void should_check_support_as_false(ChatyApiService service)
 {
     Assert.False(service.IsChatySupported(_userAllowedToUseChaty));
 }