Beispiel #1
0
    public async Task EntireUniverseTestAsync()
    {
        var dataStore = new InMemoryDataStore();

        var(planet, children) = await Planetoid.GetPlanetForNewUniverseAsync(dataStore).ConfigureAwait(false);

        Assert.IsNotNull(planet);

        var stopwatch = new Stopwatch();

        stopwatch.Start();

        var json = JsonSerializer.Serialize(children);

        stopwatch.Stop();

        var bytes = Encoding.UTF8.GetBytes(json);

        Console.WriteLine();
        Console.WriteLine($"Size (System.Text.Json): {BytesToString(bytes.Length)}");
        Console.WriteLine($"Serialization time (System.Text.Json): {stopwatch.Elapsed}");
        //Console.WriteLine();
        //Console.WriteLine("JSON (System.Text.Json):");
        //Console.WriteLine(json);

        stopwatch.Reset();
        stopwatch.Start();

        var deserialized = JsonSerializer.Deserialize <List <CosmicLocation> >(json);

        stopwatch.Stop();

        Assert.IsNotNull(deserialized);
        Assert.IsTrue(children.SequenceEqual(deserialized !));

        Console.WriteLine($"Deserialization time (System.Text.Json): {stopwatch.Elapsed}");
    }