Beispiel #1
0
        /// <summary>
        /// Test the insertion of a valid security user
        /// </summary>
        public TModel DoTestInsert(TModel objectUnderTest, IPrincipal authContext = null)
        {
            // Auth context
            if (authContext == null)
            {
                authContext = AuthenticationContext.AnonymousPrincipal;
            }

            // Store user
            IDataPersistenceService <TModel> persistenceService = ApplicationContext.Current.GetService <IDataPersistenceService <TModel> >();

            Assert.IsNotNull(persistenceService);

            var objectAfterTest = persistenceService.Insert(objectUnderTest, authContext, TransactionMode.Commit);

            // Key should be set
            Assert.AreNotEqual(Guid.Empty, objectAfterTest.Key);

            // Verify
            objectAfterTest = persistenceService.Get(objectAfterTest.Id(), authContext, false);
            if (objectAfterTest is BaseEntityData)
            {
                Assert.AreNotEqual(default(DateTimeOffset), (objectAfterTest as BaseEntityData).CreationTime);
            }

            return(objectAfterTest);
        }
        public void ClassSetup()
        {
            AuthenticationContext.EnterSystemContext();

            IIdentityProviderService identityProvider = ApplicationServiceContext.Current.GetService <IIdentityProviderService>();
            var identity = identityProvider.CreateIdentity(nameof(SecurityRolePersistenceServiceTest), "password", AuthenticationContext.Current.Principal);

            // Give this identity the administrative functions group
            IRoleProviderService roleProvider = ApplicationServiceContext.Current.GetService <IRoleProviderService>();

            roleProvider.AddUsersToRoles(new string[] { identity.Name }, new string[] { "ADMINISTRATORS" }, AuthenticationContext.Current.Principal);

            // Authorize
            s_authorization = identityProvider.Authenticate(nameof(SecurityRolePersistenceServiceTest), "password");


            IDataPersistenceService <SecurityPolicy> policyService = ApplicationServiceContext.Current.GetService <IDataPersistenceService <SecurityPolicy> >();

            s_chickenCostumePolicy = new SecurityPolicy()
            {
                Name = "Allow wearing of chicken costume",
                Oid  = "2.3.23.543.25.2"
            };
            s_chickenCostumePolicy = policyService.Insert(s_chickenCostumePolicy, TransactionMode.Commit, s_authorization);
        }
        public static void ClassSetup(TestContext context)
        {
            AppDomain.CurrentDomain.SetData(
                "DataDirectory",
                Path.Combine(context.TestDeploymentDir, string.Empty));

            IIdentityProviderService identityProvider = ApplicationContext.Current.GetService <IIdentityProviderService>();
            var identity = identityProvider.CreateIdentity(nameof(SecurityRolePersistenceServiceTest), "password", AuthenticationContext.SystemPrincipal);

            // Give this identity the administrative functions group
            IRoleProviderService roleProvider = ApplicationContext.Current.GetService <IRoleProviderService>();

            roleProvider.AddUsersToRoles(new string[] { identity.Name }, new string[] { "ADMINISTRATORS" }, AuthenticationContext.SystemPrincipal);

            // Authorize
            s_authorization = identityProvider.Authenticate(nameof(SecurityRolePersistenceServiceTest), "password");


            IDataPersistenceService <SecurityPolicy> policyService = ApplicationContext.Current.GetService <IDataPersistenceService <SecurityPolicy> >();

            s_chickenCostumePolicy = new SecurityPolicy()
            {
                Name = "Allow wearing of chicken costume",
                Oid  = "2.3.23.543.25.2"
            };
            s_chickenCostumePolicy = policyService.Insert(s_chickenCostumePolicy, s_authorization, TransactionMode.Commit);
        }
Beispiel #4
0
        /// <summary>
        /// Do a test step for an update
        /// </summary>
        public TModel DoTestInsertUpdate(TModel objectUnderTest, String propertyToChange)
        {
            // Auth context

            // Store user
            IDataPersistenceService <TModel> persistenceService = ApplicationContext.Current.GetService <IDataPersistenceService <TModel> >();

            Assert.IsNotNull(persistenceService);

            // Update the user
            var objectAfterInsert = persistenceService.Insert(objectUnderTest);

            // Update
            return(this.DoTestUpdate(objectAfterInsert, propertyToChange));
        }
Beispiel #5
0
        /// <summary>
        /// Insert troublesome place
        /// </summary>
        //[TestMethod]
        public void InsertTroublesomePlace()
        {
            IDataPersistenceService <Place> idp = ApplicationContext.Current.GetService <IDataPersistenceService <Place> >();
            XmlSerializer xsz = new XmlSerializer(typeof(Bundle));

            using (var s = typeof(PlacePersistenceServiceTest).Assembly.GetManifestResourceStream("OpenIZ.Mobile.Core.Test.IMSI.TroublesomePlaceBundle.xml"))
            {
                var bundle = xsz.Deserialize(s) as Bundle;
                bundle.Reconstitute();

                foreach (var i in bundle.Item)
                {
                    idp.Insert(i);
                }
            }
        }
Beispiel #6
0
        /// <summary>
        /// Do a test step for an update
        /// </summary>
        public TModel DoTestUpdate(TModel objectUnderTest, IPrincipal authContext, String propertyToChange)
        {
            // Auth context
            if (authContext == null)
            {
                authContext = AuthenticationContext.AnonymousPrincipal;
            }

            // Store user
            IDataPersistenceService <TModel> persistenceService = ApplicationContext.Current.GetService <IDataPersistenceService <TModel> >();

            Assert.IsNotNull(persistenceService);

            // Update the user
            var objectAfterInsert = persistenceService.Insert(objectUnderTest, authContext, TransactionMode.Commit);

            // Update
            var    propertyInfo  = typeof(TModel).GetProperty(propertyToChange);
            object originalValue = propertyInfo.GetValue(objectUnderTest);

            if (propertyInfo.PropertyType == typeof(String))
            {
                propertyInfo.SetValue(objectAfterInsert, "NEW_VALUE");
            }
            else if (propertyInfo.PropertyType == typeof(Nullable <DateTimeOffset>) ||
                     propertyInfo.PropertyType == typeof(DateTimeOffset))
            {
                propertyInfo.SetValue(objectAfterInsert, DateTimeOffset.MaxValue);
            }
            else if (propertyInfo.PropertyType == typeof(Boolean) ||
                     propertyInfo.PropertyType == typeof(Nullable <Boolean>))
            {
                propertyInfo.SetValue(objectAfterInsert, true);
            }

            var objectAfterUpdate = persistenceService.Update(objectAfterInsert, authContext, TransactionMode.Commit);

            Assert.AreEqual(objectAfterInsert.Key, objectAfterUpdate.Key);
            objectAfterUpdate = persistenceService.Get(objectAfterUpdate.Id(), authContext, false);
            // Update attributes should be set
            Assert.AreNotEqual(originalValue, propertyInfo.GetValue(objectAfterUpdate));
            Assert.AreEqual(objectAfterInsert.Key, objectAfterUpdate.Key);

            return(objectAfterUpdate);
        }
Beispiel #7
0
        /// <summary>
        /// Test the insertion of a valid security user
        /// </summary>
        public TModel DoTestInsert(TModel objectUnderTest)
        {
            // Store user
            IDataPersistenceService <TModel> persistenceService = ApplicationContext.Current.GetService <IDataPersistenceService <TModel> >();

            Assert.IsNotNull(persistenceService);

            var objectAfterTest = persistenceService.Insert(objectUnderTest);

            // Key should be set
            Assert.AreNotEqual(Guid.Empty, objectAfterTest.Key);

            // Verify
            objectAfterTest = persistenceService.Get(objectAfterTest.Key.Value);
            if (objectAfterTest is BaseEntityData)
            {
                Assert.AreNotEqual(default(DateTimeOffset), (objectAfterTest as BaseEntityData).CreationTime);
            }

            return(objectAfterTest);
        }