Ejemplo n.º 1
0
        public async Task HalBuilderFactory_ResolvesCustomConfigurations()
        {
            var container = RegistrationHelpers.CreateContainer();

            using (var server = LocalWebServer.ListenInBackground(new XUnitMockLogger(_logger)))
            {
                server.WithNextResponseOk(TestResource.SerializedDefault1);
                var factory = container.Resolve <IHalBuilderFactory>();

                var    builder     = factory.Create();
                string actual      = null;
                string actualTyped = null;
                var    resource    = await builder.WithLink(server.ListeningUri)
                                     .Advanced
                                     .WithCaching(false)
                                     .OnSending(HandlerPriority.Last, context =>
                {
                    actual      = context.Items["CustomHalConfiguration"] as string;
                    actualTyped = context.Items["CustomTypedConfiguration"] as string;
                })
                                     .ResultAsync <TestResource>();

                resource.ShouldBe(TestResource.Default1());
                actual.ShouldBe("CustomHalConfiguration: It Works!");
                actualTyped.ShouldBeNull();
            }
        }
Ejemplo n.º 2
0
        public void CustomCacheProviderActivated()
        {
            var activated = false;

            CustomCacheProvider.Activated += (sender, args) =>
            {
                activated = true;
            };

            var container = RegistrationHelpers.CreateContainer(false);

            activated.ShouldBeTrue();
        }
Ejemplo n.º 3
0
        private void register()
        {
            this.errorMessages.Clear();

            if (this.roleRegisteringFor == PersonRoles.Administrator)
            {
                this.username = this.textBoxUsername.Text;
                this.password = this.textBoxPassword.Text;
            }

            this.preValidate();

            this.validateFields();


            if (string.IsNullOrEmpty(address2))
            {
                address2 = null;
            }


            if (this.errorMessages.Count > 0)
            {
                this.displayErrorMessages();
            }
            else
            {
                if (this.roleRegisteringFor == PersonRoles.Administrator)
                {
                    bool registrationSuccess = RegistrationHelpers.RegisterAdministrator(firstName, lastName, city, state, zip, phone,
                                                                                         dob, gender, address1, address2, username, password);
                    if (!registrationSuccess)
                    {
                        MessageBox.Show("Registration unsuccessful");
                    }
                }
                else
                {
                    bool registrationSuccess = RegistrationHelpers.RegisterPatient(firstName, lastName, city, state, zip, phone,
                                                                                   dob, gender, address1, address2);
                    if (!registrationSuccess)
                    {
                        MessageBox.Show("Registration unsuccessful");
                    }
                }

                this.labelErrorMessages.Hide();
                this.Close();
            }
        }
Ejemplo n.º 4
0
        public async Task HttpBuilderFactory_ResolvesCustomValidators()
        {
            var container = RegistrationHelpers.CreateContainer();

            using (var server = LocalWebServer.ListenInBackground(new XUnitMockLogger(_logger)))
            {
                server.WithNextResponse(HttpStatusCode.Created);
                var factory = container.Resolve <IHttpBuilderFactory>();

                var builder = factory.Create();

                await Should.ThrowAsync <HttpRequestException>(builder.WithUri(server.ListeningUri).Advanced.WithCaching(false).ResultAsync());
            }
        }
Ejemplo n.º 5
0
        public async Task HttpBuilder_CanResolveAndCall()
        {
            var container = RegistrationHelpers.CreateContainer();

            using (var server = LocalWebServer.ListenInBackground(new XUnitMockLogger(_logger)))
            {
                server.WithNextResponseOk("Response");

                var builder = container.Resolve <IHttpBuilder>();

                var response = await builder.WithUri(server.ListeningUri).Advanced.WithCaching(false).ResultAsync();

                response.StatusCode.ShouldBe(HttpStatusCode.OK);
            }
        }
Ejemplo n.º 6
0
        public async Task HalBuilder_CanResolveAndCall()
        {
            var container = RegistrationHelpers.CreateContainer();

            using (var server = LocalWebServer.ListenInBackground(new XUnitMockLogger(_logger)))
            {
                server.WithNextResponseOk(TestResource.SerializedDefault1);

                var builder = container.Resolve <IHalBuilder>();

                var resource = await builder.WithLink(server.ListeningUri).Advanced.WithCaching(false).ResultAsync <TestResource>();

                resource.ShouldBe(TestResource.Default1());
            }
        }
Ejemplo n.º 7
0
        public async Task TypedBuilderFactory_CanResolveAndCall()
        {
            var container = RegistrationHelpers.CreateContainer();

            using (var server = LocalWebServer.ListenInBackground(new XUnitMockLogger(_logger)))
            {
                server.WithNextResponseOk(TestResult.SerializedDefault1);
                var factory = container.Resolve <ITypedBuilderFactory>();

                var builder = factory.Create();

                var result = await builder.WithUri(server.ListeningUri).Advanced.WithCaching(false).ResultAsync <TestResult>();

                result.ShouldBe(TestResult.Default1());
            }
        }
Ejemplo n.º 8
0
        public async Task TypedBuilderFactory_TwoBuildersDonNotShareSameSettings()
        {
            var container = RegistrationHelpers.CreateContainer();

            using (var server = LocalWebServer.ListenInBackground(new XUnitMockLogger(_logger)))
            {
                server
                .WithNextResponseTextOk("Response1")
                .WithNextResponseTextOk("Response2");

                var        factory  = container.Resolve <ITypedBuilderFactory>();
                var        actual1  = 0;
                var        actual2  = 0;
                HttpMethod method1  = null;
                HttpMethod method2  = null;
                var        builder1 = factory.Create().WithUri(server.ListeningUri)
                                      .AsGet()
                                      .Advanced.WithCaching(false)
                                      .WithContextItem("Shared", 1)
                                      .OnSending(HandlerPriority.Last, context =>
                {
                    actual1 = (int)context.Items["Shared"];
                    method1 = context.Request.Method;
                });
                var builder2 = factory.Create().WithUri(server.ListeningUri)
                               .AsPut()
                               .Advanced.WithCaching(false)
                               .WithContextItem("Shared", 2)
                               .OnSending(HandlerPriority.Last, context =>
                {
                    actual2 = (int)context.Items["Shared"];
                    method2 = context.Request.Method;
                });


                var response1 = await builder1.ResultAsync <string>();

                var response2 = await builder2.ResultAsync <string>();

                method1.ToString().ShouldNotBe(method2.ToString());
                actual1.ShouldNotBe(actual2);
            }
        }
Ejemplo n.º 9
0
        public async Task HalBuilderFactory_ResolvesCustomCacheHandlers()
        {
            var container = RegistrationHelpers.CreateContainer();

            using (var server = LocalWebServer.ListenInBackground(new XUnitMockLogger(_logger)))
            {
                server.WithNextResponse(new MockHttpResponseMessage().WithContent(TestResource.SerializedDefault1).WithPrivateCacheHeader().WithDefaultExpiration());
                var factory = container.Resolve <IHalBuilderFactory>();

                var    builder  = factory.Create();
                string actual   = null;
                var    resource = await builder.WithLink(server.ListeningUri)
                                  .Advanced.WithCaching(true)
                                  .OnCacheMiss(HandlerPriority.Last, context =>
                {
                    actual = context.Items["CustomTypedCacheHandler"] as string;
                })
                                  .ResultAsync <TestResource>();

                resource.ShouldBe(TestResource.Default1());
                actual.ShouldBe("CustomTypedCacheHandler: It Works!");
            }
        }
Ejemplo n.º 10
0
        public async Task TypedBuilderFactory_ResolvesCustomCacheHandlers()
        {
            var container = RegistrationHelpers.CreateContainer();

            using (var server = LocalWebServer.ListenInBackground(new XUnitMockLogger(_logger)))
            {
                server.WithNextResponseTextOk("Typed Result", r => r.WithPrivateCacheHeader().WithDefaultExpiration());
                var factory = container.Resolve <ITypedBuilderFactory>();

                var    builder = factory.Create();
                string actual  = null;
                var    result  = await builder.WithUri(server.ListeningUri)
                                 .Advanced.WithCaching(true)
                                 .OnCacheMiss(HandlerPriority.Last, context =>
                {
                    actual = context.Items["CustomTypedCacheHandler"] as string;
                })
                                 .ResultAsync <string>();

                result.ShouldBe("Typed Result");
                actual.ShouldBe("CustomTypedCacheHandler: It Works!");
            }
        }
Ejemplo n.º 11
0
        public async Task HttpBuilderFactory_ResolvesCustomConfigurations()
        {
            var container = RegistrationHelpers.CreateContainer();

            using (var server = LocalWebServer.ListenInBackground(new XUnitMockLogger(_logger)))
            {
                server.WithNextResponseOk("Response");
                var factory = container.Resolve <IHttpBuilderFactory>();

                var    builder  = factory.Create();
                string actual   = null;
                var    response = await builder.WithUri(server.ListeningUri)
                                  .Advanced
                                  .WithCaching(false)
                                  .OnSending(HandlerPriority.Last, context =>
                {
                    actual = context.Items["CustomHttpConfiguration"] as string;
                })
                                  .ResultAsync();

                response.StatusCode.ShouldBe(HttpStatusCode.OK);
                actual.ShouldBe("CustomHttpConfiguration: It Works!");
            }
        }
Ejemplo n.º 12
0
        public async Task HttpBuilderFactory_TwoBuildersDonNotShareSameSettings()
        {
            var container = RegistrationHelpers.CreateContainer();

            using (var server = LocalWebServer.ListenInBackground(new XUnitMockLogger(_logger)))
            {
                server
                .WithNextResponseOk("Response1")
                .WithNextResponseOk("Response2");

                var factory  = container.Resolve <IHttpBuilderFactory>();
                int actual1  = 0;
                int actual2  = 0;
                var builder1 = factory.Create().WithUri(server.ListeningUri)
                               .Advanced.WithCaching(false)
                               .WithContextItem("Shared", 1)
                               .OnSending(HandlerPriority.Last, context =>
                {
                    actual1 = (int)context.Items["Shared"];
                });
                var builder2 = factory.Create().WithUri(server.ListeningUri)
                               .Advanced.WithCaching(false)
                               .WithContextItem("Shared", 2)
                               .OnSending(HandlerPriority.Last, context =>
                {
                    actual2 = (int)context.Items["Shared"];
                });


                var response1 = await builder1.ResultAsync();

                var response2 = await builder2.ResultAsync();

                actual1.ShouldNotBe(actual2);
            }
        }
Ejemplo n.º 13
0
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName       = model.Email,
                    Email          = model.Email,
                    DateCreated    = DateTime.Now,
                    FirstName      = model.FirstName,
                    Gender         = model.Gender,
                    LastName       = model.LastName,
                    PhoneNumber    = model.PhoneNumber,
                    ProfilePicture = null,
                    DoB            = DateTime.Now,
                    IsActive       = true,
                };

                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    //new database creation
                    int msecs  = DateTime.Now.Millisecond;
                    var dbName = model.OrganizationName.Replace(" ", "") + "_" + msecs.ToString();
                    if (RegistrationHelpers.CreateNewRegisteredDatabase(dbName))
                    {
                        db.Users.Attach(user);

                        var org = new OrganizationInformation();
                        org.Id               = Guid.NewGuid();
                        org.Server           = "localhost";
                        org.Password         = "";
                        org.User             = "";
                        org.OrganizationName = model.OrganizationName;
                        org.Database         = dbName;

                        db.OrganizationInformation.Add(org);

                        ApplicationUserOrganizationInformations link = new ApplicationUserOrganizationInformations();
                        link.ApplicationUser         = user;
                        link.OrganizationInformation = org;
                        link.OrganizationId          = org.Id;
                        link.ApplicationUserId       = user.Id;

                        user.ApplicationUserOrganizationInformations.Add(link);

                        db.SaveChanges();
                    }

                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                    // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                    return(RedirectToAction("Index", "Home"));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Ejemplo n.º 14
0
        private IHttpBuilder CreateBuilder()
        {
            var container = RegistrationHelpers.CreateContainer();

            return(container.Resolve <IHttpBuilder>());
        }
Ejemplo n.º 15
0
 public SpeedTest(ITestOutputHelper logger)
 {
     _logger    = logger;
     _container = RegistrationHelpers.CreateContainer(false);
 }