예제 #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));
        }
        public async void GetSchemesHandlerTest_HappyPath_ReturnsSchemeDatasOrderedByName()
        {
            // Arrage
            IGetSchemesDataAccess dataAccess = CreateFakeDataAccess();

            IWeeeAuthorization authorization = new AuthorizationBuilder()
                .AllowInternalAreaAccess()
                .Build();

            IMap<Scheme, SchemeData> schemeMap = CreateFakeSchemeMap();

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

            GetSchemes request = new GetSchemes();

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

            // Assert
            Assert.Collection(
                results,
                (element1) => Assert.Equal(schemeData2, element1),
                (element2) => Assert.Equal(schemeData1, element2),
                (element3) => Assert.Equal(schemeData3, element3));
        }
예제 #3
0
        public async void GetSchemesHandlerTest_HappyPath_ReturnsSchemeDatasOrderedByName()
        {
            // Arrage
            IGetSchemesDataAccess dataAccess = CreateFakeDataAccess();

            IWeeeAuthorization authorization = new AuthorizationBuilder()
                                               .AllowInternalAreaAccess()
                                               .Build();

            IMap <Scheme, SchemeData> schemeMap = CreateFakeSchemeMap();

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

            GetSchemes request = new GetSchemes();

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

            // Assert
            Assert.Collection(
                results,
                (element1) => Assert.Equal(schemeData2, element1),
                (element2) => Assert.Equal(schemeData1, element2),
                (element3) => Assert.Equal(schemeData3, element3));
        }
예제 #4
0
        protected async Task <List <SchemeData> > FetchSchemes()
        {
            var request = new GetSchemes(GetSchemes.FilterType.ApprovedOrWithdrawn);

            using (var client = apiClient())
            {
                return(await client.SendAsync(User.GetAccessToken(), request));
            }
        }
예제 #5
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");
        }
예제 #6
0
        public async Task <List <SchemeData> > HandleAsync(GetSchemes message)
        {
            authorization.EnsureCanAccessInternalArea();

            var schemes = await dataAccess.GetCompleteSchemes();

            return(schemes.Select(s => schemeMap.Map(s))
                   .OrderBy(sd => sd.Name)
                   .ToList());
        }
        public async void GetSchemesHandler_WithNonInternalUser_ThrowsSecurityException(AuthorizationBuilder.UserType userType)
        {
            IGetSchemesDataAccess dataAccess = CreateFakeDataAccess();

            IWeeeAuthorization authorization = AuthorizationBuilder.CreateFromUserType(userType);

            IMap<Scheme, SchemeData> schemeMap = CreateFakeSchemeMap();

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

            GetSchemes request = new GetSchemes();

            // Act
            Func<Task<List<SchemeData>>> action = () => handler.HandleAsync(request);

            // Assert
            await Assert.ThrowsAsync<SecurityException>(action);
        }
예제 #8
0
        public async void GetSchemesHandler_WithNonInternalUser_ThrowsSecurityException(AuthorizationBuilder.UserType userType)
        {
            IGetSchemesDataAccess dataAccess = CreateFakeDataAccess();

            IWeeeAuthorization authorization = AuthorizationBuilder.CreateFromUserType(userType);

            IMap <Scheme, SchemeData> schemeMap = CreateFakeSchemeMap();

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

            GetSchemes request = new GetSchemes();

            // Act
            Func <Task <List <SchemeData> > > action = () => handler.HandleAsync(request);

            // Assert
            await Assert.ThrowsAsync <SecurityException>(action);
        }
        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");
        }
        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));
        }