Exemple #1
0
        public async Task ReportingStorageRepository_GetIntervals_ExistingEffectiveAuthorizationInterval_With_TargetPerson_Returns_EffectiveAuthorizationGrantedEvent_With_Right_EffectiveAuthorization()
        {
            //Arrange: create EffectiveAuthorizationInterval data to be stored
            var owner = new ExternalId()
            {
                Context = _ownerContext, Id = _ownerId
            };
            var user = new Person(owner, new PersonalInfo()
            {
                BirthDate             = _birthDate1,
                Initials              = _initials1,
                LastNameAtBirth       = _lastNameAtBirth1,
                LastNameAtBirthPrefix = _lastNameAtBirthPrefix1
            });

            var target = new ExternalId()
            {
                Context = _ownerContext, Id = _targetId
            };
            var targetPerson = new Person(target,
                                          new PersonalInfo()
            {
                BirthDate             = _birthDate2,
                Initials              = _initials2,
                LastNameAtBirth       = _lastNameAtBirth2,
                LastNameAtBirthPrefix = _lastNameAtBirthPrefix2
            });

            var permission = new HAS.Core.Domain.Permission()
            {
                Application = _applicationName,
                Id          = _Identifier,
                Description = _Identifier
            };
            var interval = new Interval(_dateTimeStart1, null);
            var effectiveAuthorizationInterval = new EffectiveAuthorizationInterval(interval, user, targetPerson, permission, _tenantId);

            var effectiveAuthorization = new EffectiveAuthorization()
            {
                TenantId = _tenantId, Permission = permission, User = owner, Target = target
            };

            var intervalList = new List <EffectiveAuthorizationInterval>();

            intervalList.Add(effectiveAuthorizationInterval);

            //Act: Attempt to write effectiveAuthorizationInterval to repository and getting it back
            _idToDeleteList.AddRange((await _repository.SaveAsync(intervalList)).Split(","));

            var effectiveAuthorizationIntervals = await _repository.GetIntervals(effectiveAuthorization);

            //Assert: check that there is a returned Id with some data
            Assert.IsNotNull(effectiveAuthorizationIntervals);
            Assert.IsTrue(effectiveAuthorizationIntervals.Count > 0);
            Assert.IsInstanceOfType(effectiveAuthorizationIntervals[0], typeof(EffectiveAuthorizationInterval));
            Assert.AreEqual(effectiveAuthorizationIntervals[0].TenantId, effectiveAuthorization.TenantId);
            Assert.AreEqual(effectiveAuthorizationIntervals[0].User.Key, effectiveAuthorization.User);
            Assert.AreEqual(effectiveAuthorizationIntervals[0].TargetPerson.Key, effectiveAuthorization.Target);
            Assert.AreEqual(effectiveAuthorizationIntervals[0].Permission, effectiveAuthorization.Permission);
        }
Exemple #2
0
        public async Task ReportingStorageRepository_SaveAsync_OnSuccessfulWritingEffectiveAuthorizationInterval_Without_TargetPerson_Returns_EffectiveAuthorizationInterval_Id()
        {
            //Arrange: create EffectiveAuthorizationInterval data to be stored
            var owner = new ExternalId()
            {
                Context = _ownerContext, Id = _ownerId
            };
            var user = new Person(owner, new PersonalInfo()
            {
                BirthDate = _birthDate1, Initials = _initials1, LastNameAtBirth = _lastNameAtBirth1, LastNameAtBirthPrefix = _lastNameAtBirthPrefix1
            });
            var permission = new HAS.Core.Domain.Permission()
            {
                Application = _applicationName, Id = _Identifier, Description = _Identifier
            };
            var interval = new Interval(_dateTimeStart1, null);
            var effectiveAuthorizationInterval = new EffectiveAuthorizationInterval(interval, user, null, permission, _tenantId);
            var intervalList = new List <EffectiveAuthorizationInterval>();

            intervalList.Add(effectiveAuthorizationInterval);

            //Act: Attempt to write effectiveAuthorizationInterval to repository
            _idToDeleteList.AddRange((await _repository.SaveAsync(intervalList)).Split(","));

            //Assert: check that there is a returned Id with some data
            Assert.IsNotNull(_idToDeleteList[0]);
            Assert.IsTrue(_idToDeleteList[0].Length > 0);
        }
Exemple #3
0
        public async Task ReportingStorageRepository_DeleteIntervals_ExistingEffectiveAuthorizationIntervals_Deletes_All_With_Same_Effective_Authorization_Values()
        {
            //Arrange: create EffectiveAuthorizationInterval data to be stored
            var owner = new ExternalId()
            {
                Context = _ownerContext, Id = _ownerId
            };
            var user = new Person(owner, new PersonalInfo()
            {
                BirthDate = _birthDate1, Initials = _initials1, LastNameAtBirth = _lastNameAtBirth1, LastNameAtBirthPrefix = _lastNameAtBirthPrefix1
            });

            var target = new ExternalId()
            {
                Context = _ownerContext, Id = _targetId
            };
            var targetPerson = new Person(target, new PersonalInfo()
            {
                BirthDate = _birthDate2, Initials = _initials2, LastNameAtBirth = _lastNameAtBirth2, LastNameAtBirthPrefix = _lastNameAtBirthPrefix2
            });

            var permission = new HAS.Core.Domain.Permission()
            {
                Application = _applicationName, Id = _Identifier, Description = _Identifier
            };
            var interval = new Interval(_dateTimeStart1, null);
            var effectiveAuthorizationInterval = new EffectiveAuthorizationInterval(interval, user, targetPerson, permission, _tenantId);

            var effectiveAuthorization = new EffectiveAuthorization()
            {
                TenantId = _tenantId, Permission = permission, User = owner, Target = target
            };

            var intervalList = new List <EffectiveAuthorizationInterval>();

            intervalList.Add(effectiveAuthorizationInterval);

            //Act: Attempt to write effectiveAuthorizationInterval to repository, delete it and try to retrieve it back
            _idToDeleteList.AddRange((await _repository.SaveAsync(intervalList)).Split(",")); //In case test fails

            await _repository.DeleteIntervals(effectiveAuthorization);

            var effectiveAuthorizationIntervals = await _repository.GetIntervals(effectiveAuthorization);

            //Assert: check that there is no intervals
            Assert.IsNotNull(effectiveAuthorizationIntervals);
            Assert.IsTrue(effectiveAuthorizationIntervals.Count == 0);
        }
Exemple #4
0
        public async Task ReportingStorageRepository_SaveAsync_IntervalList_Only_Saved_Ones_Remain_Stored()
        {
            //Arrange: create and insert interval list
            var owner = new ExternalId()
            {
                Context = _ownerContext, Id = _ownerId
            };
            var user = new Person(owner, new PersonalInfo()
            {
                BirthDate = _birthDate1, Initials = _initials1, LastNameAtBirth = _lastNameAtBirth1, LastNameAtBirthPrefix = _lastNameAtBirthPrefix1
            });

            var target = new ExternalId()
            {
                Context = _ownerContext, Id = _targetId
            };
            var targetPerson = new Person(target, new PersonalInfo()
            {
                BirthDate = _birthDate2, Initials = _initials2, LastNameAtBirth = _lastNameAtBirth2, LastNameAtBirthPrefix = _lastNameAtBirthPrefix2
            });

            var permission = new HAS.Core.Domain.Permission()
            {
                Application = _applicationName, Id = _Identifier, Description = _Identifier
            };
            var intervalList = new List <EffectiveAuthorizationInterval>();

            EffectiveAuthorizationInterval auxInterval;

            auxInterval = new EffectiveAuthorizationInterval(new Interval(_dateTimeStart1, _dateTimeEnd1), user, targetPerson, permission, _tenantId);
            intervalList.Add(auxInterval);
            auxInterval = new EffectiveAuthorizationInterval(new Interval(_dateTimeStart1.AddDays(1), _dateTimeEnd1.AddDays(1)), user, targetPerson, permission, _tenantId);
            intervalList.Add(auxInterval);
            auxInterval = new EffectiveAuthorizationInterval(new Interval(_dateTimeStart1.AddDays(2), _dateTimeEnd1.AddDays(2)), user, targetPerson, permission, _tenantId);
            intervalList.Add(auxInterval);

            _idToDeleteList.AddRange((await _repository.SaveAsync(intervalList)).Split(",")); //In case test fails

            var effectiveAuthorization = new EffectiveAuthorization()
            {
                TenantId = _tenantId, Permission = permission, User = owner, Target = target
            };

            //assert: check that the retrieved intervals from BBDD match
            var retrievedIntervals = (await _repository.GetIntervals(effectiveAuthorization)).OrderBy(x => x.EffectiveInterval.Start).ToList <EffectiveAuthorizationInterval>();

            Assert.IsNotNull(retrievedIntervals);
            Assert.AreEqual(3, retrievedIntervals.Count);

            Assert.AreEqual(_tenantId, retrievedIntervals[0].TenantId);
            Assert.AreEqual(owner, retrievedIntervals[0].User.Key);
            Assert.AreEqual(permission, retrievedIntervals[0].Permission);
            Assert.AreEqual(target, retrievedIntervals[0].TargetPerson.Key);
            Assert.AreEqual(_dateTimeStart1, retrievedIntervals[0].EffectiveInterval.Start);
            Assert.AreEqual(_dateTimeEnd1, retrievedIntervals[0].EffectiveInterval.End);

            Assert.AreEqual(_tenantId, retrievedIntervals[1].TenantId);
            Assert.AreEqual(owner, retrievedIntervals[1].User.Key);
            Assert.AreEqual(permission, retrievedIntervals[1].Permission);
            Assert.AreEqual(target, retrievedIntervals[1].TargetPerson.Key);
            Assert.AreEqual(_dateTimeStart1.AddDays(1), retrievedIntervals[1].EffectiveInterval.Start);
            Assert.AreEqual(_dateTimeEnd1.AddDays(1), retrievedIntervals[1].EffectiveInterval.End);

            Assert.AreEqual(_tenantId, retrievedIntervals[2].TenantId);
            Assert.AreEqual(owner, retrievedIntervals[2].User.Key);
            Assert.AreEqual(permission, retrievedIntervals[2].Permission);
            Assert.AreEqual(target, retrievedIntervals[2].TargetPerson.Key);
            Assert.AreEqual(_dateTimeStart1.AddDays(2), retrievedIntervals[2].EffectiveInterval.Start);
            Assert.AreEqual(_dateTimeEnd1.AddDays(2), retrievedIntervals[2].EffectiveInterval.End);
        }
Exemple #5
0
        public async Task ReportingStorageRepository_SaveAsync_ExistingInterval_Updates_And_Doesnt_Add_ANew()
        {
            //Arrange: create and insert interval to be udpated
            var owner = new ExternalId()
            {
                Context = _ownerContext, Id = _ownerId
            };
            var user = new Person(owner, new PersonalInfo()
            {
                BirthDate = _birthDate1, Initials = _initials1, LastNameAtBirth = _lastNameAtBirth1, LastNameAtBirthPrefix = _lastNameAtBirthPrefix1
            });

            var target = new ExternalId()
            {
                Context = _ownerContext, Id = _targetId
            };
            var targetPerson = new Person(target, new PersonalInfo()
            {
                BirthDate = _birthDate2, Initials = _initials2, LastNameAtBirth = _lastNameAtBirth2, LastNameAtBirthPrefix = _lastNameAtBirthPrefix2
            });

            var permission = new HAS.Core.Domain.Permission()
            {
                Application = _applicationName, Id = _Identifier, Description = _Identifier
            };
            var interval = new Interval(_dateTimeStart1, null);
            var effectiveAuthorizationInterval = new EffectiveAuthorizationInterval(interval, user, targetPerson, permission, _tenantId);

            var effectiveAuthorization = new EffectiveAuthorization()
            {
                TenantId = _tenantId, Permission = permission, User = owner, Target = target
            };

            var intervalList = new List <EffectiveAuthorizationInterval>();

            intervalList.Add(effectiveAuthorizationInterval);

            _idToDeleteList.AddRange((await _repository.SaveAsync(intervalList)).Split(",")); //In case test fails

            //Act: update the interval and save
            var updatedInterval = new Interval(interval.Start, _dateTimeEnd1);
            var updatedEffectiveAuthorizationInterval = new EffectiveAuthorizationInterval(updatedInterval, user, targetPerson, permission, _tenantId);

            var updatedInternalList = new List <EffectiveAuthorizationInterval>();

            updatedInternalList.Add(updatedEffectiveAuthorizationInterval);

            _idToDeleteList.AddRange((await _repository.SaveAsync(updatedInternalList)).Split(",")); //In case test fails

            //Assert: check that there is still only one interval
            var wantedIntervals = await _repository.GetIntervals(effectiveAuthorization);

            Assert.IsNotNull(wantedIntervals);
            Assert.AreEqual(1, wantedIntervals.Count);
            Assert.AreEqual(_tenantId, wantedIntervals[0].TenantId);
            Assert.AreEqual(owner, wantedIntervals[0].User.Key);
            Assert.AreEqual(permission, wantedIntervals[0].Permission);
            Assert.AreEqual(target, wantedIntervals[0].TargetPerson.Key);
            Assert.AreEqual(_dateTimeStart1, wantedIntervals[0].EffectiveInterval.Start);
            Assert.AreEqual(_dateTimeEnd1, wantedIntervals[0].EffectiveInterval.End);
        }
Exemple #6
0
        public async Task ReportingStorageRepository_DeleteIntervals_ExistingEffectiveAuthorizationIntervals_doesnt_delete_unrelated_Intervals()
        {
            int unrelatedEffectiveAuthorizationIntervals = 10;
            //Arrange: create EffectiveAuthorizationInterval data to be stored
            var owner = new ExternalId()
            {
                Context = _ownerContext, Id = _ownerId
            };
            var user = new Person(owner, new PersonalInfo()
            {
                BirthDate = _birthDate1, Initials = _initials1, LastNameAtBirth = _lastNameAtBirth1, LastNameAtBirthPrefix = _lastNameAtBirthPrefix1
            });

            var target = new ExternalId()
            {
                Context = _ownerContext, Id = _targetId
            };
            var targetPerson = new Person(target, new PersonalInfo()
            {
                BirthDate = _birthDate2, Initials = _initials2, LastNameAtBirth = _lastNameAtBirth2, LastNameAtBirthPrefix = _lastNameAtBirthPrefix2
            });

            var permission = new HAS.Core.Domain.Permission()
            {
                Application = _applicationName, Id = _Identifier, Description = _Identifier
            };
            var interval = new Interval(_dateTimeStart1, null);
            var effectiveAuthorizationInterval = new EffectiveAuthorizationInterval(interval, user, targetPerson, permission, _tenantId);

            var effectiveAuthorization = new EffectiveAuthorization()
            {
                TenantId = _tenantId, Permission = permission, User = owner, Target = target
            };

            var intervalList = new List <EffectiveAuthorizationInterval>();

            intervalList.Add(effectiveAuthorizationInterval);

            EffectiveAuthorizationInterval auxEffectiveAuthInt;

            for (int i = 0; i < unrelatedEffectiveAuthorizationIntervals; i++)
            {
                //Just change the tenantId and the EffectiveAuthorization is different
                auxEffectiveAuthInt = new EffectiveAuthorizationInterval(interval, user, targetPerson, permission, _tenantId + i);
                var deleteInValidRecordIfExists = new EffectiveAuthorization()
                {
                    TenantId = _tenantId + i, Permission = permission, User = owner, Target = target
                };
                await _repository.DeleteIntervals(deleteInValidRecordIfExists);

                intervalList.Add(auxEffectiveAuthInt);
            }

            //Act: Attempt to write effectiveAuthorizationInterval to repository, delete it and try to retrieve it back
            _idToDeleteList.AddRange((await _repository.SaveAsync(intervalList)).Split(",")); //In case test fails

            await _repository.DeleteIntervals(effectiveAuthorization);

            var intervals = new List <EffectiveAuthorizationInterval>();

            for (int i = 0; i < unrelatedEffectiveAuthorizationIntervals; i++)
            {
                intervals.AddRange(await _repository.GetIntervals(new EffectiveAuthorization()
                {
                    User = owner, Permission = permission, Target = target, TenantId = _tenantId + i
                }));
            }

            var unwantedIntervals = await _repository.GetIntervals(effectiveAuthorization);

            //Assert: check that there is no intervals
            Assert.IsNotNull(intervals);
            Assert.AreEqual(unrelatedEffectiveAuthorizationIntervals, intervals.Count);
            Assert.IsNotNull(unwantedIntervals);
            Assert.AreEqual(0, unwantedIntervals.Count);
        }