protected override TypedEntity CreateEntityForTest(Guid newGuid, Guid newGuidRedHerring, ProviderSetup providerSetup)
        {
            var entity = new Member()
                {
                    Id = new HiveId(newGuid),
                    Email = Guid.NewGuid().ToString("N") + "*****@*****.**",
                    IsApproved = true,
                    Name = "Test",
                    Password = "******",
                    Username = "******" + Guid.NewGuid().ToString("N") //must be unique
                };

            entity.Username = "******";
            entity.Name = "not-on-red-herring";
            entity.Attributes[NodeNameAttributeDefinition.AliasValue].Values["UrlName"] = "my-test-route";

            //var redHerringEntity = HiveModelCreationHelper.MockTypedEntity();
            //redHerringEntity.Id = new HiveId(newGuidRedHerring);
            //redHerringEntity.EntitySchema.Alias = "redherring-schema";

            using (var uow = providerSetup.UnitFactory.Create())
            {
                uow.EntityRepository.AddOrUpdate(entity);
                //uow.EntityRepository.AddOrUpdate(redHerringEntity);
                uow.Complete();
            }

            return entity;
        }
 /// <summary>
 /// Creates a blank member model based on the document type/entityschema for the user
 /// </summary>
 /// <returns></returns>
 private MemberEditorModel CreateNewMember()
 {
     using (var uow = Hive.Create<ISecurityStore>())
     {
         //var memberSchema = new MemberSchema();
         //get doc type model
         //var docType = BackOfficeRequestContext.Application.FrameworkContext.TypeMappers.Map<EntitySchema, DocumentTypeEditorModel>(memberSchema);
         //map (create) content model from doc type model
         var member = new Member();
         return BackOfficeRequestContext.Application.FrameworkContext.TypeMappers.Map<Member, MemberEditorModel>(member);
     }
 }
        /// <summary>
        /// Processes the submit.
        /// </summary>
        /// <param name="model">The model.</param>
        /// <param name="entity">The entity.</param>
        /// <returns></returns>
        protected ActionResult ProcessSubmit(MemberEditorModel model, Member entity)
        {
            Mandate.ParameterNotNull(model, "model");

            //bind it's data
            model.BindModel(this);

            //if there's model errors, return the view
            if (!ModelState.IsValid)
            {
                AddValidationErrorsNotification();
                return View("Edit", model);
            }

            //persist the data
            using (var uow = Hive.Create<ISecurityStore>())
            {
                // Map the user
                if (entity == null)
                {
                    //map to new entity, set default date values
                    model.LastPasswordChangeDate = DateTime.UtcNow;
                    model.LastActivityDate = DateTime.UtcNow;
                    model.LastLoginDate = DateTime.UtcNow;
                    entity = BackOfficeRequestContext.Application.FrameworkContext.TypeMappers.Map<MemberEditorModel, Member>(model);
                }
                else
                {
                    //map to existing entity
                    BackOfficeRequestContext.Application.FrameworkContext.TypeMappers.Map(model, entity);
                }

                uow.Repositories.AddOrUpdate(entity);

                //// Remove any removed user groups
                //foreach (var relation in uow.Repositories.GetParentRelations(entity.Id, FixedRelationTypes.UserGroupRelationType)
                //    .Where(x => !model.UserGroups.Contains(x.SourceId)))
                //{
                //    uow.Repositories.RemoveRelation(relation);
                //}

                //// Add any new user groups
                //var existingRelations = uow.Repositories.GetParentRelations(entity.Id, FixedRelationTypes.UserGroupRelationType).Select(x => x.SourceId).ToArray();
                //foreach (var userGroupId in model.UserGroups.Where(x => !existingRelations.Contains(x)))
                //{
                //    uow.Repositories.AddRelation(new Relation(FixedRelationTypes.UserGroupRelationType, userGroupId, entity.Id));
                //}

                uow.Complete();

                ////we may have changed the user data, so we need to ensure that the latest user data exists in the Identity object so we'll re-issue a forms auth ticket here
                //if (HttpContext.User.Identity.Name.InvariantEquals(entity.Username))
                //{
                //    HttpContext.CreateUmbracoAuthTicket(entity);
                //}

                Notifications.Add(new NotificationMessage(
                       "User.Save.Message".Localize(this),
                       "User.Save.Title".Localize(this),
                       NotificationType.Success));

                //add path for entity for SupportsPathGeneration (tree syncing) to work
                GeneratePathsForCurrentEntity(uow.Repositories.GetEntityPaths<TypedEntity>(entity.Id, FixedRelationTypes.DefaultRelationType));

                return RedirectToAction("Edit", new { id = entity.Id });
            }



        }
        public void From_Typed_Entity_To_Existing_MembershipUser()
        {
            var input = new Member()
                {
                    Comments = "some comments",
                    Email = "*****@*****.**",
                    Id = new HiveId(Guid.NewGuid()),
                    IsApproved = true,
                    IsLockedOut = false,
                    IsOnline = true,
                    LastLoginDate = DateTimeOffset.UtcNow.AddDays(-10),
                    LastActivityDate = DateTimeOffset.UtcNow.AddDays(-9),
                    LastLockoutDate = DateTimeOffset.MinValue,
                    Name = "Test",
                    LastPasswordChangeDate = DateTimeOffset.Now.AddDays(-20),
                    Password = "******",
                    PasswordQuestion = "My question is?",
                    Username = "******",
                    UtcCreated = DateTimeOffset.UtcNow.AddDays(-100),
                    UtcModified = DateTimeOffset.UtcNow,
                    UtcStatusChanged = DateTimeOffset.UtcNow
                };
            
            //create a member object to map to with data that will not match the above so we can verify the mapping worked.
            var output = new MembershipUser("test", "dontmatch", "dontmatch", "*****@*****.**", "dontmatch", "dontmatch", false, true, DateTime.Now, DateTime.Now, DateTime.Now, DateTime.Now, DateTime.Now);

            _mapper.Map(input, output);

            //Assert.AreEqual(input.Username, output.UserName);
            //Assert.AreEqual(input.ProviderUserKey, output.ProviderUserKey);
            Assert.AreEqual(input.Email, output.Email);
            //Assert.AreEqual(input.PasswordQuestion, output.PasswordQuestion);
            Assert.AreEqual(input.Comments, output.Comment);
            Assert.AreEqual(input.IsApproved, output.IsApproved);
            //Assert.AreEqual(input.IsLockedOut, output.IsLockedOut);
            //Assert.AreEqual(input.LastLockoutDate.UtcDateTime, output.LastLockoutDate.ToUniversalTime());
            //Assert.AreEqual(input.UtcCreated.UtcDateTime, output.CreationDate.ToUniversalTime());
            Assert.AreEqual(input.LastLoginDate.UtcDateTime, output.LastLoginDate.ToUniversalTime());
            Assert.AreEqual(input.LastActivityDate.UtcDateTime, output.LastActivityDate.ToUniversalTime());
            //Assert.AreEqual(input.LastPasswordChangeDate.UtcDateTime, output.LastPasswordChangedDate.ToUniversalTime());
            //Assert.AreEqual(input.IsOnline, output.IsOnline);
        }