public TimeEntryIntegrationTest() { Environment.SetEnvironmentVariable("MYSQL__CLIENT__CONNECTIONSTRING", DbTestSupport.TestDbConnectionString); DbTestSupport.ExecuteSql("TRUNCATE TABLE time_entries"); _testClient = IntegrationTestServer.Start().CreateClient(); }
public async Task ExecuteGETsInParallel() { var testServer = new IntegrationTestServer(); var semaphoreSlim = new SemaphoreSlim(4); var times = Enumerable.Range(0, 100); var trackedTasks = new List <Task>(); foreach (var time in times) { //await semaphoreSlim.WaitAsync(); trackedTasks.Add(Task.Run(async() => { var response = await testServer.GetAsync("api/characters/name/bowser/moves"); response.EnsureSuccessStatusCode(); string content = await response.Content.ReadAsStringAsync(); var parsedContent = JsonConvert.DeserializeObject <List <Move> >(content); Console.WriteLine($"request # {time} -> {parsedContent[0].Owner}"); Assert.That(parsedContent[0].Owner, Is.EqualTo("Bowser")); semaphoreSlim.Release(); })); } await Task.WhenAll(trackedTasks); }
public async Task ThenPagesReturnedCorrectly() { var totalTransfers = TestData.TransferPayments.Count; var expectedPages = (int)Math.Ceiling((double)totalTransfers / 10000); var lastPageCount = totalTransfers % 10000; var results = await IntegrationTestServer.GetInstance().Client.GetAsync("/api/transfers?page=1").ConfigureAwait(false); var resultsAsString = await results.Content.ReadAsStringAsync().ConfigureAwait(false); var items = JsonConvert.DeserializeObject <PageOfResults <AccountTransfer> >(resultsAsString); items.PageNumber.Should().Be(1); items.Items.Should().HaveCount(Math.Min(10000, totalTransfers)); results = await IntegrationTestServer.GetInstance().Client.GetAsync($"/api/transfers?page={expectedPages-1}").ConfigureAwait(false); resultsAsString = await results.Content.ReadAsStringAsync().ConfigureAwait(false); items = JsonConvert.DeserializeObject <PageOfResults <AccountTransfer> >(resultsAsString); items.PageNumber.Should().Be(expectedPages - 1); items.Items.Should().HaveCount(10000); results = await IntegrationTestServer.GetInstance().Client.GetAsync($"/api/transfers?page={expectedPages}").ConfigureAwait(false); resultsAsString = await results.Content.ReadAsStringAsync().ConfigureAwait(false); items = JsonConvert.DeserializeObject <PageOfResults <AccountTransfer> >(resultsAsString); items.PageNumber.Should().Be(expectedPages); items.Items.Should().HaveCount(lastPageCount); }
public async Task ThenTheDataIsReturnedCorrectly() { var totalExpected = TestData.TransferPayments.Count; var expectedPages = (int)Math.Ceiling((double)totalExpected / 10000); var expectedTransfer = TestData.TransferPayments.First(); var resultTransfers = new List <AccountTransfer>(); for (int i = 0; i < expectedPages; i++) { var results = await IntegrationTestServer.GetInstance().Client.GetAsync($"/api/transfers?page={i+1}").ConfigureAwait(false); var resultsAsString = await results.Content.ReadAsStringAsync().ConfigureAwait(false); var items = JsonConvert.DeserializeObject <PageOfResults <AccountTransfer> >(resultsAsString); resultTransfers.AddRange(items.Items); } resultTransfers.Should().Contain(x => x.RequiredPaymentId == expectedTransfer.RequiredPaymentEventId && x.Amount == expectedTransfer.Amount && x.CollectionPeriodName == $"{expectedTransfer.AcademicYear}-R{expectedTransfer.CollectionPeriod.ToString().PadLeft(2, '0')}" && x.CommitmentId == expectedTransfer.ApprenticeshipId && x.ReceiverAccountId == expectedTransfer.AccountId && x.SenderAccountId == expectedTransfer.TransferSenderAccountId && x.Type == TransferType.Levy ); }
public EnvIntegrationTest() { Environment.SetEnvironmentVariable("PORT", "123"); Environment.SetEnvironmentVariable("MEMORY_LIMIT", "512M"); Environment.SetEnvironmentVariable("CF_INSTANCE_INDEX", "1"); Environment.SetEnvironmentVariable("CF_INSTANCE_ADDR", "127.0.0.1"); _testClient = IntegrationTestServer.Start().CreateClient(); }
public async Task ThenTheNumberOfResultsIs10000() { var results = await IntegrationTestServer.GetInstance().Client.GetAsync("/api/payments").ConfigureAwait(false); var resultsAsString = await results.Content.ReadAsStringAsync().ConfigureAwait(false); var result = JsonConvert.DeserializeObject <PageOfResults <Payment> >(resultsAsString); result.Items.Should().HaveCount(10000); }
public async Task ThenTheNumberOfRecordsIsCorrectForCollectionPeriod() { var results = await IntegrationTestServer.GetInstance().Client.GetAsync($"/api/payments?PeriodId={TestData.AcademicYear}-R{TestData.CollectionPeriod:D2}").ConfigureAwait(false); var resultsAsString = await results.Content.ReadAsStringAsync().ConfigureAwait(false); var items = JsonConvert.DeserializeObject <PageOfResults <Payment> >(resultsAsString); items.Items.Length.Should().NotBe(0); items.Items.Should().HaveCount(10000); }
public async Task ThenTheResultsHaveEarningsInformation() { var results = await IntegrationTestServer.GetInstance().Client.GetAsync("/api/payments").ConfigureAwait(false); var resultsAsString = await results.Content.ReadAsStringAsync().ConfigureAwait(false); var result = JsonConvert.DeserializeObject <PageOfResults <Payment> >(resultsAsString); var randomItem = result.Items[new Random().Next(10000)]; randomItem.EarningDetails.Should().NotBeEmpty(); }
public async Task ThenTheNumberOfRecordsIsCorrect() { var periodCount = await TestData.GetPeriodCount(); var results = await IntegrationTestServer.GetInstance().Client.GetAsync("/api/periodends").ConfigureAwait(false); var resultsAsString = await results.Content.ReadAsStringAsync().ConfigureAwait(false); var items = JsonConvert.DeserializeObject <PeriodEnd[]>(resultsAsString); items.Length.Should().NotBe(0); items.Length.Should().Be(periodCount); }
public async Task ThenTheCountOfPaymentsWithRequiredRecordsIsCorrect() { var requiredPaymentsCount = await TestData.GetPaymentWithRequiredPaymentCount(); var results = await IntegrationTestServer.GetInstance().Client.GetAsync($"/api/v2/payments/statistics").ConfigureAwait(false); var resultsAsString = await results.Content.ReadAsStringAsync().ConfigureAwait(false); var items = JsonConvert.DeserializeObject <PaymentStatistics>(resultsAsString); items.TotalNumberOfPaymentsWithRequiredPayment.Should().Be(requiredPaymentsCount); items.TotalNumberOfPaymentsWithRequiredPayment.Should().NotBe(0); }
public async Task ThenTheNumberOfRecordsIsCorrectWhenNotFiltering() { var totalExpected = TestData.TransferPayments.Count; var expectedPages = (int)Math.Ceiling((double)totalExpected / 10000); var lastPageCount = totalExpected % 10000; var results = await IntegrationTestServer.GetInstance().Client.GetAsync($"/api/transfers?page={expectedPages}").ConfigureAwait(false); var resultsAsString = await results.Content.ReadAsStringAsync().ConfigureAwait(false); var items = JsonConvert.DeserializeObject <PageOfResults <AccountTransfer> >(resultsAsString); items.Items.Should().HaveCount(lastPageCount); }
public async Task ThenTheNumberOfRecordsIsCorrect() { var ukprn = TestData.Payments.First().Ukprn; var paymentCount = TestData.Payments.Count(x => x.Ukprn == ukprn); var results = await IntegrationTestServer.GetInstance().Client.GetAsync($"/api/payments?ukprn={ukprn}").ConfigureAwait(false); var resultsAsString = await results.Content.ReadAsStringAsync().ConfigureAwait(false); var items = JsonConvert.DeserializeObject <PageOfResults <Payment> >(resultsAsString); items.Items.Should().HaveCount(paymentCount); items.Items.Length.Should().NotBe(0); }
public async Task ThenTheNumberOfRecordsIsCorrectWhenFilteringByCollectionPeriod() { var totalExpected = TestData.TransferPayments.Count(x => x.AcademicYear == TestData.AcademicYear && x.CollectionPeriod == TestData.CollectionPeriod); var expectedPages = (int)Math.Ceiling((double)totalExpected / 10000); var lastPageCount = totalExpected % 10000; var results = await IntegrationTestServer.GetInstance().Client.GetAsync($"/api/transfers?periodId={TestData.AcademicYear}-R{TestData.CollectionPeriod.ToString().PadLeft(2, '0')}&page={expectedPages}").ConfigureAwait(false); var resultsAsString = await results.Content.ReadAsStringAsync().ConfigureAwait(false); var items = JsonConvert.DeserializeObject <PageOfResults <AccountTransfer> >(resultsAsString); items.Items.Should().HaveCount(lastPageCount); }
public async Task ThenTheDataIsCorrect() { var results = await IntegrationTestServer.GetInstance().Client.GetAsync($"/api/payments?employerAccountId={TestData.EmployerAccountId}").ConfigureAwait(false); var resultsAsString = await results.Content.ReadAsStringAsync().ConfigureAwait(false); var result = JsonConvert.DeserializeObject <PageOfResults <Payment> >(resultsAsString); for (var i = 0; i < 250; i++) { var randomReturnedPayment = result.Items[new Random().Next(10000)]; var matchingPayment = TestData.Payments.Single(x => x.EventId == Guid.Parse(randomReturnedPayment.Id)); randomReturnedPayment.Amount.Should().Be(matchingPayment.Amount); randomReturnedPayment.ApprenticeshipId.Should().Be(matchingPayment.ApprenticeshipId); randomReturnedPayment.CollectionPeriod.Month.Should().Be(PeriodExtensions.GetMonthFromPaymentEntity(matchingPayment.CollectionPeriod)); randomReturnedPayment.CollectionPeriod.Year.Should().Be(PeriodExtensions.GetYearFromPaymentEntity(matchingPayment.AcademicYear, matchingPayment.CollectionPeriod)); randomReturnedPayment.CollectionPeriod.Id.Should().Be(matchingPayment.GetPeriodId()); ((byte)randomReturnedPayment.ContractType).Should().Be(matchingPayment.ContractType); randomReturnedPayment.DeliveryPeriod.Month.Should().Be(PeriodExtensions.GetMonthFromPaymentEntity(matchingPayment.DeliveryPeriod)); randomReturnedPayment.DeliveryPeriod.Year.Should().Be(PeriodExtensions.GetYearFromPaymentEntity(matchingPayment.AcademicYear, matchingPayment.DeliveryPeriod)); randomReturnedPayment.EarningDetails.Count.Should().Be(1); var earningDetails = randomReturnedPayment.EarningDetails.Single(); earningDetails.ActualEndDate.Should().BeCloseTo(matchingPayment.EarningsActualEndDate.GetValueOrDefault(), 1000); earningDetails.CompletionAmount.Should().Be(matchingPayment.EarningsCompletionAmount); earningDetails.CompletionStatus.Should().Be(matchingPayment.EarningsCompletionStatus); earningDetails.EndpointAssessorId.Should().BeNull(); earningDetails.MonthlyInstallment.Should().Be(matchingPayment.EarningsInstalmentAmount); earningDetails.PlannedEndDate.Should().BeCloseTo(matchingPayment.EarningsPlannedEndDate.GetValueOrDefault(), 1000); earningDetails.RequiredPaymentId.Should().Be(matchingPayment.RequiredPaymentEventId.GetValueOrDefault()); earningDetails.StartDate.Should().BeCloseTo(matchingPayment.EarningsStartDate, 1000); earningDetails.TotalInstallments.Should().Be(matchingPayment.EarningsNumberOfInstalments); randomReturnedPayment.EmployerAccountId.Should().Be(matchingPayment.AccountId.ToString()); randomReturnedPayment.EmployerAccountVersion.Should().BeNullOrEmpty(); randomReturnedPayment.EvidenceSubmittedOn.Should().BeCloseTo(matchingPayment.IlrSubmissionDateTime, 1000); randomReturnedPayment.FrameworkCode.Should().Be(matchingPayment.LearningAimFrameworkCode); randomReturnedPayment.FundingAccountId.Should().BeNull(); ((byte)randomReturnedPayment.FundingSource).Should().Be(matchingPayment.FundingSource); //byte cast? randomReturnedPayment.Id.ToLower().Should().Be(matchingPayment.EventId.ToString().ToLower()); randomReturnedPayment.PathwayCode.Should().Be(matchingPayment.LearningAimPathwayCode); randomReturnedPayment.ProgrammeType.Should().Be(matchingPayment.LearningAimProgrammeType); randomReturnedPayment.StandardCode.Should().Be(matchingPayment.LearningAimStandardCode); ((byte)randomReturnedPayment.TransactionType).Should().Be(matchingPayment.TransactionType); //byte cast? randomReturnedPayment.Ukprn.Should().Be(matchingPayment.Ukprn); randomReturnedPayment.Uln.Should().Be(matchingPayment.LearnerUln); } }
public async Task ThenTheNumberOfPagesIsCorrect() { var paymentCount = await TestData.GetPaymentCount(); var remainder = paymentCount % 10000; var expectedPages = paymentCount / 10000; if (remainder > 0) { expectedPages++; } // Assuming 10000 per page var results = await IntegrationTestServer.GetInstance().Client.GetAsync("/api/payments").ConfigureAwait(false); var resultsAsString = await results.Content.ReadAsStringAsync().ConfigureAwait(false); var result = JsonConvert.DeserializeObject <PageOfResults <Payment> >(resultsAsString); result.TotalNumberOfPages.Should().Be(expectedPages); }
public async Task TearDown() { IntegrationTestServer.GetInstance().Shutdown(); await DatabaseCleanUp.DeleteTestPaymentRecords(); }
public Task TearDown() { IntegrationTestServer.Shutdown(); return(Task.CompletedTask); }
public WelcomeIntegrationTest() { Environment.SetEnvironmentVariable("WELCOME_MESSAGE", "hello from integration test"); _testClient = IntegrationTestServer.Start().CreateClient(); }