public static void ClassInitialize(TestContext context) { _testDIContext = TestDIContextFactory.CreateContext( options => options.DataPortal(dp => dp.AddServerSideDataPortal( cfg => cfg.RegisterObjectFactoryLoader <ObjectFactoryLoader <RootFactory> >()) )); }
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(); }
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"); }
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"; }
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"); } }
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))); }
public static void ClassInitialize(TestContext context) { _testDIContext = TestDIContextFactory.CreateContext( options => options .DataPortal(dp => dp.AddServerSideDataPortal(config => { config.AddInterceptorProvider <TestInterceptor>(); config.RegisterActivator <TestActivator>(); } ))); }
public static void ClassInitialize(TestContext context) { _testDIContext = TestDIContextFactory.CreateContext(options => { options.Services.AddTransient <TestableDataPortal>(); options.DataPortal( dp => dp.AddServerSideDataPortal( config => config.RegisterAuthorizerProvider <AuthorizeDataPortalStub>()) ); }); }
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)); }
public void DataPortalExecute_OnCommandObjectWithLocalProxy_CallsFactoryExecute() { TestDIContext testDIContext = TestDIContextFactory.CreateDefaultContext(); IDataPortal <CommandObject> dataPortal = testDIContext.CreateDataPortal <CommandObject>(); TestResults.Reinitialise(); var test = CommandObject.Execute(dataPortal); // return value is set in Execute method in CommandObjectFactory Assert.IsTrue(test); }
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"); }
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(); }
public void FetchLoadProperty() { TestDIContext testDIContext = TestDIContextFactory.CreateDefaultContext(); // TODO: Not sure how to have a generic factory loader now an ApplicationContext is required on the class :-( //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"); }
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"); }
public void CommandOverDataPortal() { TestDIContext customDIContext = TestDIContextFactory.CreateDefaultContext(); // TODO: Get this custom proxy code included and working //TestDIContext customDIContext = TestDIContextFactory.CreateContext( //options => options //.Services.AddTransient<DataPortalClient.IDataPortalProxy, Csla.Testing.Business.TestProxies.AppDomainProxy>() //); IDataPortal <TestCommand> dataPortal = customDIContext.CreateDataPortal <TestCommand>(); var cmd = dataPortal.Create(); cmd.Name = "test data"; var result = dataPortal.Execute(cmd); Assert.IsFalse(ReferenceEquals(cmd, result), "References should not match"); Assert.AreEqual(cmd.Name + " server", result.Name); }
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 { } }
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(); }
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")); }
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"); }
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; } }
public void DataPortalExecute_OnCommandObjectWithFalseExecuteMethod_ThrowsExeptionMehodNotFound() { TestDIContext testDIContext = TestDIContextFactory.CreateDefaultContext(); IDataPortal <CommandObjectMissingFactoryMethod> dataPortal = testDIContext.CreateDataPortal <CommandObjectMissingFactoryMethod>(); try { TestResults.Reinitialise(); var test = CommandObjectMissingFactoryMethod.Execute(dataPortal); } catch (DataPortalException ex) { // inner exception should be System.NotImplementedException and mesaage should contain methodname Assert.AreEqual(typeof(System.NotImplementedException), ex.InnerException.GetType()); Assert.IsTrue(ex.InnerException.Message.Contains("ExecuteMissingMethod")); // rethrow exception throw; } Assert.Fail("Should throw exception"); }
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"; }
public static void ClassInitialize(TestContext context) { _anonymousDIContext = TestDIContextFactory.CreateContext(new ClaimsPrincipal()); _adminDIContext = TestDIContextFactory.CreateContext(GetPrincipal("Admin")); }
public static void ClassInitialize(TestContext context) { _testDIContext = TestDIContextFactory.CreateDefaultContext(); _noCloneOnUpdateDIContext = TestDIContextFactory.CreateContext(opt => opt.DataPortal(cfg => cfg.AutoCloneOnUpdate(false))); }
public static void ClassInitialize(TestContext testContext) { _testDIContext = TestDIContextFactory.CreateDefaultContext(); }
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 }