Example #1
0
            public Task Clash()
            {
                var rocketId        = RocketId.From(2);
                var landingPosition = LandingPosition.From(new Position(5, 5));

                return(_landingTrajectoryVerifier.VerifyPosition(rocketId, landingPosition));
            }
Example #2
0
            public Task LandOutsideOfPlatform()
            {
                var rocketId        = RocketId.From(1);
                var landingPosition = LandingPosition.From(new Position(1, 1));

                return(_landingTrajectoryVerifier.VerifyPosition(rocketId, landingPosition));
            }
Example #3
0
        private LandingCheck GetPreviousLandingCheck(RocketId currentRocketId, DateTime currentTimestamp)
        {
            LandingCheck previousLandingCheck = null;

            foreach (var(rocketId, landingCheck) in _landingChecks)
            {
                if (IsSameRocket(currentRocketId, rocketId))
                {
                    continue;
                }

                if (IsAfterCurrentCheck(currentTimestamp, landingCheck))
                {
                    continue;
                }

                if (IsOlderThanAlreadyFound(previousLandingCheck, landingCheck))
                {
                    continue;
                }

                previousLandingCheck = landingCheck;
            }

            return(previousLandingCheck);
        }
Example #4
0
 public ShouldValidateUsersRequiredFieldData()
 {
     Add(
         new EditRocket.Request
     {
         Id = RocketId.New()
     }, nameof(EditRocket.Request.SerialNumber)
         );
     Add(
         new EditRocket.Request
     {
         Id           = RocketId.New(),
         SerialNumber = Faker.Random.String2(0, 9)
     },
         nameof(EditRocket.Request.SerialNumber)
         );
     Add(
         new EditRocket.Request
     {
         Id           = RocketId.New(),
         SerialNumber = Faker.Random.String2(600, 800)
     },
         nameof(EditRocket.Request.SerialNumber)
         );
 }
Example #5
0
            public async Task GlobalSetup()
            {
                var rocketId        = RocketId.From(1);
                var landingPosition = LandingPosition.From(new Position(5, 5));

                await _landingTrajectoryVerifier.VerifyPosition(rocketId, landingPosition);
            }
    public async Task Should_Get_A_LaunchRecord()
    {
        var client = Factory.Services.GetRequiredService <IRocketClient>();
        var record = await ServiceProvider.WithScoped <RocketDbContext, IClock>()
                     .Invoke(
            async(context, clock) =>
        {
            var rocket = new ReadyRocket
            {
                Id           = RocketId.New(),
                Type         = CoreRocketType.Falcon9,
                SerialNumber = "12345678901234"
            };

            var record = new LaunchRecord
            {
                Partner             = "partner",
                Payload             = "geo-fence-ftl",
                RocketId            = rocket.Id,
                ScheduledLaunchDate = clock.GetCurrentInstant().ToDateTimeOffset(),
                PayloadWeightKg     = 100,
            };
            context.Add(rocket);
            context.Add(record);

            await context.SaveChangesAsync();
            return(record);
        }
            );

        var response = await client.GetLaunchRecord.ExecuteAsync(record.Id.Value);

        response.EnsureNoErrors();

        response.Data !.LaunchRecords !.Nodes ![0].Partner.Should().Be("partner");
Example #7
0
        public async Task VerifyPosition_ShouldDetectClash_WhenMultipleRocketsAreLanding(
            int rocket1Id, int rocket2Id, int x1, int y1, int x2, int y2, string expectedOutput)
        {
            await _sut.VerifyPosition(RocketId.From(rocket1Id), LandingPosition.From(new Position(x1, y1)));

            var result = await _sut.VerifyPosition(RocketId.From(rocket2Id), LandingPosition.From(new Position(x2, y2)));

            result.Should().Be(expectedOutput);
        }
    public async Task Should_Not_Get_A_Missing_Rocket()
    {
        Func <Task> action = () => ServiceProvider.WithScoped <IMediator>().Invoke(
            mediator => mediator.Send(new GetRocket.Request {
            Id = RocketId.New()
        })
            );

        await action.Should().ThrowAsync <NotFoundException>();
    }
Example #9
0
        public async Task VerifyPosition_ShouldDetectClashBasedOnLatestLandingCheck_WhenMultipleRocketsAreLanding(
            int x1, int y1, int x2, int y2, int x3, int y3, string expectedOutput)
        {
            await _sut.VerifyPosition(RocketId.From(1), LandingPosition.From(new Position(x1, y1)));

            await _sut.VerifyPosition(RocketId.From(1), LandingPosition.From(new Position(x2, y2)));

            var result = await _sut.VerifyPosition(RocketId.From(2), LandingPosition.From(new Position(x3, y3)));

            result.Should().Be(expectedOutput);
        }
Example #10
0
        private async Task <ReadyRocket?> GetRocket(RocketId id, CancellationToken cancellationToken)
        {
            var rocket = await _dbContext.Rockets.FindAsync(new object[] { id }, cancellationToken)
                         .ConfigureAwait(false);

            if (rocket == null)
            {
                throw new NotFoundException();
            }

            return(rocket);
        }
    public async Task Should_Update_A_LaunchRecord()
    {
        var client = new LR.LaunchRecordsClient(Factory.CreateGrpcChannel());
        var clock  = ServiceProvider.GetRequiredService <IClock>();
        var record = await ServiceProvider.WithScoped <RocketDbContext, IClock>()
                     .Invoke(
            async(context, clk) =>
        {
            var rocket = new ReadyRocket
            {
                Id           = RocketId.New(),
                Type         = Core.Domain.RocketType.Falcon9,
                SerialNumber = "12345678901234"
            };
            context.Add(rocket);

            var record = new LaunchRecord
            {
                Partner             = "partner",
                Payload             = "geo-fence-ftl",
                RocketId            = rocket.Id,
                Rocket              = rocket,
                ScheduledLaunchDate = clk.GetCurrentInstant().ToDateTimeOffset(),
                PayloadWeightKg     = 100,
            };
            context.Add(record);

            await context.SaveChangesAsync();
            return(record);
        }
            );

        var launchDate = record.ScheduledLaunchDate.AddSeconds(1).ToTimestamp();
        await client.EditLaunchRecordAsync(
            new UpdateLaunchRecordRequest
        {
            Id                  = record.Id.ToString(),
            Partner             = "partner",
            Payload             = "geo-fence-ftl",
            RocketId            = record.RocketId.ToString(),
            ScheduledLaunchDate = launchDate,
            PayloadWeightKg     = 200,
        }
            );

        var response = await client.GetLaunchRecordsAsync(new GetLaunchRecordRequest { Id = record.Id.ToString() });

        response.ScheduledLaunchDate.Should().Be(launchDate);
        response.PayloadWeightKg.Should().Be(200);
    }
    public async Task Should_Update_A_LaunchRecord()
    {
        var record = await ServiceProvider.WithScoped <RocketDbContext, IClock>()
                     .Invoke(
            async(context, clock) =>
        {
            var rocket = new ReadyRocket
            {
                Id           = RocketId.New(),
                Type         = RocketType.Falcon9,
                SerialNumber = "12345678901234"
            };

            var record = new LaunchRecord
            {
                Partner             = "partner",
                Payload             = "geo-fence-ftl",
                RocketId            = rocket.Id,
                ScheduledLaunchDate = clock.GetCurrentInstant().ToDateTimeOffset(),
                PayloadWeightKg     = 100,
            };
            context.Add(rocket);
            context.Add(record);

            await context.SaveChangesAsync();
            return(record);
        }
            );

        var launchDate = record.ScheduledLaunchDate.ToInstant().Plus(Duration.FromSeconds(1));
        var response   = await ServiceProvider.WithScoped <IMediator, IClock>().Invoke(
            (mediator, clock) => mediator.Send(
                new EditLaunchRecord.Request
        {
            Id                  = record.Id,
            Partner             = "partner",
            Payload             = "geo-fence-ftl",
            RocketId            = record.RocketId,
            ScheduledLaunchDate = launchDate,
            PayloadWeightKg     = 200,
        }
                )
            );

        response.ScheduledLaunchDate.Should().Be(launchDate);
        response.PayloadWeightKg.Should().Be(200);
    }
Example #13
0
        public async Task VerifyPosition_ShouldProvideCorrectOutput_WhenMultipleRocketsAreLandingInParallel()
        {
            var(rocketId0, landingPosition0) = (RocketId.From(1), LandingPosition.From(new Position(12, 12)));
            var(rocketId1, landingPosition1) = (RocketId.From(1), LandingPosition.From(new Position(5, 5)));
            var(rocketId2, landingPosition2) = (RocketId.From(2), LandingPosition.From(new Position(6, 6)));
            var(rocketId3, landingPosition3) = (RocketId.From(3), LandingPosition.From(new Position(9, 9)));
            var(rocketId4, landingPosition4) = (RocketId.From(4), LandingPosition.From(new Position(8, 8)));
            var(rocketId5, landingPosition5) = (RocketId.From(5), LandingPosition.From(new Position(15, 15)));

            await Task.WhenAll(
                RunLandingCheck(rocketId0, landingPosition0, OutputMessages.OkForLanding),
                RunLandingCheck(rocketId1, landingPosition1, OutputMessages.OkForLanding),
                RunLandingCheck(rocketId2, landingPosition2, OutputMessages.Clash),
                RunLandingCheck(rocketId3, landingPosition3, OutputMessages.OkForLanding),
                RunLandingCheck(rocketId4, landingPosition4, OutputMessages.Clash),
                RunLandingCheck(rocketId5, landingPosition5, OutputMessages.OkForLanding)
                );
        }
        /// <summary>
        /// Verifies if given landing position is eligible for landing.
        /// </summary>
        /// <param name="rocketId">Rocket identifier.</param>
        /// <param name="position">Potential landing position to check.</param>
        /// <returns></returns>
        public async Task <string> VerifyPosition(RocketId rocketId, LandingPosition position)
        {
            if (IsOutOfPlatform(position))
            {
                return(OutputMessages.OutOfPlatform);
            }

            var landingCheck = new LandingCheck(rocketId, position, _dateTimeProvider.DateTimeUtcNow);

            var landingCheckRequest = new LandingCheckRequest(landingCheck);

            await _landingCheckChannel.WriteAsync(landingCheckRequest);

            var potentialClashPosition = await landingCheckRequest.GetResultAsync();

            return(IsClashWithPrevious(position, potentialClashPosition)
                ? OutputMessages.Clash
                : OutputMessages.OkForLanding);
        }
Example #15
0
    public async Task Should_Get_A_LaunchRecord()
    {
        var client = new LaunchRecordClient(Factory.CreateClient());
        var record = await ServiceProvider.WithScoped <RocketDbContext, IClock>()
                     .Invoke(
            async(context, clock) =>
        {
            var rocket = new ReadyRocket
            {
                Id           = RocketId.New(),
                Type         = RocketType.Falcon9,
                SerialNumber = "12345678901234"
            };

            var record = new LaunchRecord
            {
                Partner             = "partner",
                Payload             = "geo-fence-ftl",
                RocketId            = rocket.Id,
                ScheduledLaunchDate = clock.GetCurrentInstant().ToDateTimeOffset(),
                PayloadWeightKg     = 100,
            };
            context.Add(rocket);
            context.Add(record);

            await context.SaveChangesAsync();
            return(record);
        }
            );

        var response = (await client.GetLaunchRecordAsync(record.Id.Value)).Result;

        response.Partner.Should().Be("partner");
        response.Payload.Should().Be("geo-fence-ftl");
        response.RocketType.Should().Be(HttpRocketType.Falcon9);
        response.RocketSerialNumber.Should().Be("12345678901234");
        response.ScheduledLaunchDate.Should().Be(record.ScheduledLaunchDate);
    }
Example #16
0
 /// <summary>
 /// Filters launches by rocket id. Note that you have to call <see cref="BuilderBase{TReturn}.Execute"/> or <see cref="BuilderBase{TReturn}.ExecuteAsync"/>
 /// to get result from the API. Every next call of this method will override previously saved rocket id filter.
 /// </summary>
 /// <param name="rocketId">The rocket ID (Falcon1, Falcon9, etc).</param>
 /// <returns>The launch builder.</returns>
 public TBuilder WithRocketId(RocketId rocketId)
 {
     AddFilter("rocket_id", rocketId.GetEnumMemberAttributeValue(rocketId));
     return((TBuilder)this);
 }
Example #17
0
 /// <summary>
 /// Filters rocket information by the specified rocket type. Note that you have to call <see cref="BuilderBase{TReturn}.Execute"/> or
 /// <see cref="BuilderBase{TReturn}.ExecuteAsync"/> to get result from the API. Every next call of this method will override previously saved rocket type filter.
 /// </summary>
 /// <param name="type">The rocket type (Falcon1, Falcon9, etc).</param>
 /// <returns>The rocket builder.</returns>
 public RocketBuilder WithType(RocketId type)
 {
     _rocketType = type;
     return(this);
 }
Example #18
0
 private Task RunLandingCheck(RocketId rocketId, LandingPosition landingPosition, string expectedOutput)
 {
     return(_sut.VerifyPosition(rocketId, landingPosition)
            .ContinueWith(task => task.Result.Should().BeEquivalentTo(expectedOutput)));
 }
 public LandingCheck(RocketId rocketId, LandingPosition landingPosition, DateTime timestamp)
 {
     RocketId        = rocketId;
     LandingPosition = landingPosition;
     Timestamp       = timestamp;
 }
Example #20
0
        public void VerifyPosition_ShouldThrow_WhenProvidedOutOfLandingAreaLandingPosition(int x, int y)
        {
            Func <Task> action = async() => await _sut.VerifyPosition(RocketId.From(1), LandingPosition.From(new Position(x, y)));

            action.Should().Throw <LandingPositionOutsideLandingAreaException>();
        }
Example #21
0
        public async Task VerifyPosition_ShouldDetectPlatform_WhenProvidedValidLandingPosition(int x, int y, string expectedOutput)
        {
            var result = await _sut.VerifyPosition(RocketId.From(1), LandingPosition.From(new Position(x, y)));

            result.Should().Be(expectedOutput);
        }
 // ReSharper disable once RouteTemplates.ParameterTypeAndConstraintsMismatch
 public partial Task <ActionResult <RocketModel> > PatchRocket([BindRequired][FromRoute] RocketId id, [BindRequired][FromBody] EditRocket.PatchRequest model);
Example #23
0
 private static bool IsSameRocket(RocketId currentRocketId, RocketId rocketId)
 {
     return(rocketId == currentRocketId);
 }
Example #24
0
 /// <summary>
 /// Gets information about the specified rocket. This method returns only builder which doesn't retrieve data from API itself, so after apply
 /// all necessary filters you should call <see cref="BuilderBase{TReturn}.Execute"/> or <see cref="BuilderBase{TReturn}.ExecuteAsync"/> to
 /// get the data from SpaceX API.
 /// </summary>
 /// <param name="rocketType">The rocket type.</param>
 /// <returns>The rocket builder.</returns>
 public RocketBuilder GetAbout(RocketId rocketType)
 {
     return(new RocketBuilder(_httpClient, _builderDelegatesContainer).WithType(rocketType));
 }