Beispiel #1
0
        public void LeavePredefinedUser()
        {
            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);

                string otherUserName = "******" + Guid.NewGuid();
                var otherPrincipal = new Common.Principal { Name = otherUserName };
                genericRepositories.InsertOrReadId(otherPrincipal, p => p.Name);

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

                Assert.AreEqual(
                    "test1 " + otherUserName + ", test2 " + currentUserName,
                    TestUtility.DumpSorted(repository.TestCreatedBy.Simple
                        .Query(new[] { testItem1.ID, testItem2.ID })
                        .Select(item => item.Name + " " + item.Author.Name)));
            }
        }
Beispiel #2
0
        public void LeavePredefinedUser()
        {
            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);

                string otherUserName  = "******" + Guid.NewGuid();
                var    otherPrincipal = context.InsertPrincipalOrReadId(otherUserName);

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

                Assert.AreEqual(
                    "test1 " + otherUserName + ", test2 " + currentUserName,
                    TestUtility.DumpSorted(repository.TestCreatedBy.Simple
                                           .Query(new[] { testItem1.ID, testItem2.ID })
                                           .Select(item => item.Name + " " + item.Author.Name)));
            }
        }
        public void SetCurrentUser()
        {
            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.Simple {
                    ID = Guid.NewGuid(), Name = "test1"
                };
                var testItem2 = new TestCreatedBy.Simple {
                    ID = Guid.NewGuid(), Name = "test2"
                };
                repository.TestCreatedBy.Simple.Insert(testItem1, testItem2);

                Assert.AreEqual(
                    "test1 " + currentUserName + ", test2 " + currentUserName,
                    TestUtility.DumpSorted(repository.TestCreatedBy.Simple
                                           .Query(new[] { testItem1.ID, testItem2.ID })
                                           .Select(item => item.Name + " " + item.Author.Name)));
            }
        }
Beispiel #4
0
        public void SetCurrentUser()
        {
            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.Simple {
                    ID = Guid.NewGuid(), Name = "test1"
                };
                var testItem2 = new TestCreatedBy.Simple {
                    ID = Guid.NewGuid(), Name = "test2"
                };
                repository.TestCreatedBy.Simple.Insert(testItem1, testItem2);

                Assert.AreEqual(
                    "test1 " + currentUserName + ", test2 " + currentUserName,
                    TestUtility.DumpSorted(repository.TestCreatedBy.Simple
                                           .Query(new[] { testItem1.ID, testItem2.ID })
                                           .Select(item => item.Name + " " + item.Author.Name)));
            }
        }
        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");
            }
        }