Exemple #1
0
        /// <summary>
        /// Generates a value for this argument to be applied on the specified property and instance.
        /// This may return different results when called multiple times.
        /// </summary>
        public object GetValue(object Instance, PropertyInfo Property)
        {
            object[] Arguments = GetArguments(Instance, Property);
            object   Result    = ValueGenerator.GetValue(Instance, Property, Arguments);

            return(Result);
        }
        public void GetValue_Null_Success()
        {
            var stringContractField = new ContractField
            {
                Name     = "TestNull",
                Type     = FieldTypeEnum.String,
                FillMode = FieldFillModeEnum.Null
            };

            var value = ValueGenerator.GetValue(stringContractField);

            Assert.AreEqual(null, value);
        }
        public void GetValue_None_Success()
        {
            var stringContractField = new ContractField
            {
                Name     = "TestNone",
                Type     = FieldTypeEnum.String,
                FillMode = FieldFillModeEnum.None
            };

            var value = ValueGenerator.GetValue(stringContractField);

            Assert.AreEqual(string.Empty, value);
        }
        public async Task ValueGenerator_GetValue_ReturnsValueAndNumberPassedIn()
        {
            // Arrange
            int    input    = 3;
            string expected = "value3";
            string actual;

            // Act
            actual = await _valueGenerator.GetValue(input).ConfigureAwait(false);

            // Assert
            Assert.AreEqual(expected, actual);
        }
        public void GetValue_Fixed_Success()
        {
            var stringContractField = new ContractField
            {
                Name         = "TestFixed",
                Type         = FieldTypeEnum.String,
                FillMode     = FieldFillModeEnum.Fixed,
                DefaultValue = "Fixed Value"
            };

            var value = ValueGenerator.GetValue(stringContractField);

            Assert.AreEqual("Fixed Value", value);
        }
Exemple #6
0
        private T Imitate <T>(T obj, Contract contract) where T : class, new()
        {
            foreach (var prop in typeof(T).GetProperties())
            {
                var contractField = contract.Fields.FirstOrDefault(cf => cf.Name == prop.Name);
                if (contractField == null)
                {
                    continue;
                }

                var value = ValueGenerator.GetValue(contractField);
                prop.SetValue(obj, value);
            }
            return(obj);
        }
        public void GetValue_Random_Success()
        {
            var stringContractField = new ContractField
            {
                Name     = "Test",
                Type     = FieldTypeEnum.String,
                FillMode = FieldFillModeEnum.Random,
                MinValue = 5,
                MaxValue = 100
            };

            var value = ValueGenerator.GetValue(stringContractField).ToString();

            Assert.IsTrue(value.Length >= stringContractField.MinValue);
            Assert.IsTrue(value.Length <= stringContractField.MaxValue);
        }