public async Task CreateInitiative()
        {
            var newInitiativeMessages = new List <InitiativeCreatedEventArgs>();

            serviceProvider.GetRequiredService <SynchronousInitiativeMessageReceiver>()
            .CreatedHandlers.Add((e, token) => { newInitiativeMessages.Add(e); return(Task.CompletedTask); });

            var initiativeRepository = serviceProvider.GetRequiredService <IInitiativeRepository>();

            // create a basic initiative
            var newInitiative = Initiative.Create(
                title: "Test Idea",
                description: "Test creating initiatives",
                ownerPersonId: 1,
                businessContactId: 2
                );

            // add some supporting documents
            newInitiative.AddSupportingDocument(
                SupportingDocument.Create("My Document", "www.edmonton.ca", SupportingDocumentsType.BusinessCases));
            newInitiative.AddSupportingDocument(
                SupportingDocument.Create("Document2", "github.com", SupportingDocumentsType.Other));

            // add some stakeholders
            newInitiative.AddStakeholder(3, StakeholderType.BusinessContact);

            var newInitiative2 = await initiativeRepository.AddInitiativeAsync(newInitiative);

            newInitiative2.Should().NotBeNull();
            newInitiative2.Title.Should().Be("Test Idea");
            newInitiative2.SupportingDocuments.Count().Should().Be(2);

            newInitiativeMessages.Count().Should().Be(1);
        }
        public async Task <TestConfiguration> SetupMockData(ServiceProvider serviceProvider)
        {
            var repository       = serviceProvider.GetRequiredService <IInitiativeRepository>();
            var personRepository = serviceProvider.GetRequiredService <IPersonRepository>();
            int snowWhiteId      = (await personRepository.GetPersonIdByEmailAsync(SnowWhite.GetEmail())).Value;
            int sleepingBeautyId = (await personRepository.GetPersonIdByEmailAsync(SleepingBeauty.GetEmail())).Value;

            await repository.AddInitiativeAsync(Initiative.Create(title: "Test Idea 1", description: "Test Idea 1 Description ", ownerPersonId: snowWhiteId));

            await repository.AddInitiativeAsync(Initiative.Create(title: "Test Idea 2", description: "Test Idea 2 Description ", ownerPersonId: snowWhiteId));

            await repository.AddInitiativeAsync(Initiative.Create(title: "Test Idea 3", description: "Test Idea 3 Description ", ownerPersonId: sleepingBeautyId));

            return(this);
        }
Esempio n. 3
0
        private async Task <Initiative> CreateInitiativeAsync(string title,
                                                              string description,
                                                              int userId,
                                                              int?busContactUserId,
                                                              int apexId,
                                                              CancellationToken cancellationToken)
        {
            var httpContext = new DefaultHttpContext
            {
                User = await _wordPressUserSecurity.GetPrincipalAsync(userId)
            };

            _httpContextAccessor.HttpContext = httpContext;

            var newInitiative = Initiative.Create(title, description, userId, busContactUserId, skipEmailNotification: true);

            newInitiative.SetApexId(apexId);
            return(await _initiativeRepository.AddInitiativeAsync(newInitiative, cancellationToken));
        }