예제 #1
0
        private static (AliyunSmsSender, StubHttpClient) CreateSmsSender()
        {
            var options = new AliyunSmsOptions()
            {
                AccessKeySecret        = "dummy-secret",
                AccountKeyId           = "dummy-key",
                SmsServiceSignName     = "dotnetclub.net",
                SmsServiceTemplateCode = "SA873dK"
            };
            var optionsMock = new Mock <IOptions <AliyunSmsOptions> >();

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

            var client = StubHttpClient.Create().When(req =>
            {
                var response = new AliyunSmsResponse()
                {
                    RequestId = Guid.NewGuid().ToString(),
                    Code      = "OK",
                    Message   = "Sms Sent",
                    BizId     = Guid.NewGuid().ToString()
                };
                return(JsonResponse(response));
            });

            var smsSender = new AliyunSmsSender(optionsMock.Object, client, new SystemClock());

            return(smsSender, client);
        }
        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>();
        }