コード例 #1
0
        public async Task ReturnNullWhenEventsCampaignIsLocked()
        {
            var options = CreateNewContextOptions();

            const int eventId = 1;
            var message = new ShowEventQuery { EventId = eventId };

            using (var context = new AllReadyContext(options))
            {
                context.Events.Add(new Models.Event
                {
                    Id = eventId,
                    Campaign = new Campaign { Locked = true }
                });
                await context.SaveChangesAsync();
            }

            using (var context = new AllReadyContext(options))
            {
                var sut = new ShowEventQueryHandler(context);
                var result = await sut.Handle(message);

                result.ShouldBeNull();
            }
        }
コード例 #2
0
        public async Task SetsTaskSignupViewModel_WithTheCorrectData()
        {
            var options = CreateNewContextOptions();

            var appUser = new ApplicationUser
            {
                Id = "asdfasasdfaf",
                Email = "*****@*****.**",
                FirstName = "Foo",
                LastName = "Bar",
                PhoneNumber = "555-555-5555",
            };

            var message = new ShowEventQuery { EventId = 1, UserId = appUser.Id };

            using (var context = new AllReadyContext(options))
            {
                context.Users.Add(appUser);
                context.Events.Add(CreateAllReadyEventWithTasks(message.EventId, appUser));
                await context.SaveChangesAsync();
            }

            using (var context = new AllReadyContext(options))
            {
                var sut = new ShowEventQueryHandler(context);
                var eventViewModel = await sut.Handle(message);

                Assert.Equal(message.EventId, eventViewModel.SignupModel.EventId);
                Assert.Equal(appUser.Id, eventViewModel.SignupModel.UserId);
                Assert.Equal($"{appUser.FirstName} {appUser.LastName}", eventViewModel.SignupModel.Name);
            }
        }
コード例 #3
0
        public async Task CanSaveZeroTasks()
        {
            var options = CreateNewContextOptions();

            const string userId = "1";
            var user = new ApplicationUser {Id = userId};

            using (var context = new AllReadyContext(options))
            {
                context.Users.Add(user);
                await context.SaveChangesAsync();
            }

            var message = new UpdateMyTasksCommand { UserId =userId, TaskSignups = new List<TaskSignupViewModel>() };

            using (var context = new AllReadyContext(options))
            {
                var sut = new UpdateMyTasksCommandHandler(context);
                await sut.Handle(message);
            }

            using (var context = new AllReadyContext(options))
            {
                var taskSignups = context.TaskSignups.Count();
                Assert.Equal(taskSignups, 0);
            }
        }
コード例 #4
0
        public async Task HandleInvokesUpdateTaskAsyncWithCorrectData()
        {
            var options = this.CreateNewContextOptions();

            const int taskId = 1;
            var message = new UpdateTaskCommand { AllReadyTask = new AllReadyTask {Id = taskId} };

            using (var context = new AllReadyContext(options)) {
                context.Tasks.Add(new AllReadyTask {
                    Id = taskId,
                    RequiredSkills = new List<TaskSkill> {
                        new TaskSkill()
                    }
                });
                await context.SaveChangesAsync();
            }

            using (var context = new AllReadyContext(options)) {
                var sut = new UpdateTaskCommandHandler(context);
                await sut.Handle(message);
            }

            using (var context = new AllReadyContext(options)) {
                var task = context.Tasks.Include(t => t.RequiredSkills).FirstOrDefault(t => t.Id == taskId);
                Assert.NotNull(task);
                Assert.Equal(task.RequiredSkills.Count, 0);
            }
        }
コード例 #5
0
        public async Task InvokeUpdateTaskSignupAsyncForEachTaskSignupViewModelOnCommand()
        {
            var options = CreateNewContextOptions();

            const string userId = "1";
            const int firstId = 1;
            const int secondId = 2;

            var user = new ApplicationUser {Id = userId};
            var taskSignupViewModels = new List<TaskSignupViewModel> {new TaskSignupViewModel {Id = firstId}, new TaskSignupViewModel {Id = secondId}};

            using (var context = new AllReadyContext(options))
            {
                context.Users.Add(user);
                context.TaskSignups.Add(new TaskSignup { Id = firstId });
                context.TaskSignups.Add(new TaskSignup { Id = secondId });
                await context.SaveChangesAsync();
            }

            using (var context = new AllReadyContext(options))
            {
                var sut = new UpdateMyTasksCommandHandler(context) { DateTimeUtcNow = () => DateTime.UtcNow };
                await sut.Handle(new UpdateMyTasksCommand { TaskSignups = taskSignupViewModels });
            }

            using (var context = new AllReadyContext(options))
            {
                var signup1 = context.TaskSignups.FirstOrDefault(x => x.Id == firstId);
                Assert.Equal(signup1 != null, true);
                var signup2 = context.TaskSignups.FirstOrDefault(x => x.Id == secondId);
                Assert.Equal(signup2 != null, true);
            }
        }
コード例 #6
0
        public async Task WhenProviderIdIsProvidedAndIsValid_TheStatusOfTheExistingRequestIsUpdated()
        {
            string pid = "someId";
            var request = new Request
            {
                ProviderId = pid,
                Status = RequestStatus.Assigned
            };
            var command = new AddRequestCommand{Request = request};

            var options = this.CreateNewContextOptions();

            using (var context = new AllReadyContext(options)) {
                context.Requests.Add(new Request {
                    ProviderId = pid,
                    Status = RequestStatus.Assigned
                });
                await context.SaveChangesAsync();
            }

            using (var context = new AllReadyContext(options)) {
                var geocoder = new Mock<IGeocoder>();
                AddRequestCommandHandler sut = new AddRequestCommandHandler(context, geocoder.Object);


                await sut.Handle(command);
            }

            using (var context = new AllReadyContext(options)) {
                var entity = context.Requests.FirstOrDefault(x => x.ProviderId == pid);
                Assert.Equal(entity.Status, RequestStatus.Assigned);
            }
        }
コード例 #7
0
        public async Task UpdateUserHandlerInvokesUpdateUserWithTheCorrectUser()
        {
            var options = this.CreateNewContextOptions();

            const string userId = "12345";
            const string firstName = "changed";
            var message = new UpdateUser { User = new ApplicationUser {
                Id = userId,
                FirstName = firstName
            } };

            using (var context = new AllReadyContext(options)) {
                context.Users.Add(new ApplicationUser {
                    Id = userId,
                    FirstName = "notChanged"
                });
                await context.SaveChangesAsync();
            }

            using (var context = new AllReadyContext(options)) {
                var sut = new UpdateUserHandler(context);
                await sut.Handle(message);
            }

            using (var context = new AllReadyContext(options)) {
                var user = context.Users.FirstOrDefault(u => u.Id == userId);
                Assert.NotNull(user);
                Assert.Equal(user.FirstName, firstName);
            }

        }
コード例 #8
0
        public async Task ReturnsExpectedTasks()
        {
            var options = CreateNewContextOptions();

            const int eventId = 1;
            const string userId = "9D0929AC-BE6A-4A0B-A758-6C6FC31A8C47";
            var message = new GetMyTasksQuery { EventId = eventId, UserId = userId };

            using (var context = new AllReadyContext(options))
            {
                context.TaskSignups.Add(new TaskSignup
                {
                    User = new ApplicationUser { Id = userId },
                    Task = new AllReadyTask { Event = new Event { Id = eventId, Campaign = new Campaign { Locked = false }}}
                });
                await context.SaveChangesAsync();
            }

            using (var context = new AllReadyContext(options))
            {
                var sut = new GetMyTasksQueryHandler(context);
                var response = sut.Handle(message);

                Assert.True(response.Any());
            }
        }
コード例 #9
0
        public async Task HandleReturnsEventsWitUnlockedCampaigns()
        {
            var options = CreateNewContextOptions();

            const int unlockedEventId = 1;

            using (var context = new AllReadyContext(options))
            {
                var campaignEvents = new List<Event>
                {
                    new Event {Id = unlockedEventId, Campaign = new Campaign {Locked = false, ManagingOrganization = new Organization()}},
                    new Event {Id = 2, Campaign = new Campaign {Locked = true, ManagingOrganization = new Organization()}}
                };
                context.Events.AddRange(campaignEvents);
                await context.SaveChangesAsync();
            }

            using (var context = new AllReadyContext(options))
            {
                var sut = new EventsWithUnlockedCampaignsQueryHandler(context);
                var results = sut.Handle(new EventsWithUnlockedCampaignsQuery());

                Assert.Equal(results[0].Id, unlockedEventId);
            }
        }
コード例 #10
0
        public static void LoadCampaignssHandlerTestData(AllReadyContext context)
        {
            // Organizations
            context.Organizations.Add(new Organization { Id = 1, Name = "Org 1" });
            context.Organizations.Add(new Organization { Id = 2, Name = "Org 2" });

            // Campaigns
            context.Campaigns.Add(new Campaign { Name = "Campaign 1", ManagingOrganizationId = 1 });
            context.Campaigns.Add(new Campaign { Name = "Campaign 2", ManagingOrganizationId = 1 });

            context.SaveChanges();
        }
コード例 #11
0
        public static Campaign UpdateCampaignContact(this Campaign campaign, IPrimaryContactModel contactModel, AllReadyContext _context)
        {
            if (campaign.CampaignContacts == null)
            {
                campaign.CampaignContacts = new List<CampaignContact>();
            }

            var primaryCampaignContact = campaign.CampaignContacts.SingleOrDefault(tc => tc.ContactType == (int)ContactTypes.Primary);
            var contactId = primaryCampaignContact?.ContactId;
            Contact primaryContact;

            var contactInfo = string.Concat(contactModel.PrimaryContactEmail?.Trim() + contactModel.PrimaryContactFirstName?.Trim(), contactModel.PrimaryContactLastName?.Trim(), contactModel.PrimaryContactPhoneNumber?.Trim());

            if (contactId == null)
            {
                primaryContact = new Contact();
            }
            else
            {
                primaryContact = _context.Contacts.Single(c => c.Id == contactId);
            }

            if (string.IsNullOrWhiteSpace(contactInfo) && primaryCampaignContact != null)
            {
                //Delete
                _context.CampaignContacts.Remove(primaryCampaignContact);
                _context.Remove(primaryCampaignContact);//Not Needed?
                _context.Remove(primaryCampaignContact.Contact);
            }
            else
            {
                primaryContact.Email = contactModel.PrimaryContactEmail;
                primaryContact.FirstName = contactModel.PrimaryContactFirstName;
                primaryContact.LastName = contactModel.PrimaryContactLastName;
                primaryContact.PhoneNumber = contactModel.PrimaryContactPhoneNumber;
                _context.Update(primaryContact);

                if (primaryCampaignContact == null)
                {
                    primaryCampaignContact = new CampaignContact
                    {
                        Contact = primaryContact,
                        Campaign = campaign,
                        ContactType = (int)ContactTypes.Primary
                    };
                    campaign.CampaignContacts.Add(primaryCampaignContact);
                    _context.Update(primaryCampaignContact);
                }
            }
            return campaign;
        }
コード例 #12
0
        public static async Task<Organization> UpdateOrganizationContact(this Organization organization, IPrimaryContactViewModel contactModel, AllReadyContext _context)
        {
            if (organization.OrganizationContacts == null)
            {
                organization.OrganizationContacts = new List<OrganizationContact>();
            }

            var primaryCampaignContact = organization.OrganizationContacts.SingleOrDefault(tc => tc.ContactType == (int)ContactTypes.Primary);
            var contactId = primaryCampaignContact?.ContactId;
            Contact primaryContact;

            var contactInfo = string.Concat(contactModel.PrimaryContactEmail?.Trim() + contactModel.PrimaryContactFirstName?.Trim(), contactModel.PrimaryContactLastName?.Trim(), contactModel.PrimaryContactPhoneNumber?.Trim());
            if (contactId == null)
            {
                primaryContact = new Contact();
            }
            else
            {
                primaryContact = await _context.Contacts.SingleAsync(c => c.Id == contactId);
            }

            if (string.IsNullOrWhiteSpace(contactInfo) && primaryCampaignContact != null)
            {
                //Delete
                _context.OrganizationContacts.Remove(primaryCampaignContact);
                _context.Remove(primaryCampaignContact);//Not Needed?
                _context.Remove(primaryCampaignContact.Contact);
            }
            else
            {
                primaryContact.Email = contactModel.PrimaryContactEmail;
                primaryContact.FirstName = contactModel.PrimaryContactFirstName;
                primaryContact.LastName = contactModel.PrimaryContactLastName;
                primaryContact.PhoneNumber = contactModel.PrimaryContactPhoneNumber;
                _context.AddOrUpdate(primaryContact);

                if (primaryCampaignContact == null)
                {
                    primaryCampaignContact = new OrganizationContact
                    {
                        Contact = primaryContact,
                        Organization = organization,
                        ContactType = (int)ContactTypes.Primary
                    };
                    organization.OrganizationContacts.Add(primaryCampaignContact);
                    _context.AddOrUpdate(primaryCampaignContact);
                }
            }

            return organization;
        }
コード例 #13
0
        public async Task HandleInvokesAddTaskAsyncWithCorrectData()
        {
            var options = this.CreateNewContextOptions();

            using (var context = new AllReadyContext(options)) {
                var sut = new AddTaskCommandHandler(context);
                var message = new AddTaskCommand { AllReadyTask = new AllReadyTask() };
                await sut.Handle(message);
            }

            using (var context = new AllReadyContext(options)) {
                var tasks = context.Tasks.Count();
                Assert.Equal(tasks, 1);
            }
        }
コード例 #14
0
        public static void LoadOrganizationHandlerTestData(AllReadyContext context)
        {
            var htmlPrivacyPolicy = "<h2>Line 1</h2><p>Line 2</p>";

            // Organizations
            context.Organizations.Add(new Organization { Id = 1, Name = "Org 1" });
            context.Organizations.Add(new Organization { Id = 2, Name = "Org 2", PrivacyPolicy = htmlPrivacyPolicy });

            // Campaigns
            context.Campaigns.Add(new Campaign { Name = "Campaign 1", ManagingOrganizationId = 1 });
            context.Campaigns.Add(new Campaign { Name = "Campaign 2", ManagingOrganizationId = 1 });
            context.Campaigns.Add(new Campaign { Name = "Locked Campaign", ManagingOrganizationId = 1, Locked = true });
            context.Campaigns.Add(new Campaign { Name = "Unlocked Campaign", ManagingOrganizationId = 1, Locked = false });

            context.SaveChanges();
        }
コード例 #15
0
        public async Task WhenHandlingTaskByTaskIdQueryGetTaskIsInvokedWithCorrectTaskId() {
            var options = this.CreateNewContextOptions();

            const int taskId = 1;
            var message = new TaskByTaskIdQuery { TaskId = taskId };

            using (var context = new AllReadyContext(options)) {
                context.Tasks.Add(new AllReadyTask {Id = taskId});
                await context.SaveChangesAsync();
            }

            using (var context = new AllReadyContext(options)) {
                var sut = new TaskByTaskIdQueryHandler(context);
                var task = await sut.Handle(message);

                Assert.Equal(task.Id, taskId);
            }
        }
コード例 #16
0
        public async Task HandleCallsEventsByGeographyWithTheCorrectLatitiudeLongitudeAndMiles()
        {
            var options = this.CreateNewContextOptions();

            var message = new EventsByGeographyQuery() { Latitude = 1, Longitude = 2, Miles = 3 };

            using (var context = new AllReadyContext(options)) {
                context.Events.Add(new Event());
                context.Events.Add(new Event());
                await context.SaveChangesAsync();
            }

            using (var context = new AllReadyContext(options)) {
                var sut = new EventsByGeographyQueryHandler(context);
                var events = sut.Handle(message);

                Assert.Equal(events.Count, 2);
            }
        }
コード例 #17
0
        public static void LoadSkillsHandlerTestData(AllReadyContext context)
        {
            // Organizations
            context.Organizations.Add(new Organization { Id = 1, Name = "Org 1" });
            context.Organizations.Add(new Organization { Id = 2, Name = "Org 2" });

            // Skills
            context.Skills.Add(new Skill { Name = "Skill 1", Description = "Description 1", OwningOrganizationId = 1 });
            context.Skills.Add(new Skill { Name = "Skill 2", Description = "Description 2", OwningOrganizationId = 1 });
            context.Skills.Add(new Skill { Name = "Skill 3", Description = "Child of Skill 2", OwningOrganizationId = 1, ParentSkillId = 2 });

            context.Skills.Add(new Skill { Name = "Skill 4", Description = "Description 4", });
            context.Skills.Add(new Skill { Name = "Skill 5", Description = "Child of Skill 4", ParentSkillId = 4 });
            context.Skills.Add(new Skill { Name = "Skill 6", Description = "Child of skill 4", ParentSkillId = 4 });

            context.Skills.Add(new Skill { Name = "Skill 7", Description = "Description 7", OwningOrganizationId = 2 });

            context.SaveChanges();
        }
コード例 #18
0
        public async Task HandleCallsEventsByPostalCodeWithCorrectPostalCodeAndDistance()
        {
            var options = this.CreateNewContextOptions();

            var message = new EventsByPostalCodeQuery { PostalCode = "PostalCode", Distance = 100 };

            using (var context = new AllReadyContext(options)) {
                context.Events.Add(new Event());
                context.Events.Add(new Event());
                await context.SaveChangesAsync();
            }

            using (var context = new AllReadyContext(options)) {
                var sut = new EventsByPostalCodeQueryHandler(context);
                var events = sut.Handle(message);

                Assert.Equal(events.Count, 2);
            }
        }
コード例 #19
0
        public async Task ReturnNullWhenEventIsNotFound()
        {
            var options = CreateNewContextOptions();

            var message = new ShowEventQuery { EventId = 1 };

            using (var context = new AllReadyContext(options))
            {
                // add nothing
                //await context.SaveChangesAsync();
            }

            using (var context = new AllReadyContext(options))
            {
                var sut = new ShowEventQueryHandler(context);
                var result = await sut.Handle(message);

                result.ShouldBeNull();
            }
        }
コード例 #20
0
        protected override void LoadTestData()
        {
            rnd = new Random();
            context = ServiceProvider.GetService<AllReadyContext>();
            var tasks = context.Tasks.ToList();
            _task = GenerateTask();

            var htb = new Organization
            {
                Name = "Humanitarian Test",
                LogoUrl = "http://www.htbox.org/upload/home/ht-hero.png",
                WebUrl = "http://www.htbox.org",
                Campaigns = new List<Campaign>()
            };

            var firePrev = new Campaign
            {
                Name = "test Campaign",
                ManagingOrganization = htb
            };

            var myEvent = new Event
            {
                Id = rnd.Next(3,1000),
                Campaign = firePrev,
                CampaignId = firePrev.Id,
                StartDateTime = new DateTime(2015, 7, 4, 10, 0, 0).ToUniversalTime(),
                EndDateTime = new DateTime(2015, 12, 31, 15, 0, 0).ToUniversalTime(),
                Location = new Location { Id = 1 },
                RequiredSkills = new List<EventSkill>()
            };

            _task.Event = myEvent;
            context.Organizations.Add(htb);

            context.Campaigns.Add(firePrev);
            context.Events.Add(myEvent);
            context.Tasks.Add(_task);
            tasks = context.Tasks.ToList();
            context.SaveChanges();
        }
コード例 #21
0
        public async Task HandleInvokesGetResourcesByCategoryWithCorrectCategory()
        {
            var options = this.CreateNewContextOptions();

            const string category = "category";
            var message = new ResourcesByCategoryQuery { Category = category };

            using (var context = new AllReadyContext(options)) {
                context.Resources.Add(new Resource {
                    CategoryTag = category
                });
                await context.SaveChangesAsync();
            }

            using (var context = new AllReadyContext(options)) {
                var sut = new ResourcesByCategoryQueryHandler(context);
                var resource = sut.Handle(message);

                Assert.Equal(resource.Count, 1);
            }
        }
コード例 #22
0
        public static void LoadCampaignssHandlerTestData(AllReadyContext context)
        {
            // Organizations
            context.Organizations.Add(new Organization { Id = 1, Name = "Org 1" });
            context.Organizations.Add(new Organization { Id = 2, Name = "Org 2" });

            // Campaigns
            context.Campaigns.Add(new Campaign { Name = "Campaign 1", ManagingOrganizationId = 1 });
            context.Campaigns.Add(new Campaign { Name = "Campaign 2", ManagingOrganizationId = 1 });
            context.Campaigns.Add(new Campaign { Name = "Locked Campaign", ManagingOrganizationId = 1, Locked = true });
            context.Campaigns.Add(new Campaign { Name = "Unlocked Campaign", ManagingOrganizationId = 1, Locked = false });

            // Contacts

            var newContact = new Contact { Email = "*****@*****.**", FirstName = "Bill", LastName = "Gates", PhoneNumber = "01323 000000" };
            context.Contacts.Add(newContact);
            context.CampaignContacts.Add(new CampaignContact { CampaignId = 1, ContactId = newContact.Id });
            
            // Geo
            context.PostalCodes.Add(new PostalCodeGeo { City = "Cincinnati", PostalCode = "45231", State = "OH" });

            context.SaveChanges();
        }
コード例 #23
0
        public async Task CallsGetEventWithTheCorrectEventId()
        {
            var options = CreateNewContextOptions();

            const int eventId = 1;
            var message = new EventByEventIdQuery { EventId = eventId };

            using (var context = new AllReadyContext(options))
            {
                context.Events.Add(new Event
                {
                    Id = eventId
                });
                await context.SaveChangesAsync();
            }

            using (var context = new AllReadyContext(options))
            {
                var sut = new EventByEventIdQueryHandler(context);
                var e = await sut.Handle(message);

                Assert.Equal(e.Id, eventId);
            }
        }
コード例 #24
0
        public async Task UserByUserIdQueryHandlerInvokesGetUserWithTheCorrectUserId()
        {
            var options = CreateNewContextOptions();

            const string userId = "1";
            var message = new UserByUserIdQuery { UserId = userId };

            using (var context = new AllReadyContext(options))
            {
                context.Users.Add(new ApplicationUser
                {
                    Id = userId
                });
                await context.SaveChangesAsync();
            }

            using (var context = new AllReadyContext(options))
            {
                var sut = new UserByUserIdQueryHandler(context);
                var user = await sut.Handle(message);

                Assert.Equal(user.Id, userId);
            }
        }
コード例 #25
0
ファイル: Startup.cs プロジェクト: QuinntyneBrown/allReady
        // Configure is called after ConfigureServices is called.
        public async void Configure(IApplicationBuilder app,
          IHostingEnvironment env,
          ILoggerFactory loggerFactory,
          SampleDataGenerator sampleData,
          AllReadyContext context,
          IConfiguration configuration)
        {
            loggerFactory.MinimumLevel = LogLevel.Verbose;

            // todo: in RC update we can read from a logging.json config file
            loggerFactory.AddConsole((category, level) =>
            {
                if (category.StartsWith("Microsoft."))
                {
                    return level >= LogLevel.Information;
                }
                return true;
            });

            if (env.IsDevelopment())
            {
                // this will go to the VS output window
                loggerFactory.AddDebug((category, level) =>
                {
                    if (category.StartsWith("Microsoft."))
                    {
                        return level >= LogLevel.Information;
                    }
                    return true;
                });
            }

            // CORS support
            app.UseCors("allReady");

            // Configure the HTTP request pipeline.

            var usCultureInfo = new CultureInfo("en-US");
            app.UseRequestLocalization(new RequestLocalizationOptions
            {
                DefaultRequestCulture = new RequestCulture(usCultureInfo),
                SupportedCultures = new List<CultureInfo>(new[] { usCultureInfo }),
                SupportedUICultures = new List<CultureInfo>(new[] { usCultureInfo })
            });

            // Add Application Insights to the request pipeline to track HTTP request telemetry data.
            app.UseApplicationInsightsRequestTelemetry();

            // Add the following to the request pipeline only in development environment.
            if (env.IsDevelopment())
            {
                app.UseBrowserLink();
                app.UseDeveloperExceptionPage();
                app.UseDatabaseErrorPage();
            }
            else
            {
                // Add Error handling middleware which catches all application specific errors and
                // sends the request to the following path or controller action.
                app.UseExceptionHandler("/Home/Error");
            }

            // Track data about exceptions from the application. Should be configured after all error handling middleware in the request pipeline.
            app.UseApplicationInsightsExceptionTelemetry();

            // Add static files to the request pipeline.
            app.UseStaticFiles();

            // Add cookie-based authentication to the request pipeline.
            app.UseIdentity();

            // Add authentication middleware to the request pipeline. You can configure options such as Id and Secret in the ConfigureServices method.
            // For more information see http://go.microsoft.com/fwlink/?LinkID=532715
            if (Configuration["Authentication:Facebook:AppId"] != null)
            {
                app.UseFacebookAuthentication(options =>
                {
                    options.AppId = Configuration["Authentication:Facebook:AppId"];
                    options.AppSecret = Configuration["Authentication:Facebook:AppSecret"];
                });
            }
            // app.UseGoogleAuthentication();

            if (Configuration["Authentication:MicrosoftAccount:ClientId"] != null)
            {
                app.UseMicrosoftAccountAuthentication(options =>
                {
                    options.ClientId = Configuration["Authentication:MicrosoftAccount:ClientId"];
                    options.ClientSecret = Configuration["Authentication:MicrosoftAccount:ClientSecret"];
                    options.Scope.Add("wl.basic");
                    options.Scope.Add("wl.signin");
                });
            }

            if (Configuration["Authentication:Twitter:ConsumerKey"] != null)
            {
                app.UseTwitterAuthentication(options =>
                {
                    options.ConsumerKey = Configuration["Authentication:Twitter:ConsumerKey"];
                    options.ConsumerSecret = Configuration["Authentication:Twitter:ConsumerSecret"];
                });
            }
            // Add MVC to the request pipeline.
            app.UseMvc(routes =>
            {
                routes.MapRoute(
                     name: "areaRoute",
                     template: "{area:exists}/{controller}/{action=Index}/{id?}");

                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });


            // Add sample data and test admin accounts if specified in Config.Json.
            // for production applications, this should either be set to false or deleted.
            if (env.IsDevelopment() || env.IsEnvironment("Staging"))
            {
                context.Database.Migrate();
            }
            if (Configuration["SampleData:InsertSampleData"] == "true")
            {
                sampleData.InsertTestData();
            }
            if (Configuration["SampleData:InsertTestUsers"] == "true")
            {
                await sampleData.CreateAdminUser();
            }
        }
コード例 #26
0
 public DeleteActivityCommandHandler(AllReadyContext context)
 {
     _context = context;
 }
コード例 #27
0
 public UserQueryHandler(AllReadyContext context)
 {
     _context = context;
 }
コード例 #28
0
 public AddApiRequestCommandHandler(AllReadyContext context, IGeocoder geocoder, IMediator mediator)
 {
     this.context  = context;
     this.geocoder = geocoder;
     this.mediator = mediator;
 }
コード例 #29
0
 public AddTaskCommandHandlerAsync(AllReadyContext dataContext)
 {
     this.dataContext = dataContext;
 }
コード例 #30
0
 public EditTaskQueryHandlerAsync(AllReadyContext context)
 {
     _context = context;
 }
コード例 #31
0
 public AssignTaskCommandHandlerAsync(AllReadyContext context, IMediator mediator)
 {
     _context  = context;
     _mediator = mediator;
 }
コード例 #32
0
 public OrganizationSelectListQueryHandlerAsync(AllReadyContext context)
 {
     _context = context;
 }
コード例 #33
0
 public LockUnlockCampaignCommandHandler(AllReadyContext context)
 {
     _context = context;
 }
コード例 #34
0
 public SkillEditQueryHandlerAsync(AllReadyContext context)
 {
     _context = context;
 }
コード例 #35
0
 public ReorderRequestCommandHandler(AllReadyContext context)
 {
     _context = context;
 }
コード例 #36
0
ファイル: Startup.cs プロジェクト: mheggeseth/allReady
        // Configure is called after ConfigureServices is called.
        public async void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, SampleDataGenerator sampleData, AllReadyContext context, 
            IConfiguration configuration)
        {
            // todo: in RC update we can read from a logging.json config file
            loggerFactory.AddConsole((category, level) =>
            {
                if (category.StartsWith("Microsoft."))
                {
                    return level >= LogLevel.Information;
                }
                return true;
            });

            if (env.IsDevelopment())
            {
                // this will go to the VS output window
                loggerFactory.AddDebug((category, level) =>
                {
                    if (category.StartsWith("Microsoft."))
                    {
                        return level >= LogLevel.Information;
                    }
                    return true;
                });
            }

            // CORS support
            app.UseCors("allReady");

            // Configure the HTTP request pipeline.
            var usCultureInfo = new CultureInfo("en-US");
            app.UseRequestLocalization(new RequestLocalizationOptions
            {
                SupportedCultures = new List<CultureInfo>(new[] { usCultureInfo }),
                SupportedUICultures = new List<CultureInfo>(new[] { usCultureInfo })
            });

            // Add Application Insights to the request pipeline to track HTTP request telemetry data.
            app.UseApplicationInsightsRequestTelemetry();

            // Add the following to the request pipeline only in development environment.
            if (env.IsDevelopment())
            {
                app.UseBrowserLink();
                app.UseDeveloperExceptionPage();
                app.UseDatabaseErrorPage();
            }
            else if (env.IsStaging())
            {
                app.UseDeveloperExceptionPage();
                app.UseDatabaseErrorPage();
            }
            else
            {
                // Add Error handling middleware which catches all application specific errors and
                // sends the request to the following path or controller action.
                app.UseExceptionHandler("/Home/Error");
            }

            // Track data about exceptions from the application. Should be configured after all error handling middleware in the request pipeline.
            app.UseApplicationInsightsExceptionTelemetry();

            // Add static files to the request pipeline.
            app.UseStaticFiles();

            // Add cookie-based authentication to the request pipeline.
            app.UseIdentity();

            // Add token-based protection to the request inject pipeline
            app.UseTokenProtection(new TokenProtectedResourceOptions
            {
                Path = "/api/request",
                PolicyName = "api-request-injest"
            });

            // Add authentication middleware to the request pipeline. You can configure options such as Id and Secret in the ConfigureServices method.
            // For more information see http://go.microsoft.com/fwlink/?LinkID=532715
            if (Configuration["Authentication:Facebook:AppId"] != null)
            {
                var options = new FacebookOptions
                {
                    AppId = Configuration["Authentication:Facebook:AppId"],
                    AppSecret = Configuration["Authentication:Facebook:AppSecret"],
                    BackchannelHttpHandler = new FacebookBackChannelHandler(),
                    UserInformationEndpoint = "https://graph.facebook.com/v2.5/me?fields=id,name,email,first_name,last_name"
                };
                options.Scope.Add("email");

                app.UseFacebookAuthentication(options);
            }

            if (Configuration["Authentication:MicrosoftAccount:ClientId"] != null)
            {
                var options = new MicrosoftAccountOptions
                {
                    ClientId = Configuration["Authentication:MicrosoftAccount:ClientId"],
                    ClientSecret = Configuration["Authentication:MicrosoftAccount:ClientSecret"]
                };

                app.UseMicrosoftAccountAuthentication(options);
            }
            //TODO: mgmccarthy: working on getting email from Twitter
            //http://www.bigbrainintelligence.com/Post/get-users-email-address-from-twitter-oauth-ap
            if (Configuration["Authentication:Twitter:ConsumerKey"] != null)
            {
                var options = new TwitterOptions
                {
                    ConsumerKey = Configuration["Authentication:Twitter:ConsumerKey"],
                    ConsumerSecret = Configuration["Authentication:Twitter:ConsumerSecret"]
                };

                app.UseTwitterAuthentication(options);
            }

            if (Configuration["Authentication:Google:ClientId"] != null)
            {
                var options = new GoogleOptions
                {
                    ClientId = Configuration["Authentication:Google:ClientId"],
                    ClientSecret = Configuration["Authentication:Google:ClientSecret"]
                };

                app.UseGoogleAuthentication(options);
            }

            // Add MVC to the request pipeline.
            app.UseMvc(routes =>
            {
                routes.MapRoute(name: "areaRoute", template: "{area:exists}/{controller}/{action=Index}/{id?}");
                routes.MapRoute(name: "default", template: "{controller=Home}/{action=Index}/{id?}");
            });

            // Add sample data and test admin accounts if specified in Config.Json.
            // for production applications, this should either be set to false or deleted.
            if (env.IsDevelopment() || env.IsEnvironment("Staging"))
            {
                context.Database.Migrate();
            }

            if (Configuration["SampleData:InsertSampleData"] == "true")
            {
                sampleData.InsertTestData();
            }

            if (Configuration["SampleData:InsertTestUsers"] == "true")
            {
                await sampleData.CreateAdminUser();
            }
        }
コード例 #37
0
 public AllReadyDataAccessEF7(AllReadyContext dbContext)
 {
     _dbContext = dbContext;
 }
コード例 #38
0
 public DuplicateEventCommandHandler(AllReadyContext context)
 {
     _context = context;
 }
コード例 #39
0
 public CampaignSummaryQueryHandler(AllReadyContext context)
 {
     _context = context;
 }
コード例 #40
0
 public DeleteTaskCommandHandler(AllReadyContext context)
 {
     _context = context;
 }
コード例 #41
0
 public AcceptEventManagerInviteCommandHandler(AllReadyContext context)
 {
     _context = context;
 }
コード例 #42
0
 public IndexQueryHandler(AllReadyContext context)
 {
     _context = context;
 }
コード例 #43
0
 public GetMyEventsQueryHandlerAsync(AllReadyContext context)
 {
     _context = context;
 }
コード例 #44
0
        // Configure is called after ConfigureServices is called.
        public async void Configure(IApplicationBuilder app,
                                    IHostingEnvironment env,
                                    ILoggerFactory loggerFactory,
                                    SampleDataGenerator sampleData,
                                    AllReadyContext context,
                                    IConfiguration configuration)
        {
            loggerFactory.MinimumLevel = LogLevel.Verbose;

            // todo: in RC update we can read from a logging.json config file
            loggerFactory.AddConsole((category, level) =>
            {
                if (category.StartsWith("Microsoft."))
                {
                    return(level >= LogLevel.Information);
                }
                return(true);
            });

            if (env.IsDevelopment())
            {
                // this will go to the VS output window
                loggerFactory.AddDebug((category, level) =>
                {
                    if (category.StartsWith("Microsoft."))
                    {
                        return(level >= LogLevel.Information);
                    }
                    return(true);
                });
            }

            // CORS support
            app.UseCors("allReady");

            // Configure the HTTP request pipeline.

            var usCultureInfo = new CultureInfo("en-US");

            app.UseRequestLocalization(new RequestLocalizationOptions
            {
                SupportedCultures   = new List <CultureInfo>(new[] { usCultureInfo }),
                SupportedUICultures = new List <CultureInfo>(new[] { usCultureInfo })
            }, new RequestCulture(usCultureInfo));

            // Add Application Insights to the request pipeline to track HTTP request telemetry data.
            app.UseApplicationInsightsRequestTelemetry();

            // Add the following to the request pipeline only in development environment.
            if (env.IsDevelopment())
            {
                app.UseBrowserLink();
                app.UseDeveloperExceptionPage();
                app.UseDatabaseErrorPage();
            }
            else
            {
                // Add Error handling middleware which catches all application specific errors and
                // sends the request to the following path or controller action.
                app.UseExceptionHandler("/Home/Error");
            }

            // Setup Cookie Authentication
            app.UseCookieAuthentication(options =>
            {
                options.AccessDeniedPath = new PathString("/Home/AccessDenied");
            });

            // Track data about exceptions from the application. Should be configured after all error handling middleware in the request pipeline.
            app.UseApplicationInsightsExceptionTelemetry();

            // Add static files to the request pipeline.
            app.UseStaticFiles();

            // Add cookie-based authentication to the request pipeline.
            app.UseIdentity();

            // Add authentication middleware to the request pipeline. You can configure options such as Id and Secret in the ConfigureServices method.
            // For more information see http://go.microsoft.com/fwlink/?LinkID=532715
            if (Configuration["Authentication:Facebook:AppId"] != null)
            {
                app.UseFacebookAuthentication(options =>
                {
                    options.AppId     = Configuration["Authentication:Facebook:AppId"];
                    options.AppSecret = Configuration["Authentication:Facebook:AppSecret"];
                    options.Scope.Add("email");
                    options.BackchannelHttpHandler  = new FacebookBackChannelHandler();
                    options.UserInformationEndpoint = "https://graph.facebook.com/v2.5/me?fields=id,name,email,first_name,last_name";
                });
            }
            // app.UseGoogleAuthentication();

            if (Configuration["Authentication:MicrosoftAccount:ClientId"] != null)
            {
                app.UseMicrosoftAccountAuthentication(options =>
                {
                    options.ClientId     = Configuration["Authentication:MicrosoftAccount:ClientId"];
                    options.ClientSecret = Configuration["Authentication:MicrosoftAccount:ClientSecret"];
                    options.Scope.Add("wl.basic");
                    options.Scope.Add("wl.signin");
                });
            }

            if (Configuration["Authentication:Twitter:ConsumerKey"] != null)
            {
                app.UseTwitterAuthentication(options =>
                {
                    options.ConsumerKey    = Configuration["Authentication:Twitter:ConsumerKey"];
                    options.ConsumerSecret = Configuration["Authentication:Twitter:ConsumerSecret"];
                });
            }
            // Add MVC to the request pipeline.
            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "areaRoute",
                    template: "{area:exists}/{controller}/{action=Index}/{id?}");

                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });


            // Add sample data and test admin accounts if specified in Config.Json.
            // for production applications, this should either be set to false or deleted.
            if (env.IsDevelopment() || env.IsEnvironment("Staging"))
            {
                context.Database.Migrate();
            }
            if (Configuration["SampleData:InsertSampleData"] == "true")
            {
                sampleData.InsertTestData();
            }
            if (Configuration["SampleData:InsertTestUsers"] == "true")
            {
                await sampleData.CreateAdminUser();
            }
        }
コード例 #45
0
 public EventDetailQueryHandler(AllReadyContext context)
 {
     _context = context;
 }
コード例 #46
0
        public async Task SetTasksToListOfTaskViewModelForAnyTasksWhereTheUserHasNotVolunteeredInAscendingOrderByTaskStartDateTime_AndEventIsNotNullAndEventsCampaignIsUnlocked()
        {
            var options = CreateNewContextOptions();

            const int eventId = 1;
            const string userId = "asdfasdf";

            var appUser = new ApplicationUser { Id = userId };
            var message = new ShowEventQuery { EventId = eventId, UserId = userId };
            var allReadyEvent = CreateAllReadyEventWithTasks(message.EventId, appUser);

            using (var context = new AllReadyContext(options))
            {
                context.Users.Add(appUser);
                context.Events.Add(allReadyEvent);
                await context.SaveChangesAsync();
            }

            using (var context = new AllReadyContext(options))
            {
                var sut = new ShowEventQueryHandler(context);
                var eventViewModel = await sut.Handle(message);

                Assert.Equal(allReadyEvent.Tasks.Where(x => !x.AssignedVolunteers.Any(v => v.User.Id.Equals(appUser.Id))).Count(),
                    eventViewModel.Tasks.Count);
                var previousDateTime = DateTimeOffset.MinValue;
                foreach (var userTask in eventViewModel.Tasks)
                {
                    Assert.True(userTask.StartDateTime > previousDateTime);
                    previousDateTime = userTask.StartDateTime;
                }
            }
        }
コード例 #47
0
 public OrganizationDetailsQueryHandlerAsync(AllReadyContext context)
 {
     _context = context;
 }
コード例 #48
0
 public ItinerarySummaryQueryHandler(AllReadyContext context)
 {
     _context = context;
 }
コード例 #49
0
 public TaskSignupCommandHandler(IMediator mediator, AllReadyContext context)
 {
     _mediator = mediator;
     _context  = context;
 }
コード例 #50
0
 public ImportRequestsCommandHandler(AllReadyContext context, IGeocoder geocoder)
 {
     _context  = context;
     _geocoder = geocoder;
 }
コード例 #51
0
 public TaskStatusChangeHandler(AllReadyContext context, IMediator mediator)
 {
     _context  = context;
     _mediator = mediator;
 }
コード例 #52
0
 public EditEventCommandHandler(AllReadyContext context)
 {
     _context = context;
 }
コード例 #53
0
        public async Task SetUserSkillsToNull_WhenAppUserIsNull_AndEventIsNotNullAndEventsCampaignIsUnlocked()
        {
            var options = CreateNewContextOptions();

            const int eventId = 1;
            const string userId = "asdfasdf";

            var appUser = new ApplicationUser { Id = userId };
            var message = new ShowEventQuery { EventId = eventId, UserId = userId };

            using (var context = new AllReadyContext(options))
            {
                context.Users.Add(appUser);
                context.Events.Add(CreateAllReadyEventWithTasks(message.EventId, appUser));
                await context.SaveChangesAsync();
            }

            using (var context = new AllReadyContext(options))
            {
                var sut = new ShowEventQueryHandler(context);
                var eventViewModel = await sut.Handle(message);

                eventViewModel.UserSkills.ShouldBeEmpty();
            }
        }
コード例 #54
0
        // Configure is called after ConfigureServices is called.
        public async void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, SampleDataGenerator sampleData, AllReadyContext context, IConfiguration configuration)
        {
            // Put first to avoid issues with OPTIONS when calling from Angular/Browser.
            app.UseCors("allReady");

            // todo: in RC update we can read from a logging.json config file
            loggerFactory.AddConsole((category, level) =>
            {
                if (category.StartsWith("Microsoft."))
                {
                    return(level >= LogLevel.Information);
                }
                return(true);
            });

            if (env.IsDevelopment())
            {
                // this will go to the VS output window
                loggerFactory.AddDebug((category, level) =>
                {
                    if (category.StartsWith("Microsoft."))
                    {
                        return(level >= LogLevel.Information);
                    }
                    return(true);
                });
            }

            app.UseSession();

            // Add the following to the request pipeline only in development environment.
            if (env.IsDevelopment())
            {
                app.UseBrowserLink();
                app.UseDeveloperExceptionPage();
                app.UseDatabaseErrorPage();
            }
            else if (env.IsStaging())
            {
                app.UseDeveloperExceptionPage();
                app.UseDatabaseErrorPage();
            }
            else
            {
                // Add Error handling middleware which catches all application specific errors and
                // sends the request to the following path or controller action.
                app.UseExceptionHandler("/Home/Error");
            }

            // Add static files to the request pipeline.
            app.UseStaticFiles();

            app.UseRequestLocalization();

            Authentication.ConfigureAuthentication(app, Configuration);

            //call Migrate here to force the creation of the AllReady database so Hangfire can create its schema under it
            if (!env.IsProduction())
            {
                context.Database.Migrate();
            }

            //Hangfire
            app.UseHangfireDashboard("/hangfire", new DashboardOptions {
                Authorization = new[] { new HangireDashboardAuthorizationFilter() }
            });
            app.UseHangfireServer();

            // Add MVC to the request pipeline.
            app.UseMvc(routes =>
            {
                routes.MapRoute(name: "areaRoute", template: "{area:exists}/{controller}/{action=Index}/{id?}");
                routes.MapRoute(name: "default", template: "{controller=Home}/{action=Index}/{id?}");
            });

            // Add sample data and test admin accounts if specified in Config.Json.
            // for production applications, this should either be set to false or deleted.
            if (Configuration["SampleData:InsertSampleData"] == "true")
            {
                sampleData.InsertTestData();
            }

            if (Configuration["SampleData:InsertTestUsers"] == "true")
            {
                await sampleData.CreateAdminUser();
            }
        }
コード例 #55
0
 public CampaignDetailQueryHandler(AllReadyContext context)
 {
     _context = context;
 }
コード例 #56
0
 public ApiRequestProcessedNotificationHandler(AllReadyContext context, IBackgroundJobClient backgroundJobClient)
 {
     this.context             = context;
     this.backgroundJobClient = backgroundJobClient;
 }
コード例 #57
0
 public DeleteQueryHandler(AllReadyContext context)
 {
     _context = context;
 }
コード例 #58
0
 public TaskSignupSummaryQueryHandler(AllReadyContext context)
 {
     _context = context;
 }
コード例 #59
0
 public UpdateMyTasksCommandHandler(AllReadyContext dbContext)
 {
     this.dbContext = dbContext;
 }
 public SendRequestConfirmationMessagesTheDayOfAnItineraryDate(AllReadyContext context, ISmsSender smsSender, IMediator mediator)
 {
     this.context = context;
     this.smsSender = smsSender;
     this.mediator = mediator;
 }