import { ControlMock } from "../../controls/control/control.mock" ; import { NumberControlMock } from "../../controls/numbercontrol/numbercontrol.mock" ; import { AttributeMock , IAttributeComponents } from "../attribute/attribute.mock" ; export class NumberAttributeMock extends AttributeMock < NumberControlMock , number > implements Xrm . Attributes . NumberAttribute { private static defaultComponents ( components ) { components . format = components . format || "none" ; components . precision = components . precision || 0 ; if ( ! components . attributeType ) { components . attributeType = "decimal" ; } return components ; } public min : number ; public max : number ; public precision : number ; constructor ( components ) { super ( NumberAttributeMock . defaultComponents ( components ) ) ; this . min = components . min ; this . max = components . max ; this . precision = components . precision ; this . validatePrecision ( ) ; } public getFormat ( ) { return super . getFormat ( ) as Xrm . Attributes . IntegerAttributeFormat ; } public getMax ( ) { return this . max ; } public getMin ( ) { return this . min ; } public getPrecision ( ) { return this . precision ; } public setPrecision ( value ) { this . precision = value ; } public setValue ( value ) { if ( ( this . min || this . min === 0 ) && this . min > value ) { throw new Error ( ( "value cannot be below the min of " + this . min ) ) ; } else if ( ( this . max || this . max === 0 ) && this . max < value ) { throw new Error ( ( "value cannot be above the max of " + this . max ) ) ; } else { super . setValue ( value ) ; } } private validatePrecision ( ) { if ( this . precision > 10 ) { throw new Error ( ( `precision cannot be greater than 10, but was ${ this . precision }` ) ) ; } else if ( this . precision < 0 ) { throw new Error ( ( `precision cannot be less than 0, but was ${ this . precision }` ) ) ; } } } export interface INumberAttributeComponents extends IAttributeComponents < NumberControlMock , number > { min ? : number ; max ? : number ; precision ? : number ; format ? : Xrm . Attributes . IntegerAttributeFormat ; }