public void BulkGetUsersWithWrongGUID()
        {
            _story = new Story("Get Memebers By IMembershipApi");

            _story.AsA("User")
              .IWant("to be able to get members, and give wrong users' GUID")
              .SoThat("I can get nothing");

            IDictionary<Guid, UserObject> _Users = new Dictionary<Guid, UserObject>();

            Guid _temp = new Guid();

            _story.WithScenario("Get members by ImembershipApi with the only one correct Ids")
                .Given("only one correct GUID of user and fake one", () =>
                {
                    createdObjectIds.Add(_temp);
                })
                .When("I use the BulkGet, I can get users ", () => _Users = _membershipApi.BulkGet(createdObjectIds))
                .Then("The return a bunch of Users only contain null User ",
                        () =>
                        {
                            _Users[_temp].ShouldBeNull();
                        });

            //createdObjectIds.Remove(_temp);

            this.CleanUp();
        }
Exemplo n.º 2
0
        public void verify_receive_appropriate_error_message_when_user_provides_a_bad_user_name_or_password()
        {
            AuthenticationStatus authStatus = null;
            Story authenticateUserStory = new Story("Authenticate User");

            authenticateUserStory.AsA("Unauthenticated user")
                .IWant("supply my user name and password to the login form")
                .SoThat("I can  authenticate to the application");

            authenticateUserStory
                .WithScenario("User provides an invalid user name")
                .Given("My user name and password are ", "Big Daddy", "Gobldegook", delegate(string userName, string password) { UserRepositoryFactory factory = _mock.DynamicMock<UserRepositoryFactory>();

                                                                                                                                 using (_mock.Record())
                                                                                                                                 {
                                                                                                                                    Expect.Call(factory.Create(userName, password))
                                                                                                                                        .Return(_mock.DynamicMock<IUserRepository>());
                                                                                                                                 }

                                                                                                                                 _user = factory.Create(userName, password); })
                .When("I authenticate the user", delegate {_service = _mock.DynamicMock<IAuthenticationService>();
                                                            using (_mock.Record())
                                                            {
                                                                Expect.Call(_service.Authenticate(_user))
                                                                    .Return(new AuthenticationStatus(new Exception("Bad Username or Password")));
                                                            }
                                                           authStatus = _service.Authenticate(_user);})
                .Then("I should receive an Authentication status of", Status.Failed, delegate(Status expectedStatus) {Assert.AreEqual(expectedStatus, authStatus.Status);});
        }
Exemplo n.º 3
0
        public void verify_receive_appropriate_success_message_when_user_provides_a_good_user_name_and_password()
        {
            Story authenticateUserStory = new Story("Authenticate User");

            authenticateUserStory.AsA("USer with a valid user name and password")
                .IWant("supply my user name and password to the login form")
                .SoThat("I can authenticate to the application");

            authenticateUserStory
                .WithScenario("User provides a valid user name and password")
                .Given("My user name and password are ", "mmann", "validpassword_1", delegate(string userName, string password) { UserRepositoryFactory factory = _mock.DynamicMock<UserRepositoryFactory>();

                                                                                                                                 using (_mock.Record())
                                                                                                                                 {
                                                                                                                                    Expect.Call(factory.Create(userName, password))
                                                                                                                                        .Return(_mock.DynamicMock<IUserRepository>());
                                                                                                                                 }

                                                                                                                                 _user = factory.Create(userName, password); })
                .When("I authenticate the user", delegate {_service = _mock.DynamicMock<IAuthenticationService>();
                                                            using (_mock.Record())
                                                            {
                                                                Expect.Call(_service.Authenticate(_user))
                                                                    .Return(new AuthenticationStatus());
                                                            }
                                                           _authStatus = _service.Authenticate(_user);})
                .Then("I should receive an Authentication status of", Status.Success, delegate(Status expectedStatus) {Assert.AreEqual(expectedStatus, _authStatus.Status);});
        }
        public void ChangeUserPasswordObeyPasswordRule()
        {
            _story = new Story("Change Memebers' password By IMembershipApi");

            _story.AsA("User")
              .IWant("to be able to change the password")
              .SoThat("I can use new password to login");

            _story.WithScenario("Change the password with a correct GUID")
                .Given("Create a new User with old password, but the new password doesn't follow the password rule", () =>
                {
                    _Uobject = _utils.CreateUserObject("Eunge Liu", true);

                    _oldpassword = "******";

                    _newpassword = "******";

                    _membershipApi.Save(_Uobject, _oldpassword, "123Hello");

                    createdObjectIds.Add(_Uobject.UserId);

                })
                .When("I change the password ", () =>
                {

                })
                .Then("I can get Error Message from ChangePassword method",
                        () =>
                        {
                            typeof(ValidationException).ShouldBeThrownBy(() => _membershipApi.ChangePassword(_Uobject.UserId, _oldpassword, _newpassword));
                        });

            this.CleanUp();
        }
        public void GetUserByCorrectGuid()
        {
            _story = new Story("Get Memebers By IMembershipApi");

            _story.AsA("User")
              .IWant("to be able to get members, and give the correct users' GUID")
              .SoThat("I can do somethings for members");

            IDictionary<Guid, UserObject> _Users = new Dictionary<Guid, UserObject>();

            _story.WithScenario("Get members by ImembershipApi with the correct userName")
                .Given("More than one correct GUID of users", () =>
                {
                    _Uobject = _utils.CreateUserObject("Eunge Liu", true);

                    _membershipApi.Save(_Uobject, "123Hello", "123Hello");

                    createdObjectIds.Add(_Uobject.UserId);

                })
                .When("I use the Get, I can get users ", () => _Uobject2 = _membershipApi.Get(_Uobject.UserId))
                .Then("The User2 is User1",
                        () =>
                        {
                            _Uobject.ShouldEqual(_Uobject2);
                        });

            this.CleanUp();
        }
        public SaveMemeberStory()
        {
            base.GlobalSetup();

            _story = new Story("Save Memeber");
            _story.AsA("User")
              .IWant("to be able to save member status")
              .SoThat("I can update or create member info");

            _membershipApi = SpringContext.Current.GetObject<IMembershipApi>();
        }
        public void SaveANewMemberWithEmptyProperties()
        {
            _story = new Story("Save a Memeber By IMembershipApi");

            _story.AsA("User")
              .IWant("to be able to create a new member, but I don't assign value to it")
              .SoThat("I can get specific exception");

            _story.WithScenario("Save a new Member which have no value")
                .Given("the new member with nothing", () => { _Uobject = new UserObject(); })
                .When("I save this member", () => { })
                .Then("I Get an ArgumentNullException from IMembershipApi.Save()", () => typeof(ArgumentNullException).ShouldBeThrownBy(() => _membershipApi.Save(_Uobject, _password, _passwordAnswer)));
        }
Exemplo n.º 8
0
        public void ShouldInstanceNameBeNull()
        {
            Story instanceNameStory = new Story("Should instance name be null");

            QuartzAdmin.web.Models.InstanceModel instance = null;
            instanceNameStory
            .AsA("System Admin")
            .IWant("to create a new quartz instance")
            .SoThat("I can administer it using this tool");

            instanceNameStory
            .WithScenario("Create new instance with null name")
            .Given("The instance name is", null, delegate(string instanceName)
            {
                instance = new QuartzAdmin.web.Models.InstanceModel();
                instance.InstanceName = instanceName;
            })
            .And("The instance has properties", delegate(){ instance.InstanceProperties.Add(new QuartzAdmin.web.Models.InstancePropertyModel()
                {
                    PropertyName = "Hello", PropertyValue = "World"
                }); })
            .When("the instance is validated")
            .Then("the validation should fail", delegate() {
                Assert.IsFalse(instance.IsValid());
            });


            instanceNameStory
            .WithScenario("Create new instance name and with no properties")
            .Given("The instance name is", null, delegate(string instanceName)
            {
                instance = new QuartzAdmin.web.Models.InstanceModel();
                instance.InstanceName = instanceName;
            })
            .And("The instance has properties", delegate() { instance.InstanceProperties.Add(new QuartzAdmin.web.Models.InstancePropertyModel()
                {
                    PropertyName = "Hello", PropertyValue = "World"
                }); })
            .When("the instance is validated")
            .Then("the validation should fail", delegate()
            {
                Assert.IsFalse(instance.IsValid());
            });
        }
Exemplo n.º 9
0
        public void DoesInstanceConnect2()
        {
            Story instanceConnectStory = new Story("Connect to instance");

            QuartzAdmin.web.Models.InstanceRepository instanceRepo = new QuartzAdmin.web.Models.InstanceRepository();
            QuartzAdmin.web.Models.InstanceModel      instance     = null;
            Quartz.IScheduler sched = null;

            instanceConnectStory
            .AsA("System Admin")
            .IWant("to connect to a running quartz instance")
            .SoThat("I can perform admin functions");

            instanceConnectStory
            .WithScenario("Perform connection to instance")
            .Given("the instance name is", "Instance1", delegate(string instanceName) { instance = instanceRepo.GetInstance(instanceName); })
            .When("the connection is attempted", delegate() { sched = instance.GetQuartzScheduler(); })
            .Then("the connection is not null", delegate() { Assert.IsNotNull(sched); });
        }
        public void Deposit_not_implemented_properly()
        {
            var transferStory = new Story("Deposit to cash account");

            transferStory
                .AsA("savings account holder")
                .IWant("to deposit money into my cash account")
                .SoThat("I can have money for later");

            Account cash = null;

            transferStory
                .WithScenario("Savings account is in credit")
                .Given("my cash account balance is", 100,
                       accountBalance => { cash = new Account(accountBalance); })
                .When("I deposit into my cash account", 20, depositAmount => cash.Deposit(depositAmount))
                .Then("my cash account balance should be", 120,
                      expectedBalance => cash.Balance.ShouldEqual(expectedBalance));
        }
        public void Batch_must_occur_within_30_seconds()
        {
            var story = new Story("Must return an individual asset update in less than 30 seconds");
            story.AsA("Dispatcher")
                .IWant("To enter information into the system")
                .SoThat("I can see the result in visualised in the external system")

                .WithScenario("Item is updated into our internal system")
                .Given(() => DataForItem_IsUpdatedInInternalSystem(56))
                    .And(Narrative.Text("Database trigger has occured"))
                    .And(Narrative.Text("New item exists in the queue"))
                .When(Narrative.Exec("_mockConnector Service runs", StartTimer))
                    .And(() => GetFleedIdsFrom_Within_Secs("http://external.system.com", 20))
                    .And(() => HasMoreThan_Assets(310))
                    .And(() => GetsUpdatedItemsWithin_Secs(9))
                    .And(() => PutsSingleAsset_To_Within_Secs("281", "http://otherexternalsystem.com", 20))
                    .And(() => RetrievesNewDataFrom_ForAsset_XmlWithUtilisation_("http://otherexternalsystem.com", "281", 56))
                    .And(() => Within_Seconds(30));
            story.Assert();
        }
        public void Transfer_to_cash_account()
        {
            Account savings = null;
            Account cash = null;

            var transferStory = new Story("Transfer to cash account");

            transferStory
                .AsA("savings account holder")
                .IWant("to transfer money from my savings account")
                .SoThat("I can get cash easily from an ATM");

            transferStory
                .WithScenario("Savings account is in credit")

                    .Given("my savings account balance is $balance", 100, accountBalance => { savings = new Account(accountBalance); })
                        .And("my cash account balance is $balance", 10, accountBalance => { cash = new Account(accountBalance); })
                    .When("I transfer $amount to cash account", 20, transferAmount => savings.TransferTo(cash, transferAmount))
                    .Then("my savings account balance should be $balance", 80, expectedBalance => savings.Balance.ShouldEqual(expectedBalance))
                        .And("my cash account balance should be $balance", 30, expectedBalance => cash.Balance.ShouldEqual(expectedBalance))

                    .Given("my savings account balance is 400")
                        .And("my cash account balance is 100")
                    .When("I transfer 100 to cash account")
                    .Then("my savings account balance should be 300")
                        .And("my cash account balance should be 200")

                    .Given("my savings account balance is 500")
                        .And("my cash account balance is 20")
                    .When("I transfer 30 to cash account")
                    .Then("my savings account balance should be 470")
                        .And("my cash account balance should be 50");

            transferStory
                .WithScenario("Savings account is overdrawn")

                    .Given("my savings account balance is  -20")
                        .And("my cash account balance is 10")
                    .When("I transfer 20 to cash account")
                    .Then("my savings account balance should be -20")
                        .And("my cash account balance should be 10");
        }
        public void Withdraw_from_savings_account_pending()
        {
            var transferStory = new Story("Withdraw from savings account");

            transferStory
                .AsA("savings account holder")
                .IWant("to withdraw money from my savings account")
                .SoThat("I can pay for things with cash");

            transferStory
                .WithScenario("Savings account is in credit")
                    .Pending("ability to withdraw from accounts")

                    .Given("my savings account balance is 400")
                    .When("I withdraw $amount from my savings account", 100)
                    .Then("my savings account balance should be 300");
        }
        public void ChangeUserPasswordWithCorrectGuid()
        {
            _story = new Story("Change Memebers' password By IMembershipApi");

            _story.AsA("User")
              .IWant("to be able to change the password")
              .SoThat("I can use new password to login");

            _story.WithScenario("Change the password with a correct GUID")
                .Given("Create a new with old password", () =>
                {
                    _Uobject = _utils.CreateUserObject("Eunge Liu", true);

                    _oldpassword = "******";

                    _newpassword = "******";

                    _membershipApi.Save(_Uobject, _oldpassword, "123Hello");

                    createdObjectIds.Add(_Uobject.UserId);

                })
                .When("I change the password ", () =>
                        {
                    _membershipApi.ChangePassword(_Uobject.UserId, _oldpassword, _newpassword);
                        })
                .Then("The User can use new password to login",
                        () =>
                        {
                            _membershipApi.Login(_Uobject.UserName, _newpassword).ShouldEqual(LoginResults.Successful);
                        });

            this.CleanUp();
        }
        public void MemberLoginWithCorrectUserNameAndPwd()
        {
            _story = new Story("Login with UserName and Password");

            _story.AsA("User")
              .IWant("to be able to login ")
              .SoThat("I can use features");

            _story.WithScenario("login with a correct username and password")
                .Given("Create a new with old password", () =>
                {
                    _Uobject = _utils.CreateUserObject("Eunge Liu",true);

                    _oldpassword = "******";

                    _newpassword = "******";

                    _membershipApi.Save(_Uobject, _oldpassword, "123Hello");

                    createdObjectIds.Add(_Uobject.UserId);

                })
                .When("I login", () =>
                {
                    _ret = _membershipApi.Login(_Uobject.UserName, _oldpassword);
                })
                .Then("The User can get Successful Logon",
                        () =>
                        {
                            _ret.ShouldEqual(LoginResults.Successful);
                        });

            this.CleanUp();
        }
        public void ExistApplication()
        {
            _story = new Story("Judge if the Application exists");

            _story.AsA("User")
              .IWant("to be able to Judge if the Application exists")
              .SoThat("I can decide to create the application or not");

            _story.WithScenario("Judge the application ")
                .Given("an unexisting application Name ", () =>
                {
                    _ApplicationObject = new ApplicationObject() { Description = "Haha", Name = "App" };
                })
                .When("I get this Application", () =>
                {
                    _applicationApi.Exists("App").ShouldBeFalse();
                })
                .Then(" I can create the object and judge if it exists ", () =>
                {
                    _applicationApi.Save(_ApplicationObject);

                    createdApplicationIds.Add(_ApplicationObject.Id);

                    _applicationApi.Exists("App").ShouldBeTrue();
                });
            this.CleanUp();
        }
        public void GetApplication()
        {
            _story = new Story("Get the Application");

            _story.AsA("User")
              .IWant("to be able to get an existing Application")
              .SoThat("I can modify the object");

            _story.WithScenario("Get the Application By correct application Name or application Id")
                .Given("an existing application Name or application Id",
                    () =>
                     {
                         _ApplicationObject = new ApplicationObject() { Description = "Application", Name = "App" };
                         _applicationApi.Save(_ApplicationObject);

                         createdApplicationIds.Add(_ApplicationObject.Id);
                     })
                .When("I get this Application",
                    () =>
                        {
                            _ApplicationObject1 = _applicationApi.Get(_ApplicationObject.Id);

                            _ApplicationObject2 = _applicationApi.Get(_ApplicationObject.Name);
                        })
                .Then("The Objects I get should be equal", () =>
                                                              {
                                                                  _ApplicationObject.Id.ShouldEqual(_ApplicationObject1.Id);
                                                                  //_ApplicationObject.Id.ShouldEqual(_ApplicationObject2.Id);

                                                              });

            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();
        }
        public void BulkGetWithOneCorrectUserId()
        {
            _story = new Story("Get Memebers By IMembershipApi");

            _story.AsA("User")
              .IWant("to be able to get members, and give only one correct users' GUID")
              .SoThat("I can do somethings for members");

            IDictionary<Guid, UserObject> _Users = new Dictionary<Guid, UserObject>();

            Guid _temp = new Guid();

            _story.WithScenario("Get members by ImembershipApi with the only one correct Ids")
                .Given("only one correct GUID of user and fake one", () =>
                {
                    _Uobject = _utils.CreateUserObject("Eunge Liu", true);

                    _membershipApi.Save(_Uobject, "123Hello", "123Hello");

                    createdObjectIds.Add(_Uobject.UserId);
                    createdObjectIds.Add(_temp);
                })
                .When("I use the BulkGet, I can get users ", () => _Users = _membershipApi.BulkGet(createdObjectIds))
                .Then("The return a bunch of Users have contain only the User1 ",
                        () =>
                        {
                            _Users[_Uobject.UserId].ShouldEqual(_Uobject);

                            _Users[_temp].ShouldBeNull();
                        });

            //createdObjectIds.Remove(_temp);

            this.CleanUp();
        }
        public void ShouldInstancePropertiesBeEmpty()
        {


            Story instanceNameStory = new Story("Should instance name be null");
            QuartzAdmin.web.Models.InstanceModel instance = null;
            instanceNameStory
                .AsA("System Admin")
                .IWant("to create a new quartz instance")
                .SoThat("I can administer it using this tool");

            instanceNameStory
                .WithScenario("Create new instance with empty properties")
                .Given("The instance name is", "HelloWorld", delegate(string instanceName)
                {
                    instance = new QuartzAdmin.web.Models.InstanceModel();
                    instance.InstanceName = instanceName;

                })
                .When("the instance is validated")
                .Then("the validation should fail", delegate(){Assert.IsFalse(instance.IsValid());});

        }
        public void DoesInstanceConnect2()
        {
            Story instanceConnectStory = new Story("Connect to instance");
            QuartzAdmin.web.Models.InstanceRepository instanceRepo = new QuartzAdmin.web.Models.InstanceRepository();
            QuartzAdmin.web.Models.InstanceModel instance = null;
            Quartz.IScheduler sched = null;

            instanceConnectStory
                .AsA("System Admin")
                .IWant("to connect to a running quartz instance")
                .SoThat("I can perform admin functions");

            instanceConnectStory
                .WithScenario("Perform connection to instance")
                .Given("the instance name is", "Instance1", delegate(string instanceName) { instance = instanceRepo.GetInstance(instanceName); })
                .When("the connection is attempted", delegate() { sched = instance.GetQuartzScheduler(); })
                .Then("the connection is not null", delegate() { Assert.IsNotNull(sched); });




        }
        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 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 GetUserByInCorrectUserName()
        {
            _story = new Story("Get Memebers By IMembershipApi");

            _story.AsA("User")
              .IWant("to be able to get members, and give the incorrect users' userName")
              .SoThat("I can get Error Message");

            _story.WithScenario("Get members by ImembershipApi with the Incorrect userName")
               .Given("More than one correct GUID of users", () =>
               {
               })
               .When("I use the Get, I can get users ", () => _Uobject2 = _membershipApi.Get("Wild Name"))
               .Then("The return is null",
                       () =>
                       {
                           _Uobject2.ShouldBeNull();
                       });

            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 SaveANewOrganizationWithEmptyProperties()
        {
            _story = new Story("Save a Organization By IOrganizationApi");

            _story.AsA("User")
              .IWant("to be able to create a new Organization, but I don't assign value to it")
              .SoThat("I can get specific exception");

            _story.WithScenario("Save a new Organization which have no value")
                .Given("the new member with nothing", () =>
                {
                    _OrganObject1 = new OrganizationObject();
                })
                .When("I save this Organization", () => { })
                .Then("I Get an ArgumentNullException from IOrganizationApi.Save()", () => typeof(ArgumentNullException).ShouldBeThrownBy(() => _organizationApi.Save(_OrganObject1)));

            this.CleanUp();
        }
        public void GetApplicationWithError()
        {
            _story = new Story("Get the Application");

            _story.AsA("User")
                .IWant("to be able to get an existing Application")
                .SoThat("I can modify the object");
            Guid _temp = new Guid();
            _story.WithScenario("Get the Application By correct application Name or application Id")
                .Given("an existing application Name or application Id", () =>
                                                                             {

                                                                             })
                .When("I get this Application", () =>
                                                    {
                                                        _ApplicationObject1 = _applicationApi.Get(_temp);

                                                        _ApplicationObject2 = _applicationApi.Get("");
                                                    })
                .Then("The Objects I get should be equal", () =>
                                                               {
                                                                   _ApplicationObject1.ShouldBeNull();
                                                                   _ApplicationObject2.ShouldBeNull();
                                                                   ;

                                                               });

            this.CleanUp();
        }
        public void ChangeUserPasswordWithWrongGuid()
        {
            _story = new Story("Change Memebers' password By IMembershipApi");

            _story.AsA("User")
              .IWant("to be able to change the password")
              .SoThat("I can use new password to login");

            Guid _temp = new Guid();

            _story.WithScenario("Change the password with a Incorrect GUID")
                .Given("Create a new with old password", () =>
                {

                    _oldpassword = "******";

                    _newpassword = "******";

                    createdObjectIds.Add(_temp);

                })
                .When("I change the password ", () =>
                {

                })
                .Then("I can get Error Message from ChangePassword method",
                        () =>
                        {
                            typeof(NullReferenceException).ShouldBeThrownBy(()=>_membershipApi.ChangePassword(_temp, _oldpassword, _newpassword));
                        });

            this.CleanUp();
        }
        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 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 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 void BulkGetWithCorrectUserId()
        {
            _story = new Story("Get Memebers By IMembershipApi");

            _story.AsA("User")
              .IWant("to be able to get members, and give the correct users' GUID")
              .SoThat("I can do somethings for members");

            IDictionary<Guid, UserObject> _Users = new Dictionary<Guid, UserObject>();

            _story.WithScenario("Get members by ImembershipApi with the correct Ids")
                .Given("More than one correct GUID of users", () =>
                {
                    _Uobject = _utils.CreateUserObject("Eunge Liu",true);
                    _Uobject2 = _utils.CreateUserObject("Tim Yi", true);

                    _membershipApi.Save(_Uobject, "123Hello", "123Hello");
                    _membershipApi.Save(_Uobject2, "123Hello", "123Hello");

                    createdObjectIds.Add(_Uobject.UserId);
                    createdObjectIds.Add(_Uobject2.UserId);

                })
                .When("I use the BulkGet, I can get users ", () => _Users = _membershipApi.BulkGet(createdObjectIds))
                .Then("The return a bunch of Users have contain the User1 and User2",
                        () =>
                        {
                            _Users.ContainsKey(_Uobject.UserId).ShouldBeTrue();
                            _Users.ContainsKey(_Uobject2.UserId).ShouldBeTrue();
                        });

            this.CleanUp();
        }