Esempio n. 1
0
    public void Test_ObjectsChangeTracker_GetChanges_RegisterObject()
    {
        var tracker = new ObjectsChangeTracker();
        var a       = new A();

        tracker.RegisterObject(a);
        a.F2 = 3;
        var changes = tracker.GetChanges(a);

        changes[0].Name.ShouldBe(nameof(A.F2));
        tracker.RegisterObject(a);
        changes = tracker.GetChanges(a);
        changes.Length.ShouldBe(0);

        a.F1 = "new";
        a.F2 = 13;
        a.F3 = false;

        for (var i = 0; i < 10; ++i)
        {
            tracker.GetChanges(a);
        }

        changes = tracker.GetChanges(a);

        changes.Select(c => c.Name).ShouldBe(new[] { "F1", "F2", "F3" });

        changes = tracker.GetChanges(new A());
        Assert.Null(changes);
    }
Esempio n. 2
0
        public void UpdateCustomer()
        {
            ObjectMapperManager objMan = new ObjectMapperManager();

            Guid guid = Guid.NewGuid();

            using (var ts = new TransactionScope())
                using (var connection = CreateConnection())
                {
                    var customer = DBTools.ExecuteReader(
                        connection,
                        "select top 1 * from [dbo].[Customers]",
                        null,
                        r => r.ToObject <Customer>()
                        );

                    var tracker = new ObjectsChangeTracker();
                    tracker.RegisterObject(customer);
                    customer.Address = guid.ToString();

                    DBTools.UpdateObject(
                        connection,
                        customer,
                        "Customers",
                        new[] { "CustomerID" },
                        tracker,
                        DbSettings.MSSQL
                        );
                }
        }
Esempio n. 3
0
    // [Fact]
    /// <summary>
    ///   Updates the customer.
    /// </summary>
    public void UpdateCustomer()
    {
        var objMan = new Mapper();

        var guid = Guid.NewGuid();

        // todo: there is a bug , In the callstack of DBTools and DataReaderToObjectMapper occur two times Reader.Read(); so..
        using var ts         = new TransactionScope();
        using var connection = CreateConnection();

        var customer = DbTools.ExecuteReader(
            connection,
            "select * from Customers limit 1 ",
            null,
            r => r.ToObject <Customer>());

        customer.ShouldNotBeNull();

        var tracker = new ObjectsChangeTracker();

        tracker.RegisterObject(customer);
        customer.Address = guid.ToString();

        var result = DbTools.UpdateObject(
            connection,
            customer,
            "Customers",
            new[] { "CustomerID" },
            tracker,
            DbSettings.Mssql);

        result.Result.ShouldBe(1);
    }
Esempio n. 4
0
    /// <summary>
    ///   Reads the single.
    /// </summary>
    /// <param name="reader">The reader.</param>
    /// <param name="changeTracker">The change tracker.</param>
    /// <returns>`0.</returns>
    public TEntity ReadSingle(IDataReader reader, ObjectsChangeTracker changeTracker)
    {
        var result = MapUsingState(reader, reader);

        changeTracker?.RegisterObject(result);

        return(result);
    }
Esempio n. 5
0
        public void EntryUpdateStack()
        {
            var cc = _tracker.GetChanges(this);

            _oldValues = new Dictionary <string, object>();
            foreach (var trackingMember in cc)
            {
                _oldValues.Add(trackingMember.name, trackingMember.value);
            }
            _tracker.RegisterObject(this);
        }
Esempio n. 6
0
        public void UpdateCustomer()
        {
            ObjectMapperManager objMan = new ObjectMapperManager();

            Guid guid = Guid.NewGuid();

            // todo: there is a bug , In the callstack of DBTools and DataReaderToObjectMapper ocur two times Reader.Read(); so..

            using (var ts = new TransactionScope())
                using (var connection = CreateConnection())
                {
                    var customer = DBTools.ExecuteReader(
                        connection,
                        "select * from Customers limit 1 ",
                        null,
                        r => r.ToObject <Customer>()
                        );
                    Assert.IsNotNull(customer);



                    var tracker = new ObjectsChangeTracker();
                    tracker.RegisterObject(customer);
                    customer.Address = guid.ToString();

                    var result = DBTools.UpdateObject(
                        connection,
                        customer,
                        "Customers",
                        new[] { "CustomerID" },
                        tracker,
                        DbSettings.MSSQL
                        );
                    Assert.IsTrue(result.Result == 1);
                }
        }
Esempio n. 7
0
 protected BaseEntity()
 {
     _tracker = new ObjectsChangeTracker();
     _tracker.RegisterObject(this);
 }