コード例 #1
0
        public async Task HandleAsync_Always_ReturnsSchemesOrderedBySchemeName()
        {
            // Arrange
            IWeeeAuthorization authorization = AuthorizationBuilder.CreateUserWithAllRights();

            IMap <Scheme, SchemeData> schemeMap = new SchemeMap(A.Dummy <IMapper>(), A.Fake <IMap <Address, AddressData> >(), A.Fake <IMap <Contact, ContactData> >());

            Organisation organisation = Organisation.CreateSoleTrader("Test Organisation");

            Scheme scheme1 = new Scheme(organisation);

            scheme1.UpdateScheme("Scheme C", "WEE/11AAAA11/SCH", "WEE1234567", ObligationType.Both, A.Dummy <UKCompetentAuthority>());
            scheme1.SetStatus(SchemeStatus.Approved);

            Scheme scheme2 = new Scheme(organisation);

            scheme2.UpdateScheme("Scheme A", "WEE/11AAAA11/SCH", "WEE1234567", ObligationType.Both, A.Dummy <UKCompetentAuthority>());
            scheme2.SetStatus(SchemeStatus.Approved);

            Scheme scheme3 = new Scheme(organisation);

            scheme3.UpdateScheme("Scheme D", "WEE/11AAAA11/SCH", "WEE1234567", ObligationType.Both, A.Dummy <UKCompetentAuthority>());
            scheme3.SetStatus(SchemeStatus.Approved);

            Scheme scheme4 = new Scheme(organisation);

            scheme4.UpdateScheme("Scheme B", "WEE/11AAAA11/SCH", "WEE1234567", ObligationType.Both, A.Dummy <UKCompetentAuthority>());
            scheme4.SetStatus(SchemeStatus.Approved);

            IGetSchemesDataAccess dataAccess = A.Fake <IGetSchemesDataAccess>();

            A.CallTo(() => dataAccess.GetSchemes()).Returns(
                new List <Scheme>()
            {
                scheme1,
                scheme2,
                scheme3,
                scheme4
            });

            GetSchemesHandler handler = new GetSchemesHandler(
                authorization,
                schemeMap,
                dataAccess);

            // Act
            GetSchemes request = new GetSchemes(GetSchemes.FilterType.Approved);

            List <SchemeData> results = await handler.HandleAsync(request);

            // Assert
            Assert.NotNull(results);
            Assert.Equal(4, results.Count);

            Assert.Collection(results,
                              r => Assert.Equal("Scheme A", r.SchemeName),
                              r => Assert.Equal("Scheme B", r.SchemeName),
                              r => Assert.Equal("Scheme C", r.SchemeName),
                              r => Assert.Equal("Scheme D", r.SchemeName));
        }
コード例 #2
0
        public async void GetSchemesExternalHandlerHandleAsync_GivenGetSchemeExternalRequest_ReturnListOfSchemesThatAreApprovedOrWithdrawn()
        {
            using (var database = new DatabaseWrapper())
            {
                var context = database.WeeeContext;
                var mapper  = new SchemeMap(A.Fake <IMapper>(), A.Fake <IMap <Address, AddressData> >(), A.Fake <IMap <Contact, ContactData> >());

                var          name                 = "Test Name" + Guid.NewGuid();
                var          tradingName          = "Test Trading Name" + Guid.NewGuid();
                const string crn                  = "ABC12345";
                var          organisationApproved = Organisation.CreateRegisteredCompany(name, crn, tradingName);
                organisationApproved.OrganisationStatus = OrganisationStatus.Complete;
                var organisationPending = Organisation.CreateRegisteredCompany(name, crn, tradingName);
                organisationPending.OrganisationStatus = OrganisationStatus.Complete;
                var organisationWithdrawn = Organisation.CreateRegisteredCompany(name, crn, tradingName);
                organisationWithdrawn.OrganisationStatus = OrganisationStatus.Complete;
                var organisationRejected = Organisation.CreateRegisteredCompany(name, crn, tradingName);
                organisationRejected.OrganisationStatus = OrganisationStatus.Complete;

                context.Organisations.Add(organisationApproved);
                context.Organisations.Add(organisationPending);
                context.Organisations.Add(organisationWithdrawn);
                context.Organisations.Add(organisationRejected);
                await context.SaveChangesAsync();

                var schemeApproved = new Scheme(organisationApproved.Id);
                schemeApproved.SetStatus(SchemeStatus.Approved);
                context.Schemes.Add(schemeApproved);
                var schemeApprovedData = mapper.Map(schemeApproved);

                var schemePending = new Scheme(organisationPending.Id);
                schemePending.SetStatus(SchemeStatus.Pending);
                context.Schemes.Add(schemePending);

                var schemeWithdrawn = new Scheme(organisationWithdrawn.Id);
                schemeWithdrawn.SetStatus(SchemeStatus.Approved);
                schemeWithdrawn.SetStatus(SchemeStatus.Withdrawn);
                context.Schemes.Add(schemeWithdrawn);
                var schemeWithdrawnData = mapper.Map(schemeWithdrawn);

                var schemeRejected = new Scheme(organisationRejected.Id);
                schemeRejected.SetStatus(SchemeStatus.Rejected);
                context.Schemes.Add(schemeRejected);

                await context.SaveChangesAsync();

                var dataAccess = new GetSchemesDataAccess(database.WeeeContext);

                var results = await dataAccess.GetCompleteSchemes();

                var handler = new GetSchemesExternalHandler(dataAccess, mapper, A.Fake <IWeeeAuthorization>());

                var request = new GetSchemesExternal();

                var schemeDataList = new List <SchemeData>();

                var result = await handler.HandleAsync(request);
            }
        }
コード例 #3
0
        public async Task HandleAsync_WithFilterSetToApprovedOrWithdrawn_ReturnsSchemesWithStatusOfApprovedOrWithdrawn()
        {
            // Arrange
            IWeeeAuthorization authorization = AuthorizationBuilder.CreateUserWithAllRights();

            var mapper = new SchemeMap(A.Fake <IMapper>(), A.Fake <IMap <Address, AddressData> >(), A.Fake <IMap <Contact, ContactData> >());

            Organisation organisation = Organisation.CreateSoleTrader("Test Organisation");

            Scheme schemePending = new Scheme(organisation);

            schemePending.UpdateScheme("Scheme Pending", "WEE/11AAAA11/SCH", "WEE1234567", ObligationType.Both, A.Dummy <UKCompetentAuthority>());

            Scheme schemeApproved = new Scheme(organisation);

            schemeApproved.UpdateScheme("Scheme Approved", "WEE/11AAAA11/SCH", "WEE1234567", ObligationType.Both, A.Dummy <UKCompetentAuthority>());
            schemeApproved.SetStatus(SchemeStatus.Approved);

            Scheme schemeRejected = new Scheme(organisation);

            schemeRejected.UpdateScheme("Scheme Rejected", "WEE/11AAAA11/SCH", "WEE1234567", ObligationType.Both, A.Dummy <UKCompetentAuthority>());
            schemeRejected.SetStatus(SchemeStatus.Rejected);

            Scheme schemeWithdrawn = new Scheme(organisation);

            schemeWithdrawn.UpdateScheme("Scheme Withdrawn", "WEE/11AAAA11/SCH", "WEE1234567", ObligationType.Both, A.Dummy <UKCompetentAuthority>());
            schemeWithdrawn.SetStatus(SchemeStatus.Approved);
            schemeWithdrawn.SetStatus(SchemeStatus.Withdrawn);

            IGetSchemesDataAccess dataAccess = A.Fake <IGetSchemesDataAccess>();

            A.CallTo(() => dataAccess.GetSchemes()).Returns(
                new List <Scheme>()
            {
                schemePending,
                schemeApproved,
                schemeRejected,
                schemeWithdrawn
            });

            GetSchemesHandler handler = new GetSchemesHandler(
                authorization,
                mapper,
                dataAccess);

            // Act
            GetSchemes request = new GetSchemes(GetSchemes.FilterType.ApprovedOrWithdrawn);

            List <SchemeData> results = await handler.HandleAsync(request);

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

            Assert.Contains(results, r => r.SchemeName == "Scheme Approved");
            Assert.Contains(results, r => r.SchemeName == "Scheme Withdrawn");
        }
コード例 #4
0
        public void Authenticate()
        {
            User = UserRepository.GetUser(EmailTextBox.Text);
            if (User == null)
            {
                User = new User
                {
                    Email = EmailTextBox.Text
                };
                UserExists = false;
            }
            else
            {
                UserExists = true;
            }

            foreach (var data in AuthenticationData)
            {
                SchemeMap[data.Scheme]();
            }
            OnComplete(AuthenticationData.All(data => data.Authenticated));
        }
コード例 #5
0
        public async Task HandleAsync_WithFilterSetToApproved_ReturnsSchemesWithStatusOfApproved()
        {
            // Arrange
            IWeeeAuthorization authorization = AuthorizationBuilder.CreateUserWithAllRights();

            IMap<Scheme, SchemeData> schemeMap = new SchemeMap(A.Dummy<IMapper>());

            Domain.Organisation.Organisation organisation = Domain.Organisation.Organisation.CreateSoleTrader("Test Organisation");

            Scheme schemePending = new Scheme(organisation);
            schemePending.UpdateScheme("Scheme Pending", "WEE/11AAAA11/SCH", "WEE1234567", ObligationType.Both, A.Dummy<UKCompetentAuthority>());

            Scheme schemeApproved = new Scheme(organisation);
            schemeApproved.UpdateScheme("Scheme Approved", "WEE/11AAAA11/SCH", "WEE1234567", ObligationType.Both, A.Dummy<UKCompetentAuthority>());
            schemeApproved.SetStatus(SchemeStatus.Approved);

            Scheme schemeRejected = new Scheme(organisation);
            schemeRejected.UpdateScheme("Scheme Rejected", "WEE/11AAAA11/SCH", "WEE1234567", ObligationType.Both, A.Dummy<UKCompetentAuthority>());
            schemeRejected.SetStatus(SchemeStatus.Rejected);

            Scheme schemeWithdrawn = new Scheme(organisation);
            schemeWithdrawn.UpdateScheme("Scheme Withdrawn", "WEE/11AAAA11/SCH", "WEE1234567", ObligationType.Both, A.Dummy<UKCompetentAuthority>());
            schemeWithdrawn.SetStatus(SchemeStatus.Approved);
            schemeWithdrawn.SetStatus(SchemeStatus.Withdrawn);

            IGetSchemesDataAccess dataAccess = A.Fake<IGetSchemesDataAccess>();
            A.CallTo(() => dataAccess.GetSchemes()).Returns(
                new List<Scheme>()
                {
                    schemePending,
                    schemeApproved,
                    schemeRejected,
                    schemeWithdrawn
                });

            GetSchemesHandler handler = new GetSchemesHandler(
                authorization,
                schemeMap,
                dataAccess);

            // Act
            GetSchemes request = new GetSchemes(GetSchemes.FilterType.Approved);

            List<SchemeData> results = await handler.HandleAsync(request);

            // Assert
            Assert.NotNull(results);
            Assert.Equal(1, results.Count);

            Assert.Contains(results, r => r.SchemeName == "Scheme Approved");
        }
コード例 #6
0
        public async Task <IActionResult> Post()
        {
            var client     = new ClovaClient();
            var cekRequest = await client.GetRequest(
                Request.Headers["SignatureCEK"],
                Request.Body);

            var cekResponse = new CEKResponse();

            switch (cekRequest.Request.Type)
            {
            case RequestType.LaunchRequest:
            {
                cekResponse.AddText("スキル設定画面で設定したパソコンのアプリケーションを起動します。");
                cekResponse.ShouldEndSession = false;
                break;
            }

            case RequestType.IntentRequest:
            {
                switch (cekRequest.Request.Intent.Name)
                {
                case "LaunchAppIntent":
                    var name = cekRequest.Request.Intent.Slots["name"];
                    if (SchemeMap.ContainsKey(name.Value))
                    {
                        var ignore = InvokeAppAsync(cekRequest.Session.User.AccessToken, SchemeMap[name.Value]);
                        cekResponse.AddText($"{name.Value}を起動しました。");
                    }
                    break;
                }
                break;
            }

            case RequestType.SessionEndedRequest:
            {
                break;
            }
            }

            return(new OkObjectResult(cekResponse));
        }
コード例 #7
0
        public async Task HandleAsync_Always_ReturnsSchemesOrderedBySchemeName()
        {
            // Arrange
            IWeeeAuthorization authorization = AuthorizationBuilder.CreateUserWithAllRights();

            IMap<Scheme, SchemeData> schemeMap = new SchemeMap(A.Dummy<IMapper>());

            Domain.Organisation.Organisation organisation = Domain.Organisation.Organisation.CreateSoleTrader("Test Organisation");

            Scheme scheme1 = new Scheme(organisation);
            scheme1.UpdateScheme("Scheme C", "WEE/11AAAA11/SCH", "WEE1234567", ObligationType.Both, A.Dummy<UKCompetentAuthority>());
            scheme1.SetStatus(SchemeStatus.Approved);

            Scheme scheme2 = new Scheme(organisation);
            scheme2.UpdateScheme("Scheme A", "WEE/11AAAA11/SCH", "WEE1234567", ObligationType.Both, A.Dummy<UKCompetentAuthority>());
            scheme2.SetStatus(SchemeStatus.Approved);

            Scheme scheme3 = new Scheme(organisation);
            scheme3.UpdateScheme("Scheme D", "WEE/11AAAA11/SCH", "WEE1234567", ObligationType.Both, A.Dummy<UKCompetentAuthority>());
            scheme3.SetStatus(SchemeStatus.Approved);

            Scheme scheme4 = new Scheme(organisation);
            scheme4.UpdateScheme("Scheme B", "WEE/11AAAA11/SCH", "WEE1234567", ObligationType.Both, A.Dummy<UKCompetentAuthority>());
            scheme4.SetStatus(SchemeStatus.Approved);

            IGetSchemesDataAccess dataAccess = A.Fake<IGetSchemesDataAccess>();
            A.CallTo(() => dataAccess.GetSchemes()).Returns(
                new List<Scheme>()
                {
                    scheme1,
                    scheme2,
                    scheme3,
                    scheme4
                });

            GetSchemesHandler handler = new GetSchemesHandler(
                authorization,
                schemeMap,
                dataAccess);

            // Act
            GetSchemes request = new GetSchemes(GetSchemes.FilterType.Approved);

            List<SchemeData> results = await handler.HandleAsync(request);

            // Assert
            Assert.NotNull(results);
            Assert.Equal(4, results.Count);

            Assert.Collection(results,
                r => Assert.Equal("Scheme A", r.SchemeName),
                r => Assert.Equal("Scheme B", r.SchemeName),
                r => Assert.Equal("Scheme C", r.SchemeName),
                r => Assert.Equal("Scheme D", r.SchemeName));
        }