< Summary

Information
Class: MyNet.Fakers.Geography.AddressFaker
Assembly: MyNet.Fakers
File(s): https://raw.githubusercontent.com/sandre58/MyNet/5aaaab311aa14541478b9e402357d98b657a23e4/src/MyNet.Fakers/Geography/AddressFaker.cs
Tag: 342_31701152804
Line coverage
100%
Covered lines: 17
Uncovered lines: 0
Coverable lines: 17
Total lines: 68
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
Address(...)100%11100%
Street(...)100%11100%
City(...)100%11100%
PostalCode(...)100%11100%
Coordinates()100%11100%

File(s)

https://raw.githubusercontent.com/sandre58/MyNet/5aaaab311aa14541478b9e402357d98b657a23e4/src/MyNet.Fakers/Geography/AddressFaker.cs

#LineLine coverage
 1// -----------------------------------------------------------------------
 2// <copyright file="AddressFaker.cs" company="Stéphane ANDRE">
 3// Copyright (c) Stéphane ANDRE. All rights reserved.
 4// </copyright>
 5// -----------------------------------------------------------------------
 6
 7using System.Globalization;
 8using MyNet.Generator;
 9using MyNet.Geography;
 10using MyNet.Globalization.Localization.Providers;
 11using MyNet.Text.Randomize;
 12
 13namespace MyNet.Fakers.Geography;
 14
 15/// <summary>
 16/// Current implementation of <see cref="IAddressFaker"/>.
 17/// </summary>
 18public sealed class AddressFaker(
 19    ITextRandomGenerator patternGenerator,
 20    IRandomGenerator random,
 21    ICultureScopedServiceSource<IAddressFakerProvider> source,
 22    IStreetFaker streetFaker,
 23    ICountryFaker countryFaker) : IAddressFaker
 24{
 25    /// <inheritdoc />
 26    public Address Address(CultureInfo? culture = null)
 27    {
 628        var street = Street(culture);
 629        var city = City(culture);
 630        var postal = PostalCode(culture);
 631        var country = countryFaker.Country();
 32
 633        return new Address(
 634            Street: street,
 635            PostalCode: postal,
 636            City: city,
 637            Country: country);
 38    }
 39
 40    /// <inheritdoc />
 641    public string Street(CultureInfo? culture = null) => streetFaker.Street(culture);
 42
 43    /// <inheritdoc />
 44    public string City(CultureInfo? culture = null)
 45    {
 646        var provider = source.Get(culture);
 647        return random.Item(provider.Cities);
 48    }
 49
 50    /// <inheritdoc />
 51    public string PostalCode(CultureInfo? culture = null)
 52    {
 653        var provider = source.Get(culture);
 54
 655        return patternGenerator.RandomizeWithRandomPattern(random, provider.PostalCodeFormats);
 56    }
 57
 58    /// <inheritdoc />
 59    public Coordinates Coordinates()
 60    {
 61        // Realistic global bounds
 362        var lat = random.Double(-90, 90);
 363        var lon = random.Double(-180, 180);
 64
 365        return new Coordinates(lat, lon);
 66    }
 67}
 68