Exemplo n.º 1
0
        public async Task GetComplianceYearsHandler_NotOrganisationUser_ThrowsSecurityException()
        {
            // Arrange
            Guid pcsId = new Guid("A7905BCD-8EE7-48E5-9E71-2B571F7BBC81");

            IWeeeAuthorization authorization = new AuthorizationBuilder().DenyInternalOrOrganisationAccess().Build();
            WeeeContext        context       = A.Fake <WeeeContext>();

            GetComplianceYearsHandler handler = new GetComplianceYearsHandler(authorization, context);

            GetComplianceYears request = new GetComplianceYears(pcsId);

            // Act
            Func <Task> action = async() => await handler.HandleAsync(request);

            // Asert
            await Assert.ThrowsAsync <SecurityException>(action);
        }
        public async Task GetComplianceYearsHandler_NotOrganisationUser_ThrowsSecurityException()
        {
            // Arrange
            Guid pcsId = new Guid("A7905BCD-8EE7-48E5-9E71-2B571F7BBC81");

            IWeeeAuthorization authorization = new AuthorizationBuilder().DenyInternalOrOrganisationAccess().Build();
            WeeeContext context = A.Fake<WeeeContext>();

            GetComplianceYearsHandler handler = new GetComplianceYearsHandler(authorization, context);

            GetComplianceYears request = new GetComplianceYears(pcsId);

            // Act
            Func<Task> action = async () => await handler.HandleAsync(request); 

            // Asert
            await Assert.ThrowsAsync<SecurityException>(action);
        }
Exemplo n.º 3
0
        public async Task <List <int> > HandleAsync(GetComplianceYears request)
        {
            authorization.EnsureInternalOrOrganisationAccess(request.PcsId);

            var organisation = await context.Organisations.FindAsync(request.PcsId);

            if (organisation == null)
            {
                string message = string.Format("An organisation could not be found with ID \"{0}\".", request.PcsId);
                throw new ArgumentException(message);
            }

            return(await context.MemberUploads
                   .Where(mu => mu.OrganisationId == request.PcsId)
                   .Where(mu => mu.IsSubmitted)
                   .Where(mu => mu.ComplianceYear.HasValue)
                   .GroupBy(mu => (int)mu.ComplianceYear)
                   .Select(group => group.Key)
                   .OrderByDescending(year => year)
                   .ToListAsync());
        }
        public async Task GetComplianceYearsHandler_OrganisationDoesNotExist_ThrowsArgumentException()
        {
            // Arrange
            Guid pcsId = new Guid("A7905BCD-8EE7-48E5-9E71-2B571F7BBC81");

            IWeeeAuthorization authorization = AuthorizationBuilder.CreateUserWithAllRights();
            
            WeeeContext context = A.Fake<WeeeContext>();
            var organisations = dbContextHelper.GetAsyncEnabledDbSet<Organisation>(new List<Organisation>());
            A.CallTo(() => organisations.FindAsync(pcsId)).Returns((Organisation)null);
            A.CallTo(() => context.Organisations).Returns(organisations);

            GetComplianceYearsHandler handler = new GetComplianceYearsHandler(authorization, context);

            GetComplianceYears request = new GetComplianceYears(pcsId);

            // Act
            Func<Task> action = async () => await handler.HandleAsync(request);

            // Asert
            await Assert.ThrowsAsync<ArgumentException>(action);
        }
Exemplo n.º 5
0
        public async Task GetComplianceYearsHandler_OrganisationDoesNotExist_ThrowsArgumentException()
        {
            // Arrange
            Guid pcsId = new Guid("A7905BCD-8EE7-48E5-9E71-2B571F7BBC81");

            IWeeeAuthorization authorization = AuthorizationBuilder.CreateUserWithAllRights();

            WeeeContext context       = A.Fake <WeeeContext>();
            var         organisations = dbContextHelper.GetAsyncEnabledDbSet <Organisation>(new List <Organisation>());

            A.CallTo(() => organisations.FindAsync(pcsId)).Returns((Organisation)null);
            A.CallTo(() => context.Organisations).Returns(organisations);

            GetComplianceYearsHandler handler = new GetComplianceYearsHandler(authorization, context);

            GetComplianceYears request = new GetComplianceYears(pcsId);

            // Act
            Func <Task> action = async() => await handler.HandleAsync(request);

            // Asert
            await Assert.ThrowsAsync <ArgumentException>(action);
        }