public async Task ResolvePerson_EmptyId_ThrowsException() { MockInMemoryLogger logger = new MockInMemoryLogger(); try { var personalInfoEnrichmentService = new PersonalInfoEnrichmentService( new Mock <IPersonLocalStorage>().Object, new Mock <IPersonalInfoExternalServiceFactory>().Object, logger); var externalId = new ExternalId() { Context = "Youforce" }; await personalInfoEnrichmentService.ResolvePerson(externalId); } catch (Exception e) { Assert.AreEqual(typeof(ArgumentException), e.GetType()); } finally { var log = logger.Logs.Dequeue(); Assert.AreEqual(LogLevel.Error, log.LogLevel); Assert.AreEqual("PersonalInfoEnrichmentService: Invalid External ID", log.Message); } }
public async Task ResolvePerson_ExternalIdNotFoundInLocalStorage_UnknownContext_ReturnsPersonWithoutEnrichmentInfo() { var externalId = new ExternalId() { Context = "Other", Id = "0001" }; Mock <IPersonLocalStorage> localStorage = new Mock <IPersonLocalStorage>(); localStorage.Setup(x => x.FindPersonAsync(externalId)).ReturnsAsync(() => null); Mock <IPersonalInfoExternalServiceFactory> extServiceFactory = new Mock <IPersonalInfoExternalServiceFactory>(); extServiceFactory.Setup(x => x.Resolve("Other")).Returns(() => null); var logger = new MockInMemoryLogger(); var personalInfoEnrichmentService = new PersonalInfoEnrichmentService(localStorage.Object, extServiceFactory.Object, logger); var person = await personalInfoEnrichmentService.ResolvePerson(externalId); Assert.IsNotNull(person); Assert.AreEqual(externalId.Context, person.Key.Context); Assert.AreEqual(externalId.Id, person.Key.Id); Assert.IsNull(person.PersonalInfo); var log = logger.Logs.Dequeue(); Assert.AreEqual(LogLevel.Warning, log.LogLevel); Assert.AreEqual( $"PersonalInfoEnrichmentService: Error on getting Personal Info for ExternalId [Context: {externalId.Context}, Id: {externalId.Id}]. Can't find a valid resolver api for given context. Person will be created based on Technical Keys only.", log.Message); }
public async Task AddEffectiveAuthorizationAsync_GrantedAndRevokedEventsForUnexistingUserContextAndWithoutTarget_ClosedIntervalIsCreatedInReadModelWithoutEnrichedPersonalInfo() { //Create a raw event var user = new ExternalId() { Context = "unexistingContext", Id = _userId }; var permission = new Permission() { Application = "YOUFORCE", Id = "HomeAccess", Description = "" }; var effectiveAuthorization = new EffectiveAuthorization() { TenantId = _tenantId, Permission = permission, User = user }; var eaGrantedEvent = new EffectiveAuthorizationGrantedEvent() { From = _from, EffectiveAuthorization = effectiveAuthorization, DateCreated = DateTime.Now }; var eaRevokedEvent = new EffectiveAuthorizationRevokedEvent() { Until = _until, EffectiveAuthorization = effectiveAuthorization, DateCreated = DateTime.Now }; _eventIdList.Add(await _repository.WriteRawEventAsync(eaGrantedEvent)); _eventIdList.Add(await _repository.WriteRawEventAsync(eaRevokedEvent)); //Data Enrichment var eaHandlerFactory = new EffectiveAuthorizationHandlerFactory(); eaHandlerFactory.RegisterHandler(typeof(EffectiveAuthorizationRevokedEvent), new PermissionRevokedHandler()); eaHandlerFactory.RegisterHandler(typeof(EffectiveAuthorizationGrantedEvent), new PermissionGrantedHandler()); var eatimelineFactory = new EffectiveAuthorizationTimelineFactory(_repository, eaHandlerFactory); var logger = new MockInMemoryLogger(); var prService = PersonalInfoEnrichmentServiceHelper.BuildService(logger); var readModel = new ReportingInMemoryStorage(); var dataEnrichmentService = new DataEnrichmentService(eatimelineFactory, prService, readModel); await dataEnrichmentService.AddEffectiveAuthorizationAsync(eaRevokedEvent); //Assertions var expectedUser = new Person(user, null); var intervals = readModel.GetIntervals(effectiveAuthorization).Result; Assert.AreEqual(1, intervals.Count); Assert.AreEqual(_tenantId, intervals[0].TenantId); Assert.AreEqual(user, intervals[0].User.Key); Assert.IsNull(intervals[0].User.PersonalInfo); Assert.AreEqual(permission, intervals[0].Permission); Assert.AreEqual(null, intervals[0].TargetPerson); Assert.AreEqual(_from, intervals[0].EffectiveInterval.Start); Assert.AreEqual(_until, intervals[0].EffectiveInterval.End); }
public async Task AddEffectiveAuthorizationAsync_GrantedEventForExistingUserAndTarget_OpenIntervalIsCreatedInReadModelWithEnrichedPersonalInfo() { //Create a raw event var user = new ExternalId() { Context = _context, Id = _userId }; var permission = new Permission() { Application = "YOUFORCE", Id = "HomeAccess", Description = "Home Access" }; var target = new ExternalId() { Id = _targetId, Context = _context }; var effectiveAuthorization = new EffectiveAuthorization() { TenantId = _tenantId, Permission = permission, User = user, Target = target }; var eaEvent = new EffectiveAuthorizationGrantedEvent() { From = _from, EffectiveAuthorization = effectiveAuthorization, DateCreated = DateTime.Now }; //Add event to the memory event store _eventIdList.Add(await _repository.WriteRawEventAsync(eaEvent)); //Data Enrichment var eaHandlerFactory = new EffectiveAuthorizationHandlerFactory(); eaHandlerFactory.RegisterHandler(typeof(EffectiveAuthorizationGrantedEvent), new PermissionGrantedHandler()); var eatimelineFactory = new EffectiveAuthorizationTimelineFactory(_repository, eaHandlerFactory); var logger = new MockInMemoryLogger(); var prService = PersonalInfoEnrichmentServiceHelper.BuildService(logger); var readModel = new ReportingInMemoryStorage(); var dataEnrichmentService = new DataEnrichmentService(eatimelineFactory, prService, readModel); await dataEnrichmentService.AddEffectiveAuthorizationAsync(eaEvent); //Assertions var expectedUser = new Person(user, _userPersonalInfo); var expectedTarget = new Person(target, _targetPersonalInfo); var intervals = readModel.GetIntervals(effectiveAuthorization).Result; Assert.AreEqual(1, intervals.Count); Assert.AreEqual(_tenantId, intervals[0].TenantId); Assert.AreEqual(expectedUser, intervals[0].User); Assert.AreEqual(permission, intervals[0].Permission); Assert.AreEqual(expectedTarget, intervals[0].TargetPerson); Assert.AreEqual(_from, intervals[0].EffectiveInterval.Start); }
public ReportDetailControllerTest() { _EAAggregateBusiness = new Mock <IEAAggregateBusiness>(); _Logger = new MockInMemoryLogger(); }