コード例 #1
0
        public void GivenEmployment_WhenEmploymentPeriodIsNotValid_ThenEmployeeIsNotInSalesRepUserGroup()
        {
            var salesRep = new Persons(this.DatabaseSession).FindBy(Persons.Meta.LastName, "salesRep");
            var internalOrganisation = new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation");

            var usergroups = internalOrganisation.UserGroupsWhereParty;
            usergroups.Filter.AddEquals(UserGroups.Meta.Parent, new Roles(this.DatabaseSession).Sales.UserGroupWhereRole);
            var salesRepUserGroup = usergroups.First;

            Assert.AreEqual(1, salesRepUserGroup.Members.Count);
            Assert.Contains(salesRep, salesRepUserGroup.Members);

            salesRep.EmploymentsWhereEmployee.First.FromDate = DateTime.UtcNow.AddDays(+1);
            salesRep.EmploymentsWhereEmployee.First.RemoveThroughDate();

            this.DatabaseSession.Derive(true);

            Assert.AreEqual(0, salesRepUserGroup.Members.Count);

            salesRep.EmploymentsWhereEmployee.First.FromDate = DateTime.UtcNow;
            salesRep.EmploymentsWhereEmployee.First.RemoveThroughDate();

            this.DatabaseSession.Derive(true);

            Assert.AreEqual(1, salesRepUserGroup.Members.Count);
            Assert.Contains(salesRep, salesRepUserGroup.Members);

            salesRep.EmploymentsWhereEmployee.First.FromDate = DateTime.UtcNow.AddDays(-2);
            salesRep.EmploymentsWhereEmployee.First.ThroughDate = DateTime.UtcNow.AddDays(-1);

            this.DatabaseSession.Derive(true);

            Assert.AreEqual(0, salesRepUserGroup.Members.Count);
        }
コード例 #2
0
ファイル: SaveTests.cs プロジェクト: whesius/allors
        public void AdministratorRemoveMany()
        {
            // Arrange
            var administrator = new Persons(this.Session).FindBy(Persons.Meta.UserName, Users.AdministratorUserName);

            var c1a = new C1Builder(this.Session)
               .Build();

            var c1b = new C1Builder(this.Session)
               .Build();

            var c1c = new C1Builder(this.Session)
               .Build();

            c1a.AddC1C1One2Many(c1b);
            c1a.AddC1C1One2Many(c1c);

            this.Session.Derive();
            this.Session.Commit();

            var saveRequest = new SaveRequest
            {
                Objects = new[] {
                    new SaveRequestObject
                    {
                        I = c1a.Id.ToString(),
                        V = c1a.Strategy.ObjectVersion.ToString(),
                        Roles = new List<SaveRequestRole>
                        {
                            new SaveRequestRole
                            {
                                T = "C1C1One2Many",
                                R = new [] { c1c.Id.ToString() }
                            }
                        }
                    }
                }
            };

            var controller = new AngularController { AllorsSession = this.Session, AuthenticatedUser = administrator };

            // Act
            var jsonResult = (JsonResult)controller.Save(saveRequest);
            var saveResponse = (SaveResponse)jsonResult.Data;

            // Assert
            this.Session.Rollback();

            saveResponse.Errors.Count.ShouldEqual(0);

            c1a.C1C1One2Manies.ShouldNotBeSameAs(new[] { c1b });
        }
コード例 #3
0
ファイル: SetupController.cs プロジェクト: Mathus/dipu
        private static void SetupDefault()
        {
            var database = Config.Default;
            database.Init();

            using (var session = database.CreateSession())
            {
                new Setup(session).Apply();

                var passwordHasher = new PasswordHasher();

                var koen = new Persons(session).Extent().First(x => "*****@*****.**".Equals(x.UserEmail));
                koen.UserPasswordHash = passwordHasher.HashPassword("a");

                new UserGroups(session).Administrators.AddMember(koen);

                session.Derive();
                session.Commit();
            }
        }
コード例 #4
0
ファイル: LoadTests.cs プロジェクト: whesius/allors
        public void Administrator()
        {
            // Arrange
            var administrator = new Persons(this.Session).FindBy(Persons.Meta.UserName, Users.AdministratorUserName);

            var c1a = new C1Builder(this.Session)
               .WithC1AllorsString("c1")
               .WithI1AllorsString("i1")
               .WithI12AllorsString("i12")
               .Build();

            this.Session.Derive();
            this.Session.Commit();

            var loadRequest = new LoadRequest
            {
                Objects = new[] { c1a.Id.ToString() }
            };

            var controller = new AngularController { AllorsSession = this.Session, AuthenticatedUser = administrator};

            // Act
            var jsonResult = (JsonResult)controller.Load(loadRequest);
            var loadResponse = (LoadResponse)jsonResult.Data;

            // Assert
            loadResponse.Objects.Length.ShouldEqual(1);

            var responseC1a = loadResponse.Objects[0];

            responseC1a.Roles.Length.ShouldEqual(2);

            var responseC1AllorsString = responseC1a.Roles.First(v => v[0].Equals("C1AllorsString"));
            responseC1AllorsString[1].ShouldEqual("rw");
            responseC1AllorsString[2].ShouldEqual("c1");

            var responseI1AllorsString = responseC1a.Roles.First(v => v[0].Equals("I1AllorsString"));
            responseI1AllorsString[1].ShouldEqual("rw");
            responseI1AllorsString[2].ShouldEqual("i1");
        }
コード例 #5
0
ファイル: Setup.cs プロジェクト: whesius/allors
        private void BaseOnPostSetup()
        {
            var guest = new Persons(this.session).FindBy(Persons.Meta.UserName, Users.GuestUserName);
            new UserGroups(this.session).Guests.AddMember(guest);
            Singleton.Instance(this.session).Guest = guest;

            var administrator = new Persons(this.session).FindBy(Persons.Meta.UserName, Domain.Users.AdministratorUserName);
            new UserGroups(this.session).Administrators.AddMember(administrator);
        }
コード例 #6
0
ファイル: SaveTests.cs プロジェクト: whesius/allors
        public void AdministratorSetUnit()
        {
            // Arrange
            var administrator = new Persons(this.Session).FindBy(Persons.Meta.UserName, Users.AdministratorUserName);

            var c1a = new C1Builder(this.Session)
               .WithC1AllorsString("c1")
               .WithI1AllorsString("i1")
               .WithI12AllorsString("i12")
               .Build();

            this.Session.Derive();
            this.Session.Commit();

            var saveRequest = new SaveRequest
            {
                Objects = new[] {
                    new SaveRequestObject
                    {
                        I = c1a.Id.ToString(),
                        V = c1a.Strategy.ObjectVersion.ToString(),
                        Roles = new List<SaveRequestRole>
                        {
                            new SaveRequestRole
                            {
                                T = "C1AllorsString",
                                S = "new c1"
                            }
                        }
                    }
                }
            };

            var controller = new AngularController { AllorsSession = this.Session,AuthenticatedUser = administrator};

            // Act
            var jsonResult = (JsonResult)controller.Save(saveRequest);
            var saveResponse = (SaveResponse)jsonResult.Data;

            // Assert
            this.Session.Rollback();

            saveResponse.Errors.Count.ShouldEqual(0);

            c1a.C1AllorsString.ShouldEqual("new c1");
        }