public void BasicOrganizationTest()
        {
            IOrganizationApi organizationApi = SpringContext.Current.GetObject<IOrganizationApi>();

            OrganizationTypeObject department = new OrganizationTypeObject { Name = "department", Domain = "Department", Description = "department-desc" };
            organizationApi.Save(department);
            createdOrganizationTypeIds.Add(department.OrganizationTypeId);

            OrganizationObject shOrganization = new OrganizationObject
            {
                OrganizationCode = "sh021",
                OrganizationName = "sh-department",
                OrganizationTypeId = department.OrganizationTypeId,
                Status = OrganizationStatus.Enabled,
                Description = "sh-desc"
            };

            organizationApi.Save(shOrganization);
            createdOrganizationIds.Add(shOrganization.OrganizationId);

            OrganizationObject cdOrganization = new OrganizationObject
            {
                OrganizationCode = "cd028",
                OrganizationName = "cd-department",
                OrganizationTypeId = department.OrganizationTypeId,
                Status = OrganizationStatus.Enabled,
                Description = "cd-desc"
            };

            organizationApi.Save(cdOrganization);
            createdOrganizationIds.Add(cdOrganization.OrganizationId);

            shOrganization = organizationApi.GetOrganization(shOrganization.OrganizationId);
            Assert.AreEqual("sh021", shOrganization.OrganizationCode);
            Assert.AreEqual("sh-department", shOrganization.OrganizationName);
            Assert.IsFalse(shOrganization.ParentOrganizationId.HasValue);
            Assert.AreEqual(OrganizationStatus.Enabled, shOrganization.Status);
            Assert.AreEqual("sh-desc", shOrganization.Description);

            cdOrganization = organizationApi.GetOrganization(cdOrganization.OrganizationId);
            Assert.IsNotNull(cdOrganization);

            shOrganization.OrganizationName = "021-depart";
            shOrganization.Description = "021-desc";
            organizationApi.Save(shOrganization);

            shOrganization = organizationApi.GetOrganization(shOrganization.OrganizationId);
            Assert.AreEqual("021-depart", shOrganization.OrganizationName);
            Assert.IsFalse(shOrganization.ParentOrganizationId.HasValue);
            Assert.AreEqual(OrganizationStatus.Enabled, shOrganization.Status);
            Assert.AreEqual("021-desc", shOrganization.Description);

            shOrganization = organizationApi.GetOrganizationByName("021-depart");
            Assert.AreEqual("021-depart", shOrganization.OrganizationName);

            shOrganization = organizationApi.GetOrganizationByCode("sh021");
            Assert.AreEqual("021-depart", shOrganization.OrganizationName);
        }
        public void UpdateOrganizationStatusTest()
        {
            IOrganizationApi organizationApi = SpringContext.Current.GetObject<IOrganizationApi>();

            OrganizationTypeObject department = new OrganizationTypeObject { Name = "department", Domain = "Department", Description = "department-desc" };
            organizationApi.Save(department);
            createdOrganizationTypeIds.Add(department.OrganizationTypeId);

            OrganizationObject shOrganization = new OrganizationObject
            {
                OrganizationCode = "sh",
                OrganizationName = "sh-department",
                OrganizationTypeId = department.OrganizationTypeId,
                Status = OrganizationStatus.Enabled,
                Description = "sh-desc"
            };

            organizationApi.Save(shOrganization);
            createdOrganizationIds.Add(shOrganization.OrganizationId);

            OrganizationObject cdOrganization = new OrganizationObject
            {
                OrganizationCode = "cd",
                OrganizationName = "cd-department",
                OrganizationTypeId = department.OrganizationTypeId,
                Status = OrganizationStatus.Enabled,
                ParentOrganizationId = shOrganization.OrganizationId,
                Description = "cd-desc"
            };

            organizationApi.Save(cdOrganization);
            createdOrganizationIds.Add(cdOrganization.OrganizationId);

            // update parent's status from Enabled to Disabled will affect its children
            shOrganization.Status = OrganizationStatus.Disabled;
            organizationApi.Save(shOrganization);
            shOrganization = organizationApi.GetOrganization(shOrganization.OrganizationId);
            cdOrganization = organizationApi.GetOrganization(cdOrganization.OrganizationId);
            Assert.AreEqual(OrganizationStatus.Disabled, shOrganization.Status);
            Assert.AreEqual(OrganizationStatus.Disabled, cdOrganization.Status);

            // update parent's status from Disabled to Enabled won't affect its children
            shOrganization.Status = OrganizationStatus.Enabled;
            organizationApi.Save(shOrganization);
            shOrganization = organizationApi.GetOrganization(shOrganization.OrganizationId);
            cdOrganization = organizationApi.GetOrganization(cdOrganization.OrganizationId);
            Assert.AreEqual(OrganizationStatus.Enabled, shOrganization.Status);
            Assert.AreEqual(OrganizationStatus.Disabled, cdOrganization.Status);

            cdOrganization.Status = OrganizationStatus.Enabled;
            organizationApi.Save(cdOrganization);

            // update child's status from Enabled to Disabled won't affect its parent
            cdOrganization.Status = OrganizationStatus.Disabled;
            organizationApi.Save(cdOrganization);
            shOrganization = organizationApi.GetOrganization(shOrganization.OrganizationId);
            cdOrganization = organizationApi.GetOrganization(cdOrganization.OrganizationId);
            Assert.AreEqual(OrganizationStatus.Enabled, shOrganization.Status);
            Assert.AreEqual(OrganizationStatus.Disabled, cdOrganization.Status);
        }
        public void WrongChildOrganizationStatusOnCreatingTest()
        {
            IOrganizationApi organizationApi = SpringContext.Current.GetObject<IOrganizationApi>();
            OrganizationTypeObject department = new OrganizationTypeObject { Name = "department", Domain = "Department", Description = "department-desc" };
            organizationApi.Save(department);
            createdOrganizationTypeIds.Add(department.OrganizationTypeId);

            OrganizationObject shOrganization = new OrganizationObject
            {
                OrganizationCode = "sh",
                OrganizationName = "sh-department",
                OrganizationTypeId = department.OrganizationTypeId,
                Status = OrganizationStatus.Disabled,
                Description = "sh-desc"
            };

            organizationApi.Save(shOrganization);
            createdOrganizationIds.Add(shOrganization.OrganizationId);

            OrganizationObject cdOrganization = new OrganizationObject
            {
                OrganizationCode = "cd",
                OrganizationName = "cd-department",
                OrganizationTypeId = department.OrganizationTypeId,
                Status = OrganizationStatus.Enabled,
                ParentOrganizationId = shOrganization.OrganizationId,
                Description = "cd-desc"
            };

            organizationApi.Save(cdOrganization);
        }
        public void FindOrganizationTest()
        {
            IOrganizationApi organizationApi = SpringContext.Current.GetObject<IOrganizationApi>();

            OrganizationTypeObject department = new OrganizationTypeObject { Name = "department", Domain = "Department", Description = "department-desc" };
            organizationApi.Save(department);
            createdOrganizationTypeIds.Add(department.OrganizationTypeId);

            OrganizationObject shanghai = new OrganizationObject
            {
                OrganizationCode = "sh",
                OrganizationName = "shanghai department",
                OrganizationTypeId = department.OrganizationTypeId,
                Status = OrganizationStatus.Enabled,
                Description = "shanghai desc"
            };

            organizationApi.Save(shanghai);
            createdOrganizationIds.Add(shanghai.OrganizationId);

            OrganizationObject chengdu = new OrganizationObject
            {
                OrganizationCode = "cd",
                OrganizationName = "chengdu department",
                OrganizationTypeId = department.OrganizationTypeId,
                Status = OrganizationStatus.Enabled,
                Description = "chengdu desc"
            };

            organizationApi.Save(chengdu);
            createdOrganizationIds.Add(chengdu.OrganizationId);

            int recordCount;
            LinqPredicate linqPredicate = new LinqPredicate("OrganizationName.EndsWith(@0) And Status=@1", "department", OrganizationStatus.Enabled);
            IEnumerable<OrganizationObject> organizations = organizationApi.FindOrganizations(linqPredicate, null, 0, 10, out recordCount);
            Assert.AreEqual(2, recordCount);
        }
        public void SaveOrganizationTest()
        {
            IOrganizationApi organizationApi = SpringContext.Current.GetObject<IOrganizationApi>();

            OrganizationTypeObject department = new OrganizationTypeObject { Name = "department", Domain = "Department", Description = "department-desc" };
            organizationApi.Save(department);
            createdOrganizationTypeIds.Add(department.OrganizationTypeId);

            OrganizationObject shanghai = new OrganizationObject
            {
                OrganizationCode = "sh",
                OrganizationName = "sh-department",
                OrganizationTypeId = department.OrganizationTypeId,
                Status = OrganizationStatus.Enabled,
                Description = "sh-desc"
            };

            organizationApi.Save(shanghai);
            createdOrganizationIds.Add(shanghai.OrganizationId);

            shanghai = organizationApi.GetOrganization(shanghai.OrganizationId);
            shanghai.OrganizationName = "shanghai organization";
            shanghai.Description = "shanghai organization description";
            organizationApi.Save(shanghai);

            shanghai = organizationApi.GetOrganization(shanghai.OrganizationId);
            Assert.AreEqual("shanghai organization", shanghai.OrganizationName);
            Assert.AreEqual("shanghai organization description", shanghai.Description);
        }
        /// <summary>
        /// Get the copy of current object.
        /// </summary>
        /// <returns></returns>
        public OrganizationObject Clone()
        {
            OrganizationObject copy = new OrganizationObject
            {
                OrganizationId = this.OrganizationId,
                Description = this.Description,
                ParentOrganizationId = this.ParentOrganizationId,
                Hierarchies = this.Hierarchies,
                Status = this.Status,
                OrganizationCode = this.OrganizationCode,
                OrganizationName = this.OrganizationName,
                OrganizationTypeId = this.OrganizationTypeId,
                CreatedBy = this.CreatedBy,
                CreatedDate = this.CreatedDate,
                LastUpdatedBy = this.LastUpdatedBy,
                LastUpdatedDate = this.LastUpdatedDate,
                ExtensionDataTypeId = this.ExtensionDataTypeId
            };

            this.ClonePropertiesTo(copy);
            return copy;
        }
        public void TestCreate()
        {
            UserDetailPanel page = new UserDetailPanel();

            DetailPanelPageProxy proxy = new DetailPanelPageProxy(page);

            IOrganizationApi organizationApi = SpringContext.Current.GetObject<IOrganizationApi>();

            using (var httpEnv = new HttpEnvironment())
            {
                httpEnv.SetRequestUrl(@"/UserDetailPanel/DynamicPage.svc?Domain=Department");

                #region bind web control
                Guid guid = Guid.NewGuid();
                string surfix = guid.ToString().Substring(0, 5);

                OrganizationSelector OrganizationSelector = new OrganizationSelector();
                //IList<OrganizationObject> ds = new List<OrganizationObject>();
                OrganizationObject organization = new OrganizationObject()
                {
                    OrganizationCode = "123456" + surfix,
                    OrganizationName = "org" + surfix,
                    Status = OrganizationStatus.Enabled,
                    OrganizationTypeId = organizationApi.FindOrganizationTypes(new List<string>() { "Department" }).Select(x => x.OrganizationTypeId).FirstOrDefault(),
                    Description = "organ"
                };

                organizationApi.Save(organization);
                //ds.Add(organization);
                createdOrganizationIds.Add(organization.OrganizationId);

                OrganizationSelector.SelectedOrganization = organization;

                proxy.Set("OrganizationSelector", OrganizationSelector);

                TextBox TextBoxUserName = new TextBox();
                TextBoxUserName.Text = "Eunge" + surfix;
                proxy.Set("TextBoxUserName", TextBoxUserName);

                TextBox TextBoxPassword = new TextBox();
                TextBoxPassword.Text = "Password" + surfix;
                proxy.Set("TextBoxPassword", TextBoxPassword);

                TextBox TextBoxConfirmPassword = new TextBox();
                TextBoxConfirmPassword.Text = "Password" + surfix;
                proxy.Set("TextBoxConfirmPassword", TextBoxConfirmPassword);

                TextBox TextBoxDisplayName = new TextBox();
                TextBoxDisplayName.Text = "Eunge" + surfix;
                proxy.Set("TextBoxDisplayName", TextBoxConfirmPassword);

                TextBox TextBoxEmail = new TextBox();
                TextBoxEmail.Text = "*****@*****.**";
                proxy.Set("TextBoxEmail", TextBoxEmail);

                TextBox TextBoxMobile = new TextBox();
                TextBoxMobile.Text = "13456789009";
                proxy.Set("TextBoxMobile", TextBoxMobile);

                ExtensionDataForm UserExtensionDataForm = null;
                proxy.Set("UserExtensionDataForm", UserExtensionDataForm);

                TextBox TextBoxComment = new TextBox();
                TextBoxComment.Text = "13456789009" + surfix;
                proxy.Set("TextBoxComment", TextBoxComment);

                Array statusData = new string[] { "true", "false" };
                RadioButtonList RadioButtonListStatus = new RadioButtonList();
                RadioButtonListStatus.DataSource = statusData;
                RadioButtonListStatus.DataBind();
                RadioButtonListStatus.SelectedIndex = 0;
                proxy.Set("RadioButtonListStatus", RadioButtonListStatus);

                TextBox TextBoxCreationDate = new TextBox();
                TextBoxCreationDate.Text = System.DateTime.UtcNow.ToShortTimeString();
                proxy.Set("TextBoxCreationDate", TextBoxCreationDate);

                TextBox TextBoxLastLoginDate = new TextBox();
                TextBoxLastLoginDate.Text = System.DateTime.UtcNow.ToShortTimeString();
                proxy.Set("TextBoxLastLoginDate", TextBoxLastLoginDate);

                TextBox TextBoxLastActivityDate = new TextBox();
                TextBoxLastActivityDate.Text = System.DateTime.UtcNow.ToShortTimeString();
                proxy.Set("TextBoxLastActivityDate", TextBoxLastActivityDate);

                TextBox TextBoxLockedOutDate = new TextBox();
                TextBoxLockedOutDate.Text = System.DateTime.UtcNow.ToShortTimeString();
                proxy.Set("TextBoxLockedOutDate", TextBoxLockedOutDate);

                TextBox TextBoxLastPasswordChangedDate = new TextBox();
                TextBoxLastPasswordChangedDate.Text = System.DateTime.UtcNow.ToShortTimeString();
                proxy.Set("TextBoxLastPasswordChangedDate", TextBoxLastPasswordChangedDate);

                TextBox TextBoxLastUpdatedDate = new TextBox();
                TextBoxLastUpdatedDate.Text = System.DateTime.UtcNow.ToShortTimeString();
                proxy.Set("TextBoxLastUpdatedDate", TextBoxLastUpdatedDate);

                PermissionTreeView @PermissionTreeView = null;
                proxy.Set("PermissionTreeView", @PermissionTreeView);

                #endregion
                string entity = proxy.Create();
                createdObjectIds.Add(new Guid(entity));

            }
        }
        public void TestQuery()
        {
            OrganizationManagement page = new OrganizationManagement();

            DynamicPageProxy proxy = new DynamicPageProxy(page);

            IOrganizationApi organizationApi = SpringContext.Current.GetObject<IOrganizationApi>();

            using (var httpEnv = new HttpEnvironment())
            {
                #region Create Data
                Guid guid = Guid.NewGuid();
                string surfix = guid.ToString().Substring(0, 5);
                OrganizationObject testOrganization = new OrganizationObject()
                {
                    OrganizationCode = "78903" + surfix,
                    OrganizationName = "testOrganizationUpdate" + surfix,
                    OrganizationTypeId = organizationApi.FindOrganizationTypes(new List<string>() { "Department" }).Select(x => x.OrganizationTypeId).FirstOrDefault(),
                    Status = OrganizationStatus.Enabled
                };

                organizationApi.Save(testOrganization);
                createdOrganizationIds.Add(testOrganization.OrganizationId);
                #endregion

                httpEnv.SetRequestUrl(@"/OrganizationManagement/DynamicPage.svc?Domain=Department");

                QueryParameterExpression expression = new QueryParameterExpression("organizationName", QueryFieldOperators.Equal, "testOrganizationUpdate" + surfix);

                SortExpression sort = new SortExpression("organizationName");

                QueryParameter parameters = new QueryParameter()
                {
                    //Expressions = express,
                    PageIndex = 0,
                    PageSize = 10,
                    SortExpression = sort
                };

                parameters.Expressions.Add(expression);

                QueryResults results = proxy.Query(parameters);

                foreach (var result in results.Results)
                {
                    Assert.AreEqual(DataBinder.Eval(result,"organizationName"), "testOrganizationUpdate" + surfix);
                }
            }
        }
        public void TestUpdate()
        {
            OrganizationDetailPanel testpage = new OrganizationDetailPanel();

            DetailPanelPageProxy proxy = new DetailPanelPageProxy(testpage);

            IOrganizationApi organizationApi = SpringContext.Current.GetObject<IOrganizationApi>();

            Guid guid = Guid.NewGuid();

            string surfix = guid.ToString().Substring(0, 5);

            using (var httpEnv = new HttpEnvironment())
            {
                #region Setup the pre-required data
                //Setup the right URL
                httpEnv.SetRequestUrl("/OrganizationDetailPanel/DynamicPage.svc?Domain=Department");

                OrganizationObject testOrganization = new OrganizationObject()
                {
                    OrganizationCode = "78903"+surfix,
                    OrganizationName = "testOrganizationUpdate" + surfix,
                    OrganizationTypeId = organizationApi.FindOrganizationTypes(new List<string>() { "Department" }).Select(x => x.OrganizationTypeId).FirstOrDefault(),
                    Status = OrganizationStatus.Enabled
                };

                organizationApi.Save(testOrganization);
                createdOrganizationIds.Add(testOrganization.OrganizationId);

                #endregion

                OrganizationObject organization = organizationApi.GetOrganizationByName("testOrganizationUpdate"+surfix);

                #region Setup the Updated Code
                //Binding the required web controls
                TextBox organizationCode = new TextBox();
                organizationCode.Text = "78903" + surfix;
                proxy.Set("TextBoxOrganizationCode", organizationCode);

                TextBox organizationName = new TextBox();
                organizationName.Text = "OrganziationTest" + surfix;
                proxy.Set("TextBoxOrganizationName", organizationName);

                DropDownList DropDownListOrganizationType = new DropDownList();
                var typeData = organizationApi.FindOrganizationTypes(new List<string>() { "Department" }).Select(x => x.OrganizationTypeId);

                DropDownListOrganizationType.Items.Clear();
                DropDownListOrganizationType.DataSource = typeData;
                DropDownListOrganizationType.DataBind();
                DropDownListOrganizationType.SelectedIndex = 1;

                proxy.Set("DropDownListOrganizationType", DropDownListOrganizationType);

                Array statusData = new string[] { "Enabled", "Disabled", "Pending" };
                RadioButtonList RadioButtonListOrganizationStatus = new RadioButtonList();
                RadioButtonListOrganizationStatus.DataSource = statusData;
                RadioButtonListOrganizationStatus.DataBind();
                RadioButtonListOrganizationStatus.SelectedIndex = 0;
                proxy.Set("RadioButtonListOrganizationStatus", RadioButtonListOrganizationStatus);
                #endregion
                proxy.Update(organization.OrganizationId.ToString());

                OrganizationObject organizationUpdated = organizationApi.GetOrganization(organization.OrganizationId);

                Assert.AreNotEqual(organizationUpdated.OrganizationName, "testOrganization" + surfix);
                Assert.AreEqual(organizationUpdated.OrganizationName, "OrganziationTest" + surfix);
            }
        }
        public void TestLoadWritableEntity()
        {
            OrganizationDetailPanel testpage = new OrganizationDetailPanel();

            DetailPanelPageProxy proxy = new DetailPanelPageProxy(testpage);

            IOrganizationApi organizationApi = SpringContext.Current.GetObject<IOrganizationApi>();

            Guid guid = Guid.NewGuid();

            string surfix = guid.ToString().Substring(0, 5);

            using (var httpEnv = new HttpEnvironment())
            {
                #region Setup the pre-required data
                //Setup the right URL
                httpEnv.SetRequestUrl("/OrganizationDetailPanel/DynamicPage.svc?Domain=Department");

                OrganizationObject testOrganization = new OrganizationObject()
                {
                    OrganizationCode = "78901" + surfix,
                    OrganizationName = "testOrganization1" + surfix,
                    OrganizationTypeId = organizationApi.FindOrganizationTypes(new List<string>() { "Department" }).Select(x => x.OrganizationTypeId).FirstOrDefault(),
                    Status = OrganizationStatus.Enabled
                };
                organizationApi.Save(testOrganization);

                #endregion

                OrganizationObject organization = organizationApi.GetOrganizationByName("testOrganization1" + surfix);

                proxy.LoadWritableEntity(organization.OrganizationId.ToString());

                Assert.AreEqual(organization.OrganizationName, ((TextBox)proxy.Get("TextBoxOrganizationName")).Text);

                createdOrganizationIds.Add(testOrganization.OrganizationId);
            }
        }