コード例 #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FileController"/> class.
 /// </summary>
 /// <param name="logger">The logger<see cref="ILogger{FileController}"/>.</param>
 /// <param name="loadBalancerFactory">Load-Balancer factory<see cref="ILoadBalancerFactory"/>.</param>
 public FileController(
     ILogger <FileController> logger,
     ILoadBalancerFactory loadBalancerFactory,
     IFileHttpClient fileHttpClient)
 {
     _logger = logger;
     _loadBalancerFactory = loadBalancerFactory;
     _fileHttpClient      = fileHttpClient;
 }
コード例 #2
0
        public async Task Get_EmptyUri_BadRequest()
        {
            ILogger <FileController> _loggerStub    = Substitute.For <ILogger <FileController> >();
            ILoadBalancerFactory     factoryStub    = Substitute.For <ILoadBalancerFactory>();
            IFileHttpClient          fileClientStub = Substitute.For <IFileHttpClient>();

            var controller = new FileController(_loggerStub, factoryStub, fileClientStub);
            var result     = await controller.Get("");

            Assert.IsTrue(result is BadRequestResult);
        }
コード例 #3
0
        public async Task Get_InternalError_StatusCode500()
        {
            ILogger <FileController> _loggerStub = Substitute.For <ILogger <FileController> >();
            ILoadBalancerFactory     factoryStub = Substitute.For <ILoadBalancerFactory>();

            factoryStub.GetInstance().Throws(new Exception("Something wrong"));
            IFileHttpClient fileClientStub = Substitute.For <IFileHttpClient>();

            var controller = new FileController(_loggerStub, factoryStub, fileClientStub);
            var result     = await controller.Get("/something/error");

            Assert.IsTrue(result is StatusCodeResult);
            StatusCodeResult resultWithCode = result as StatusCodeResult;

            Assert.AreEqual(500, resultWithCode.StatusCode);
        }
コード例 #4
0
        public async Task Get_CorrectUri_FileResult()
        {
            ILogger <FileController> _loggerStub = Substitute.For <ILogger <FileController> >();
            ILoadBalancerFactory     factoryStub = Substitute.For <ILoadBalancerFactory>();

            factoryStub.GetInstance().Returns(new InstanceTarget {
                Ip = "localhost", Port = 1000
            });
            IFileHttpClient fileClientStub = Substitute.For <IFileHttpClient>();

            fileClientStub.GetAsync(Arg.Any <string>(), Arg.Any <string>()).Returns(Task.FromResult(
                                                                                        new DownloadFile {
                Content = Encoding.UTF8.GetBytes("Test"), FileName = "Test.bin"
            }));

            var controller = new FileController(_loggerStub, factoryStub, fileClientStub);
            var result     = await controller.Get("/src/comicbook");

            Assert.IsTrue(result is FileResult);
        }