Exemplo n.º 1
0
        public void WorksWithConstraints()
        {
            using (var container = new RhetosTestContainer())
            {
                var context    = container.Resolve <Common.ExecutionContext>();
                var repository = container.Resolve <Common.DomRepository>();

                string currentUserName = container.Resolve <IUserInfo>().UserName;
                Assert.IsTrue(!string.IsNullOrWhiteSpace(currentUserName));
                var currentPrincipal = context.InsertPrincipalOrReadId(currentUserName);

                var testItem1 = new TestCreatedBy.WithConstraints {
                    ID = Guid.NewGuid(), Name = "test1"
                };
                var testItem2 = new TestCreatedBy.WithConstraints {
                    ID = Guid.NewGuid(), Name = "test2"
                };
                repository.TestCreatedBy.WithConstraints.Insert(testItem1, testItem2);

                Assert.AreEqual(
                    "test1 " + currentUserName + ", test2 " + currentUserName,
                    TestUtility.DumpSorted(repository.TestCreatedBy.WithConstraints
                                           .Query(new[] { testItem1.ID, testItem2.ID })
                                           .Select(item => item.Name + " " + item.Author.Name)));
            }
        }
Exemplo n.º 2
0
        public void FailsOnDenyUserEdit()
        {
            using (var container = new RhetosTestContainer())
            {
                var genericRepositories = container.Resolve <GenericRepositories>();
                var repository          = container.Resolve <Common.DomRepository>();

                string currentUserName = container.Resolve <IUserInfo>().UserName;
                Assert.IsTrue(!string.IsNullOrWhiteSpace(currentUserName));
                var currentPrincipal = new Common.Principal {
                    Name = currentUserName
                };
                genericRepositories.InsertOrReadId(currentPrincipal, p => p.Name);

                var testItem1 = new TestCreatedBy.WithConstraints {
                    ID = Guid.NewGuid(), Name = "test1"
                };
                var testItem2 = new TestCreatedBy.WithConstraints {
                    ID = Guid.NewGuid(), Name = "test2", AuthorID = currentPrincipal.ID
                };

                TestUtility.ShouldFail <Rhetos.UserException>(
                    () => repository.TestCreatedBy.WithConstraints.Insert(new[] { testItem1, testItem2 }, checkUserPermissions: true),
                    "It is not allowed to directly enter", "Author");
            }
        }
Exemplo n.º 3
0
        public void SupportsAnonymous()
        {
            using (var scope = TestScope.Create(builder => builder.RegisterType <AnonUser>().As <IUserInfo>()))
            {
                var repository = scope.Resolve <Common.DomRepository>();

                var testSimple = new TestCreatedBy.Simple();
                repository.TestCreatedBy.Simple.Insert(testSimple);
                Assert.IsNull(repository.TestCreatedBy.Simple.Load(new[] { testSimple.ID }).Single().AuthorID);

                var testWithConstraints = new TestCreatedBy.WithConstraints();
                TestUtility.ShouldFail <Rhetos.UserException>(
                    () => repository.TestCreatedBy.WithConstraints.Insert(testWithConstraints),
                    "required property", "Author");
            }
        }
Exemplo n.º 4
0
        public void FailsOnDenyUserEdit()
        {
            using (var container = new RhetosTestContainer())
            {
                var genericRepositories = container.Resolve<GenericRepositories>();
                var repository = container.Resolve<Common.DomRepository>();

                string currentUserName = container.Resolve<IUserInfo>().UserName;
                Assert.IsTrue(!string.IsNullOrWhiteSpace(currentUserName));
                var currentPrincipal = new Common.Principal { Name = currentUserName };
                genericRepositories.InsertOrReadId(currentPrincipal, p => p.Name);

                var testItem1 = new TestCreatedBy.WithConstraints { ID = Guid.NewGuid(), Name = "test1" };
                var testItem2 = new TestCreatedBy.WithConstraints { ID = Guid.NewGuid(), Name = "test2", AuthorID = currentPrincipal.ID };

                TestUtility.ShouldFail<Rhetos.UserException>(
                    () => repository.TestCreatedBy.WithConstraints.Insert(new[] { testItem1, testItem2 }, checkUserPermissions: true),
                    "It is not allowed to directly enter", "Author");
            }
        }
Exemplo n.º 5
0
        public void FailsOnDenyUserEdit()
        {
            using (var scope = TestScope.Create())
            {
                var context    = scope.Resolve <Common.ExecutionContext>();
                var repository = scope.Resolve <Common.DomRepository>();

                string currentUserName = scope.Resolve <IUserInfo>().UserName;
                Assert.IsTrue(!string.IsNullOrWhiteSpace(currentUserName));
                var currentPrincipal = context.InsertPrincipalOrReadId(currentUserName);

                var testItem1 = new TestCreatedBy.WithConstraints {
                    ID = Guid.NewGuid(), Name = "test1"
                };
                var testItem2 = new TestCreatedBy.WithConstraints {
                    ID = Guid.NewGuid(), Name = "test2", AuthorID = currentPrincipal.ID
                };

                TestUtility.ShouldFail <Rhetos.UserException>(
                    () => repository.TestCreatedBy.WithConstraints.Insert(new[] { testItem1, testItem2 }, checkUserPermissions: true),
                    "It is not allowed to directly enter", "Author");
            }
        }
Exemplo n.º 6
0
        public void WorksWithConstraints()
        {
            using (var container = new RhetosTestContainer())
            {
                var genericRepositories = container.Resolve<GenericRepositories>();
                var repository = container.Resolve<Common.DomRepository>();

                string currentUserName = container.Resolve<IUserInfo>().UserName;
                Assert.IsTrue(!string.IsNullOrWhiteSpace(currentUserName));
                var currentPrincipal = new Common.Principal { Name = currentUserName };
                genericRepositories.InsertOrReadId(currentPrincipal, p => p.Name);

                var testItem1 = new TestCreatedBy.WithConstraints { ID = Guid.NewGuid(), Name = "test1" };
                var testItem2 = new TestCreatedBy.WithConstraints { ID = Guid.NewGuid(), Name = "test2" };
                repository.TestCreatedBy.WithConstraints.Insert(testItem1, testItem2);

                Assert.AreEqual(
                    "test1 " + currentUserName + ", test2 " + currentUserName,
                    TestUtility.DumpSorted(repository.TestCreatedBy.WithConstraints
                        .Query(new[] { testItem1.ID, testItem2.ID })
                        .Select(item => item.Name + " " + item.Author.Name)));
            }
        }