public EmployeesControllerIntegrationTests(TestWebApplicationFactory <Startup> factory)
        {
            _httpClientHelper = new HttpClientHelper(factory.CreateDefaultClient());
            var repository = new EmployeeRepository(factory.Context, new LoggerFactory());

            _controller = new EmployeesController(repository);
        }
        public BaseIntegrationTest()
        {
            var factory = new TestWebApplicationFactory <Startup>();

            Client      = factory.CreateClient();
            DataContext = factory.DataContext ?? throw new Exception("Failed to initialise the test data context");
        }
예제 #3
0
        public EngineRoutesSteps(TestWebApplicationFactory factory)

        {
            var engine = new MyEngine
            {
                //Id = "6048d0b57757e1f98eb48273",
                Id = new ObjectId(timestamp: 1617721631, machine: 7894647, pid: 13311, increment: 5403081),
                /*, creationTime: "2021-04-06T15:07:11Z"*/
                Code       = 16,
                Name       = "Beuate",
                IsEnable   = true,
                SearchText = "string",
                Scopes     = new List <Scope> {
                    new Scope {
                        ScopeId = 2, Name = "string", Order = 0, IsEnable = true
                    }
                },
                InputFields = new List <InputField> {
                    new InputField {
                        InputId = 1, IsEnable = true, IsMandatory = true, Label = "string", Order = 0, Type = "string", Parameters = new List <Parameter> {
                            new Parameter {
                                ScopeParameterId = 1, ExternalCodeId = 0, Order = 0, Label = "string"
                            }
                        }
                    }
                },
                BackGroundImages = new List <BackGroundImage> {
                    new BackGroundImage {
                        Alt = "string", IsEnable = true, OpenInNewTab = true, Order = 0, UrlImageDesktop = "string", UrlLinkDesktop = "string", UrlImageMobile = "string", UrlLinkMobile = "string"
                    }
                },
                Logo = new List <Logo> {
                    new Logo {
                        UrlImageDesktop = "string", UrlLinkDesktop = "string", UrlImageMobile = "string", UrlLinkMobile = "string", Alt = "string", IsEnable = true, OpenInNewTab = true
                    }
                },
                MarketingText = new List <MarketingText> {
                    new MarketingText {
                        IsEnable = true, Text = "string"
                    }
                }
            };

            _engineReadRepository.Setup(r => r.CreateEngine(engine)).Returns(_inMemoryEngineReadRepository.CreateEngine(engine));
            _engineReadRepository.Setup(r => r.GetEngineById(It.IsIn(16))).Returns(_inMemoryEngineReadRepository.GetEngineById(16));
            _engineReadRepository.Setup(r => r.GetEngines()).Returns(_inMemoryEngineReadRepository.GetEngines());
            _engineReadRepository.Setup(r => r.DeleteEngine(It.IsIn(16))).Returns(_inMemoryEngineReadRepository.DeleteEngine(16));
            _engineReadRepository.Setup(r => r.UpdateEngine(It.IsIn(16), engine)).Returns(_inMemoryEngineReadRepository.UpdateEngine(16, engine));

            _factory = factory.WithWebHostBuilder(
                builder => builder.ConfigureTestServices(
                    services =>
            {
                services.AddScoped(ser => _engineReadRepository);
                services.AddScoped(ser => _engineReadRepository.Object);
            }));


            _client = _factory.CreateClient();
        }
 public SubmissionCrawlerCoordinatorTests(
     TestWebApplicationFactory <Startup> factory,
     ITestOutputHelper outputHelper) : base(factory, outputHelper)
 {
     _coordinator = Factory.Services.GetService <SubmissionCrawlerCoordinator>();
     _crawlerMock = new CrawlerMock();
 }
예제 #5
0
    public async Task DecodeRelaxedWhenEncodingIsSupported()
    {
        await using var factory = new TestWebApplicationFactory <TestWebApplicationStartup>()
                                  .WithWebHostBuilder(builder =>
        {
            builder.ConfigureTestServices(services =>
            {
                services.AddRequestDecompression();
            });
        });

        using var client = factory.CreateClient();

        var requestString  = "Hello World!";
        var requestContent = new ByteArrayContent(AsBrotliEncodedByteArray(requestString));

        requestContent.Headers.ContentEncoding.Add("br");

        var responseMessage = await client.PostAsync("/", requestContent);

        var responseString = await responseMessage.Content.ReadAsStringAsync();

        responseMessage.Headers.TryGetValues(HeaderNames.AcceptEncoding, out var acceptEncoding);

        Assert.AreEqual(HttpStatusCode.OK, responseMessage.StatusCode);
        Assert.AreEqual(requestString, responseString);
        Assert.IsNull(acceptEncoding);
    }
예제 #6
0
        public OrdersAPITests(IntegrationTestFixture integrationTestFixture)
        {
            _context = integrationTestFixture.Context;
            _webApplicationFactory = integrationTestFixture.WebApplicationFactory;

            integrationTestFixture.Dispose(); // clean data before each test
        }
예제 #7
0
        public void GivenIAmAEmployerUsingTheReservationService()
        {
            var testData = new TestData
            {
                AccountLegalEntity = new AccountLegalEntity
                {
                    AccountId                        = TestDataValues.NonLevyAccountId,
                    AccountLegalEntityId             = TestDataValues.NonLevyAccountLegalEntityId,
                    AccountLegalEntityPublicHashedId = TestDataValues.NonLevyHashedAccountLegalEntityId,
                    AccountLegalEntityName           = "Test Legal Entity",
                    IsLevy        = false,
                    LegalEntityId = 1
                }
            };

            _factory = new TestWebApplicationFactory("employer");
            _client  = _factory.WithWebHostBuilder(builder =>
            {
                builder.ConfigureServices(collection =>
                                          collection.ConfigureTestServiceCollection(
                                              _factory.ConfigurationRoot, testData));
                builder.ConfigureTestServices(services =>
                {
                    services.AddAuthentication("IntegrationTest")
                    .AddScheme <TestAuthenticationSchemeOptions, TestAuthenticationHandler>(
                        "IntegrationTest", options => { options.EmployerAccountId = TestDataValues.NonLevyHashedAccountId; });
                });
            }).CreateClient();
            _client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("IntegrationTest");
        }
예제 #8
0
    public async Task DecodeRelaxedWhenEncodingIsNotSupportedAndAdvertized()
    {
        await using var factory = new TestWebApplicationFactory <TestWebApplicationStartup>()
                                  .WithWebHostBuilder(builder =>
        {
            builder.ConfigureTestServices(services =>
            {
                services.AddRequestDecompression(options =>
                {
                    Assert.IsTrue(options.AllowUnsupportedEncodings);
                    Assert.IsFalse(options.AdvertiseSupportedEncodings);

                    options.AdvertiseSupportedEncodings = true;
                });
            });
        });

        using var client = factory.CreateClient();

        var requestString  = "Hello World!";
        var requestContent = new StringContent(requestString);

        requestContent.Headers.ContentEncoding.Add("deflate");

        var responseMessage = await client.PostAsync("/", requestContent);

        var responseString = await responseMessage.Content.ReadAsStringAsync();

        responseMessage.Headers.TryGetValues(HeaderNames.AcceptEncoding, out var acceptEncoding);

        Assert.AreEqual(HttpStatusCode.OK, responseMessage.StatusCode);
        Assert.IsNull(acceptEncoding);
    }
예제 #9
0
 public DatabaseInserterTests(TestWebApplicationFactory <Startup> factory, ITestOutputHelper outputHelper) : base(
         factory, outputHelper)
 {
     _inserter = Factory.Services
                 .GetService <DatabaseInserterFactory>()
                 .CreateInstance <Submission>();
 }
 public CustomersControllerTests(
     //WebApplicationFactory<Startup> factory  // Postgres
     TestWebApplicationFactory <Startup> factory // SqlLite
     )
 {
     _factory = factory;
 }
 public ClaimsPrincipalValidatorTests(
     DbDependentTestApplicationFactory appFactory,
     TestWebApplicationFactory webApplicationFactory
     )
 {
     _appFactory            = appFactory;
     _webApplicationFactory = webApplicationFactory;
 }
예제 #12
0
 public WidgetTest(TestWebApplicationFactory <Startup> fixture, ITestOutputHelper testOutputHelper)
 {
     this.fixture          = fixture;
     this.testOutputHelper = testOutputHelper;
     testServerClient      = fixture.CreateClient(new WebApplicationFactoryClientOptions {
         AllowAutoRedirect = false
     });
 }
 protected CRUDClient(TestWebApplicationFactory <Startup> factory, string relativeUrl)
 {
     _client = factory.CreateClient(new WebApplicationFactoryClientOptions
     {
         AllowAutoRedirect = false
     });
     absoluteUri = new Uri(_client.BaseAddress, relativeUrl);
 }
예제 #14
0
 public HttpTestClient()
 {
     TestWebApplicationFactory = new TestWebApplicationFactory();
     DefaultClient             = GetDefaultClient();
     AdminClient          = GetAdminClient();
     AuthorClient         = GetAuthorClient();
     InactiveAuthorClient = GetInactiveAuthorClient();
 }
예제 #15
0
 public CofoundryPagesControllerTests(
     DbDependentTestApplicationFactory appFactory,
     TestWebApplicationFactory webApplicationFactory
     )
 {
     _appFactory            = appFactory;
     _webApplicationFactory = webApplicationFactory;
 }
 public AuthorizeUserAreaAttributeTests(
     DbDependentTestApplicationFactory appFactory,
     TestWebApplicationFactory webApplicationFactory
     )
 {
     _appFactory            = appFactory;
     _webApplicationFactory = webApplicationFactory;
 }
 public ProblemControllerTests(
     TestWebApplicationFactory <Startup> factory,
     ITestOutputHelper outputHelper) : base(factory, outputHelper)
 {
     // to make Flurl test work correctly
     // see https://github.com/tmenier/Flurl/issues/504#issuecomment-601817280
     Factory.Server.PreserveExecutionContext = true;
 }
예제 #18
0
 public CategoryTest(
     TestWebApplicationFactory factory,
     ITestOutputHelper output
     ) : base(factory, output)
 {
     Command = new CategoryCommand
     {
         Title = "Category"
     };
 }
        public EstimateTaskControllerTest(TestWebApplicationFactory <DocumentsKM.Startup> factory)
        {
            _httpClient = factory.WithWebHostBuilder(builder =>
            {
                builder.ConfigureTestServices(services =>
                {
                    services.AddSingleton <IPolicyEvaluator, FakePolicyEvaluator>();
                });
            }).CreateClient();

            _authHttpClient = factory.CreateClient();
        }
예제 #20
0
        public BaseServiceTest(TestWebApplicationFactory <Startup> factory, ETestType type = ETestType.Empty)
        {
            if (factory is null)
            {
                return;
            }
            _factory = factory.WithWebHostBuilder(builder =>
            {
                builder.ConfigureTestServices(services =>
                {
                    services.AddMoqRepository(type);
                });
            });

            _serviceScope = _factory.Services.CreateScope();
        }
예제 #21
0
        public void Setup()
        {
            var factory = new TestWebApplicationFactory <FirewallStartup>(async context =>
            {
                await context.Response.SetBodyFromStringAsync("Hello world!");
            });

            client = factory.CreateDefaultClient();

            var simpleFactory = new TestWebApplicationFactory <SimpleStartup>(async context =>
            {
                await context.Response.SetBodyFromStringAsync("Hello world!");
            });

            simpleClient = simpleFactory.CreateDefaultClient();
        }
        // Define your mocks here so you can access them in your test classes
        // fe: public readonly Mock<IMocked> MockedMock;

        public TestBaseFixture()
        {
            this.factory = new TestWebApplicationFactory <StarterKit.Startup.Startup>();

            // Transaction scope is running into issues in .net core 3.1
            // https://github.com/dotnet/aspnetcore/issues/18001
            factory.Server.PreserveExecutionContext = true;

            this.Client = factory.CreateClient();

            using var scope      = factory.Server.Host.Services.CreateScope();
            this.serviceProvider = factory.Server.Host.Services;

            // Initialize your mock in scope. Helper method AddMock will get the required mock from the service.
            // this.MockedMock = AddMock<IMocked>(scope);
        }
예제 #23
0
        public FileControllerTests(TestWebApplicationFactory <Startup> factory)
        {
            _authenticationContext = new AuthenticationContext
            {
                EmailKey      = "Input.Email",
                EmailValue    = "*****@*****.**",
                PasswordKey   = "Input.Password",
                PasswordValue = "demo",
                LoginUri      = "Account/login?returnUrl=/admin"
            };

            _factory = factory;
            _client  = _factory.CreateClient(new WebApplicationFactoryClientOptions {
                AllowAutoRedirect = false
            });
        }
예제 #24
0
        public ProductTest
        (
            TestWebApplicationFactory factory,
            ITestOutputHelper output
        ) : base(factory, output)
        {
            var category = CategoryGenerator.GenerateAndSave(CategoryRepository);

            Command = new ProductCreateCommand
            {
                Title       = "Product Title",
                Description = "Product description",
                Price       = 150,
                Quantity    = 10,
                CategoryId  = category.Id
            };
        }
예제 #25
0
        public async Task Index_WhenHostingEnvironmentIsNotDevelopment_RedirectToSignIn()
        {
            // Arrange
            var client = new TestWebApplicationFactory().CreateClient(
                new WebApplicationFactoryClientOptions
            {
                AllowAutoRedirect = false
            }
                );

            // Act
            var response = await client.GetAsync("/");

            // Assert
            Assert.Equal(HttpStatusCode.Redirect, response.StatusCode);
            Assert.Equal("/SignIn", response.Headers.Location.OriginalString);
        }
예제 #26
0
        public void Setup()
        {
            _factory = new TestWebApplicationFactory();
            _client  = _factory.CreateClient(new WebApplicationFactoryClientOptions
            {
                // here some sample options like security tokens etc...
            });
            var services = _factory.Server.Host.Services;

            _context = services.GetRequiredService <ApplicationDbContext>();
            _mapper  = services.GetRequiredService <IMapper>();
            var databaseInitializer = services.GetRequiredService <IDatabaseInitializer>();

            databaseInitializer.SeedAsync().Wait();
            JsonConvert.DefaultSettings = () => new JsonSerializerSettings
            {
                ReferenceLoopHandling = ReferenceLoopHandling.Ignore
            };
        }
예제 #27
0
        public BaseControllerTest(TestWebApplicationFactory <Startup> factory, ETestType type = ETestType.Empty)
        {
            if (factory is null)
            {
                return;
            }
            _factory = factory.WithWebHostBuilder(builder =>
            {
                builder.ConfigureTestServices(services =>
                {
                    services.AddMoqRepository(type);
                    services.AddMoqService(type);
                });
            });

            GetClient = _factory.CreateClient(new WebApplicationFactoryClientOptions
            {
                AllowAutoRedirect = false,
            });

            _serviceScope = _factory.Services.CreateScope();
        }
 public WatchFunctionIntegrationTests(
     TestWebApplicationFactory <TestStartup> factory)
 {
     _factory = factory;
 }
예제 #29
0
 public HealthControllerTests(TestWebApplicationFactory <Startup> factory)
 {
     _factory = factory;
 }
예제 #30
0
 public RolesApiTests(TestWebApplicationFactory <Startup> factory)
 {
     _factory = factory;
 }