コード例 #1
0
        public void Test_Update_AutoActivateReferences()
        {
            // Create the mock entities
            TestUser user = CreateStrategy.New <TestUser>(false).Create <TestUser>();

            user.ID        = Guid.NewGuid();
            user.FirstName = "Test";
            user.LastName  = "User";

            TestRole role = CreateStrategy.New <TestRole>(false).Create <TestRole>();

            role.ID   = Guid.NewGuid();
            role.Name = "Test Role";

            // Assign the user to the role
            user.Roles = new TestRole[] { role };

            // Save the entities
            SaveStrategy.New(role, false).Save(role);
            SaveStrategy.New(user, false).Save(user);

            // Retrieve the mock user from the data store
            TestUser foundUser = RetrieveStrategy.New <TestUser>(false).Retrieve <TestUser>("ID", user.ID);

            // Change a standard property value
            foundUser.FirstName = "Test2";

            // Update WITHOUT having activated the user manually
            // This update should automatically activate the user entity before updating and
            // should therefore persist the references
            UpdateStrategy.New(foundUser, false).Update(foundUser);

            // Retrieve the mock user again
            TestUser foundUser2 = RetrieveStrategy.New <TestUser>(false).Retrieve <TestUser>("ID", user.ID);

            // Manually activate the user
            foundUser2.Activate();

            // Assert that the referenced roles are found on the user which indicates
            // that the update strategy did automatically activate the entity and persist
            // the references
            Assert.IsNotNull(foundUser2.Roles, "Roles property is null.");
            Assert.AreEqual(1, foundUser2.Roles.Length, "Invalid number of roles assigned to user.");
        }