Esempio n. 1
0
        public async Task AddEffectiveAuthorizationAsync_Event_Stored_With_Invalid_Authorization_No_Permission_Throws_NullReferenceException()
        {
            //Arrange
            var eaEventsStorate = new RawEventInMemoryStorage();

            var eaHandlerFactory = new EffectiveAuthorizationHandlerFactory();

            eaHandlerFactory.RegisterHandler(typeof(EffectiveAuthorizationGrantedEvent), new PermissionGrantedHandler());

            var eatimelineFactory = new EffectiveAuthorizationTimelineFactory(eaEventsStorate, eaHandlerFactory);

            var prService = new PersonalInfoEnrichmentService(new MockPersonalLocalStorage(), new MockPersonalInfoExternalServiceFactory(), new MockInMemoryLogger());
            var rpStorage = new ReportingInMemoryStorage();

            var permission = new Permission()
            {
                Application = _defaultApplication, Id = _defaultPermissionId, Description = _defaultDescription
            };
            var effectiveAuthorization = new EffectiveAuthorization()
            {
                TenantId = _tenantId, Permission = permission
            };
            var eaEvent = new EffectiveAuthorizationGrantedEvent()
            {
                From = new DateTime(2018, 1, 1), EffectiveAuthorization = effectiveAuthorization
            };

            await eaEventsStorate.WriteRawEventAsync(eaEvent); //event needs to be previously writteng to storage.

            var dataEnrichmentService = new DataEnrichmentService(eatimelineFactory, prService, rpStorage);

            //Act & Assert
            await Assert.ThrowsExceptionAsync <NullReferenceException>(() => dataEnrichmentService.AddEffectiveAuthorizationAsync(eaEvent));
        }
Esempio n. 2
0
        public async Task AddEffectiveAuthorizationAsync_Event_Stored_With_Valid_Authorization_Without_Target_Calls_IReportingStorage_SaveAsyc()
        {
            //Arrange
            var eaEventsStorate = new RawEventInMemoryStorage();

            var eaHandlerFactory = new EffectiveAuthorizationHandlerFactory();

            eaHandlerFactory.RegisterHandler(typeof(EffectiveAuthorizationGrantedEvent), new PermissionGrantedHandler());

            var eatimelineFactory = new EffectiveAuthorizationTimelineFactory(eaEventsStorate, eaHandlerFactory);

            var prService = new PersonalInfoEnrichmentService(new MockPersonalLocalStorage(), new MockPersonalInfoExternalServiceFactory(), new MockInMemoryLogger());

            var rpStorageMock = new Mock <IReportingStorage>();
            var owner         = new ExternalId()
            {
                Id = _defaultId, Context = _defaultContext
            };
            var permission = new Permission()
            {
                Application = _defaultApplication, Id = _defaultPermissionId, Description = _defaultDescription
            };
            var effectiveAuthorization = new EffectiveAuthorization()
            {
                TenantId = _tenantId, Permission = permission, User = owner
            };
            var eaEvent = new EffectiveAuthorizationGrantedEvent()
            {
                From = new DateTime(2018, 1, 1), EffectiveAuthorization = effectiveAuthorization
            };

            await eaEventsStorate.WriteRawEventAsync(eaEvent); //event needs to be previously writteng to storage.

            var dataEnrichmentService = new DataEnrichmentService(eatimelineFactory, prService, rpStorageMock.Object);

            //Act
            await dataEnrichmentService.AddEffectiveAuthorizationAsync(eaEvent);

            //Assert
            rpStorageMock.Verify(v => v.SaveAsync(It.IsAny <IList <EffectiveAuthorizationInterval> >()));
        }