public void Initialize_ValidRootObjectWithChild_NoExceptionRaised()
        {
            // Arrange
            bool executed = false;
            IDataPortal <Root> dataPortal = DataPortalFactory.CreateDataPortal <Root>();
            Root  rootObject  = dataPortal.Fetch(new Root.Criteria("Test Data"));
            Child childObject = rootObject.Children.AddNew();

            childObject.Data = "Test child data";
            ApplicationContext      applicationContext = ApplicationContextFactory.CreateTestApplicationContext();
            RevalidatingInterceptor sut  = new RevalidatingInterceptor(applicationContext);
            InterceptArgs           args = new InterceptArgs()
            {
                ObjectType = typeof(Root),
                Operation  = DataPortalOperations.Update,
                Parameter  = rootObject,
                IsSync     = true
            };

            applicationContext.SetExecutionLocation(ApplicationContext.ExecutionLocations.Server);
            applicationContext.LocalContext["__logicalExecutionLocation"] = ApplicationContext.LogicalExecutionLocations.Server;

            // Act
            sut.Initialize(args);
            executed = true;

            // Assert
            Assert.IsTrue(executed);
        }
        public void Initialize_InvalidGrandChildObject_ExceptionRaised()
        {
            // Arrange
            IDataPortal <Root> dataPortal = DataPortalFactory.CreateDataPortal <Root>();
            Root  rootObject  = dataPortal.Create(new Root.Criteria("Test Data"));
            Child childObject = rootObject.Children.AddNew();

            childObject.Data = "Test child data";
            GrandChild              grandChildObject   = childObject.GrandChildren.AddNew();
            ApplicationContext      applicationContext = ApplicationContextFactory.CreateTestApplicationContext();
            RevalidatingInterceptor sut  = new RevalidatingInterceptor(applicationContext);
            InterceptArgs           args = new InterceptArgs()
            {
                ObjectType = typeof(Root),
                Operation  = DataPortalOperations.Update,
                Parameter  = rootObject,
                IsSync     = true
            };

            applicationContext.SetExecutionLocation(ApplicationContext.ExecutionLocations.Server);
            applicationContext.LocalContext["__logicalExecutionLocation"] = ApplicationContext.LogicalExecutionLocations.Server;

            // Act and Assert
            Assert.ThrowsException <Rules.ValidationException>(() => sut.Initialize(args));
        }
        public void Initialize_PrimitiveCriteria_NoExceptionRaised()
        {
            // Arrange
            bool executed = false;
            PrimitiveCriteria       criteria           = new PrimitiveCriteria(1);
            ApplicationContext      applicationContext = ApplicationContextFactory.CreateTestApplicationContext();
            RevalidatingInterceptor sut  = new RevalidatingInterceptor(applicationContext);
            InterceptArgs           args = new InterceptArgs()
            {
                ObjectType = typeof(Root),
                Operation  = DataPortalOperations.Update,
                Parameter  = criteria,
                IsSync     = true
            };

            applicationContext.SetExecutionLocation(ApplicationContext.ExecutionLocations.Server);
            applicationContext.LocalContext["__logicalExecutionLocation"] = ApplicationContext.LogicalExecutionLocations.Server;

            // Act
            sut.Initialize(args);
            executed = true;

            // Assert
            Assert.IsTrue(executed);
        }
Ejemplo n.º 4
0
        public void UseMobileFormatter()
        {
            ApplicationContext applicationContext;

            applicationContext = ApplicationContextFactory.CreateTestApplicationContext();

            var serializer = ApplicationContext.SerializationFormatter;

            Assert.AreEqual(typeof(Csla.Serialization.Mobile.MobileFormatter), serializer);
            var s = Csla.Serialization.SerializationFormatterFactory.GetFormatter(applicationContext);

            Assert.IsInstanceOfType(s, typeof(Csla.Serialization.Mobile.MobileFormatter));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Create an Http Proxy instance for use in testing
        /// </summary>
        /// <returns>An instance of Csla.Channels.Http.HttpProxy for use in testing</returns>
        private Csla.Channels.Http.HttpProxy CreateTestHttpProxy()
        {
            Csla.Channels.Http.HttpProxy        proxy;
            Csla.Channels.Http.HttpProxyOptions proxyOptions;
            System.Net.Http.HttpClient          httpClient;

            var applicationContext = ApplicationContextFactory.CreateTestApplicationContext();

            httpClient   = new System.Net.Http.HttpClient();
            proxyOptions = new Csla.Channels.Http.HttpProxyOptions();
            proxy        = new Csla.Channels.Http.HttpProxy(applicationContext, httpClient, proxyOptions);

            return(proxy);
        }
Ejemplo n.º 6
0
        public void CloneClaimsPrincipal()
        {
            ApplicationContext applicationContext = ApplicationContextFactory.CreateTestApplicationContext();

            var i = new ClaimsIdentity();

            i.AddClaim(new Claim("name", "Franklin"));
            var p  = new ClaimsPrincipal(i);
            var p1 = (ClaimsPrincipal)Core.ObjectCloner.GetInstance(applicationContext).Clone(p);

            Assert.AreNotSame(p, p1, "Should be different instances");
            Assert.AreEqual(p.Claims.Count(), p1.Claims.Count(), "Should have same number of claims");
            var c = p1.Claims.Where(r => r.Type == "name").First();

            Assert.AreEqual("Franklin", c.Value, "Claim value should match");
        }
        public void ReadConfigCore()
        {
            ApplicationContext applicationContext = ApplicationContextFactory.CreateTestApplicationContext();
            var config = new ConfigurationBuilder()
                         .AddJsonFile("appsettings.coresettings.test.json")
                         .Build()
                         .ConfigureCsla();

            Assert.AreEqual(PropertyChangedModes.Windows, (PropertyChangedModes)Enum.Parse(typeof(PropertyChangedModes), ConfigurationManager.AppSettings["CslaPropertyChangedMode"]));
            Assert.AreEqual("test1,test2", ConfigurationManager.AppSettings["CslaPropertyInfoFactory"], "CslaPropertyInfoFactory");
            Assert.AreEqual("testReader", ConfigurationManager.AppSettings["CslaReader"], "CslaReader");
            Assert.AreEqual("testSerializationFormatter", ConfigurationManager.AppSettings["CslaSerializationFormatter"], "CslaSerializationFormatter");
            Assert.AreEqual("10", ConfigurationManager.AppSettings["CslaPrincipalCacheSize"], "CslaPrincipalCacheSize");
            Assert.IsInstanceOfType(CslaReaderWriterFactory.GetCslaWriter(applicationContext), typeof(TestCslaWriter), "CslaWriter");
            Assert.AreEqual("testDbProvider", ConfigurationManager.AppSettings["CslaDbProvider"], "CslaDbProvider");
            Assert.AreEqual("RepeatableRead", ConfigurationManager.AppSettings["CslaDefaultTransactionIsolationLevel"], "DefaultTransactionIsolationLevel");
            Assert.AreEqual("60", ConfigurationManager.AppSettings["CslaDefaultTransactionTimeoutInSeconds"], "DefaultTransactionTimeoutInSeconds");
        }
Ejemplo n.º 8
0
        public void UseCustomFormatter()
        {
            ApplicationContext applicationContext;

            applicationContext = ApplicationContextFactory.CreateTestApplicationContext();
            try
            {
                Csla.Configuration.ConfigurationManager.AppSettings["CslaSerializationFormatter"] = "Csla.Serialization.Mobile.MobileFormatter,Csla";
                var serializer = ApplicationContext.SerializationFormatter;
                Assert.AreEqual(ApplicationContext.SerializationFormatters.CustomFormatter, serializer);
                var s = Csla.Serialization.SerializationFormatterFactory.GetFormatter(applicationContext);
                Assert.IsInstanceOfType(s, typeof(Csla.Serialization.Mobile.MobileFormatter));
            }
            finally
            {
                Csla.Configuration.ConfigurationManager.AppSettings["CslaSerializationFormatter"] = "MobileFormatter";
            }
        }