public void Setup()
        {
            _factory = new ApiWebApplicationFactory();
            var http = _factory.CreateClient();

            _apiClient = new ApiTestClient(http);
        }
 public void GivenInitClient()
 {
     _factory = new ApiWebApplicationFactory();
     _client  = _factory.CreateClient();
     _currencyAutomatedTestHelper = new CurrencyAutomatedTestHelper(_client);
     _currencyAutomatedTestHelper.GenerateTokenString();
 }
        public void GivenARequestToTheController()
        {
            _factory    = new ApiWebApplicationFactory();
            _httpClient = _factory.CreateClient();

            _httpClient
            .DefaultRequestHeaders
            .Accept
            .Add(new MediaTypeWithQualityHeaderValue("application/json"));
        }
Exemple #4
0
        protected ApiTestBase(ApiWebApplicationFactory <Startup> factory)
        {
            Factory = factory;

            Client = factory.CreateClient(new WebApplicationFactoryClientOptions
            {
                AllowAutoRedirect = false
            });

            Client.BaseAddress = new Uri("https://localhost:44319");
            Client.DefaultRequestHeaders
            .Accept
            .Add(new MediaTypeWithQualityHeaderValue("application/json"));     //ACCEPT header
        }
Exemple #5
0
        public void Setup()
        {
            _factory = new ApiWebApplicationFactory();
            _client  = _factory.CreateClient();

            pdfs    = DataGenerator.GetPdfs();
            options = new DbContextOptionsBuilder <PdfContext>()
                      .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()) // Needs to be torn down fully for each test
                      .EnableSensitiveDataLogging(true)
                      .Options;

            mockService = new Mock <IPdfService>();
            mockLogger  = new Mock <ILogger <PdfController> >();

            var list = new List <Pdf>();

            trueGuid  = new Guid("7e7ceb51-37e0-4ebb-897c-ce801b0e37fe");
            falseGuid = new Guid("12345678901234567890123456789011");
            validPdf  = new Pdf()
            {
                Id = trueGuid
            };
            invalidPdf = new Pdf()
            {
                Id = falseGuid
            };

            mockService.Setup(repo => repo.GetPdfs(FileOrder.NameAscending)).ReturnsAsync(list);

            mockService.Setup(repo => repo.GetPdf(trueGuid)).ReturnsAsync(validPdf);
            mockService.Setup(repo => repo.GetPdf(falseGuid)).ReturnsAsync((Pdf)null);


            mockService.Setup(repo => repo.InsertPdf(validPdf)).Returns(Task.FromResult(1));
            mockService.Setup(repo => repo.InsertPdf(invalidPdf)).Returns(Task.FromResult(0));


            mockService.Setup(repo => repo.DeletePdf(trueGuid)).Throws(new Exception($"Pdf '{trueGuid}' is active, can't be deleted"));
            mockService.Setup(repo => repo.DeletePdf(falseGuid)).Returns(Task.FromResult(invalidPdf));


            controller = new PdfController(mockLogger.Object, mockService.Object);
        }
Exemple #6
0
        public void Setup()
        {
            _factory = new ApiWebApplicationFactory();
            _client  = _factory.CreateClient();

            var getResponse    = _client.GetAsync("/api/pdf?order=NameDescending").Result;
            var stringResponse = getResponse.Content.ReadAsStringAsync().Result;

            pdfs = JsonConvert.DeserializeObject <List <Pdf> >(stringResponse);

            if (!pdfs.Any())
            {
                var    fileName = "pdf.pdf";
                var    io       = File.Open(fileName, FileMode.Open);
                byte[] Bytes    = new byte[io.Length + 1];
                io.Read(Bytes, 0, Bytes.Length);

                using (var content = new MultipartFormDataContent())
                {
                    var fileContent = new ByteArrayContent(Bytes);

                    fileContent.Headers.ContentDisposition
                        = new System.Net.Http.Headers.ContentDispositionHeaderValue("form-data")
                        {
                        FileName = "1" + fileName
                        };
                    content.Add(fileContent);
                    var response1 = _client.PostAsync("/api/pdf", content).Result;

                    fileContent.Headers.ContentDisposition
                        = new System.Net.Http.Headers.ContentDispositionHeaderValue("form-data")
                        {
                        FileName = "2" + fileName
                        };
                    var response2 = _client.PostAsync("/api/pdf", content).Result;

                    var allResponse       = _client.GetAsync("/api/pdf?order=NameDescending").Result;
                    var allStringResponse = allResponse.Content.ReadAsStringAsync().Result;
                    pdfs     = JsonConvert.DeserializeObject <List <Pdf> >(allStringResponse);
                    trueGuid = pdfs.First().Id;
                }
            }
        }
Exemple #7
0
 public IntegrationTestWithDatabase()
 {
     dbFixture  = new DbFixture();
     factory    = new ApiWebApplicationFactory(ConfigureWebHostBuilder());
     httpClient = factory.CreateClient();
 }
Exemple #8
0
 public ApiIntegrationTest(ApiWebApplicationFactory <Startup> factory)
 {
     Client = factory.CreateClient();
 }
Exemple #9
0
 public static void InitOnce(TestContext context)
 {
     Factory = new ApiWebApplicationFactory();
     Client  = Factory.CreateClient();
     Client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Test");
 }
 public IntegrationTest()
 {
     factory    = new ApiWebApplicationFactory();
     httpClient = factory.CreateClient();
 }
Exemple #11
0
 public void GivenARequestToTheController()
 {
     _factory            = new ApiWebApplicationFactory();
     _client             = _factory.CreateClient();
     _client.BaseAddress = new Uri("https://localhost:44349/");
 }
Exemple #12
0
 public void Setup()
 {
     _factory    = new ApiWebApplicationFactory();
     _httpClient = _factory.CreateClient();
 }
Exemple #13
0
 public void OnetimeSetup()
 {
     factory = new ApiWebApplicationFactory();
     client  = factory.CreateClient();
 }
 public void GivenARequestToTheController()
 {
     _factory = new ApiWebApplicationFactory();
     _client  = _factory.CreateClient();
 }