示例#1
0
        public void TestCreateEntity( )
        {
            var c = new Report
            {
                Name = "EDC"
            };

            c.Save( );

            var p = new ReportColumn
            {
                Name            = "Col1",
                ColumnForReport = c
            };

            p.Save( );

            Assert.IsNotNull(c);
            Assert.IsNotNull(p);

            p.Delete( );
            c.Delete( );

            p = (ReportColumn)Entity.Get(p.Id, false);
            c = (Report)Entity.Get(c.Id, false);

            Assert.IsNull(p);
            Assert.IsNull(c);
        }
示例#2
0
        public void TestRelationshipEnumeratorForReadableRead( )
        {
            var deleteList = new List <EntityRef>( );

            try
            {
                var edc = new Report
                {
                    Name = "EDC"
                };
                edc.Save( );
                deleteList.Add(edc);

                var jude = new ReportColumn
                {
                    Name            = "Jude",
                    Alias           = "edc:jude",
                    ColumnForReport = edc
                };
                jude.Save( );
                deleteList.Add(jude);

                var pete = new ReportColumn
                {
                    Name            = "Pete",
                    Alias           = "edc:pete",
                    ColumnForReport = edc
                };
                pete.Save( );
                deleteList.Add(pete);

                Assert.AreEqual(2, edc.ReportColumns.Count);

                IEnumerator <ReportColumn> inumerator = edc.ReportColumns.GetEnumerator( );

                var writableEdc = Entity.Get <Report>(edc.Id, true);

                writableEdc.ReportColumns.Clear( );
                writableEdc.Save( );

                int count = 0;
                while (inumerator.MoveNext( ))
                {
                    count++;
                    ReportColumn referenced = inumerator.Current;
                    Assert.IsNotNull(referenced, "The referenced object is still there.");
                }

                Assert.AreEqual(2, count, "We still have two things in the iterator.");
            }
            finally
            {
                Entity.Delete(deleteList);
            }
        }
示例#3
0
        public void TestWritableRelationshipsClearTheReadCacheOnSave( )
        {
            var deleteList = new List <EntityRef>( );

            try
            {
                var edc = new Report
                {
                    Name = "EDC"
                };
                edc.Save( );
                deleteList.Add(edc);

                var jude = new ReportColumn
                {
                    Name  = "Jude",
                    Alias = "edc:jude"
                };
                jude.Save( );
                deleteList.Add(jude);

                var writeableJude = Entity.Get <ReportColumn>(jude.Id, true);
                edc = Entity.Get <Report>(edc.Id);

                writeableJude.ColumnForReport = edc;

                var shadowJude = Entity.Get <ReportColumn>(jude.Id);
                Assert.AreNotEqual(shadowJude.ColumnForReport, writeableJude.ColumnForReport, "writable copies are not shared");

                writeableJude.Save( );

                Assert.IsNotNull(shadowJude.ColumnForReport, "Readable relationships should be updated when a write on the related obejects occur.");

                var readableJude = Entity.Get <ReportColumn>(jude.Id);

                Assert.IsNotNull(readableJude.ColumnForReport, "Should have been updated");

                Assert.AreEqual(shadowJude.ColumnForReport.Id, readableJude.ColumnForReport.Id, "Readable copies are shared and are flushed and updated when saves occur that overlap with them");
            }
            finally
            {
                Entity.Delete(deleteList);
            }
        }
示例#4
0
        public void TestCachingReadOnlyEntityIgnoreWrites( )
        {
            // Note: in order to remove dependencies on 'Shared' objects, the following changes were made in this test:
            // 'Organisation' got changed to 'Report'
            // 'Employee' got changed to 'ReportColumn'
            // 'WorksFor' got changed to 'ColumnForReport'

            var organisationA = new Report( );

            organisationA.Save( );

            var organisationB = new Report();

            organisationB.Save( );

            var organisationC = new Report();

            organisationC.Save( );

            var employee = new ReportColumn
            {
                Name            = "Initial Name",
                ColumnForReport = organisationA
            };

            employee.Save( );

            using (new EntitySnapshotContext( ))
            {
                // This will cache the employee
                var readOnlyEmployee = Entity.Get <ReportColumn>(employee.Id);

                EntitySnapshotContextData snaphotData = EntitySnapshotContext.GetContextData( );

                IEntity cachedEntity;
                Assert.IsTrue(snaphotData.TryGetEntity(readOnlyEmployee.Id, out cachedEntity), "The entity should be cached");
                Assert.AreEqual("Initial Name", readOnlyEmployee.Name, "The name of the read only employee is invalid");
                Assert.AreEqual(organisationA.Id, readOnlyEmployee.ColumnForReport.Id, "The organisation of the read only employee is invalid");

                // Get a writable copy and change the name & organisation
                var writeableEmployee = readOnlyEmployee.AsWritable <ReportColumn>();
                writeableEmployee.Name            = "New Name";
                writeableEmployee.ColumnForReport = organisationB;
                writeableEmployee.Save( );

                // Ensure that requesting a read only employee returns the cached one
                readOnlyEmployee = Entity.Get <ReportColumn>(employee.Id);
                Assert.AreEqual("Initial Name", readOnlyEmployee.Name);
                Assert.AreEqual(organisationA.Id, readOnlyEmployee.ColumnForReport.Id, "The organisation of the read only employee is invalid");

                // Ensure that requesting a writeable employee returns the new one
                writeableEmployee = Entity.Get <ReportColumn>(employee.Id, true);
                Assert.AreEqual("New Name", writeableEmployee.Name);
                Assert.AreEqual(organisationB.Id, writeableEmployee.ColumnForReport.Id, "The organisation of the writeable employee is invalid");
            }

            // This will cache the employee
            var readOnlyEmployee2 = Entity.Get <ReportColumn>(employee.Id);

            Assert.AreEqual("New Name", readOnlyEmployee2.Name);
            Assert.AreEqual(organisationB.Id, readOnlyEmployee2.ColumnForReport.Id, "The organisation of the read only employee is invalid");

            // Get a writable copy and change the name
            var writeableEmployee2 = readOnlyEmployee2.AsWritable <ReportColumn>();

            writeableEmployee2.Name            = "New Name2";
            writeableEmployee2.ColumnForReport = organisationC;
            writeableEmployee2.Save( );

            // Ensure that requesting a read only employee returns the new one
            readOnlyEmployee2 = Entity.Get <ReportColumn>(employee.Id);
            Assert.AreEqual("New Name2", readOnlyEmployee2.Name);
            Assert.AreEqual(organisationC.Id, readOnlyEmployee2.ColumnForReport.Id, "The organisation of the read only employee is invalid");

            // Ensure that requesting a writeable employee returns the new one
            writeableEmployee2 = Entity.Get <ReportColumn>(employee.Id, true);
            Assert.AreEqual("New Name2", writeableEmployee2.Name);
            Assert.AreEqual(organisationC.Id, writeableEmployee2.ColumnForReport.Id, "The organisation of the writeable employee is invalid");
        }