public void CheckAndRecord(ConstraintsViolations violations)
        {
            if (_type.IsAbstract)
            {
                violations.Add("SmartType " + _type + " is abstract but abstract classes cannot be value objects");
            }

            if (_type.IsInterface)
            {
                violations.Add("SmartType " + _type + " is an interface but interfaces cannot be value objects");
            }
        }
Ejemplo n.º 2
0
        public void ShouldThrowExceptionContainingAllViolationMessagesWhenMoreThanOneViolationWasAdded()
        {
            //GIVEN
            var violations = new ConstraintsViolations();
            var violation1 = Any.String();
            var violation2 = Any.String();
            var violation3 = Any.String();

            violations.Add(violation1);
            violations.Add(violation2);
            violations.Add(violation3);

            //WHEN - THEN
            new Action(violations.AssertNone).Should().Throw <Exception>()
            .And.Message.Should().ContainAll(violation1, violation2, violation3);
        }
        public void CheckAndRecord(ConstraintsViolations violations)
        {
            var properties = SmartType.For(_type).GetAllPublicInstanceProperties();

            foreach (var item in properties.Where(item => item.HasPublicSetter()))
            {
                violations.Add(item.ShouldNotBeMutableButIs());
            }
        }
Ejemplo n.º 4
0
        public void ShouldThrowExceptionWhenAtLeastOneViolationWasAdded()
        {
            //GIVEN
            var violations = new ConstraintsViolations();

            violations.Add(Any.String());

            //WHEN - THEN
            new Action(violations.AssertNone).Should().ThrowExactly <XunitException>();
        }
Ejemplo n.º 5
0
        public void ShouldThrowExceptionContainingAllViolationMessagesWhenMoreThanOneViolationWasAdded()
        {
            //GIVEN
            var violations = new ConstraintsViolations();
            var violation1 = Any.String();
            var violation2 = Any.String();
            var violation3 = Any.String();

            violations.Add(violation1);
            violations.Add(violation2);
            violations.Add(violation3);

            //WHEN - THEN
            var exception = Assert.Throws <AssertionException>(violations.AssertNone);

            StringAssert.Contains(violation1, exception.Message);
            StringAssert.Contains(violation2, exception.Message);
            StringAssert.Contains(violation3, exception.Message);
        }
Ejemplo n.º 6
0
        public void ShouldThrowExceptionWhenAtLeastOneViolationWasAdded()
        {
            //GIVEN
            var violations = new ConstraintsViolations();

            violations.Add(Any.String());

            //WHEN - THEN
            Assert.Throws <AssertionException>(violations.AssertNone);
        }
Ejemplo n.º 7
0
        private void CheckImmutability(ConstraintsViolations violations, Type type)
        {
            var fields        = SmartType.For(type).GetAllInstanceFields().ToList();
            var fieldWrappers = fields
                                .Where(item => item.IsNotDeveloperDefinedReadOnlyField());

            foreach (var item in fieldWrappers)
            {
                violations.Add(item.ShouldNotBeMutableButIs());
            }
        }
Ejemplo n.º 8
0
 public static void DoesNotThrow(Action action, string message, ConstraintsViolations errors)
 {
     try
     {
         action();
     }
     catch (Exception e)
     {
         errors.Add(message + ", but instead caught: " + e);
     }
 }