Exemplo n.º 1
0
        public async Task Should_remove_checkpoints()
        {
            var now      = DateTime.UtcNow;
            var original = new[]
            {
                new Checkpoint {
                    RiderId = "111", Timestamp = now
                },
                new Checkpoint {
                    RiderId = "222", Timestamp = now.AddMinutes(1)
                },
                new Checkpoint {
                    RiderId = "333", Timestamp = now.AddMinutes(2)
                },
                new Checkpoint {
                    RiderId = "444", Timestamp = now.AddMinutes(3)
                },
                new Checkpoint {
                    RiderId = "555", Timestamp = now.AddMinutes(4)
                }
            };

            var tagListHandler = WithCheckpointStorageService(storageService =>
            {
                foreach (var cp in original)
                {
                    storageService.AppendCheckpoint(cp);
                }
                return(new SimulatorBuilder(storageService).Build());
            });

            using var svc = CreateCheckpointService();
            var client = new CheckpointServiceClient(svc.ListenUri);

            (await client.DeleteCheckpoint(original[0].Id)).Should().Be(1);
            var cps = await client.GetCheckpoints();

            cps.Count.Should().Be(4);
            cps.Should().NotContain(x => x.Id == original[0].Id);

            (await client.DeleteCheckpoints(now.AddMinutes(1.5), now.AddMinutes(3.5))).Should().Be(2);
            cps = await client.GetCheckpoints();

            cps.Count.Should().Be(2);
            cps.Should().NotContain(x => x.Id == original[2].Id || x.Id == original[3].Id);

            (await client.DeleteCheckpoints()).Should().Be(2);
            cps = await client.GetCheckpoints();

            cps.Count.Should().Be(0);
        }
Exemplo n.º 2
0
        public async Task HttpClient_should_wait_for_webhost_to_start()
        {
            // Make service slow on startup by putting 5000ms sleep
            var sw = Stopwatch.StartNew();

            using var svc = CreateCheckpointService(5000);
            var client = new CheckpointServiceClient(svc.ListenUri);
            // Get data from service should succeed, but take 5000+ ms
            var response = await client.GetCheckpoints();

            response.Should().BeEmpty();
            sw.Stop();
            sw.ElapsedMilliseconds.Should().BeGreaterThan(5000);
        }
Exemplo n.º 3
0
        public async Task Should_return_stored_checkpoints()
        {
            var ts = DateTime.UtcNow;

            WithCheckpointStorageService(storageService =>
            {
                storageService.AppendCheckpoint(new Checkpoint("stored1", ts));
                storageService.AppendCheckpoint(new Checkpoint("stored2", ts.AddSeconds(100)));
            });

            using var svc = CreateCheckpointService();
            var client      = new CheckpointServiceClient(svc.ListenUri);
            var checkpoints = await client.GetCheckpoints();

            checkpoints.Should().NotBeNull();
            checkpoints.Count.Should().Be(2);
            checkpoints.Should().Contain(x => x.RiderId == "stored1");
            checkpoints.Should().Contain(x => x.RiderId == "stored2");
        }