Ejemplo n.º 1
0
        public void TestSetMemento()
        {
            IDomainObjectMementoService service = DomainObjectMementoService.GetInstance();
            Customer customer = new Customer(null)
            {
                Name = "John Doe", Number = "123"
            };
            IDomainObjectMemento snapshotMemento = service.CreateMemento(customer);

            //Test original
            Assert.AreEqual("John Doe", customer.Name);
            Assert.AreEqual("123", customer.Number);

            //Alter
            customer.Name   = "Juan dela Cruz";
            customer.Number = "345";

            //Test altered persistency
            Assert.AreEqual("Juan dela Cruz", customer.Name);
            Assert.AreEqual("345", customer.Number);

            //Restore
            IDomainObject domainObject = customer;

            service.SetMemento(ref domainObject, snapshotMemento);

            //Test original
            IDomainObjectMemento latestSnapshotMemento = service.CreateMemento(customer);

            Assert.AreEqual("John Doe", customer.Name);
            Assert.AreEqual("123", customer.Number);
            Assert.AreEqual(snapshotMemento.HashCode, latestSnapshotMemento.HashCode);
        }
Ejemplo n.º 2
0
        public void TestCreateMemento()
        {
            IDomainObjectMementoService service = DomainObjectMementoService.GetInstance();
            Customer customer = new Customer(null)
            {
                Name = "John Doe", Number = "123"
            };
            IDomainObjectMemento memento = service.CreateMemento(customer);

            Assert.AreEqual("John Doe", memento.GetPropertyValue("Name"));
            Assert.AreEqual("123", memento.GetPropertyValue("Number"));
        }
Ejemplo n.º 3
0
        public void SetMemento <TEntity>(ref TEntity entity, IDomainObjectMemento memento)
            where TEntity : IDomainObject
        {
            if (entity == null)
            {
                throw new ArgumentNullException("'entity' parameter is required");
            }

            if (memento == null)
            {
                throw new ArgumentNullException("'memento' parameter is required");
            }

            IList <string> propertyNames = memento.GetPropertyNames();

            for (int index = 0; index < propertyNames.Count; index++)
            {
                memento.SetPropertyValue(propertyNames[index], ref entity);
            }
        }