Ejemplo n.º 1
0
        public void ShouldWriteJsonAndDeserializeIntoSameObject()
        {
            MathDomain         original = new MathDomain();
            ValueDomainSegment vds      = new ValueDomainSegment(1024);
            RangeDomainSegment rds      = new RangeDomainSegment(new Random800_90(), 0, 1024, 128);

            original.AddSegment(vds);
            original.AddSegment(rds);

            var serializedObject = JsonConvert.SerializeObject(
                original,
                new JsonSerializerSettings
            {
                Converters = new List <JsonConverter> {
                    new DomainConverter()
                },
                NullValueHandling = NullValueHandling.Ignore
            }
                );

            var deserializedObject =
                JsonConvert.DeserializeObject <MathDomain>(
                    serializedObject,
                    new DomainConverter()
                    );

            var vdsReObjectified = deserializedObject.DomainSegments.OfType <ValueDomainSegment>().First();
            var rdsReObjectified = deserializedObject.DomainSegments.OfType <RangeDomainSegment>().First();

            Assert.AreEqual(original.DomainSegments.Count(), deserializedObject.DomainSegments.Count(), "count");
            Assert.AreEqual(vds.ToString(), vdsReObjectified.ToString(), nameof(vds));
            Assert.AreEqual(rds.ToString(), rdsReObjectified.ToString(), nameof(rds));
        }
Ejemplo n.º 2
0
        public void ShouldReturnValueFromConstructorUsingGetValues(int value)
        {
            _subject = new ValueDomainSegment(value);

            var result = _subject.GetValues(1).ToList();

            Assert.AreEqual(value, result[0]);
        }
Ejemplo n.º 3
0
        public void ShouldContainValueSetInConstructor(int value)
        {
            _subject = new ValueDomainSegment(value);

            var result = _subject.IsWithinDomain(value);

            Assert.IsTrue(result);
        }
Ejemplo n.º 4
0
        public void ShouldReturnValueWhenMinSpecifiedIsValue(int value, int minimum, int maximum, bool expectItemReturned)
        {
            _subject = new ValueDomainSegment(value);

            var result = _subject.GetValues(minimum, maximum, 1).ToList();

            Assert.AreEqual(expectItemReturned, result.Count == 1);
        }
Ejemplo n.º 5
0
        public void ShouldReturnSingleValueFromSegmentWhenAskingForMultiple(int value)
        {
            _subject = new ValueDomainSegment(value);

            var result = _subject.GetValues(5).ToList();

            Assert.AreEqual(value, result[0], nameof(value));
            Assert.AreEqual(1, result.Count, nameof(result.Count));
        }
Ejemplo n.º 6
0
        public void ShouldBeSameMinMax(int value)
        {
            _subject = new ValueDomainSegment(value);

            var result = _subject.RangeMinMax;

            Assert.AreEqual(value, result.Minimum, "minimum");
            Assert.AreEqual(value, result.Maximum, "maximum");
        }
Ejemplo n.º 7
0
        public void ShouldReturnSingleValueThatMatchesCondition(int value, bool resultShouldHaveContent)
        {
            _subject = new ValueDomainSegment(value);

            var result = _subject.GetValues(v => v > 0, 1).ToList();

            Assert.AreEqual(resultShouldHaveContent, result.Count != 0);

            if (resultShouldHaveContent)
            {
                Assert.AreEqual(value, result[0]);
            }
        }
Ejemplo n.º 8
0
        public void ShouldSetValueIfParamMaxIsLessThanValue(int originalValue, int maxValue)
        {
            _subject = new ValueDomainSegment(originalValue);

            _subject.SetMaximumAllowedValue(maxValue);

            if (originalValue > maxValue)
            {
                Assert.AreEqual(maxValue, _subject.GetValues(1).ToList()[0]);
            }
            else
            {
                Assert.AreEqual(originalValue, _subject.GetValues(1).ToList()[0]);
            }
        }
Ejemplo n.º 9
0
        public void ShouldWriteJsonAndDeserializeIntoSameObject()
        {
            MathDomain         original = new MathDomain();
            ValueDomainSegment vds      = new ValueDomainSegment(1024);
            RangeDomainSegment rds      = new RangeDomainSegment(new Random800_90(), 0, 1024, 128);

            original.AddSegment(vds);
            original.AddSegment(rds);

            var serializedObject = JsonSerializer.Serialize(original, _jsonSerializerOptions);

            var deserializedObject = JsonSerializer.Deserialize <MathDomain>(serializedObject, _jsonSerializerOptions);

            Assert.IsNotNull(deserializedObject, $"{nameof(deserializedObject)} was null.");

            var vdsReObjectified = deserializedObject.DomainSegments.OfType <ValueDomainSegment>().First();
            var rdsReObjectified = deserializedObject.DomainSegments.OfType <RangeDomainSegment>().First();

            Assert.AreEqual(original.DomainSegments.Count(), deserializedObject.DomainSegments.Count(), "count");
            Assert.AreEqual(vds.ToString(), vdsReObjectified.ToString(), nameof(vds));
            Assert.AreEqual(rds.ToString(), rdsReObjectified.ToString(), nameof(rds));
        }