Ejemplo n.º 1
0
        public void TestBypassReadWriteWithRightsTurnNotificationBackOn()
        {
            TestDIContext testDIContext = TestDIContextFactory.CreateContext(GetPrincipal("Admin"));
            IDataPortal <BypassBusinessBase> dataPortal = testDIContext.CreateDataPortal <BypassBusinessBase>();

            UnitTestContext    context = GetContext();
            bool               propertyChangedFired = false;
            BypassBusinessBase testObj = dataPortal.Fetch();

            testObj.PropertyChanged += (o, e) =>
            {
                propertyChangedFired = true;
            };
            testObj.LoadIdByPass(1);
            context.Assert.AreEqual(1, testObj.ReadIdByPass());
            context.Assert.AreEqual(false, propertyChangedFired);
            context.Assert.AreEqual(false, testObj.IsDirty);

            testObj.LoadIdByNestedPass(3);
            context.Assert.AreEqual(3, testObj.ReadIdByPass());
            context.Assert.AreEqual(false, propertyChangedFired);
            context.Assert.AreEqual(false, testObj.IsDirty);

            testObj.LoadId(2);
            context.Assert.AreEqual(true, propertyChangedFired);
            context.Assert.AreEqual(2, testObj.ReadId());
            context.Assert.AreEqual(true, testObj.IsDirty);

            context.Assert.Success();
            context.Complete();
        }
Ejemplo n.º 2
0
        public void UpdateTransactionScopeUsingDefaultTransactionLevelAndTimeout()
        {
            TestDIContext testDIContext = TestDIContextFactory.CreateContext(
                options => options
                .Data(
                    cfg => cfg
                    .DefaultTransactionIsolationLevel(TransactionIsolationLevel.RepeatableRead)
                    .DefaultTransactionTimeoutInSeconds(45)
                    )
                .DataPortal(
                    dp => dp.AddServerSideDataPortal(cfg => cfg.RegisterObjectFactoryLoader <ObjectFactoryLoader <RootFactory5> >()))
                );
            IDataPortal <Root> dataPortal = testDIContext.CreateDataPortal <Root>();

            var root = dataPortal.Create();

            root.Data = "abc";


            root = dataPortal.Update(root);
            Assert.AreEqual(TransactionalTypes.TransactionScope, root.TransactionalType, "Transactional type should match");
            Assert.AreEqual("RepeatableRead", root.IsolationLevel, "Transactional isolation should match");
            Assert.AreEqual(45, root.TransactionTimeout, "Transactional timeout should match");

            Assert.AreEqual("Update", root.Data, "Data should match");
            Assert.IsFalse(root.IsNew, "Should not be new");
            Assert.IsFalse(root.IsDirty, "Should not be dirty");
        }
Ejemplo n.º 3
0
 public static void ClassInitialize(TestContext context)
 {
     _testDIContext = TestDIContextFactory.CreateContext(
         options => options.DataPortal(dp => dp.AddServerSideDataPortal(
                                           cfg => cfg.RegisterObjectFactoryLoader <ObjectFactoryLoader <RootFactory> >())
                                       ));
 }
Ejemplo n.º 4
0
        public void DenyWritePerType()
        {
            TestDIContext testDIContext = TestDIContextFactory.CreateContext(new System.Security.Claims.ClaimsPrincipal());
            IDataPortal <PerTypeAuthorization> dataPortal = testDIContext.CreateDataPortal <PerTypeAuthorization>();

            PerTypeAuthorization root = dataPortal.Create();

            root.Test = "test";
        }
Ejemplo n.º 5
0
        public void TestAuthorizationRulesAfterSerialization()
        {
            TestDIContext adminDIContext = TestDIContextFactory.CreateContext(GetPrincipal("Admin"));
            IDataPortal <Security.PermissionsRoot> dataPortal = _testDIContext.CreateDataPortal <Security.PermissionsRoot>();

            Security.PermissionsRoot root = dataPortal.Create();

            try
            {
                root.FirstName = "something";
                Assert.Fail("Exception didn't occur");
            }
            catch (Csla.Security.SecurityException ex)
            {
                Assert.AreEqual("Property set not allowed", ex.Message);
            }

            dataPortal = adminDIContext.CreateDataPortal <Security.PermissionsRoot>();
            root       = dataPortal.Create();

            try
            {
                root.FirstName = "something";
            }
            catch (Csla.Security.SecurityException)
            {
                Assert.Fail("exception occurred");
            }

            // TODO: Not sure how to recreate this test now; can't change context under the data portal mid flight
            //Csla.ApplicationContext.User = new ClaimsPrincipal();

            Csla.Test.Security.PermissionsRoot rootClone = root.Clone();

            try
            {
                rootClone.FirstName = "something else";
                Assert.Fail("Exception didn't occur");
            }
            catch (Csla.Security.SecurityException ex)
            {
                Assert.AreEqual("Property set not allowed", ex.Message);
            }

            // TODO: Not sure how to recreate this test now; can't change context under the data portal mid flight
            //Csla.ApplicationContext.User = GetPrincipal("Admin");

            try
            {
                rootClone.FirstName = "something new";
            }
            catch (Csla.Security.SecurityException)
            {
                Assert.Fail("exception occurred");
            }
        }
Ejemplo n.º 6
0
        public void PerTypeAuthEditObjectViaInterface()
        {
            TestDIContext customDIContext = TestDIContextFactory.CreateContext(
                options => options.DataPortal(
                    dp => dp.AddServerSideDataPortal(cfg => cfg.RegisterActivator <PerTypeAuthDPActivator>())
                    ));
            ApplicationContext applicationContext = customDIContext.CreateTestApplicationContext();

            Assert.IsFalse(BusinessRules.HasPermission(applicationContext, AuthorizationActions.EditObject, typeof(IPerTypeAuthRoot)));
        }
Ejemplo n.º 7
0
 public static void ClassInitialize(TestContext context)
 {
     _testDIContext = TestDIContextFactory.CreateContext(
         options => options
         .DataPortal(dp => dp.AddServerSideDataPortal(config =>
     {
         config.AddInterceptorProvider <TestInterceptor>();
         config.RegisterActivator <TestActivator>();
     }
                                                      )));
 }
Ejemplo n.º 8
0
 public static void ClassInitialize(TestContext context)
 {
     _testDIContext = TestDIContextFactory.CreateContext(options =>
     {
         options.Services.AddTransient <TestableDataPortal>();
         options.DataPortal(
             dp => dp.AddServerSideDataPortal(
                 config => config.RegisterAuthorizerProvider <AuthorizeDataPortalStub>())
             );
     });
 }
Ejemplo n.º 9
0
        public void UseCustomSerializationFormatter()
        {
            TestDIContext customDIContext = TestDIContextFactory.CreateContext(options => options
                                                                               .Serialization(cfg => cfg
                                                                                              .SerializationFormatter(typeof(NetDataContractSerializerWrapper))));
            ApplicationContext applicationContext = customDIContext.CreateTestApplicationContext();

            var formatter = SerializationFormatterFactory.GetFormatter(applicationContext);

            Assert.IsInstanceOfType(formatter, typeof(NetDataContractSerializerWrapper));
        }
Ejemplo n.º 10
0
        public void FetchLoadProperty()
        {
            TestDIContext testDIContext = TestDIContextFactory.CreateContext(
                options => options.DataPortal(
                    dp => dp.AddServerSideDataPortal(cfg => cfg.RegisterObjectFactoryLoader <ObjectFactoryLoader <RootFactory3> >()))
                );
            IDataPortal <Root> dataPortal = testDIContext.CreateDataPortal <Root>();

            var root = dataPortal.Fetch();

            Assert.AreEqual("Fetch", root.Data, "Data should match");
            Assert.IsFalse(root.IsNew, "Should not be new");
            Assert.IsFalse(root.IsDirty, "Should not be dirty");
        }
Ejemplo n.º 11
0
        public void TestBypassFactory()
        {
            TestDIContext testDIContext = TestDIContextFactory.CreateContext(GetPrincipal("Admin"));
            IDataPortal <BypassBusinessBaseUsingFactory> dataPortal = testDIContext.CreateDataPortal <BypassBusinessBaseUsingFactory>();

            UnitTestContext context = GetContext();

            BypassBusinessBaseUsingFactory obj = BypassBusinessBaseUsingFactory.GetObject(dataPortal);

            context.Assert.AreEqual(false, obj.IsDirty);
            context.Assert.AreEqual(7, obj.ReadId2ByPass());
            context.Assert.Success();
            context.Complete();
        }
Ejemplo n.º 12
0
        public void CreateWithParam()
        {
            TestDIContext testDIContext = TestDIContextFactory.CreateContext(
                // TODO: What proxy can we use for this test? Old one was Remoting, now retired
                //  options => options.Services.AddTransient<DataPortalClient.IDataPortalProxy, Testing.Business.TestProxies.AppDomainProxy>(),
                opts => opts.DataPortal(dp => dp.AddServerSideDataPortal(cfg => cfg.RegisterObjectFactoryLoader <ObjectFactoryLoader <RootFactory> >())),
                new System.Security.Claims.ClaimsPrincipal());

            IDataPortal <Root> dataPortal = testDIContext.CreateDataPortal <Root>();

            var root = dataPortal.Create("abc");

            Assert.AreEqual("Create abc", root.Data, "Data should match");
            Assert.AreEqual(Csla.ApplicationContext.ExecutionLocations.Client, root.Location, "Location should match");
            Assert.IsTrue(root.IsNew, "Should be new");
            Assert.IsTrue(root.IsDirty, "Should be dirty");
        }
Ejemplo n.º 13
0
        public void FailUpdateContext()
        {
            TestDIContext testDIContext            = TestDIContextFactory.CreateContext(opts => opts.DataPortal(cfg => cfg.DataPortalReturnObjectOnException(true)));
            IDataPortal <ExceptionRoot> dataPortal = testDIContext.CreateDataPortal <ExceptionRoot>();

            try
            {
                TestResults.Reinitialise();

                ExceptionRoot root;
                try
                {
                    root = dataPortal.Create(new ExceptionRoot.Criteria());
                    Assert.Fail("Create exception didn't occur");
                }
                catch (DataPortalException ex)
                {
                    root = (ExceptionRoot)ex.BusinessObject;
                    Assert.AreEqual("Fail create", ex.GetBaseException().Message, "Base exception message incorrect");
                    Assert.IsTrue(ex.Message.StartsWith("DataPortal.Create failed"), "Exception message incorrect");
                }

                root.Data = "boom";
                try
                {
                    root = root.Save();

                    Assert.Fail("Insert exception didn't occur");
                }
                catch (DataPortalException ex)
                {
                    root = (ExceptionRoot)ex.BusinessObject;
                    Assert.AreEqual("Fail insert", ex.GetBaseException().Message, "Base exception message incorrect");
                    Assert.IsTrue(ex.Message.StartsWith("DataPortal.Update failed"), "Exception message incorrect");
                }

                Assert.AreEqual("boom", root.Data, "Business object not returned");
                Assert.AreEqual("create", TestResults.GetResult("create"), "GlobalContext not preserved");
            }
            finally
            {
            }
        }
Ejemplo n.º 14
0
        public void TestBypassWriteNoRightsDoNotBypassBackingField()
        {
            TestDIContext testDIContext = TestDIContextFactory.CreateContext(GetPrincipal("Admin"));
            IDataPortal <BypassBusinessBase> dataPortal = testDIContext.CreateDataPortal <BypassBusinessBase>();

            UnitTestContext    context = GetContext();
            BypassBusinessBase testObj = dataPortal.Fetch();
            bool propertyChangedFired  = false;

            testObj.PropertyChanged += (o, e) =>
            {
                propertyChangedFired = true;
            };
            testObj.LoadId4(1);
            context.Assert.AreEqual(true, testObj.IsDirty);
            context.Assert.AreEqual(1, testObj.ReadId4ByPass());
            context.Assert.AreEqual(true, propertyChangedFired);
            context.Assert.Success();
            context.Complete();
        }
Ejemplo n.º 15
0
        public void TestAuthExecute()
        {
            TestDIContext customDIContext                    = TestDIContextFactory.CreateContext(GetPrincipal("Admin"));
            IDataPortal <PermissionsRoot> dataPortal         = customDIContext.CreateDataPortal <PermissionsRoot>();
            ApplicationContext            applicationContext = customDIContext.CreateTestApplicationContext();

            TestResults.Reinitialise();

            PermissionsRoot pr = dataPortal.Create();

            //should work, because we are now logged in as an admin
            pr.DoWork();

            Assert.AreEqual(true, applicationContext.Principal.IsInRole("Admin"));

            //set to null so the other testmethods continue to throw exceptions
            applicationContext.User = new ClaimsPrincipal();

            Assert.AreEqual(false, applicationContext.Principal.IsInRole("Admin"));
        }
Ejemplo n.º 16
0
        public void UpdateTransactionScope()
        {
            TestDIContext testDIContext = TestDIContextFactory.CreateContext(
                opts => opts.DataPortal(dp => dp.AddServerSideDataPortal(cfg => cfg.RegisterObjectFactoryLoader <ObjectFactoryLoader <RootFactory1> >()))
                );
            IDataPortal <Root> dataPortal = testDIContext.CreateDataPortal <Root>();

            var root = dataPortal.Fetch();

            root.Data = "abc";

            root = dataPortal.Update(root);
            Assert.AreEqual(TransactionalTypes.TransactionScope, root.TransactionalType, "Transactional type should match");
            Assert.AreEqual("Serializable", root.IsolationLevel, "Transactional isolation should match");
            Assert.AreEqual(30, root.TransactionTimeout, "Transactional timeout should match");

            Assert.AreEqual("Update", root.Data, "Data should match");
            Assert.IsFalse(root.IsNew, "Should not be new");
            Assert.IsFalse(root.IsDirty, "Should not be dirty");
        }
Ejemplo n.º 17
0
        public void CreateMissing()
        {
            TestDIContext testDIContext = TestDIContextFactory.CreateContext(
                // TODO: What proxy can we use for this test? Old one was Remoting, now retired
                //  options => options.Services.AddTransient<DataPortalClient.IDataPortalProxy, Testing.Business.TestProxies.AppDomainProxy>(),
                opts => opts.DataPortal(dp => dp.AddServerSideDataPortal(cfg => cfg.RegisterObjectFactoryLoader <ObjectFactoryLoader <RootFactory1> >())),
                new System.Security.Claims.ClaimsPrincipal()
                );

            IDataPortal <Root> dataPortal = testDIContext.CreateDataPortal <Root>();

            try
            {
                var root = dataPortal.Create("abc", 123);
            }
            catch (DataPortalException ex)
            {
                throw ex.BusinessException;
            }
        }
Ejemplo n.º 18
0
        public void TestAuthorizationAfterEditCycle()
        {
            TestDIContext customDIContext                    = TestDIContextFactory.CreateContext(GetPrincipal("Admin"));
            IDataPortal <PermissionsRoot> dataPortal         = customDIContext.CreateDataPortal <PermissionsRoot>();
            ApplicationContext            applicationContext = customDIContext.CreateTestApplicationContext();

            TestResults.Reinitialise();

            PermissionsRoot pr = dataPortal.Create();

            pr.FirstName = "something";

            pr.BeginEdit();
            pr.FirstName = "ba";
            pr.CancelEdit();

            applicationContext.User = new ClaimsPrincipal();

            PermissionsRoot prClone = pr.Clone();

            applicationContext.User = GetPrincipal("Admin");
            prClone.FirstName       = "somethiansdfasdf";
        }
Ejemplo n.º 19
0
        public void TestAuthBeginEditRules()
        {
            Guid          managerInstanceId;
            TestDIContext customDIContext = TestDIContextFactory.CreateContext(GetPrincipal("Admin"));
            IDataPortal <DataPortal.DpRoot> dataPortal = customDIContext.CreateDataPortal <DataPortal.DpRoot>();
            ApplicationContext applicationContext      = customDIContext.CreateTestApplicationContext();

            TestResults.Reinitialise();

            DataPortal.DpRoot root = dataPortal.Create(new DataPortal.DpRoot.Criteria());

            Assert.AreEqual(true, applicationContext.Principal.IsInRole("Admin"));

            root.Data = "Something new";

            root.BeginEdit();

            #region "Pre-Testing"

            root.Data = "Something new 1";

            //Is it denying read properly?
            managerInstanceId = ((ApplicationContextManagerUnitTests)applicationContext.ContextManager).InstanceId;
            Debug.WriteLine(managerInstanceId);
            string result = root.DenyReadOnProperty;
            //Assert.AreEqual(managerInstanceId.ToString(), result);
            Assert.AreEqual("[DenyReadOnProperty] Can't read property", root.DenyReadOnProperty,
                            "Read should have been denied");

            //Is it denying write properly?
            root.DenyWriteOnProperty = "DenyWriteOnProperty";

            Assert.AreEqual("[DenyWriteOnProperty] Can't write variable", root.Auth,
                            "Write should have been denied");

            //Is it denying both read and write properly?
            Assert.AreEqual("[DenyReadWriteOnProperty] Can't read property", root.DenyReadWriteOnProperty,
                            "Read should have been denied");

            root.DenyReadWriteOnProperty = "DenyReadWriteONproperty";

            Assert.AreEqual("[DenyReadWriteOnProperty] Can't write variable", root.Auth,
                            "Write should have been denied");

            //Is it allowing both read and write properly?
            Assert.AreEqual(root.AllowReadWriteOnProperty, root.Auth,
                            "Read should have been allowed");

            root.AllowReadWriteOnProperty = "No value";
            Assert.AreEqual("No value", root.Auth,
                            "Write should have been allowed");

            #endregion

            #region "Cancel Edit"

            //Cancel the edit and see if the authorization rules still work
            root.CancelEdit();

            //Is it denying read properly?
            Assert.AreEqual("[DenyReadOnProperty] Can't read property", root.DenyReadOnProperty,
                            "Read should have been denied");

            //Is it denying write properly?
            root.DenyWriteOnProperty = "DenyWriteOnProperty";

            Assert.AreEqual("[DenyWriteOnProperty] Can't write variable", root.Auth,
                            "Write should have been denied");

            //Is it denying both read and write properly?
            Assert.AreEqual("[DenyReadWriteOnProperty] Can't read property", root.DenyReadWriteOnProperty,
                            "Read should have been denied");

            root.DenyReadWriteOnProperty = "DenyReadWriteONproperty";

            Assert.AreEqual("[DenyReadWriteOnProperty] Can't write variable", root.Auth,
                            "Write should have been denied");

            //Is it allowing both read and write properly?
            Assert.AreEqual(root.AllowReadWriteOnProperty, root.Auth,
                            "Read should have been allowed");

            root.AllowReadWriteOnProperty = "No value";
            Assert.AreEqual("No value", root.Auth,
                            "Write should have been allowed");

            #endregion

            #region "Apply Edit"

            //Apply this edit and see if the authorization rules still work
            //Is it denying read properly?
            Assert.AreEqual("[DenyReadOnProperty] Can't read property", root.DenyReadOnProperty,
                            "Read should have been denied");

            //Is it denying write properly?
            root.DenyWriteOnProperty = "DenyWriteOnProperty";

            Assert.AreEqual("[DenyWriteOnProperty] Can't write variable", root.Auth,
                            "Write should have been denied");

            //Is it denying both read and write properly?
            Assert.AreEqual("[DenyReadWriteOnProperty] Can't read property", root.DenyReadWriteOnProperty,
                            "Read should have been denied");

            root.DenyReadWriteOnProperty = "DenyReadWriteONproperty";

            Assert.AreEqual("[DenyReadWriteOnProperty] Can't write variable", root.Auth,
                            "Write should have been denied");

            //Is it allowing both read and write properly?
            Assert.AreEqual(root.AllowReadWriteOnProperty, root.Auth,
                            "Read should have been allowed");

            root.AllowReadWriteOnProperty = "No value";
            Assert.AreEqual("No value", root.Auth,
                            "Write should have been allowed");


            #endregion
        }
Ejemplo n.º 20
0
 public static void ClassInitialize(TestContext context)
 {
     _anonymousDIContext = TestDIContextFactory.CreateContext(new ClaimsPrincipal());
     _adminDIContext     = TestDIContextFactory.CreateContext(GetPrincipal("Admin"));
 }
Ejemplo n.º 21
0
 public static void ClassInitialize(TestContext context)
 {
     _testDIContext            = TestDIContextFactory.CreateDefaultContext();
     _noCloneOnUpdateDIContext = TestDIContextFactory.CreateContext(opt => opt.DataPortal(cfg => cfg.AutoCloneOnUpdate(false)));
 }