Пример #1
0
        public void AuditUsingSpecificTypeAuditorUpdateQux()
        {
            MyDefaultAuditor.SetCallbacksExpected();
            QuxAuditor.SetCallbacksExpected();
            var qux = GetTestService("Quxes").GetAction("New Instance").InvokeReturnObject();

            qux.Save();
            MyDefaultAuditor.SetCallbacksUnexpected();
            QuxAuditor.SetCallbacksUnexpected();

            var quxUpdatedCount = 0;

            var newValue = Guid.NewGuid().ToString();

            QuxAuditor.Auditor.objectUpdatedCallback = (p, o) => {
                Assert.AreEqual("sven", p.Identity.Name);
                Assert.IsNotNull(o);
                Assert.AreEqual("NakedObjects.SystemTest.Audit.Qux", o.GetType().GetProxiedType().FullName);
                Assert.AreEqual(newValue, ((Qux)o).Prop1);
                quxUpdatedCount++;
            };

            NakedObjectsFramework.TransactionManager.StartTransaction();

            qux.GetPropertyByName("Prop1").SetValue(newValue);

            NakedObjectsFramework.TransactionManager.EndTransaction();
            Assert.AreEqual(1, quxUpdatedCount, "expect qux auditor to be called for updates");
        }
        public void DefaultAuditorCalledForNonSpecificTypeUpdate()
        {
            MyDefaultAuditor.SetActionCallbacksExpected();
            ITestObject bar = GetTestService("Bars").GetAction("New Instance").InvokeReturnObject();

            MyDefaultAuditor.SetActionCallbacksUnexpected();

            int defaultUpdatedCount   = 0;
            int defaultPersistedCount = 0;

            string newValue = Guid.NewGuid().ToString();

            MyDefaultAuditor.Auditor.objectPersistedCallback = (p, o) => {
                Assert.AreEqual("sven", p.Identity.Name);
                Assert.IsNotNull(o);
                Assert.AreEqual("NakedObjects.SystemTest.Audit.Bar", o.GetType().GetProxiedType().FullName);
                Assert.IsNull(((Bar)o).Prop1);
                defaultPersistedCount++;
            };

            bar.Save();

            MyDefaultAuditor.Auditor.objectUpdatedCallback = (p, o) => {
                Assert.AreEqual("sven", p.Identity.Name);
                Assert.IsNotNull(o);
                Assert.AreEqual("NakedObjects.SystemTest.Audit.Bar", o.GetType().GetProxiedType().FullName);
                Assert.AreEqual(newValue, ((Bar)o).Prop1);
                defaultUpdatedCount++;
            };
            NakedObjectsFramework.TransactionManager.StartTransaction();
            bar.GetPropertyByName("Prop1").SetValue(newValue);
            NakedObjectsFramework.TransactionManager.EndTransaction();
            Assert.AreEqual(1, defaultUpdatedCount, "expect default auditor to be called for updates");
            Assert.AreEqual(1, defaultPersistedCount, "expect default auditor to be called for persists");
        }
        public void DefaultAuditorCalledForNonSpecificTypeServiceAction()
        {
            ITestService bar = GetTestService(typeof(SimpleRepository <Bar>));

            MyDefaultAuditor.SetActionCallbacksUnexpected();

            int defaultCalledCount = 0;

            MyDefaultAuditor.Auditor.serviceActionInvokedCallback = (p, a, s, b, pp) => {
                Assert.AreEqual("sven", p.Identity.Name);
                Assert.AreEqual("NewInstance", a);
                Assert.AreEqual("Bars", s);
                Assert.IsFalse(b);
                Assert.AreEqual(0, pp.Length);
                defaultCalledCount++;
            };

            bar.GetAction("New Instance").InvokeReturnObject();
            Assert.AreEqual(1, defaultCalledCount, "expect default auditor to be called");
        }
        public void AuditUsingSpecificTypeAuditorServiceActionQux()
        {
            ITestService qux = GetTestService("Qux Service");

            MyDefaultAuditor.SetActionCallbacksUnexpected();

            int quxCalledCound = 0;

            QuxAuditor.Auditor.serviceActionInvokedCallback = (p, a, s, b, pp) => {
                Assert.AreEqual("sven", p.Identity.Name);
                Assert.AreEqual("AnAction", a);
                Assert.AreEqual("Qux Service", s);
                Assert.IsFalse(b);
                Assert.AreEqual(0, pp.Length);
                quxCalledCound++;
            };

            qux.GetAction("An Action").InvokeReturnObject();
            Assert.AreEqual(1, quxCalledCound, "expect qux auditor to be called");
        }
        public void AuditUsingSpecificTypeAuditorServiceAction()
        {
            ITestService foo = GetTestService("Foo Service");

            MyDefaultAuditor.SetActionCallbacksUnexpected();

            int fooCalledCount = 0;

            FooAuditor.Auditor.serviceActionInvokedCallback = (p, a, s, b, pp) => {
                Assert.AreEqual("sven", p.Identity.Name);
                Assert.AreEqual("AnAction", a);
                Assert.AreEqual("Foo Service", s);
                Assert.IsFalse(b);
                Assert.AreEqual(0, pp.Length);
                fooCalledCount++;
            };

            foo.GetAction("An Action").InvokeReturnObject();
            Assert.AreEqual(1, fooCalledCount, "expect foo auditor to be called");
        }
Пример #6
0
        public void DefaultAuditorCalledForNonSpecificTypePersist()
        {
            MyDefaultAuditor.SetCallbacksExpected();
            var bar = GetTestService("Bars").GetAction("New Instance").InvokeReturnObject();

            MyDefaultAuditor.SetCallbacksUnexpected();

            var defaultPersistedCount = 0;

            MyDefaultAuditor.Auditor.objectPersistedCallback = (p, o) => {
                Assert.AreEqual("sven", p.Identity?.Name);
                Assert.IsNotNull(o);
                Assert.AreEqual("NakedObjects.SystemTest.Audit.Bar", o.GetType().GetProxiedType().FullName);
                Assert.IsNull(((Bar)o).Prop1);
                defaultPersistedCount++;
            };

            bar.Save();

            Assert.AreEqual(1, defaultPersistedCount, "expect default auditor to be called for persists");
        }
Пример #7
0
        public void AuditUsingSpecificTypeAuditorPersistQux()
        {
            MyDefaultAuditor.SetCallbacksExpected();
            var qux = GetTestService("Quxes").GetAction("New Instance").InvokeReturnObject();

            MyDefaultAuditor.SetCallbacksUnexpected();

            var quxPersistedCount = 0;

            QuxAuditor.Auditor.objectPersistedCallback = (p, o) => {
                Assert.AreEqual("sven", p.Identity?.Name);
                Assert.IsNotNull(o);
                Assert.AreEqual("NakedObjects.SystemTest.Audit.Qux", o.GetType().GetProxiedType().FullName);
                Assert.IsNull(((Qux)o).Prop1);
                quxPersistedCount++;
            };

            qux.Save();

            Assert.AreEqual(1, quxPersistedCount, "expect qux auditor to be called for persists");
        }
        public void DefaultAuditorCalledForNonSpecificTypeAction()
        {
            MyDefaultAuditor.SetActionCallbacksExpected();
            ITestObject bar = GetTestService(typeof(SimpleRepository <Bar>)).GetAction("New Instance").InvokeReturnObject();

            MyDefaultAuditor.SetActionCallbacksUnexpected();

            int defaultCalledCount = 0;

            MyDefaultAuditor.Auditor.actionInvokedCallback = (p, a, o, b, pp) => {
                Assert.AreEqual("sven", p.Identity.Name);
                Assert.AreEqual("AnAction", a);
                Assert.IsNotNull(o);
                Assert.AreEqual("NakedObjects.SystemTest.Audit.Bar", o.GetType().GetProxiedType().FullName);
                Assert.IsFalse(b);
                Assert.AreEqual(0, pp.Length);
                defaultCalledCount++;
            };

            bar.GetAction("An Action").InvokeReturnObject();
            Assert.AreEqual(1, defaultCalledCount, "expect default auditor to be called");
        }
        public void AuditUsingSpecificTypeAuditorActionQux()
        {
            MyDefaultAuditor.SetActionCallbacksExpected();
            ITestObject qux = GetTestService("Quxes").GetAction("New Instance").InvokeReturnObject();

            MyDefaultAuditor.SetActionCallbacksUnexpected();

            int quxCalledCound = 0;

            QuxAuditor.Auditor.actionInvokedCallback = (p, a, o, b, pp) => {
                Assert.AreEqual("sven", p.Identity.Name);
                Assert.AreEqual("AnAction", a);
                Assert.IsNotNull(o);
                Assert.AreEqual("NakedObjects.SystemTest.Audit.Qux", o.GetType().FullName);
                Assert.IsFalse(b);
                Assert.AreEqual(0, pp.Length);
                quxCalledCound++;
            };

            qux.GetAction("An Action").InvokeReturnObject();
            Assert.AreEqual(1, quxCalledCound, "expect qux auditor to be called");
        }
        public void AuditUsingSpecificTypeAuditorImplicitQueryOnlyAction()
        {
            MyDefaultAuditor.SetActionCallbacksExpected();
            ITestObject foo = GetTestService("Foos").GetAction("New Instance").InvokeReturnObject();

            MyDefaultAuditor.SetActionCallbacksUnexpected();

            int fooCalledCount = 0;

            FooAuditor.Auditor.actionInvokedCallback = (p, a, o, b, pp) => {
                Assert.AreEqual("sven", p.Identity.Name);
                Assert.AreEqual("AnotherQueryOnlyAction", a);
                Assert.IsNotNull(o);
                Assert.AreEqual("NakedObjects.SystemTest.Audit.Foo", o.GetType().FullName);
                Assert.IsTrue(b);
                Assert.AreEqual(0, pp.Length);
                fooCalledCount++;
            };

            foo.GetAction("Another Query Only Action").InvokeReturnCollection();
            Assert.AreEqual(1, fooCalledCount, "expect foo auditor to be called");
        }
Пример #11
0
        public void AuditUsingSpecificTypeAuditorActionWithParm()
        {
            MyDefaultAuditor.SetActionCallbacksExpected();
            ITestObject foo = GetTestService("Foos").GetAction("New Instance").InvokeReturnObject();

            MyDefaultAuditor.SetActionCallbacksUnexpected();

            int fooCalledCount = 0;

            FooAuditor.Auditor.actionInvokedCallback = (p, a, o, b, pp) => {
                Assert.AreEqual("sven", p.Identity.Name);
                Assert.AreEqual("AnActionWithParm", a);
                Assert.IsNotNull(o);
                Assert.AreEqual("NakedObjects.SystemTest.Audit.Foo", o.GetType().FullName);
                Assert.IsFalse(b);
                Assert.AreEqual(1, pp.Count());
                Assert.AreEqual(1, pp[0]);
                fooCalledCount++;
            };

            foo.GetAction("An Action With Parm").InvokeReturnObject(1);
            Assert.AreEqual(1, fooCalledCount, "expect foo auditor to be called");
        }
Пример #12
0
        public void AuditUsingSpecificTypeAuditorAction()
        {
            MyDefaultAuditor.SetCallbacksExpected();

            var foo = GetTestService(typeof(SimpleRepository <Foo>)).GetAction("New Instance").InvokeReturnObject();

            MyDefaultAuditor.SetCallbacksUnexpected();

            var fooCalledCount = 0;

            FooAuditor.Auditor.actionInvokedCallback = (p, a, o, b, pp) => {
                Assert.AreEqual("sven", p.Identity.Name);
                Assert.AreEqual("AnAction", a);
                Assert.IsNotNull(o);
                Assert.AreEqual("NakedObjects.SystemTest.Audit.Foo", o.GetType().FullName);
                Assert.IsFalse(b);
                Assert.AreEqual(0, pp.Length);
                fooCalledCount++;
            };

            foo.GetAction("An Action").InvokeReturnObject();
            Assert.AreEqual(1, fooCalledCount, "expect foo auditor to be called");
        }
        public void AuditUsingSpecificTypeAuditorServiceActionWithParms()
        {
            MyDefaultAuditor.SetActionCallbacksExpected();
            ITestService foo    = GetTestService("Foo Service");
            ITestObject  fooObj = GetTestService("Foos").GetAction("New Instance").InvokeReturnObject();

            MyDefaultAuditor.SetActionCallbacksUnexpected();

            int fooCalledCount = 0;

            FooAuditor.Auditor.serviceActionInvokedCallback = (p, a, s, b, pp) => {
                Assert.AreEqual("sven", p.Identity.Name);
                Assert.AreEqual("AnActionWithParms", a);
                Assert.AreEqual("Foo Service", s);
                Assert.IsFalse(b);
                Assert.AreEqual(2, pp.Length);
                Assert.AreEqual(1, pp[0]);
                Assert.AreSame(fooObj.NakedObject.Object, pp[1]);
                fooCalledCount++;
            };

            foo.GetAction("An Action With Parms").InvokeReturnObject(1, fooObj);
            Assert.AreEqual(1, fooCalledCount, "expect foo auditor to be called");
        }