Esempio n. 1
0
        private void CreateData()
        {
            foreach (Organization organization in OrganizationData.GenerateSampleOrganizations())
            {
                if (organization.Id == TestConstants.OrganizationId3)
                {
                    _billingManager.ApplyBillingPlan(organization, BillingManager.FreePlan, UserData.GenerateSampleUser());
                }
                else
                {
                    _billingManager.ApplyBillingPlan(organization, BillingManager.SmallPlan, UserData.GenerateSampleUser());
                }

                _organizationRepository.Add(organization);
            }

            foreach (Project project in ProjectData.GenerateSampleProjects())
            {
                var organization = _organizationRepository.GetById(project.OrganizationId);
                organization.ProjectCount += 1;
                _organizationRepository.Save(organization);

                _projectRepository.Add(project);
            }
        }
Esempio n. 2
0
 private Task CreateOrganizationAndProjectsAsync()
 {
     return(Task.WhenAll(
                _organizationRepository.AddAsync(OrganizationData.GenerateSampleOrganizations(), o => o.ImmediateConsistency()),
                _projectRepository.AddAsync(ProjectData.GenerateSampleProjects(), o => o.ImmediateConsistency())
                ));
 }
Esempio n. 3
0
 private Task CreateTestOrganizationAndProjectsAsync()
 {
     return(Task.WhenAll(
                _organizationRepository.AddAsync(OrganizationData.GenerateSampleOrganizations(GetService <BillingManager>(), GetService <BillingPlans>()), o => o.ImmediateConsistency()),
                _projectRepository.AddAsync(ProjectData.GenerateSampleProjects(), o => o.ImmediateConsistency())
                ));
 }
        public async Task CreateOrganizationAndProjectsAsync()
        {
            await _organizationRepository.AddAsync(OrganizationData.GenerateSampleOrganizations());

            await _projectRepository.AddAsync(ProjectData.GenerateSampleProjects());

            await _configuration.Client.RefreshAsync(Indices.All);
        }
        public void AddSampleOrganizations()
        {
            if (_sampleOrganizationsAdded)
            {
                return;
            }

            AddData(OrganizationRepository.CollectionName, OrganizationData.GenerateSampleOrganizations());
            _sampleOrganizationsAdded = true;
        }
Esempio n. 6
0
        protected override void CreateData()
        {
            Repository.Add(ProjectData.GenerateSampleProject());
            _organizationRepository.Add(OrganizationData.GenerateSampleOrganizations());

            var membershipProvider = new MembershipProvider(_userRepository.Collection);

            foreach (User user in UserData.GenerateSampleUsers())
            {
                membershipProvider.CreateAccount(user);
            }
        }
Esempio n. 7
0
        //private ByteArrayContent CompressString(string data) {
        //    byte[] bytes = Encoding.UTF8.GetBytes(data);
        //    using (var stream = new MemoryStream()) {
        //        using (var zipper = new GZipStream(stream, CompressionMode.Compress, true))
        //            zipper.Write(bytes, 0, bytes.Length);

        //        var content = new ByteArrayContent(stream.ToArray());
        //        content.Headers.ContentType = new MediaTypeHeaderValue("text/plain") {
        //            CharSet = "utf-8"
        //        };
        //        content.Headers.ContentEncoding.Add("gzip");
        //        return content;
        //    }
        //}

        //private ByteArrayContent JsonCompress(object data) {
        //    byte[] bytes = Encoding.UTF8.GetBytes(_serializer.SerializeToString(data));
        //    using (var stream = new MemoryStream()) {
        //        using (var zipper = new GZipStream(stream, CompressionMode.Compress, true))
        //            zipper.Write(bytes, 0, bytes.Length);

        //        var content = new ByteArrayContent(stream.ToArray());
        //        content.Headers.ContentType = new MediaTypeHeaderValue("application/json") {
        //            CharSet = "utf-8"
        //        };
        //        content.Headers.ContentEncoding.Add("gzip");
        //        return content;
        //    }
        //}

        private Task CreateOrganizationAndProjectsAsync()
        {
            var organizationRepository = GetService <IOrganizationRepository>();
            var projectRepository      = GetService <IProjectRepository>();
            var tokenRepository        = GetService <ITokenRepository>();

            return(Task.WhenAll(
                       organizationRepository.AddAsync(OrganizationData.GenerateSampleOrganizations(GetService <BillingManager>(), GetService <BillingPlans>()), o => o.ImmediateConsistency()),
                       projectRepository.AddAsync(ProjectData.GenerateSampleProjects(), o => o.ImmediateConsistency()),
                       tokenRepository.AddAsync(TokenData.GenerateSampleApiKeyToken(), o => o.ImmediateConsistency())
                       ));
        }
Esempio n. 8
0
        public async Task AddSampleOrganizationsAsync()
        {
            if (_sampleOrganizationsAdded)
            {
                return;
            }

            await _organizationRepository.AddAsync(OrganizationData.GenerateSampleOrganizations());

            await _client.RefreshAsync();

            _sampleOrganizationsAdded = true;
        }
Esempio n. 9
0
        private void CreateData()
        {
            foreach (Organization organization in OrganizationData.GenerateSampleOrganizations())
            {
                if (organization.Id == TestConstants.OrganizationId3)
                {
                    _billingManager.ApplyBillingPlan(organization, BillingManager.FreePlan, UserData.GenerateSampleUser());
                }
                else
                {
                    _billingManager.ApplyBillingPlan(organization, BillingManager.SmallPlan, UserData.GenerateSampleUser());
                }

                organization.StripeCustomerId = Guid.NewGuid().ToString("N");
                organization.CardLast4        = "1234";
                organization.SubscribeDate    = DateTime.Now;

                if (organization.IsSuspended)
                {
                    organization.SuspendedByUserId = TestConstants.UserId;
                    organization.SuspensionCode    = SuspensionCode.Billing;
                    organization.SuspensionDate    = DateTime.Now;
                }

                _organizationRepository.Add(organization);
            }

            foreach (Project project in ProjectData.GenerateSampleProjects())
            {
                var organization = _organizationRepository.GetById(project.OrganizationId);
                _organizationRepository.Save(organization);

                _projectRepository.Add(project);
            }

            foreach (User user in UserData.GenerateSampleUsers())
            {
                if (user.Id == TestConstants.UserId)
                {
                    user.OrganizationIds.Add(TestConstants.OrganizationId2);
                    user.OrganizationIds.Add(TestConstants.OrganizationId3);
                }

                if (!user.IsEmailAddressVerified)
                {
                    user.VerifyEmailAddressToken           = Guid.NewGuid().ToString();
                    user.VerifyEmailAddressTokenExpiration = DateTime.Now.AddDays(1);
                }
                _userRepository.Add(user);
            }
        }
        protected override void CreateData()
        {
            var membershipProvider = new MembershipProvider(_userRepository.Collection);

            foreach (User user in UserData.GenerateSampleUsers())
            {
                membershipProvider.CreateAccount(user);
            }
            _projectRepository.Add(ProjectData.GenerateSampleProjects());
            _organizationRepository.Add(OrganizationData.GenerateSampleOrganizations());

            //_errorStackRepository.Add(ErrorStackData.GenerateErrorStack(id: TestConstants.ErrorStackId, organizationId: TestConstants.OrganizationId, projectId: TestConstants.ProjectId));
            //_errorStackRepository.Add(ErrorStackData.GenerateErrorStack(id: TestConstants.ErrorStackId2, organizationId: TestConstants.OrganizationId, projectId: TestConstants.ProjectIdWithNoRoles));
        }
Esempio n. 11
0
        private async Task CreateDataAsync()
        {
            await _client.RefreshAsync();

            foreach (Organization organization in OrganizationData.GenerateSampleOrganizations())
            {
                if (organization.Id == TestConstants.OrganizationId3)
                {
                    BillingManager.ApplyBillingPlan(organization, BillingManager.FreePlan, UserData.GenerateSampleUser());
                }
                else
                {
                    BillingManager.ApplyBillingPlan(organization, BillingManager.SmallPlan, UserData.GenerateSampleUser());
                }

                organization.StripeCustomerId = Guid.NewGuid().ToString("N");
                organization.CardLast4        = "1234";
                organization.SubscribeDate    = DateTime.Now;

                if (organization.IsSuspended)
                {
                    organization.SuspendedByUserId = TestConstants.UserId;
                    organization.SuspensionCode    = SuspensionCode.Billing;
                    organization.SuspensionDate    = DateTime.Now;
                }

                await _organizationRepository.AddAsync(organization, true);
            }

            await _projectRepository.AddAsync(ProjectData.GenerateSampleProjects(), true);

            foreach (User user in UserData.GenerateSampleUsers())
            {
                if (user.Id == TestConstants.UserId)
                {
                    user.OrganizationIds.Add(TestConstants.OrganizationId2);
                    user.OrganizationIds.Add(TestConstants.OrganizationId3);
                }

                if (!user.IsEmailAddressVerified)
                {
                    user.CreateVerifyEmailAddressToken();
                }

                await _userRepository.AddAsync(user, true);
            }

            await _client.RefreshAsync();
        }
Esempio n. 12
0
        private async Task CreateDataAsync(int eventCount = 0, bool multipleProjects = true)
        {
            var orgs = OrganizationData.GenerateSampleOrganizations(_billingManager, _plans);
            await _organizationRepository.AddAsync(orgs, o => o.Cache());

            var projects = ProjectData.GenerateSampleProjects();
            await _projectRepository.AddAsync(projects, o => o.Cache());

            await _configuration.Client.RefreshAsync(Indices.All);

            if (eventCount > 0)
            {
                await CreateEventsAsync(eventCount, multipleProjects?projects.Select(p => p.Id).ToArray() : new[] { TestConstants.ProjectId });
            }
        }
Esempio n. 13
0
        private async Task CreateDataAsync(int eventCount = 100, bool multipleProjects = true)
        {
            var orgs = OrganizationData.GenerateSampleOrganizations();
            await _organizationRepository.AddAsync(orgs);

            var projects = ProjectData.GenerateSampleProjects();
            await _projectRepository.AddAsync(projects);

            var events = EventData.GenerateEvents(eventCount, projectIds: multipleProjects ? projects.Select(p => p.Id).ToArray() : new[] { TestConstants.ProjectId }, startDate: DateTimeOffset.UtcNow.SubtractDays(60), endDate: DateTimeOffset.UtcNow);

            foreach (var eventGroup in events.GroupBy(ev => ev.ProjectId))
            {
                await _eventPipeline.RunAsync(eventGroup);
            }
        }
Esempio n. 14
0
        private async Task CreateDataAsync()
        {
            foreach (var organization in OrganizationData.GenerateSampleOrganizations(_billingManager, _plans))
            {
                if (organization.Id == TestConstants.OrganizationId3)
                {
                    _billingManager.ApplyBillingPlan(organization, _plans.FreePlan, UserData.GenerateSampleUser());
                }
                else
                {
                    _billingManager.ApplyBillingPlan(organization, _plans.SmallPlan, UserData.GenerateSampleUser());
                }

                organization.StripeCustomerId = Guid.NewGuid().ToString("N");
                organization.CardLast4        = "1234";
                organization.SubscribeDate    = SystemClock.UtcNow;

                if (organization.IsSuspended)
                {
                    organization.SuspendedByUserId = TestConstants.UserId;
                    organization.SuspensionCode    = SuspensionCode.Billing;
                    organization.SuspensionDate    = SystemClock.UtcNow;
                }

                await _organizationRepository.AddAsync(organization, o => o.Cache());
            }

            await _projectRepository.AddAsync(ProjectData.GenerateSampleProjects(), o => o.Cache());

            foreach (var user in UserData.GenerateSampleUsers())
            {
                if (user.Id == TestConstants.UserId)
                {
                    user.OrganizationIds.Add(TestConstants.OrganizationId2);
                    user.OrganizationIds.Add(TestConstants.OrganizationId3);
                }

                if (!user.IsEmailAddressVerified)
                {
                    user.CreateVerifyEmailAddressToken();
                }

                await _userRepository.AddAsync(user, o => o.Cache());
            }

            await _configuration.Client.RefreshAsync(Indices.All);
        }
Esempio n. 15
0
        private async Task CreateDataAsync(int eventCount = 0, bool multipleProjects = true)
        {
            await _client.RefreshAsync();

            var orgs = OrganizationData.GenerateSampleOrganizations();
            await _organizationRepository.AddAsync(orgs, true);

            var projects = ProjectData.GenerateSampleProjects();
            await _projectRepository.AddAsync(projects, true);

            await _client.RefreshAsync();

            if (eventCount > 0)
            {
                await CreateEventsAsync(eventCount, multipleProjects?projects.Select(p => p.Id).ToArray() : new[] { TestConstants.ProjectId });
            }
        }
        protected override void CreateData()
        {
            foreach (Organization organization in OrganizationData.GenerateSampleOrganizations())
            {
                if (organization.Id == TestConstants.OrganizationId3)
                {
                    _billingManager.ApplyBillingPlan(organization, BillingManager.FreePlan, UserData.GenerateSampleUser());
                }
                else
                {
                    _billingManager.ApplyBillingPlan(organization, BillingManager.SmallPlan, UserData.GenerateSampleUser());
                }

                Repository.Add(organization);
            }

            foreach (Project project in ProjectData.GenerateSampleProjects())
            {
                var organization = Repository.GetById(project.OrganizationId);
                organization.ProjectCount += 1;
                Repository.Update(organization);

                _projectRepository.Add(project);
            }

            var membershipProvider = new MembershipProvider(_userRepository.Collection);

            foreach (User user in UserData.GenerateSampleUsers())
            {
                if (user.Id == TestConstants.UserId)
                {
                    user.OrganizationIds.Add(TestConstants.OrganizationId2);
                    user.OrganizationIds.Add(TestConstants.OrganizationId3);
                }

                if (user.Id == TestConstants.UserIdWithNoRoles)
                {
                    user.OrganizationIds.Add(TestConstants.OrganizationId2);
                }

                membershipProvider.CreateAccount(user);
            }
        }
Esempio n. 17
0
        public async Task GetByFilterAsyncAsync()
        {
            var organizations = OrganizationData.GenerateSampleOrganizations(GetService <BillingManager>(), GetService <BillingPlans>());
            var organization1 = organizations.Single(o => String.Equals(o.Id, TestConstants.OrganizationId));
            var organization2 = organizations.Single(o => String.Equals(o.Id, TestConstants.OrganizationId2));

            var project1 = await _repository.AddAsync(ProjectData.GenerateProject(id: TestConstants.ProjectId, organizationId: organization1.Id, name: "One"), o => o.ImmediateConsistency());

            var project2 = await _repository.AddAsync(ProjectData.GenerateProject(id: TestConstants.SuspendedProjectId, organizationId: organization1.Id, name: "Two"), o => o.ImmediateConsistency());

            var results = await _repository.GetByFilterAsync(new ExceptionlessSystemFilter(organizations), null, null);

            Assert.NotNull(results);
            Assert.Equal(2, results.Documents.Count);

            results = await _repository.GetByFilterAsync(new ExceptionlessSystemFilter(organization1), null, null);

            Assert.NotNull(results);
            Assert.Equal(2, results.Documents.Count);

            results = await _repository.GetByFilterAsync(new ExceptionlessSystemFilter(organization2), null, null);

            Assert.NotNull(results);
            Assert.Empty(results.Documents);

            results = await _repository.GetByFilterAsync(new ExceptionlessSystemFilter(organization1), "name:one", null);

            Assert.NotNull(results);
            Assert.Single(results.Documents);
            Assert.Equal(project1.Name, results.Documents.Single().Name);

            await _repository.RemoveAsync(project2.Id, o => o.Notifications(false).ImmediateConsistency());

            results = await _repository.GetByFilterAsync(new ExceptionlessSystemFilter(organization1), null, null);

            Assert.NotNull(results);
            Assert.Single(results.Documents);
            await _repository.RemoveAllAsync(o => o.Notifications(false));
        }