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);
        }
Beispiel #2
0
        /// <summary>
        /// Test update only
        /// </summary>
        /// <param name="objectUnderTest"></param>
        /// <param name="propertyToChange"></param>
        /// <returns></returns>
        public TModel DoTestUpdate(TModel objectUnderTest, String propertyToChange)
        {
            IDataPersistenceService <TModel> persistenceService = ApplicationContext.Current.GetService <IDataPersistenceService <TModel> >();

            Assert.IsNotNull(persistenceService);

            var    propertyInfo = typeof(TModel).GetProperty(propertyToChange);
            Object oldValue     = propertyInfo.GetValue(objectUnderTest);

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

            var objectAfterUpdate = persistenceService.Update(objectUnderTest);

            Assert.AreEqual(objectUnderTest.Key, objectAfterUpdate.Key);
            objectAfterUpdate = persistenceService.Get(objectAfterUpdate.Key.Value);
            // Update attributes should be set
            Assert.AreNotEqual(oldValue, propertyInfo.GetValue(objectAfterUpdate));
            Assert.AreEqual(objectUnderTest.Key, objectAfterUpdate.Key);

            return(objectAfterUpdate);
        }
Beispiel #3
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 #4
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);
        }