Beispiel #1
0
        public RangeAttribute(uint from, uint to, uint step)
        {
            Guard.ArgumentValid(step > 0, "Step must be greater than zero", nameof(step));
            Guard.ArgumentValid(to >= from, "Value of to must be greater than or equal to from", nameof(to));

            _from = from;
            _to   = to;
            _step = step;
        }
Beispiel #2
0
        public RangeAttribute(int from, int to, int step)
        {
            Guard.ArgumentValid(step > 0 && to >= from || step < 0 && to <= from,
                                "Step must be positive with to >= from or negative with to <= from", nameof(step));

            _from = from;
            _to   = to;
            _step = step;
        }
Beispiel #3
0
        public RangeAttribute(double from, double to, double step)
        {
            Guard.ArgumentValid(step > 0.0D && to >= from || step < 0.0D && to <= from,
                                "Step must be positive with to >= from or negative with to <= from", nameof(step));

            _from = from;
            _to   = to;
            _step = step;
        }
Beispiel #4
0
            public override IEnumerable GetData(IParameterInfo parameter)
            {
                Guard.ArgumentValid(parameter.ParameterType.GetTypeInfo().IsEnum, "EnumDataSource requires an enum parameter", "parameter");

                Randomizer randomizer = Randomizer.GetRandomizer(parameter.ParameterInfo);

                DataType = parameter.ParameterType;

                for (int i = 0; i < _count; i++)
                {
                    yield return(randomizer.NextEnum(parameter.ParameterType));
                }
            }
Beispiel #5
0
        /// <summary>
        /// Construct a range of unsigned ints specifying the step size
        /// </summary>
        /// <param name="from"></param>
        /// <param name="to"></param>
        /// <param name="step"></param>
        //[CLSCompliant(false)]
        public RangeAttribute(uint from, uint to, uint step)
        {
            Guard.ArgumentValid(step > 0, "Step must be greater than zero", "step");
            Guard.ArgumentValid(to >= from, "Value of to must be greater than or equal to from", "to");

            uint count = (to - from) / step + 1;

            this.data = new object[count];
            uint index = 0;

            for (uint val = from; index < count; val += step)
            {
                this.data[index++] = val;
            }
        }
Beispiel #6
0
        /// <summary>
        /// Construct a range of ints specifying the step size
        /// </summary>
        /// <param name="from"></param>
        /// <param name="to"></param>
        /// <param name="step"></param>
        public RangeAttribute(int from, int to, int step)
        {
            Guard.ArgumentValid(step > 0 && to >= from || step < 0 && to <= from,
                                "Step must be positive with to >= from or negative with to <= from", "step");

            int count = (to - from) / step + 1;

            this.data = new object[count];
            int index = 0;

            for (int val = from; index < count; val += step)
            {
                this.data[index++] = val;
            }
        }
Beispiel #7
0
        public RangeAttribute(ulong from, ulong to, ulong step)
        {
            Guard.ArgumentValid(step > 0, "Step must be greater than zero", nameof(step));
            Guard.ArgumentValid(to >= from, "Value of to must be greater than or equal to from", nameof(to));

            ulong count = (to - from) / step + 1;

            _data = new object[count];
            ulong index = 0;

            for (ulong val = from; index < count; val += step)
            {
                _data[index++] = val;
            }
        }
Beispiel #8
0
        /// <summary>
        /// Construct a range of longs
        /// </summary>
        /// <param name="from"></param>
        /// <param name="to"></param>
        /// <param name="step"></param>
        public RangeAttribute(long from, long to, long step)
        {
            Guard.ArgumentValid(step > 0L && to >= from || step < 0L && to <= from,
                                "Step must be positive with to >= from or negative with to <= from", nameof(step));

            long count = (to - from) / step + 1;

            _data = new object[count];
            int index = 0;

            for (long val = from; index < count; val += step)
            {
                _data[index++] = val;
            }
        }
Beispiel #9
0
        /// <summary>
        /// Construct a range of floats
        /// </summary>
        /// <param name="from"></param>
        /// <param name="to"></param>
        /// <param name="step"></param>
        public RangeAttribute(float from, float to, float step)
        {
            Guard.ArgumentValid(step > 0.0F && to >= from || step < 0.0F && to <= from,
                                "Step must be positive with to >= from or negative with to <= from", "step");

            float aStep = Math.Abs(step);
            float tol   = aStep / 1000;
            int   count = (int)(Math.Abs(to - from) / aStep + tol + 1);

            this.data = new object[count];
            int index = 0;

            for (float val = from; index < count; val += step)
            {
                this.data[index++] = val;
            }
        }
Beispiel #10
0
        /// <summary>
        /// Construct a range of doubles
        /// </summary>
        /// <param name="from"></param>
        /// <param name="to"></param>
        /// <param name="step"></param>
        public RangeAttribute(double from, double to, double step)
        {
            Guard.ArgumentValid(step > 0.0D && to >= from || step < 0.0D && to <= from,
                                "Step must be positive with to >= from or negative with to <= from", nameof(step));

            double aStep = Math.Abs(step);
            double tol   = aStep / 1000;
            int    count = (int)(Math.Abs(to - from) / aStep + tol + 1);

            _data = new object[count];
            int index = 0;

            for (double val = from; index < count; val += step)
            {
                _data[index++] = val;
            }
        }
Beispiel #11
0
        /// <summary>
        /// Attach a file to the current test result
        /// </summary>
        /// <param name="filePath">Relative or absolute file path to attachment</param>
        /// <param name="description">Optional description of attachment</param>
        public static void AddTestAttachment(string filePath, string description = null)
        {
            Guard.ArgumentNotNull(filePath, nameof(filePath));
            Guard.ArgumentValid(filePath.IndexOfAny(Path.GetInvalidPathChars()) == -1,
                                $"Test attachment file path contains invalid path characters. {filePath}", nameof(filePath));

            if (!Path.IsPathRooted(filePath))
            {
                filePath = Path.Combine(TestContext.CurrentContext.WorkDirectory, filePath);
            }

            if (!File.Exists(filePath))
            {
                throw new FileNotFoundException("Test attachment file path could not be found.", filePath);
            }

            var result = TestExecutionContext.CurrentContext.CurrentResult;

            result.AddTestAttachment(new TestAttachment(filePath, description));
        }
        public void ApplyToTest(Test test)
        {
            Guard.ArgumentValid(test.Method is object, "This attribute must only be applied to tests that have an associated method.", nameof(test));

            if (!test.Properties.ContainsKey(PropertyNames.Description) && Description != null)
            {
                test.Properties.Set(PropertyNames.Description, Description);
            }

            if (!test.Properties.ContainsKey(PropertyNames.Author) && Author != null)
            {
                test.Properties.Set(PropertyNames.Author, Author);
            }

            if (!test.Properties.ContainsKey(PropertyNames.TestOf) && TestOf != null)
            {
                test.Properties.Set(PropertyNames.TestOf, TestOf.FullName);
            }

            if (_hasExpectedResult && test.Method.GetParameters().Length > 0)
            {
                test.MakeInvalid("The 'TestAttribute.ExpectedResult' property may not be used on parameterized methods.");
            }
        }
Beispiel #13
0
 /// <summary>
 /// Construct an ApartmentAttribute
 /// </summary>
 /// <param name="apartmentState">The apartment state that this test must be run under. You must pass in a valid apartment state.</param>
 public ApartmentAttribute(ApartmentState apartmentState)
 {
     Guard.ArgumentValid(apartmentState != ApartmentState.Unknown, "must be STA or MTA", nameof(apartmentState));
     Properties.Add(PropertyNames.ApartmentState, apartmentState);
 }