//[Description("https://bitbucket.org/Readify/neo4jclient/issue/89")]
        public void ShouldSerializeCustomValueWithCustomJsonConverter()
        {
            //Arrange
            var serializer = new CustomJsonSerializer
            {
                JsonConverters = new [] { new TestValueAConverter() }
            };

            var model = new TestModelA
            {
                CustomValue = new TestValueA
                {
                    A = 'o',
                    B = 'p'
                }
            };

            //Act
            var rawResult = serializer.Serialize(model);

            //Assert
            const string expectedRawOutput =
                "{\r\n  \"CustomValue\": \"op\"\r\n}";

            Assert.Equal(expectedRawOutput, rawResult);
        }
 public void TestCreation()
 {
     Assert.That(delegate
     {
         var test = new TestModelA();
         return(PropertyHelper.GetProperties(test));
     }, Is.Not.Empty);
 }
 public void TestVisibility()
 {
     Assert.That(delegate
     {
         var test = new TestModelA();
         return(PropertyHelper.GetProperties(test));
     }, Has.None.Property(nameof(PropertyHelper.Name)).EqualTo("ProtectedStringValue"));
 }
 public void TestFailedWrite()
 {
     Assert.That(delegate
     {
         var test       = new TestModelA();
         var properties = PropertyHelper.GetProperties(test);
         var property   = properties.Single(p => p.Name == nameof(TestModelA.ReadOnlyGuid));
         property.SetValue(test, Guid.NewGuid()); // throw
     }, Throws.InvalidOperationException);
 }
        public void TestFailedRead()
        {
            var value = Guid.NewGuid().ToString();

            Assert.That(delegate
            {
                var test       = new TestModelA();
                var properties = PropertyHelper.GetProperties(test);
                var property   = properties.Single(p => p.Name == nameof(TestModelA.PrivateRead));
                Assert.That(() => property.SetValue(test, value), Throws.Nothing);
                return(property.GetValue(test)); // throw
            }, Throws.InvalidOperationException);
        }
        public void TestMutability()
        {
            var value = Guid.NewGuid().ToString();

            Assert.That(delegate
            {
                var test       = new TestModelA();
                var properties = PropertyHelper.GetProperties(test);
                var property   = properties.Single(p => p.Name == nameof(TestModelA.StringValue));
                Assert.That(() => property.GetValue(test), Is.Not.EqualTo(value));
                property.SetValue(test, value);
                return(property.GetValue(test));
            }, Is.EqualTo(value));
        }
示例#7
0
        public void FluentValidator_Execute_Validator_InValid_Succeeds()
        {
            IValidator<TestModelA> validator = new TestModelA_Validator();
            var ObjectToValidate = new TestModelA()
            {
                StringProperty = null,
                ObjectProperty = new TestModelB()
                {
                    StringProperty = null
                }
            };

            var result = validator.Execute(ObjectToValidate);

            Assert.IsFalse(result.Success);
            Assert.AreEqual(2, result.ValidationMessages.Count);
        }
示例#8
0
        public void FluentValidator_Execute_Validator_Valid_Succeeds()
        {
            IValidator<TestModelA> validator = new TestModelA_Validator();
            var ObjectToValidate = new TestModelA()
            {
                StringProperty = "NotEmptyOrNull",
                ObjectProperty = new TestModelB()
                {
                    StringProperty = "NotEmptyOrNull"
                }
            };

            var result = validator.Execute(ObjectToValidate);

            Assert.IsTrue(result.Success);
            Assert.AreEqual(0, result.ValidationMessages.Count);
        }
示例#9
0
        public string HelloWorld()
        {
            var a = new TestModelA()
            {
                Id   = 4,
                Name = "Hello World!"
            };

            var b = new TestModelB();

            a.Map(b);

            try
            {
                int number0 = 0;
                int result  = 5 / number0;
            }
            catch (Exception e)
            {
                _logger.LogError(new EventId(), e, string.Empty);
            }

            return(b.Name);
        }
        public void ShouldSerializeCustomValueWithCustomJsonConverter()
        {
            //Arrange
            var serializer = new CustomJsonSerializer
                {
                    JsonConverters = new []{new TestValueAConverter()}
                };

            var model = new TestModelA
                {
                    CustomValue = new TestValueA
                        {
                            A = 'o',
                            B = 'p'
                        }
                };

            //Act
            var rawResult = serializer.Serialize(model);

            //Assert
            const string expectedRawOutput =
            "{\r\n  \"CustomValue\": \"op\"\r\n}";

            Assert.AreEqual(expectedRawOutput, rawResult);
        }