public UrlControllerTest(TestHost <Startup> server) { this.server = server; client = server.CreateClient(new WebApplicationFactoryClientOptions { AllowAutoRedirect = false }); }
public async Task ShouldBeHttpStatusCodeOK() { var users = TestData.FileStorage.GetUsers(); var user = users.First(); user.Profile = null; _httpClient = TestHost.CreateClient(); var testServer = TestHost.Server; testServer.CleanupDbContext(); await testServer.UsingScopeAsync( async scope => { var userManager = scope.GetRequiredService <IUserService>(); var result = await userManager.CreateAsync(user); result.Succeeded.Should().BeTrue(); }); // Act using var response = await this.ExecuteAsync( new ForgotPasswordRequest { Email = "*****@*****.**" }); // Assert response.EnsureSuccessStatusCode(); response.StatusCode.Should().Be(HttpStatusCode.OK); }
public async Task Scenario_ChallengeStateIsValid_ShouldBeTrue(int seed) { // Arrange var faker = new Faker(); var challengeFaker = TestData.FakerFactory.CreateChallengeFaker(seed, Game.LeagueOfLegends, ChallengeState.Inscription); var fakeChallenge = challengeFaker.FakeChallenge(); TestHost.CreateClient(); var testServer = TestHost.Server; testServer.CleanupDbContext(); await testServer.UsingScopeAsync( async scope => { var challengeRepository = scope.GetRequiredService <IChallengeRepository>(); challengeRepository.Create(fakeChallenge); await challengeRepository.CommitAsync(false); }); // Assert await testServer.UsingScopeAsync( async scope => { var challengeRepository = scope.GetRequiredService <IChallengeRepository>(); var challenge = await challengeRepository.FindChallengeOrNullAsync(fakeChallenge.Id); challenge.Should().NotBeNull(); challenge?.Should().Be(fakeChallenge); challenge?.Timeline.State.Should().Be(ChallengeState.Inscription); }); var participant1 = new Participant( new ParticipantId(), new UserId(), PlayerId.Parse(Guid.NewGuid().ToString()), new UtcNowDateTimeProvider()); // Act await testServer.UsingScopeAsync( async scope => { var challengeRepository = scope.GetRequiredService <IChallengeRepository>(); var challenge = await challengeRepository.FindChallengeOrNullAsync(fakeChallenge.Id); challenge.Should().NotBeNull(); challenge?.Register(participant1); await challengeRepository.CommitAsync(false); }); // Assert await testServer.UsingScopeAsync( async scope => { var challengeRepository = scope.GetRequiredService <IChallengeRepository>(); var challenge = await challengeRepository.FindChallengeOrNullAsync(fakeChallenge.Id); challenge.Should().NotBeNull(); challenge?.Participants.Should().Contain(participant1); challenge?.Timeline.State.Should().Be(ChallengeState.Inscription); }); // Act await testServer.UsingScopeAsync( async scope => { var challengeRepository = scope.GetRequiredService <IChallengeRepository>(); var challenge = await challengeRepository.FindChallengeOrNullAsync(fakeChallenge.Id); challenge.Should().NotBeNull(); var entries = challenge?.Entries - challenge?.Participants.Count; for (var index = 0; index < entries; index++) { challenge?.Register( new Participant( new ParticipantId(), new UserId(), PlayerId.Parse(Guid.NewGuid().ToString()), new UtcNowDateTimeProvider())); } challenge?.Start(new UtcNowDateTimeProvider()); await challengeRepository.CommitAsync(false); }); // Assert await testServer.UsingScopeAsync( async scope => { var challengeRepository = scope.GetRequiredService <IChallengeRepository>(); var challenge = await challengeRepository.FindChallengeOrNullAsync(fakeChallenge.Id); challenge.Should().NotBeNull(); challenge?.Participants.Should().HaveCount(challenge.Entries); challenge?.Timeline.State.Should().Be(ChallengeState.InProgress); }); var match1 = new Match( new GameUuid(Guid.NewGuid()), new UtcNowDateTimeProvider(), TimeSpan.FromSeconds(3600), fakeChallenge.Scoring.Map(faker.Game().Stats()), new UtcNowDateTimeProvider()); // Act await testServer.UsingScopeAsync( async scope => { var challengeRepository = scope.GetRequiredService <IChallengeRepository>(); var challenge = await challengeRepository.FindChallengeOrNullAsync(fakeChallenge.Id); challenge.Should().NotBeNull(); var participant = challenge?.Participants.Single(p => p == participant1); participant?.Snapshot( new List <IMatch> { match1 }, new UtcNowDateTimeProvider()); await challengeRepository.CommitAsync(false); }); // Assert await testServer.UsingScopeAsync( async scope => { var challengeRepository = scope.GetRequiredService <IChallengeRepository>(); var challenge = await challengeRepository.FindChallengeOrNullAsync(fakeChallenge.Id); challenge.Should().NotBeNull(); var participant = challenge?.Participants.Single(p => p == participant1); participant?.Matches.Should().Contain(match1); participant?.SynchronizedAt.Should().NotBeNull(); challenge?.Timeline.State.Should().Be(ChallengeState.InProgress); }); var match2 = new Match( new GameUuid(Guid.NewGuid()), new UtcNowDateTimeProvider(), TimeSpan.FromSeconds(3600), new List <Stat> { new Stat(new StatName(fakeChallenge.Game.Name), new StatValue(23847883M), new StatWeighting(1)) }, new UtcNowDateTimeProvider()); // Act await testServer.UsingScopeAsync( async scope => { var challengeRepository = scope.GetRequiredService <IChallengeRepository>(); var challenge = await challengeRepository.FindChallengeOrNullAsync(fakeChallenge.Id); challenge.Should().NotBeNull(); var participant = challenge?.Participants.Single(p => p == participant1); participant?.Snapshot( new List <IMatch> { match2 }, new UtcNowDateTimeProvider()); await challengeRepository.CommitAsync(false); }); // Assert await testServer.UsingScopeAsync( async scope => { var challengeRepository = scope.GetRequiredService <IChallengeRepository>(); var challenge = await challengeRepository.FindChallengeOrNullAsync(fakeChallenge.Id); challenge.Should().NotBeNull(); var participant = challenge?.Participants.Single(p => p == participant1); participant?.Matches.Should().BeEquivalentTo(match1, match2); participant?.SynchronizedAt.Should().NotBeNull(); challenge?.Timeline.State.Should().Be(ChallengeState.InProgress); }); }
private static async Task<string> SendAndGetCookie(TestHost.TestServer server, string uri) { var request = new HttpRequestMessage(HttpMethod.Get, uri); var response = await server.CreateClient().SendAsync(request); if (response.Headers.Contains("Set-Cookie")) { return response.Headers.GetValues("Set-Cookie").ToList().First(); } return null; }
public void AttractionApiTestSetup() { _server = new TestHost <Startup>(); _client = _server.CreateClient(); }