コード例 #1
0
        public void AllowSave()
        {
            using (var container = new RhetosTestContainer())
            {
                var simple = container.Resolve <Common.DomRepository>().TestAllowSave.Simple;
                var s1     = new TestAllowSave.Simple {
                    Code = 1, Name = "a", CodeAS = null, NameAS = null
                };
                var s2 = new TestAllowSave.Simple {
                    Code = 1, Name = "aaaaa", CodeAS = 2, NameAS = "b"
                };

                simple.Insert(s1, s2);
                Assert.AreEqual("1a, 1aaaaa2b", TestUtility.DumpSorted(simple.Query(new[] { s1.ID, s2.ID }), s => s.Code + s.Name + s.CodeAS + s.NameAS));
                Assert.AreEqual(0, simple.Validate(new[] { s1.ID, s2.ID }, onSave: true).Count(), "There should be no invalid items with errors that are checked on save.");

                // Errors that are NOT checked on save:
                var errors = simple.Validate(new[] { s1.ID, s2.ID }, onSave: false);
                Assert.AreEqual(
                    TestUtility.DumpSorted(new[] {
                    "The required property CodeAS is not set./CodeAS/" + s1.ID,
                    "The required property NameAS is not set./NameAS/" + s1.ID,
                    "[Test] Longer than 3.//" + s2.ID,
                    "[Test] Longer than 4./Name/" + s2.ID
                }),
                    TestUtility.DumpSorted(errors,
                                           error => string.Format(error.Message, error.MessageParameters) + "/" + error.Property + "/" + error.ID));
            }
        }
コード例 #2
0
 public void InvalidString()
 {
     using (var container = new RhetosTestContainer())
     {
         var simple = container.Resolve <Common.DomRepository>().TestAllowSave.Simple;
         var s1     = new TestAllowSave.Simple {
             Code = 1, Name = null, CodeAS = 2, NameAS = "b"
         };
         TestUtility.ShouldFail <UserException>(
             () => simple.Insert(s1),
             "It is not allowed to enter TestAllowSave.Simple because the required property Name is not set.",
             "SystemMessage: DataStructure:TestAllowSave.Simple,ID:", ",Property:Name");
     }
     using (var container = new RhetosTestContainer())
     {
         var simple = container.Resolve <Common.DomRepository>().TestAllowSave.Simple;
         var s1     = new TestAllowSave.Simple {
             Code = 1, Name = "", CodeAS = 2, NameAS = "b"
         };
         TestUtility.ShouldFail <UserException>(
             () => simple.Insert(s1),
             "It is not allowed to enter TestAllowSave.Simple because the required property Name is not set.",
             "SystemMessage: DataStructure:TestAllowSave.Simple,ID:", ",Property:Name");
     }
 }
コード例 #3
0
        public void AllowSave()
        {
            foreach (bool useDatabaseNullSemantics in new[] { false, true })
            {
                using (var scope = TestScope.Create(builder => builder.ConfigureUseDatabaseNullSemantics(useDatabaseNullSemantics)))
                {
                    var simple = scope.Resolve <Common.DomRepository>().TestAllowSave.Simple;
                    var s1     = new TestAllowSave.Simple {
                        Code = 1, Name = "a", CodeAS = null, NameAS = null
                    };
                    var s2 = new TestAllowSave.Simple {
                        Code = 1, Name = "aaaaa", CodeAS = 2, NameAS = "b"
                    };

                    simple.Insert(s1, s2);
                    Assert.AreEqual("1a, 1aaaaa2b", TestUtility.DumpSorted(simple.Load(new[] { s1.ID, s2.ID }), s => s.Code + s.Name + s.CodeAS + s.NameAS));
                    Assert.AreEqual(0, simple.Validate(new[] { s1.ID, s2.ID }, onSave: true).Count(), "There should be no invalid items with errors that are checked on save.");

                    // Errors that are NOT checked on save:
                    var errors = simple.Validate(new[] { s1.ID, s2.ID }, onSave: false);
                    Assert.AreEqual(
                        TestUtility.DumpSorted(new[] {
                        "The required property CodeAS is not set./CodeAS/" + s1.ID,
                        "The required property NameAS is not set./NameAS/" + s1.ID,
                        "[Test] Longer than 3.//" + s2.ID,
                        "[Test] Longer than 4./Name/" + s2.ID
                    }),
                        TestUtility.DumpSorted(errors,
                                               error => string.Format(error.Message, error.MessageParameters) + "/" + error.Property + "/" + error.ID));
                }
            }
        }
コード例 #4
0
 public void ValidData()
 {
     using (var container = new RhetosTestContainer())
     {
         var simple = container.Resolve <Common.DomRepository>().TestAllowSave.Simple;
         var s1     = new TestAllowSave.Simple {
             Code = 1, Name = "a", CodeAS = 2, NameAS = "b"
         };
         simple.Insert(s1);
         Assert.AreEqual("1a2b", simple.Query(new[] { s1.ID }).Select(s => s.Code + s.Name + s.CodeAS + s.NameAS).Single());
     }
 }
コード例 #5
0
 public void InvalidInteger()
 {
     using (var scope = TestScope.Create())
     {
         var simple = scope.Resolve <Common.DomRepository>().TestAllowSave.Simple;
         var s1     = new TestAllowSave.Simple {
             Code = null, Name = "a", CodeAS = 2, NameAS = "b"
         };
         TestUtility.ShouldFail <UserException>(
             () => simple.Insert(s1),
             "It is not allowed to enter TestAllowSave.Simple because the required property Code is not set.",
             "SystemMessage: DataStructure:TestAllowSave.Simple,ID:", ",Property:Code");
     }
 }
コード例 #6
0
        public void AllowSaveEmptyString()
        {
            using (var container = new RhetosTestContainer())
            {
                var simple = container.Resolve <Common.DomRepository>().TestAllowSave.Simple;
                var s1     = new TestAllowSave.Simple {
                    Code = 1, Name = "a", CodeAS = 2, NameAS = ""
                };

                simple.Insert(s1);
                Assert.AreEqual("1a2", simple.Query(new[] { s1.ID }).Select(s => s.Code + s.Name + s.CodeAS + s.NameAS).Single());
                Assert.AreEqual(0, simple.Validate(new[] { s1.ID }, onSave: true).Count(), "There should be no invalid items with errors that are checked on save.");

                // Errors that are NOT checked on save:
                var errors = simple.Validate(new[] { s1.ID }, onSave: false);
                Assert.AreEqual(
                    "The required property NameAS is not set./NameAS",
                    TestUtility.DumpSorted(errors, error => string.Format(error.Message, error.MessageParameters) + "/" + error.Property));
                Assert.IsTrue(errors.All(e => e.ID == s1.ID));
            }
        }