[][src]Enum mockery::datatypes::RandomData

pub enum RandomData {
    FirstName,
    LastName,
    FullName,
    Email,
    Number {
        digits: usize,
    },
    NumberBetween {
        min: usize,
        max: usize,
    },
    Paragraphs {
        amount: Option<usize>,
    },
    Paragraph,
    Sentences {
        amount: Option<usize>,
    },
    Sentence,
    Company,
    City,
    StreetAddress,
    Latitude,
    Longitude,
    LatLong,
    LongLat,
    GeoPoint,
    Postcode,
    FullAddress,
    UUID4,
    PhoneNumber,
    LoremPicsum {
        width: Option<usize>,
        height: Option<usize>,
        grayscale: Option<bool>,
    },
    NullValue,
    String {
        content: String,
    },
    Reference {
        model: String,
        field: String,
    },
}

An Enum that represents all of the possible random data generation types. Where the type is a struct it should be written in a specification as a nested map type, where the outer map contains a single property correlating to the struct variant with value should be a map containing the struct values.

Examples

Basic Model (JSON)

To model a company identification card that contains basic employee information using simple types:

{
    "information_card": {
        "name": "FullName",
        "contact_email": "Email",
        "contact_number": "PhoneNumber",
        "address": "FullAddress"
    }
}

Model With Struct Types (JSON)

To use complex data types that take arguments, you need to write the property values as nested map types. This example models an Under-25 Travelcard for a train company, where the age of the person needs to be between 18 and 25. The NumberBetween type takes two arguments:

{
    "travelcard": {
        "name": "FullName",
        "address": "FullAddress",
        "age": {
            "NumberBetween": {
                "min": 18,
                "max": 25
            }
        }
    }
}

Variants

FirstName

Generates a latin first name

LastName

Generates a latin surname

FullName

Generates a combination of a FirstName and LastName, combined with a space between them

Email

Generates a safe email address

Number

Generates an integer with the given number of digits.

Examples

Number: { "digits": 3 } will generate a number between 100 and 999, inclusive

Fields of Number

digits: usize

The number of digits the generated number should have, to get a number with an appropriate order of magnitude

NumberBetween

Generate a random number between the minimum and maximum boundaries

Examples

NumberBetween: { "min": 23, "max": 50 } will generate a number between 23 and 49, inclusive

Fields of NumberBetween

min: usize

The minimum boundary for the generated number. This boundary is inclusive

max: usize

The maximum boundary for the generated number. This boundary is exclusive

Paragraphs

Generate a number of paragraphs containing raw lorem ipsum text (No formatting)

Fields of Paragraphs

amount: Option<usize>

The number of paragraphs to generate. Defaults to 1

Paragraph

Generate a single paragraph of lorem ipsum text. This is a convenience for specifying Paragraphs as a simple type without options

Sentences

Generate a number of sentences containing raw lorem ipsum text (No formatting)

Fields of Sentences

amount: Option<usize>

The number of sentences to generate. Defaults to 1

Sentence

Generate a single sentence of lorem ipsum text. This is a convenience for specifying Sentences as a simple type without options

Company

Generates the name of a local company - usually an amalgamation of name-parts

City

Generates the name of a city

StreetAddress

Generates a sensible street address (including house number and street name components)

Latitude

Generates a valid latitude component

Longitude

Generates a valid longitude component

LatLong

Generates a coordinate pair, formatted as a JSON array of (Latitude, Longitude)

LongLat

Generates a coordinate pair, formatted as a JSON array of (Longitude, Latitude)

GeoPoint

Generates a GeoJson point object using the WKT formatting for postgis recognition and insertion

Postcode

Generates a valid postcode

FullAddress

Generates an address with StreetAddress, City and PostCode components, separated by commas

UUID4

Generates a valid V4 UUID, generally useful for object IDs

PhoneNumber

Generates a valid phone number

LoremPicsum

Generates a URL to a random picture with the given dimensions and optional greyscale mode. Where one of the size values is absent, the image will be a square as dictated by the other value that is present. Where both are absent, the image will be a 200x200 pixel square.

Fields of LoremPicsum

width: Option<usize>height: Option<usize>grayscale: Option<bool>
NullValue
String

Fields of String

content: String
Reference

Fields of Reference

model: Stringfield: String

Methods

impl RandomData[src]

pub fn into_data(self) -> String[src]

Consumes the RandomData instance and turns it into a random piece of data, corresponding to its type

Trait Implementations

impl Clone for RandomData[src]

impl ToString for RandomData[src]

impl Debug for RandomData[src]

impl Serialize for RandomData[src]

impl<'de> Deserialize<'de> for RandomData[src]

Auto Trait Implementations

Blanket Implementations

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = !

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Fake for T[src]

impl<V, T> VZip<V> for T where
    V: MultiLane<T>, 

impl<T> DeserializeOwned for T where
    T: Deserialize<'de>, 
[src]