当前位置: 首页>>代码示例>>C#>>正文


C# ModelHelper.GetOrCreateUser方法代码示例

本文整理汇总了C#中ModelHelper.GetOrCreateUser方法的典型用法代码示例。如果您正苦于以下问题:C# ModelHelper.GetOrCreateUser方法的具体用法?C# ModelHelper.GetOrCreateUser怎么用?C# ModelHelper.GetOrCreateUser使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ModelHelper的用法示例。


在下文中一共展示了ModelHelper.GetOrCreateUser方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: using

        public async Task MemberUploadSubmissionHandler_SubmitMemberUpload_NewRegisteredProducer_ContainsCorrectValueFor_CurrentSubmission()
        {
            using (var database = new DatabaseWrapper())
            {
                var helper = new ModelHelper(database.Model);

                var scheme = helper.CreateScheme();
                string registrationNumber = "AAAA";
                int complianceYear = 2016;

                var registeredProducer = helper.GetOrCreateRegisteredProducer(scheme, complianceYear, registrationNumber);

                var memberUpload = helper.CreateMemberUpload(scheme);
                memberUpload.ComplianceYear = complianceYear;
                memberUpload.IsSubmitted = false;

                var producerSubmission = helper.CreateProducerAsCompany(memberUpload, registrationNumber);

                // At least one user is required in the database.
                helper.GetOrCreateUser("A user");

                database.Model.SaveChanges();

                User user = await database.WeeeContext.Users.FirstAsync();
                IDomainUserContext domainUserContext = A.Fake<IDomainUserContext>();
                A.CallTo(() => domainUserContext.GetCurrentUserAsync()).Returns(user);

                var handler = new MemberUploadSubmissionHandler(A.Dummy<IWeeeAuthorization>(), database.WeeeContext, domainUserContext);
                await handler.HandleAsync(new MemberUploadSubmission(scheme.OrganisationId, memberUpload.Id));

                var registeredProducerDb = FindRegisteredProducer(database, registeredProducer.Id);

                Assert.Equal(registeredProducerDb.CurrentSubmission.Id, producerSubmission.Id);
            }
        }
开发者ID:EnvironmentAgency,项目名称:prsd-weee,代码行数:35,代码来源:MemberUploadSubmissionHandlerTests.cs

示例2: HandleAsync_CreatesUserWithStandardUserRole

        public async Task HandleAsync_CreatesUserWithStandardUserRole()
        {
            using (DatabaseWrapper database = new DatabaseWrapper())
            {
                // Arrange
                ModelHelper helper = new ModelHelper(database.Model);
                DomainHelper domainHelper = new DomainHelper(database.WeeeContext);

                var user = helper.GetOrCreateUser("TestUser");
                user.Email = "[email protected]";

                database.Model.SaveChanges();

                var handler = new AddCompetentAuthorityUserHandler(database.WeeeContext, A.Dummy<ITestUserEmailDomains>());

                // Act
                var competentAuthorityUserId = await handler.HandleAsync(new AddCompetentAuthorityUser(user.Id));
                var competentAuthorityUser = domainHelper.GetCompetentAuthorityUser(competentAuthorityUserId);

                // Assert
                Assert.Equal(user.Id, competentAuthorityUser.UserId);
                Assert.NotNull(competentAuthorityUser.Role);
                Assert.Equal("InternalUser", competentAuthorityUser.Role.Name);
            }
        }
开发者ID:EnvironmentAgency,项目名称:prsd-weee,代码行数:25,代码来源:AddCompetentAuthorityUserHandlerTests.cs

示例3: FetchInvoiceRunsAsync_WithSpecifiedAuthority_OnlyReturnsInvoiceRunsForTheSpecifiedAuthority

        public async Task FetchInvoiceRunsAsync_WithSpecifiedAuthority_OnlyReturnsInvoiceRunsForTheSpecifiedAuthority()
        {
            using (DatabaseWrapper wrapper = new DatabaseWrapper())
            {
                // Arrange
                ModelHelper helper = new ModelHelper(wrapper.Model);
                AspNetUser user = helper.GetOrCreateUser("TestUser");

                Weee.Tests.Core.Model.Country country = new Weee.Tests.Core.Model.Country();
                country.Id = new Guid("FA20ED45-5488-491D-A117-DFC09C9C1BA2");
                country.Name = "Test Country";

                CompetentAuthority databaseAuthority1 = new CompetentAuthority();
                databaseAuthority1.Id = new Guid("DDE398F6-809E-416D-B70D-B36606F221FC");
                databaseAuthority1.Name = "Test Authority 1";
                databaseAuthority1.Abbreviation = "T1";
                databaseAuthority1.Country = country;
                databaseAuthority1.Email = "TestEmailAddress";
                wrapper.Model.CompetentAuthorities.Add(databaseAuthority1);

                CompetentAuthority databaseAuthority2 = new CompetentAuthority();
                databaseAuthority2.Id = new Guid("FBCEDC2F-0825-4066-B24E-86D3A2FD892B");
                databaseAuthority2.Name = "Test Authority 2";
                databaseAuthority2.Abbreviation = "T2";
                databaseAuthority2.Country = country;
                databaseAuthority2.Email = "TestEmailAddress2";
                wrapper.Model.CompetentAuthorities.Add(databaseAuthority2);

                InvoiceRun invoiceRunForAuthority1 = new InvoiceRun();
                invoiceRunForAuthority1.Id = new Guid("CE7A2617-AE16-403E-A7BF-BF01AD223872");
                invoiceRunForAuthority1.CompetentAuthority = databaseAuthority1;
                invoiceRunForAuthority1.IssuedByUserId = user.Id;
                invoiceRunForAuthority1.IssuedDate = new DateTime(2015, 1, 1);
                wrapper.Model.InvoiceRuns.Add(invoiceRunForAuthority1);

                InvoiceRun invoiceRunForAuthority2 = new InvoiceRun();
                invoiceRunForAuthority2.Id = new Guid("728CDF55-1C3C-4BE0-80CB-0BC82CC9DFA3");
                invoiceRunForAuthority2.CompetentAuthority = databaseAuthority2;
                invoiceRunForAuthority2.IssuedByUserId = user.Id;
                invoiceRunForAuthority2.IssuedDate = new DateTime(2015, 1, 1);
                wrapper.Model.InvoiceRuns.Add(invoiceRunForAuthority2);

                wrapper.Model.SaveChanges();

                UKCompetentAuthority domainAuthority1 = wrapper.WeeeContext.UKCompetentAuthorities.Find(databaseAuthority1.Id);

                FetchInvoiceRunsDataAccess dataAccess = new FetchInvoiceRunsDataAccess(wrapper.WeeeContext);

                // Act
                IReadOnlyList<Domain.Charges.InvoiceRun> results = await dataAccess.FetchInvoiceRunsAsync(domainAuthority1);

                // Assert
                Assert.NotNull(results);
                Assert.Equal(1, results.Count);
                Assert.Equal(new Guid("CE7A2617-AE16-403E-A7BF-BF01AD223872"), results[0].Id);
            }
        }
开发者ID:EnvironmentAgency,项目名称:prsd-weee,代码行数:57,代码来源:FetchInvoiceRunsDataAccessTests.cs

示例4: using

        public async Task FetchnvoicedMemberUploadsAsync_WithSpecifiedAuthority_OOnlyReturnsInvoicedMemberUploadsForTheSpecifiedAuthority()
        {
            using (DatabaseWrapper wrapper = new DatabaseWrapper())
            {
                // Arrange
                ModelHelper helper = new ModelHelper(wrapper.Model);
                AspNetUser user = helper.GetOrCreateUser("TestUser");

                Weee.Tests.Core.Model.Country country = new Weee.Tests.Core.Model.Country();
                country.Id = new Guid("FA20ED45-5488-491D-A117-DFC09C9C1BA2");
                country.Name = "Test Country";

                CompetentAuthority databaseAuthority1 = new CompetentAuthority();
                databaseAuthority1.Id = new Guid("DDE398F6-809E-416D-B70D-B36606F221FC");
                databaseAuthority1.Name = "Test Authority 1";
                databaseAuthority1.Abbreviation = "T1";
                databaseAuthority1.Country = country;
                databaseAuthority1.Email = "TestEmailAddress";
                wrapper.Model.CompetentAuthorities.Add(databaseAuthority1);

                InvoiceRun invoiceRunForAuthority1 = new InvoiceRun();
                invoiceRunForAuthority1.Id = new Guid("CE7A2617-AE16-403E-A7BF-BF01AD223872");
                invoiceRunForAuthority1.CompetentAuthority = databaseAuthority1;
                invoiceRunForAuthority1.IssuedByUserId = user.Id;
                invoiceRunForAuthority1.IssuedDate = new DateTime(2015, 1, 1);
                wrapper.Model.InvoiceRuns.Add(invoiceRunForAuthority1);

                var scheme = helper.CreateScheme();
                scheme.CompetentAuthorityId = databaseAuthority1.Id;
                var memberUpload = helper.CreateSubmittedMemberUpload(scheme, invoiceRunForAuthority1);

                wrapper.Model.SaveChanges();

                UKCompetentAuthority domainAuthority1 = wrapper.WeeeContext.UKCompetentAuthorities.Find(databaseAuthority1.Id);

                CommonDataAccess dataAccess = new CommonDataAccess(wrapper.WeeeContext);

                // Act
                IReadOnlyList<Domain.Scheme.MemberUpload> results = await dataAccess.FetchInvoicedMemberUploadsAsync(domainAuthority1);

                // Assert
                Assert.NotNull(results);
                Assert.Equal(1, results.Count);
                Assert.Equal(memberUpload.Id, results[0].Id);
            }
        }
开发者ID:EnvironmentAgency,项目名称:prsd-weee,代码行数:46,代码来源:CommonDataAccessTests.cs

示例5: FetchInvoiceRunsAsync_Always_ReturnsResultsOrderedByIssuedDateDescending

        public async Task FetchInvoiceRunsAsync_Always_ReturnsResultsOrderedByIssuedDateDescending()
        {
            using (DatabaseWrapper wrapper = new DatabaseWrapper())
            {
                // Arrange
                ModelHelper helper = new ModelHelper(wrapper.Model);
                AspNetUser user = helper.GetOrCreateUser("TestUser");

                Weee.Tests.Core.Model.Country country = new Weee.Tests.Core.Model.Country();
                country.Id = new Guid("FA20ED45-5488-491D-A117-DFC09C9C1BA2");
                country.Name = "Test Country";

                CompetentAuthority databaseAuthority = new CompetentAuthority();
                databaseAuthority.Id = new Guid("DDE398F6-809E-416D-B70D-B36606F221FC");
                databaseAuthority.Name = "Test Authority 1";
                databaseAuthority.Abbreviation = "T1";
                databaseAuthority.Country = country;
                databaseAuthority.Email = "TestEmailAddress";
                wrapper.Model.CompetentAuthorities.Add(databaseAuthority);

                InvoiceRun invoiceRun1 = new InvoiceRun();
                invoiceRun1.Id = new Guid("CE7A2617-AE16-403E-A7BF-BF01AD223872");
                invoiceRun1.CompetentAuthority = databaseAuthority;
                invoiceRun1.IssuedByUserId = user.Id;
                invoiceRun1.IssuedDate = new DateTime(2015, 1, 2);
                wrapper.Model.InvoiceRuns.Add(invoiceRun1);

                InvoiceRun invoiceRun2 = new InvoiceRun();
                invoiceRun2.Id = new Guid("728CDF55-1C3C-4BE0-80CB-0BC82CC9DFA3");
                invoiceRun2.CompetentAuthority = databaseAuthority;
                invoiceRun2.IssuedByUserId = user.Id;
                invoiceRun2.IssuedDate = new DateTime(2015, 1, 1);
                wrapper.Model.InvoiceRuns.Add(invoiceRun2);

                InvoiceRun invoiceRun3 = new InvoiceRun();
                invoiceRun3.Id = new Guid("B235CD4F-8188-4BC0-ADA2-55FD6B34BC01");
                invoiceRun3.CompetentAuthority = databaseAuthority;
                invoiceRun3.IssuedByUserId = user.Id;
                invoiceRun3.IssuedDate = new DateTime(2015, 1, 3);
                wrapper.Model.InvoiceRuns.Add(invoiceRun3);

                wrapper.Model.SaveChanges();

                UKCompetentAuthority domainAuthority = wrapper.WeeeContext.UKCompetentAuthorities.Find(databaseAuthority.Id);

                FetchInvoiceRunsDataAccess dataAccess = new FetchInvoiceRunsDataAccess(wrapper.WeeeContext);

                // Act
                IReadOnlyList<Domain.Charges.InvoiceRun> results = await dataAccess.FetchInvoiceRunsAsync(domainAuthority);

                // Assert
                Assert.NotNull(results);
                Assert.Equal(3, results.Count);
                Assert.Collection(results,
                    r1 => Assert.Equal(new DateTime(2015, 1, 3), r1.IssuedDate),
                    r2 => Assert.Equal(new DateTime(2015, 1, 2), r2.IssuedDate),
                    r3 => Assert.Equal(new DateTime(2015, 1, 1), r3.IssuedDate));
            }
        }
开发者ID:EnvironmentAgency,项目名称:prsd-weee,代码行数:59,代码来源:FetchInvoiceRunsDataAccessTests.cs

示例6: FetchInvoiceRunsAsync_Always_EagerLoadsIssuedByUser

        public async Task FetchInvoiceRunsAsync_Always_EagerLoadsIssuedByUser()
        {
            using (DatabaseWrapper wrapper = new DatabaseWrapper())
            {
                // Arrange
                ModelHelper helper = new ModelHelper(wrapper.Model);
                AspNetUser user = helper.GetOrCreateUser("TestUser");

                Weee.Tests.Core.Model.Country country = new Weee.Tests.Core.Model.Country();
                country.Id = new Guid("FA20ED45-5488-491D-A117-DFC09C9C1BA2");
                country.Name = "Test Country";

                CompetentAuthority databaseAuthority = new CompetentAuthority();
                databaseAuthority.Id = new Guid("DDE398F6-809E-416D-B70D-B36606F221FC");
                databaseAuthority.Name = "Test Authority 1";
                databaseAuthority.Abbreviation = "T1";
                databaseAuthority.Country = country;
                databaseAuthority.Email = "TestEmailAddress";
                wrapper.Model.CompetentAuthorities.Add(databaseAuthority);

                InvoiceRun invoiceRun = new InvoiceRun();
                invoiceRun.Id = new Guid("CE7A2617-AE16-403E-A7BF-BF01AD223872");
                invoiceRun.CompetentAuthority = databaseAuthority;
                invoiceRun.IssuedByUserId = user.Id;
                invoiceRun.IssuedDate = new DateTime(2015, 1, 2);
                wrapper.Model.InvoiceRuns.Add(invoiceRun);

                wrapper.Model.SaveChanges();

                UKCompetentAuthority domainAuthority = wrapper.WeeeContext.UKCompetentAuthorities.Find(databaseAuthority.Id);

                FetchInvoiceRunsDataAccess dataAccess = new FetchInvoiceRunsDataAccess(wrapper.WeeeContext);

                // Act
                IReadOnlyList<Domain.Charges.InvoiceRun> results = await dataAccess.FetchInvoiceRunsAsync(domainAuthority);

                // Assert
                Assert.NotNull(results);
                Assert.Equal(1, results.Count);
                Assert.NotNull(results[0].IssuedByUser);
            }
        }
开发者ID:EnvironmentAgency,项目名称:prsd-weee,代码行数:42,代码来源:FetchInvoiceRunsDataAccessTests.cs


注:本文中的ModelHelper.GetOrCreateUser方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。