Esempio n. 1
0
        public GameObject NextSpawn()
        {
            if (null == random)
            {
                random = new UnityRandom();
            }
            WeightedRandom wr = new WeightedRandom(random);

            float totalWeight = 0.0f;

            foreach (Item item in spawnItems)
            {
                totalWeight += item.weight;
                wr.Add(new Weight(item.weight, item));
            }

            var weight = wr.ChooseRandom();

            if (null == weight)
            {
                return(null);
            }
            if (null == weight.target)
            {
                return(null);
            }

            return(((Item)weight.target).spawnObject);
        }
        public static ComponentBuilder <TConfig, FluentBootstrap.Forms.Form> AjaxForm <TConfig, TComponent>(
            this BootstrapHelper <TConfig, TComponent> helper,
            string formAction,
            System.Web.Mvc.Ajax.AjaxOptions ajaxOptions = null
            ) where TConfig : BootstrapConfig where TComponent : Component, ICanCreate <FluentBootstrap.Forms.Form>
        {
            var id = SomeRandom.Id();

            ajaxOptions = ajaxOptions ?? new AjaxOptions()
            {
                InsertionMode  = InsertionMode.Replace,
                UpdateTargetId = "main-modal-body",
                OnSuccess      = "indexViewModel.modalLoaded",
                OnFailure      = "indexViewModel.postFailed",
                OnComplete     = "Ladda.bind('.ladda-button')",
            };

            var form = helper.Form()
                       .AddAttribute("action", formAction)
                       .AddAttribute("method", "post")
                       .AddAttributes(ajaxOptions.ToUnobtrusiveHtmlAttributes())
                       .SetId(id);

            return(form);
        }
 public async Task can_create_user()
 {
     var result = await Target.CreateAsync(new ApplicationUser()
     {
         UserName = SomeRandom.EmailAddress(),
         Email    = SomeRandom.EmailAddress(),
     }, SomeRandom.Password());
 }
        public async Task ensure_has_claim()
        {
            var claim = new Claim(SomeRandom.String(), SomeRandom.String());
            var user  = DbContext.Users.First();

            var result = await Target.EnsureHasClaimAsync(user.Id, claim.Type, claim.Value);

            result.Succeeded.Should().BeTrue();
            await Target.EnsureHasClaimAsync(user.Id, claim.Type, claim.Value);

            var claims = await Target.GetClaimsAsync(user.Id);

            claims.Where(c => c.Type == claim.Type).Should().HaveCount(1);
        }
Esempio n. 5
0
        public static void SeedContext(ApplicationDbContext context)
        {
            var userManager = new ApplicationUserManager(new UserStore <ApplicationUser>(context));
            var roleManager = new RoleManager <IdentityRole>(new RoleStore <IdentityRole>(context));

            roleManager.Create(new IdentityRole()
            {
                Name = Constants.Roles.Administrator
            });
            var adminEmail = "*****@*****.**";
            var user       = userManager.FindByName(adminEmail);

            if (user == null)
            {
                user = new ApplicationUser()
                {
                    UserName = "******",
                    Email    = "*****@*****.**",
                    Person   = new Person()
                    {
                        FirstName = "Admin",
                        LastName  = "Istrator",
                    }
                };
                var result = userManager.Create(user, Guid.NewGuid().ToString() + SomeRandom.String(10).ToUpper() + "!");
                if (!result.Succeeded)
                {
                    throw new InvalidOperationException(String.Join(";", result.Errors));
                }
                userManager.AddClaim(user.Id, new Claim(Constants.Claims.Staff, bool.TrueString));
            }
            try
            {
                if (!userManager.IsInRole(user.Id, Constants.Roles.Administrator))
                {
                    userManager.AddToRole(user.Id, Constants.Roles.Administrator);
                }
            }
            catch
            {
                // we'll need to run again.
            }
            var userShortage = 200 - context.Users.Count();

            for (int i = 0; i < userShortage; i++)
            {
                var randomUser = new ApplicationUser()
                {
                    UserName = $"{SomeRandom.String()}@example.com",
                    Email    = $"{SomeRandom.String()}@example.com",
                    Person   = new Person()
                    {
                        FirstName    = SomeRandom.Name(),
                        LastName     = SomeRandom.Name(),
                        EmailAddress = SomeRandom.EmailAddress(),
                        PhoneNumber  = SomeRandom.PhoneNumber()
                    }
                };
                userManager.Create(randomUser, SomeRandom.Name(20) + ".1");
            }

            var tb = new TagBuilder(context);

            if (!context.Tags.Any())
            {
                tb.CreateContextTag("Business", "Business", "A loss in a business context.")
                .WithLosses("Employee", "Employee family member")
                .WithRelationships("HR", "Employee", "Employee family member", "Owner", "Other");
                tb.CreateContextTag("Personal", "Personal", "A loss in a family context.")
                .WithLosses("Child", "Parent", "Sibling", "Friend", "Other")
                .WithRelationships("Parent", "Child", "Sibling", "Spouse", "Extended family", "Pastor", "Other");
                tb.CreateContextTag("Educational", "Educational", "A loss at a school or university.")
                .WithLosses("Student", "Faculty", "Staff", "Family of student")
                .WithRelationships("Administrator", "Faculty", "Student", "Family", "Other");
                tb.CreateContextTag("Organizational", "Church, sports team, or other organization", "A loss at a church or social organization.")
                .WithLosses("Member", "Affiliate")
                .WithRelationships("Member", "Leader");
            }

            for (int i = 1; i < 7; i++)
            {
                context.Items.AddOrUpdate(new Article()
                {
                    Id         = i,
                    CreatedBy  = user.UserName,
                    CreatedUtc = DateTimeOffset.UtcNow,
                    Content    =
                        "Lorem ipsum dolor sit amet, sapien etiam, nunc amet dolor ac odio mauris justo. Luctus arcu, urna praesent at id quisque ac. Arcu es massa vestibulum malesuada, integer vivamus elit eu mauris eus, cum eros quis aliquam wisi. Nulla wisi laoreet suspendisse integer vivamus elit eu mauris hendrerit facilisi, mi mattis pariatur aliquam pharetra eget.",
                    Title = "Article " + i,
                    Order = i,
                });
            }

            for (int i = 1; i < 5; i++)
            {
                context.Items.AddOrUpdate(new ToDo()
                {
                    Id         = i + 7,
                    CreatedBy  = user.UserName,
                    CreatedUtc = DateTimeOffset.UtcNow,
                    Content    =
                        "Luctus arcu, urna praesent at id quisque ac. Arcu es massa vestibulum malesuada, integer vivamus elit eu mauris eus.",
                    Title = "ToDo " + i,
                    Order = i,
                });
            }
        }
Esempio n. 6
0
 public WeightedRandom(SomeRandom random)
 {
     this.random = random;
 }