Пример #1
0
    public async Task Should_Not_Be_Authorized_On_Given_Record()
    {
        var id     = new LaunchRecordId(new Guid("bad361de-a6d5-425a-9cf6-f9b2dd236be6"));
        var client = new LaunchRecordClient(Factory.CreateClient());
        await ServiceProvider.WithScoped <RocketDbContext>()
        .Invoke(
            async z =>
        {
            var faker  = new RocketFaker();
            var rocket = faker.Generate();
            var record = new LaunchRecordFaker(new[] { rocket }.ToList()).Generate();
            z.Add(rocket);
            record.Id = id;
            z.Add(record);

            await z.SaveChangesAsync();
            return(record.Id);
        }
            );


        Func <Task> action = () => client.DeleteLaunchRecordAsync(id.Value);
        await action.Should().ThrowAsync <ApiException <ProblemDetails> >()
        .Where(z => z.StatusCode == 403 && z.Result.Status == 403 && z.Result.Title == "Forbidden");
    }
Пример #2
0
    public async Task Should_Not_Be_Authorized_On_Given_Record()
    {
        var id = new LaunchRecordId(new Guid("bad361de-a6d5-425a-9cf6-f9b2dd236be6"));
        await ServiceProvider.WithScoped <RocketDbContext>()
        .Invoke(
            async z =>
        {
            var faker  = new RocketFaker();
            var rocket = faker.Generate();
            var record = new LaunchRecordFaker(new[] { rocket }.ToList()).Generate();
            z.Add(rocket);
            record.Id = id;
            z.Add(record);

            await z.SaveChangesAsync();
            return(record.Id);
        }
            );

        Func <Task> action = () => ServiceProvider.WithScoped <IMediator>().Invoke(
            mediator => mediator.Send(new DeleteLaunchRecord.Request {
            Id = id
        })
            );
        await action.Should().ThrowAsync <NotAuthorizedException>();
    }
Пример #3
0
    public async Task Should_Remove_LaunchRecord()
    {
        var id = await ServiceProvider.WithScoped <RocketDbContext>()
                 .Invoke(
            async z =>
        {
            var faker  = new RocketFaker();
            var rocket = faker.Generate();
            var record = new LaunchRecordFaker(new[] { rocket }.ToList()).Generate();
            z.Add(rocket);
            z.Add(record);

            await z.SaveChangesAsync();
            return(record.Id);
        }
            );

        await ServiceProvider.WithScoped <IMediator>().Invoke(
            mediator => mediator.Send(new DeleteLaunchRecord.Request {
            Id = id
        })
            );

        ServiceProvider.WithScoped <RocketDbContext>().Invoke(c => c.LaunchRecords.Should().BeEmpty());
    }
Пример #4
0
    public async Task Should_List_Rockets()
    {
        var client = new RocketClient(Factory.CreateClient());
        await ServiceProvider.WithScoped <RocketDbContext>()
        .Invoke(
            async z =>
        {
            var faker = new RocketFaker();
            z.AddRange(faker.Generate(10));

            await z.SaveChangesAsync();
        }
            );

        var response = await client.ListRocketsAsync();

        response.Result.Should().HaveCount(10);
    }
    public async Task Should_List_Rockets()
    {
        await ServiceProvider.WithScoped <RocketDbContext>()
        .Invoke(
            async z =>
        {
            var faker = new RocketFaker();
            z.AddRange(faker.Generate(10));

            await z.SaveChangesAsync();
        }
            );

        var response = await ServiceProvider.WithScoped <IMediator>().Invoke(
            mediator => mediator.CreateStream(new ListRockets.Request(null)).ToListAsync()
            );

        response.Should().HaveCount(10);
    }
    public async Task Should_Remove_Rocket()
    {
        var client = new RocketClient(Factory.CreateClient());
        var id     = await ServiceProvider.WithScoped <RocketDbContext>()
                     .Invoke(
            async z =>
        {
            var faker  = new RocketFaker();
            var rocket = faker.Generate();
            z.Add(rocket);

            await z.SaveChangesAsync().ConfigureAwait(false);
            return(rocket.Id);
        }
            );

        await client.RemoveRocketAsync(id.Value);

        ServiceProvider.WithScoped <RocketDbContext>().Invoke(c => c.Rockets.Should().BeEmpty());
    }
Пример #7
0
    public async Task Should_List_Rockets()
    {
        var client = Factory.Services.GetRequiredService <IRocketClient>();
        await ServiceProvider.WithScoped <RocketDbContext>()
        .Invoke(
            async z =>
        {
            var faker = new RocketFaker();
            z.AddRange(faker.Generate(10));

            await z.SaveChangesAsync();
        }
            );

        var response = await client.GetRockets.ExecuteAsync();

        response.EnsureNoErrors();

        response.Data !.Rockets !.Nodes !.Should().HaveCount(10);
    }
Пример #8
0
    public async Task Should_Remove_LaunchRecord()
    {
        var client = new LaunchRecordClient(Factory.CreateClient());
        var id     = await ServiceProvider.WithScoped <RocketDbContext>()
                     .Invoke(
            async z =>
        {
            var faker  = new RocketFaker();
            var rocket = faker.Generate();
            var record = new LaunchRecordFaker(new[] { rocket }.ToList()).Generate();
            z.Add(rocket);
            z.Add(record);

            await z.SaveChangesAsync();
            return(record.Id);
        }
            );

        await client.DeleteLaunchRecordAsync(id.Value);

        ServiceProvider.WithScoped <RocketDbContext>().Invoke(c => c.LaunchRecords.Should().BeEmpty());
    }
Пример #9
0
    public async Task Should_ResponseMessage_When_MessageIsValid()
    {
        await _factory.Services.WithScoped <RocketDbContext>()
        .Invoke(
            async z =>
        {
            var faker   = new RocketFaker();
            var rockets = faker.Generate(3);
            var records = new LaunchRecordFaker(rockets).Generate(10);
            z.AddRange(rockets);
            z.AddRange(records);
            await z.SaveChangesAsync();
        }
            );

        // Given
        var client = new Grpc.Rockets.RocketsClient(_factory.CreateGrpcChannel());

        // When
        var response = await client.ListRockets(new ListRocketsRequest()).ResponseStream.ReadAllAsync().ToListAsync();

        // Then nothing happen.
        response.Should().HaveCountGreaterThan(0);
    }