public void Setup() { string serviceUri1 = @"/OrganizationService.svc/json/SaveOrganizationType"; string serviceUri2 = @"/OrganizationService.svc/json/SaveOrganization"; organizationTypeObject = new OrganizationTypeObject() { Name = "Manager" + Guid.NewGuid().ToString().Substring(0, 5), Domain = "Department", Description = "department-desc", LastUpdatedDate = System.DateTime.Now }; string organizationTypeId = TestServicesHelper.GetResponse<HttpWebRequest>(serviceUri1, userName, password, TestServicesHelper.PostDataByJsonWithContent, TestServicesHelper.GenerateJsonByType(organizationTypeObject), null).Replace("\"", ""); organizationTypeObject.OrganizationTypeId = new Guid(organizationTypeId); organizationObject = new OrganizationObject() { OrganizationCode = "sh021" + Guid.NewGuid().ToString().Substring(0, 5), OrganizationName = "sh-department" + Guid.NewGuid().ToString().Substring(0, 5), OrganizationTypeId = organizationTypeObject.OrganizationTypeId, Status = OrganizationStatus.Enabled, Description = "sh-desc", CreatedDate = System.DateTime.Now, LastUpdatedDate = System.DateTime.Now }; string organizationId = TestServicesHelper.GetResponse<HttpWebRequest>(serviceUri2, userName, password, TestServicesHelper.PostDataByJsonWithContent, TestServicesHelper.GenerateJsonByType(organizationObject), null).Replace("\"", ""); organizationObject.OrganizationId = new Guid(organizationId); }
public void Setup() { string serviceUri1 = @"/OrganizationService.svc/json/SaveOrganizationType"; string serviceUri2 = @"/OrganizationService.svc/json/SaveOrganization"; organizationTypeObject = new OrganizationTypeObject() { Name = "Manager" + Guid.NewGuid().ToString().Substring(0, 5), Domain = "Department", Description = "department-desc", LastUpdatedDate = System.DateTime.Now }; string organizationTypeId = TestServicesHelper.GetResponse<HttpWebRequest>(serviceUri1, userName, password, TestServicesHelper.PostDataByJsonWithContent, TestServicesHelper.GenerateJsonByType(organizationTypeObject),null).Replace("\"", ""); organizationTypeObject.OrganizationTypeId = new Guid(organizationTypeId); organizationObject = new OrganizationObject() { OrganizationCode = "sh021" + Guid.NewGuid().ToString().Substring(0, 5), OrganizationName = "sh-department" + Guid.NewGuid().ToString().Substring(0, 5), OrganizationTypeId = organizationTypeObject.OrganizationTypeId, Status = OrganizationStatus.Enabled, Description = "sh-desc", CreatedDate = System.DateTime.Now, LastUpdatedDate = System.DateTime.Now }; string organizationId = TestServicesHelper.GetResponse<HttpWebRequest>(serviceUri2, userName, password, TestServicesHelper.PostDataByJsonWithContent, TestServicesHelper.GenerateJsonByType(organizationObject),null).Replace("\"", ""); organizationObject.OrganizationId = new Guid(organizationId); common = new UserObject { UserName = "******" + Guid.NewGuid().ToString().Substring(0, 5), DisplayName = "CommonUser" + Guid.NewGuid().ToString().Substring(0, 5), LastActivityDate = DateTime.Now, LastLockoutDate = DateTime.Now, LastLoginDate = DateTime.Now, LastPasswordChangedDate = DateTime.Now, CreationDate = System.DateTime.Now, OrganizationId = organizationObject.OrganizationId, LastUpdatedDate = DateTime.Now, PasswordQuestion = pwdAns }; string serviceUriUser = string.Format("/MembershipService.svc/json/Save"); string contentUser = TestServicesHelper.GenerateJsonByType(common); IDictionary<string, string> parameters = new Dictionary<string, string>(); parameters.Add("password", pwd); parameters.Add("passwordAnswer", pwdAns); string id = TestServicesHelper.GetResponse<HttpWebRequest>(serviceUriUser, userName, password, TestServicesHelper.PostDataByJsonWithContent, contentUser, parameters).Replace("\"", ""); common.UserId = new Guid(id); super = new RoleObject { RoleName = "super", Domain = "Department", Description = "super role" }; string serviceUri = @"/RoleService.svc/json/Save"; string content = TestServicesHelper.GenerateJsonByType(super); string Roleid = TestServicesHelper.GetResponse<HttpWebRequest>(serviceUri, userName, password, TestServicesHelper.PostDataByJsonWithContent, content,null).Replace("\"", ""); super.RoleId = new Guid(Roleid); }
/// <summary> /// Save organization type object. /// </summary> /// <param name="organizationTypeObject"></param> /// <returns></returns> public string SaveOrganizationTypeXml(OrganizationTypeObject organizationTypeObject) { return SaveOrganizationTypeJson(organizationTypeObject); }
/// <summary> /// Save organization type object. /// </summary> /// <param name="organizationTypeObject"></param> /// <returns></returns> public string SaveOrganizationTypeJson(OrganizationTypeObject organizationTypeObject) { if (organizationTypeObject == null) throw new BadRequestException(string.Format(CultureInfo.InvariantCulture, Resources.OrganizationCannotBeEmpty)); try { organizationApi.Save(organizationTypeObject); return organizationTypeObject.OrganizationTypeId.ToString(); } catch (ArgumentException ex) { throw new BadRequestException(string.Format(CultureInfo.InvariantCulture, ex.Message)); } catch (BadRequestException bad) { throw new BadRequestException(string.Format(CultureInfo.InvariantCulture, bad.Message)); } catch (FormatException formatEx) { throw new BadRequestException(string.Format(CultureInfo.InvariantCulture, formatEx.Message)); } catch (Exception exp) { Logger.Instance(this).Error(exp); throw new InternalServerErrorException(); } }
/// <summary> /// Create organization type into specified application. /// </summary> /// <param name="applicationId"></param> /// <param name="orgType"></param> protected static void CreateOrganizationType(Guid applicationId, OrganizationTypeObject orgType) { Kit.NotNull(orgType, "orgType"); using (MembershipDataContext ctx = DataContextFactory.Create<MembershipDataContext>()) { OrganizationType organizationType = new OrganizationType { ApplicationId = applicationId, Domain = orgType.Domain, Name = orgType.Name, Description = orgType.Description, Predefined = true, LastUpdatedDate = DateTime.UtcNow }; ctx.OrganizationTypes.InsertOnSubmit(organizationType); ctx.SubmitChanges(); orgType.OrganizationTypeId = organizationType.OrganizationTypeId; } }
/// <summary> /// Create a new organization type from detail panel and return its id. /// The method needs to create a new entity and set control values to its properties then persist it. /// </summary> /// <returns>returns the id of new created organization type.</returns> public override string Create() { this.ValidateInput(Guid.Empty); string domainValue = this.DropDownListDomain != null ? this.DropDownListDomain.SelectedValue : authenticationContext.TempVariables["Domain.Value"] as string; OrganizationTypeObject organizationTypeObject = new OrganizationTypeObject { Name = this.TextBoxName.Text, Description = this.TextBoxDescription.Text, Domain = domainValue, Predefined = false }; organizationApi.Save(organizationTypeObject); return organizationTypeObject.OrganizationTypeId.ToString(); }
/// <summary> /// Update an existed organization type from detail panel. /// The method needs to load an existed entity by specified id and set control values to overwrite its original properties then persist it. /// </summary> /// <param name="entityId"></param> public override void Update(string entityId) { Guid organizationTypeId = new Guid(entityId); this.ValidateInput(organizationTypeId); string domainValue = this.DropDownListDomain != null ? this.DropDownListDomain.SelectedValue : authenticationContext.TempVariables["Domain.Value"] as string; OrganizationTypeObject organizationTypeObject = new OrganizationTypeObject { OrganizationTypeId = organizationTypeId }; organizationTypeObject.Name = this.TextBoxName.Text; organizationTypeObject.Description = this.TextBoxDescription.Text; organizationTypeObject.Domain = domainValue; organizationApi.Save(organizationTypeObject); }
public void BulkGetOrganizationTypes() { _story = new Story("Find More than one OrganizationTypes By IOrganizationApi"); _story.AsA("User") .IWant("to be able to find more than one existing OrganizationTypes") .SoThat("I can get the OrganizationTypes"); IList<string> domains = new List<string>(); domains.Add("Inc"); domains.Add("Inc2"); domains.Add("Customer"); IEnumerable<OrganizationTypeObject> _temp = null; _story.WithScenario("find more than OrganizationTypes ") .Given("the domain of the organizationtype", () => { _OrganTypeObject1 = _utils.CreateOrganizationTypeOject("Depart1","Inc"); _organizationApi.Save(_OrganTypeObject1); createdOrganizationTypeIds.Add(_OrganTypeObject1.OrganizationTypeId); //_OrganTypeObject2 = _utils.CreateOrganizationTypeOject("Depart2", "Inc"); //_organizationApi.Save(_OrganTypeObject2); //createdOrganizationTypeIds.Add(_OrganTypeObject2.OrganizationTypeId); _OrganTypeObject3 = _utils.CreateOrganizationTypeOject("Depart3", "Customer"); _organizationApi.Save(_OrganTypeObject3); createdOrganizationTypeIds.Add(_OrganTypeObject3.OrganizationTypeId); }) .When("I bulkget organizations", () => { _temp = _organizationApi.FindOrganizationTypes(domains); }) .Then("I can get all the organizations in this List", () => { _temp.Contains(_OrganTypeObject1).ShouldBeTrue(); _temp.Contains(_OrganTypeObject3).ShouldBeTrue(); }); this.CleanUp(); }
public void SetUserToRoleAndUpdateStory() { _story = new Story("Create a Role By IRoleApi"); IPlatformConfiguration platformConfiguration = SpringContext.Current.GetObject<IPlatformConfiguration>(); IMembershipApi membershipApi = SpringContext.Current.GetObject<IMembershipApi>(); IOrganizationApi organizationApi = SpringContext.Current.GetObject<IOrganizationApi>(); UserObject eunge = null; //IDictionary<Guid, RoleObject> _objects; _story.AsA("User") .IWant("to be able to set User to Role") .SoThat("I can do something"); _story.WithScenario("Set existing User to an Existing Role By IRoleApi ") .Given("Create several new role", () => { OrganizationTypeObject department = new OrganizationTypeObject { Name = "department", Domain = "Inc", Description = "department-desc" }; organizationApi.Save(department); createdOrganizationTypeIds.Add(department.OrganizationTypeId); powerAdministrators = new RoleObject { RoleName = "powerAdministrators", Description = "powerAdministrators-desc", OrganizationTypeIds = new Collection<Guid> { department. OrganizationTypeId } }; business = new RoleObject { RoleName = "business", Description = "business-desc", OrganizationTypeIds = new Collection<Guid> { department.OrganizationTypeId } }; roleApi.Save(powerAdministrators); roleApi.Save(business); createdRoleIds.AddRange(new Guid[] { powerAdministrators.RoleId, business.RoleId }); }) .And("Create User", () => { eunge = new UserObject { OrganizationId = platformConfiguration.Organization.OrganizationId, UserName = "******", DisplayName = "Eunge", Email = "*****@*****.**", Comment = "The author of BaoJianSoft.", IsApproved = true }; membershipApi.Save(eunge, "password1", null); createdUserIds.Add(eunge.UserId); }) .When("Set User to the Roles", () => { roleApi.SetUserToRoles(eunge.UserId, new Guid[] { powerAdministrators.RoleId }); roleApi.SetUserToRoles(eunge.UserId, new Guid[] { powerAdministrators.RoleId, business.RoleId }); typeof(ArgumentException).ShouldBeThrownBy(() => roleApi.SetUserToRoles(new Guid(), new Guid[] { powerAdministrators.RoleId })); }) .Then("I get the relationship among these roles and User", () => { roleApi.FindByUserId(eunge.UserId).Count().ShouldEqual(2); roleApi.IsUserInRole(eunge.UserId, powerAdministrators.RoleId).ShouldBeTrue(); roleApi.IsUserInRole(eunge.UserId, business.RoleId).ShouldBeTrue(); }); _story.WithScenario("Update an Existing Role By IRoleApi ") .Given("an existing Role", () => { }) .When("Update the Role's Role Name", () => { powerAdministrators.RoleName = "NotAdmin"; roleApi.Save(powerAdministrators); }) .Then("I still can get the Role by UserId",()=> { var temp = roleApi.FindByUserId(eunge.UserId).Where(x => x.RoleName == powerAdministrators.RoleName); if(temp is RoleObject) ((RoleObject)temp).RoleName.ShouldEqual("NotAdmin"); }); _story.WithScenario("Delete an Existing Role which assoicate with an existing User By IRoleApi ") .Given("an existing Role", () => { }) .When("Delete the Role", () => { roleApi.Delete(powerAdministrators.RoleId); }) .Then("I can get noting by userId", () => { powerAdministrators1 = roleApi.FindByUserId(eunge.UserId).Where(x => x.RoleName == powerAdministrators1.RoleName) as RoleObject; powerAdministrators1.ShouldBeNull(); }); this.CleanUp(); }
public void SaveRolesStory() { _story = new Story("Create a Role By IRoleApi"); //IDictionary<Guid, RoleObject> _objects; _story.AsA("User") .IWant("to be able to create a Role") .SoThat("I can do something"); _story.WithScenario("create a Role By IRoleApi including Create the Same Name;Same Domain; Same Description; Empty Name; ") .Given("Create several new roles", () => { IOrganizationApi organizationApi = SpringContext.Current.GetObject<IOrganizationApi>(); OrganizationTypeObject department = new OrganizationTypeObject { Name = "department", Domain = "Inc", Description = "department-desc" }; organizationApi.Save(department); createdOrganizationTypeIds.Add(department.OrganizationTypeId); OrganizationTypeObject customer = new OrganizationTypeObject { Name = "customer", Domain = "Customer", Description = "customer-desc" }; organizationApi.Save(customer); createdOrganizationTypeIds.Add(customer.OrganizationTypeId); powerAdministrators = new RoleObject { RoleName = "", Description = "powerAdministrators-desc", OrganizationTypeIds = new Collection<Guid> { department.OrganizationTypeId }, Predefined = true }; business = new RoleObject { RoleName = "business", Description = "business-desc", OrganizationTypeIds = new Collection<Guid> { department.OrganizationTypeId } }; customers = new RoleObject { RoleName = "customers", Description = "customers-desc", OrganizationTypeIds = new Collection<Guid> { customer.OrganizationTypeId } }; }) .When("I save this member", () => { //roleApi.Save(powerAdministrators); roleApi.Save(business); roleApi.Save(customers); //createdRoleIds.Add(powerAdministrators.RoleId); createdRoleIds.Add(business.RoleId); createdRoleIds.Add(customers.RoleId); }) .Then("I get these roles", () => { typeof(ArgumentNullException).ShouldBeThrownBy(()=>roleApi.Save(powerAdministrators)); }); this.CleanUp(); }
public void GetRolesStory() { _story = new Story("Get a Role By IRoleApi"); IDictionary<Guid, RoleObject> _objects; _story.AsA("User") .IWant("to be able to get a Role") .SoThat("I can do something"); _story.WithScenario("Get a Role By IRoleApi ") .Given("Create several new roles", () => { IOrganizationApi organizationApi = SpringContext.Current.GetObject<IOrganizationApi>(); OrganizationTypeObject department = new OrganizationTypeObject { Name = "department", Domain = "Inc", Description = "department-desc" }; organizationApi.Save(department); createdOrganizationTypeIds.Add(department.OrganizationTypeId); OrganizationTypeObject customer = new OrganizationTypeObject { Name = "customer", Domain = "Customer", Description = "customer-desc" }; organizationApi.Save(customer); createdOrganizationTypeIds.Add(customer.OrganizationTypeId); powerAdministrators = new RoleObject { RoleName = "powerAdministrators", Description = "powerAdministrators-desc", OrganizationTypeIds = new Collection<Guid> { department.OrganizationTypeId }, Predefined = true }; business = new RoleObject { RoleName = "business", Description = "business-desc", OrganizationTypeIds = new Collection<Guid> { department.OrganizationTypeId } }; customers = new RoleObject { RoleName = "customers", Description = "customers-desc", OrganizationTypeIds = new Collection<Guid> { customer.OrganizationTypeId } }; }) .When("I save this member", () => { roleApi.Save(powerAdministrators); roleApi.Save(business); roleApi.Save(customers); createdRoleIds.Add(powerAdministrators.RoleId); createdRoleIds.Add(business.RoleId); createdRoleIds.Add(customers.RoleId); }) .Then("I get these roles", () => { powerAdministrators1 = roleApi.Get(powerAdministrators.RoleId); powerAdministrators1.ShouldEqual(powerAdministrators); business1 = roleApi.Get(business.RoleName); business1.ShouldEqual(business); _objects = roleApi.BulkGet(createdRoleIds); _objects[powerAdministrators.RoleId].ShouldEqual(powerAdministrators1); roleApi.Delete(customers.RoleId); _objects = roleApi.BulkGet(createdRoleIds); _objects.ContainsKey(customers.RoleId).ShouldBeFalse(); createdRoleIds.Add(new Guid()); _objects = roleApi.BulkGet(createdRoleIds); createdRoleIds.Count.ShouldEqual(_objects.Count + 2); }); this.CleanUp(); }
/// <summary> /// Save organization type object. /// </summary> /// <param name="organizationTypeObject"></param> /// <exception cref="ValidationException">etc organization type name does exist.</exception> public void Save(OrganizationTypeObject organizationTypeObject) { Kit.NotNull(organizationTypeObject, "organizationTypeObject"); Kit.NotNull(organizationTypeObject.Name, "organizationTypeObject.Name"); if (!this.platformConfiguration.Domains.Select(d => d.Value).Contains(organizationTypeObject.Domain)) throw new ArgumentException(string.Format(Resources.InvalidOrganizationTypeDomain, organizationTypeObject.Domain), "organizationTypeObject.Domain"); Kit.NotNull(organizationTypeObject, "organizationTypeObject"); Kit.NotNull(organizationTypeObject.Name, "organizationTypeObject.Name"); if (!this.platformConfiguration.Domains.Select(d => d.Value).Contains(organizationTypeObject.Domain)) throw new ArgumentException(string.Format(Resources.InvalidOrganizationTypeDomain, organizationTypeObject.Domain), "organizationTypeObject.Domain"); try { using (TransactionScope ts = new TransactionScope()) using (MembershipDataContext ctx = DataContextFactory.Create<MembershipDataContext>()) { OrganizationType organizationType = null; DeleteStatus originalDeleteStatus = DeleteStatus.Deleted; using (ValidationScope validationScope = new ValidationScope(true)) { if (ctx.OrganizationTypes.Where(x => x.Name == organizationTypeObject.Name && x.ApplicationId == this.authenticationContext.ApplicationId && x.OrganizationTypeId != organizationTypeObject.OrganizationTypeId).Count() > 0) { validationScope.Error(Resources.ExistedOrganizationTypeName, organizationTypeObject.Name); } if (organizationTypeObject.OrganizationTypeId == Guid.Empty) { organizationType = new OrganizationType { ApplicationId = this.authenticationContext.ApplicationId }; ctx.OrganizationTypes.InsertOnSubmit(organizationType); } else { organizationType = ctx.OrganizationTypes.FirstOrDefault(orgType => orgType.OrganizationTypeId == organizationTypeObject.OrganizationTypeId); if (organizationType == null) validationScope.Error(Resources.InvalidOrganizationTypeID); originalDeleteStatus = organizationType.DeleteStatus; } } // set organization type properties. organizationType.Domain = organizationTypeObject.Domain; organizationType.Name = organizationTypeObject.Name; organizationType.Description = organizationTypeObject.Description; organizationType.LastUpdatedDate = DateTime.UtcNow; organizationType.Predefined = organizationTypeObject.Predefined; organizationType.DeleteStatus = organizationTypeObject.DeleteStatus; // if disable an existed organization type if (organizationTypeObject.OrganizationTypeId != Guid.Empty && organizationTypeObject.DeleteStatus == DeleteStatus.Deleted && organizationTypeObject.DeleteStatus != originalDeleteStatus) { // remove the cache copy for disabled organizations. IEnumerable<Guid> disabledOrganizationIds = (from org in ctx.Organizations where org.ApplicationId == this.authenticationContext.ApplicationId && org.OrganizationTypeId == organizationTypeObject.OrganizationTypeId && org.Status != OrganizationStatus.Disabled select org.OrganizationId).ToList(); foreach (Guid disabledOrganizationId in disabledOrganizationIds) base.RemoveCache(disabledOrganizationId); // batch disable the organizations by sql command string command = string.Format(CultureInfo.InvariantCulture, "UPDATE {0} SET Status={1} WHERE ApplicationId='{2}' AND OrganizationTypeId='{3}' AND Status<>{1}", ctx.Mapping.GetTable(typeof(Organization)).TableName, (int)OrganizationStatus.Disabled, this.authenticationContext.ApplicationId, organizationTypeObject.OrganizationTypeId); ctx.ExecuteCommand(command); } ctx.SubmitChanges(); ts.Complete(); organizationTypeObject.OrganizationTypeId = organizationType.OrganizationTypeId; organizationTypeObject.LastUpdatedDate = organizationType.LastUpdatedDate; // remove cache. base.RemoveCache(CacheKey4AllOrganizationTypes); } } catch (ValidationException) { throw; } catch (Exception exp) { Logger.Instance(this).Error(exp); throw; } }
public void BulkGetOrganizations() { _story = new Story("Find More than one Organizations By IOrganizationApi"); _story.AsA("User") .IWant("to be able to find more than one existing Organization") .SoThat("I can get the organizations"); IDictionary<Guid, OrganizationObject> _temp = null; _story.WithScenario("find more than Organization ") .Given("the a bunch of GUID of the organizations", () => { _OrganTypeObject1 = _utils.CreateOrganizationTypeOject("Depart","Inc"); _organizationApi.Save(_OrganTypeObject1); createdOrganizationTypeIds.Add(_OrganTypeObject1.OrganizationTypeId); _OrganObject1 = _utils.CreateOrganizationObject(_OrganTypeObject1.OrganizationTypeId, "sh1", "sh1"); _organizationApi.Save(_OrganObject1); createdOrganizationIds.Add(_OrganObject1.OrganizationId); _OrganObject2 = _utils.CreateOrganizationObject(_OrganTypeObject1.OrganizationTypeId, "sh2", "sh2"); _OrganObject2.ParentOrganizationId = _OrganObject1.OrganizationId; _organizationApi.Save(_OrganObject2); createdOrganizationIds.Add(_OrganObject2.OrganizationId); _OrganObject3 = _utils.CreateOrganizationObject(_OrganTypeObject1.OrganizationTypeId, "sh3", "sh3"); _OrganObject3.ParentOrganizationId = _OrganObject1.OrganizationId; _organizationApi.Save(_OrganObject3); createdOrganizationIds.Add(_OrganObject3.OrganizationId); }) .When("I call bulkget organizations", () => { _temp = _organizationApi.BulkGetOrganizations(createdOrganizationIds); }) .Then("I can get all the organizations in this List", () => { _temp[_OrganObject2.OrganizationId].ShouldEqual(_OrganObject2); _temp[_OrganObject3.OrganizationId].ShouldEqual(_OrganObject3); _temp[_OrganObject1.OrganizationId].ShouldEqual(_OrganObject1); }); this.CleanUp(); }
public void GetOrganizationWithCorrectGuidAndCorrectName() { _story = new Story("Find a Organization By IOrganizationApi"); _story.AsA("User") .IWant("to be able to find an existing Organization") .SoThat("I can modify the object"); _story.WithScenario("find an existing Organization ") .Given("the GUID and Name of the organization", () => { _OrganTypeObject1 = _utils.CreateOrganizationTypeOject("Depart","Inc"); _organizationApi.Save(_OrganTypeObject1); createdOrganizationTypeIds.Add(_OrganTypeObject1.OrganizationTypeId); _OrganObject1 = _utils.CreateOrganizationObject(_OrganTypeObject1.OrganizationTypeId, "hangzhou1", "hangzhou1"); _organizationApi.Save(_OrganObject1); createdOrganizationIds.Add(_OrganObject1.OrganizationId); }) .When("I get the organization", () => { _OrganObject2 = _organizationApi.GetOrganization(_OrganObject1.OrganizationId); _OrganObject3 = _organizationApi.GetOrganizationByName(_OrganObject1.OrganizationName); _OrganObject4 = _organizationApi.GetOrganizationByCode(_OrganObject1.OrganizationCode); }) .Then("I Get two same Organization", () => { _OrganObject2.ShouldEqual(_OrganObject1); _OrganObject2.ShouldEqual(_OrganObject3); _OrganObject2.ShouldEqual(_OrganObject4); }); this.CleanUp(); }
public void FindChildOrganization() { _story = new Story("Find More than one Child Organizations of Parent Organization By IOrganizationApi"); _story.AsA("User") .IWant("to be able to find more than one existing Child Organization") .SoThat("I can get the child organization"); IEnumerable<Guid> _temp = null; _story.WithScenario("find more than one existing Child Organization ") .Given("the GUID of the parent organization", () => { _OrganTypeObject1 = _utils.CreateOrganizationTypeOject("Depart","Inc"); _organizationApi.Save(_OrganTypeObject1); createdOrganizationTypeIds.Add(_OrganTypeObject1.OrganizationTypeId); _OrganObject1 = _utils.CreateOrganizationObject(_OrganTypeObject1.OrganizationTypeId, "wuhan2", "wuhan2"); _organizationApi.Save(_OrganObject1); createdOrganizationIds.Add(_OrganObject1.OrganizationId); _OrganObject2 = _utils.CreateOrganizationObject(_OrganTypeObject1.OrganizationTypeId, "wuhan3", "wuhan3"); _OrganObject2.ParentOrganizationId = _OrganObject1.OrganizationId; _organizationApi.Save(_OrganObject2); createdOrganizationIds.Add(_OrganObject2.OrganizationId); _OrganObject3 = _utils.CreateOrganizationObject(_OrganTypeObject1.OrganizationTypeId, "tianjiang", "tianjiang"); _OrganObject3.ParentOrganizationId = _OrganObject1.OrganizationId; _organizationApi.Save(_OrganObject3); createdOrganizationIds.Add(_OrganObject3.OrganizationId); }) .When("I get the GUID of children organization", () => { _temp = _organizationApi.FindAllEnabledChildOrganizationIds(_OrganObject1.OrganizationId); }) .Then("I can confirm GUID of Children in this List", () => { _temp.Contains(_OrganObject2.OrganizationId); _temp.Contains(_OrganObject3.OrganizationId); }); this.CleanUp(); }
public void HierarchyTreeStory() { _story = new Story("Save the Hierarchy data And Bind to Organization Type"); _story.AsA("User") .IWant("Create Hierarchy Data") .SoThat("I can bind the Hierarchy to the object that have cascade relationship"); _story.WithScenario("Save Hierarchy Data") .Given("a Hierarchy data which is new ", () => { _HierarchyDataObject = new HierarchyDataObject() { Code = "1111", Description = "Sample", HierarchyType = "Tree", Name = "Root" }; _HierarchyApi.Save(_HierarchyDataObject); createHierarchyIds.Add(_HierarchyDataObject.Id); }) .And("create More than one Organization ", () => { _OrganizationTypeObject1 = _Organutils.CreateOrganizationTypeOject("Root", "Inc"); _OrganizationApi.Save(_OrganizationTypeObject1); createdOrganizationTypeIds.Add(_OrganizationTypeObject1.OrganizationTypeId); _OrganizationObject1 = _Organutils.CreateOrganizationObject(_OrganizationTypeObject1.OrganizationTypeId, "Tim", "sh"); _OrganizationObject2 = _Organutils.CreateOrganizationObject(_OrganizationTypeObject1.OrganizationTypeId, "Euge", "sc"); _OrganizationApi.Save(_OrganizationObject1); _OrganizationApi.Save(_OrganizationObject2); createdOrganizationIds.Add(_OrganizationObject1.OrganizationId); createdOrganizationIds.Add(_OrganizationObject2.OrganizationId); }) .When("Have the Hierarchy Data", () => { _HierarchyDataObject1 = _HierarchyApi.GetHierarchyData(_HierarchyDataObject.Id); _HierarchyDataObject2 = _HierarchyApi.GetHierarchyData("Tree", "Root"); _HierarchyDataObject1.Id.ShouldEqual(_HierarchyDataObject.Id); _HierarchyDataObject2.Id.ShouldEqual(_HierarchyDataObject.Id); }) .Then("I can use the Hierarchy Data to bind to Organization object", () => { _RelationshipObject1 = new RelationshipObject() { ReferenceObjectId = _HierarchyDataObject.Id, RelationshipType = "Tree" }; _RelationShipApi.Save(_OrganizationObject1.OrganizationId, _RelationshipObject1); _RelationShipApi.Save(_OrganizationObject2.OrganizationId, _RelationshipObject1); _RelationshipObject2 = _RelationShipApi.GetOneToOne(_OrganizationObject1.OrganizationId, _RelationshipObject1.RelationshipType); _RelationshipObject3 = _RelationShipApi.GetOneToOne(_OrganizationObject2.OrganizationId, _RelationshipObject1.RelationshipType); _RelationshipObject2.ReferenceObjectId.ShouldEqual(_RelationshipObject3.ReferenceObjectId); _RelationshipObject2.Ordinal.ShouldEqual(_RelationshipObject3.Ordinal); }) .WithScenario("How to create Hierarchy in Organization") .Given("Remove the relationship between Organ1 and Organ2", () => { _RelationShipApi.Remove(_OrganizationObject1.OrganizationId); _RelationShipApi.Remove(_OrganizationObject2.OrganizationId, "Tree"); }) .And("Create a child Hierarchy data ", () => { _HierarchyDataObject2 = new HierarchyDataObject() { Code = "1111", Description = "Sample", HierarchyType = "Tree", Name = "Leaf", ParentHierarchyDataId = _HierarchyDataObject.Id }; _HierarchyApi.Save(_HierarchyDataObject2); }) .When("I add the hierarchy data to Organization", () => { _OrganizationObject1.Hierarchies.Add("Tree", _HierarchyDataObject.Id); _OrganizationObject2.Hierarchies.Add("Tree", _HierarchyDataObject2.Id); _OrganizationApi.Save(_OrganizationObject1); _OrganizationApi.Save(_OrganizationObject2); }) .Then("I can get children HierarchyData by Hierarchy", () => { _HierarchyDataObject1 = null; _HierarchyDataObject1 = _HierarchyApi.GetImmediateChildren("Tree", _HierarchyDataObject.Id).FirstOrDefault(); _HierarchyDataObject1.Id.ShouldEqual(_HierarchyDataObject2.Id); }) .WithScenario("Delete the children Hierarchy Data") .Given("an Existing parent Hierarchy Data and an existing child", () => { }) .When("I delete the parent hierarchy Data", () => { _HierarchyApi.DeleteHierarchyData(_HierarchyDataObject.Id); }) .Then("I cannot get the parent data, and Organization should not have this Hierarchy data", () => { }); this.CleanUp(); }
public void DeleteRolesStory() { _story = new Story("Delete a Role By IRoleApi"); _story.AsA("User") .IWant("to be able to delete a Role") .SoThat("I can re-create"); _story.WithScenario("Delete a Role By IRoleApi with correct Role Id ") .Given("Create several new roles", () => { IOrganizationApi organizationApi = SpringContext.Current.GetObject<IOrganizationApi>(); OrganizationTypeObject department = new OrganizationTypeObject { Name = "department", Domain = "Inc", Description = "department-desc" }; organizationApi.Save(department); createdOrganizationTypeIds.Add(department.OrganizationTypeId); OrganizationTypeObject customer = new OrganizationTypeObject { Name = "customer", Domain = "Customer", Description = "customer-desc" }; organizationApi.Save(customer); createdOrganizationTypeIds.Add(customer.OrganizationTypeId); powerAdministrators = new RoleObject { RoleName = "powerAdministrators", Description = "powerAdministrators-desc", OrganizationTypeIds = new Collection<Guid> { department.OrganizationTypeId }, Predefined = true }; business = new RoleObject { RoleName = "business", Description = "business-desc", OrganizationTypeIds = new Collection<Guid> { department.OrganizationTypeId } }; customers = new RoleObject { RoleName = "customers", Description = "customers-desc", OrganizationTypeIds = new Collection<Guid> { customer.OrganizationTypeId } }; }) .When("I save this member", () => { roleApi.Save(powerAdministrators); roleApi.Save(business); roleApi.Save(customers); createdRoleIds.Add(powerAdministrators.RoleId); createdRoleIds.Add(business.RoleId); createdRoleIds.Add(customers.RoleId); }) .Then("I Delete these roles, I cannot get it any more", () => { roleApi.Delete(powerAdministrators.RoleId); roleApi.Get(powerAdministrators.RoleId).ShouldBeNull(); roleApi.Delete(new Guid()); }); this.CleanUp(); }
public OrganizationTypeObject CreateOrganizationTypeOject(string _Name,string _Domain) { OrganizationTypeObject department = new OrganizationTypeObject { Name = _Name, Domain = _Domain, Description = "department-desc" }; return department; }