public void TestCommandTimeoutConfig()
        {
            switch (aggTestColl.es.Connection.ProviderSignature.DataProviderName)
            {
            case "EntitySpaces.SqlClientProvider":
                // Collection
                aggTestColl = new AggregateTestCollection();
                Assert.AreEqual(39, aggTestColl.es.Connection.CommandTimeout);
                Assert.IsTrue(aggTestColl.Query.Load(), "Query.Load");
                aggTestColl = new AggregateTestCollection();
                Assert.AreEqual(39, aggTestColl.es.Connection.CommandTimeout);
                Assert.IsTrue(aggTestColl.LoadAll(), "LoadAll");

                // Entity
                aggTest = new AggregateTest();
                Assert.AreEqual(39, aggTest.es.Connection.CommandTimeout);
                aggTest.Query.es.Top = 1;
                Assert.IsTrue(aggTest.Query.Load(), "Query.Load");
                int aggKey = aggTest.Id.Value;
                aggTest = new AggregateTest();
                Assert.AreEqual(39, aggTest.es.Connection.CommandTimeout);
                Assert.IsTrue(aggTest.LoadByPrimaryKey(aggKey), "LoadByPK");
                break;

            default:
                Assert.Ignore("tested for SQL Server only");
                break;
            }
        }
        public void SerializeDeserializeLoadEntityBinary()
        {
            if (aggTest.es.Connection.Name == "SqlCe")
            {
                Assert.Ignore("Not tested for SqlCe.");
            }
            else
            {
                int key = 0;
                aggTest.Query.Where(
                    aggTest.Query.LastName == "Douglas",
                    aggTest.Query.FirstName == "Fred");
                aggTest.Query.Load();
                key = aggTest.Id.Value;

                aggTest = new AggregateTest();
                aggTest.LoadByPrimaryKey(key);

                BinaryFormatter bf = new BinaryFormatter();
                MemoryStream    ms = new MemoryStream();
                bf.Serialize(ms, aggTest);

                ms.Position = 0;
                aggClone    = (AggregateTest)bf.Deserialize(ms);
                ms.Close();

                Assert.AreEqual("Douglas", aggClone.str().LastName);
            }
        }
        public void ConfigNotReadOnly()
        {
            AggregateTest entity = new AggregateTest();

            Assert.AreEqual("AggregateDb", entity.es.Connection.Name);

            string oldDefault = esConfigSettings.ConnectionInfo.Default;

            esConfigSettings.ConnectionInfo.Default = "ForeignKeyTest";

            entity = new AggregateTest();
            Assert.AreEqual("ForeignKeyTest", entity.es.Connection.Name);

            if (entity.es.Connection.ProviderSignature.DataProviderName == "EntitySpaces.OracleClientProvider")
            {
                Assert.IsTrue(entity.es.Connection.ConnectionString.ToLower().Contains("hierarchical"));
            }
            else
            {
                Assert.IsTrue(entity.es.Connection.ConnectionString.ToLower().Contains("foreignkeytest"));
            }

            entity.es.Connection.ConnectionString = "Test";
            Assert.AreEqual("Test", entity.es.Connection.ConnectionString);

            esConfigSettings.ConnectionInfo.Default = oldDefault;
        }
        public void SerializeDeserializeFindEntityBinary()
        {
            int key = 0;

            aggTestColl.LoadAll();
            foreach (AggregateTest test in aggTestColl)
            {
                if (test.LastName == "Doe")
                {
                    key = test.Id.Value;
                    break;
                }
            }
            aggTest = aggTestColl.FindByPrimaryKey(key);

            BinaryFormatter bf = new BinaryFormatter();
            MemoryStream    ms = new MemoryStream();

            bf.Serialize(ms, aggTest);

            ms.Position = 0;
            aggClone    = (AggregateTest)bf.Deserialize(ms);
            ms.Close();

            Assert.AreEqual("Doe", aggClone.str().LastName);
        }
Пример #5
0
        public void PagingWithTop()
        {
            AggregateTestCollection collection = new AggregateTestCollection();

            if (collection.es.Connection.Name == "SqlCe" ||
                collection.es.Connection.ProviderMetadataKey ==
                "esSqlCe4" ||
                collection.es.Connection.ProviderMetadataKey ==
                "esSqlCe")
            {
                Assert.Ignore("Not tested for SqlCe.");
            }
            else
            {
                switch (collection.es.Connection.ProviderSignature.DataProviderName)
                {
                case "EntitySpaces.MSAccessProvider":
                case "EntitySpaces.VistaDBProvider":
                case "EntitySpaces.VistaDB4Provider":
                    Assert.Ignore("Not supported");
                    break;

                default:
                    AggregateTestCollection all = new AggregateTestCollection();

                    all.Query.es.Top = 20;
                    all.Query
                    .OrderBy(all.Query.LastName, esOrderByDirection.Ascending)
                    .OrderBy(all.Query.Id, esOrderByDirection.Ascending);
                    all.Query.Load();

                    collection = new AggregateTestCollection();

                    collection.Query.es.Top = 20;
                    collection.Query
                    .Select(collection.Query.Id, collection.Query.LastName, collection.Query.FirstName, collection.Query.IsActive)
                    .OrderBy(collection.Query.LastName, esOrderByDirection.Ascending)
                    .OrderBy(collection.Query.Id, esOrderByDirection.Ascending);
                    collection.Query.es.PageNumber = 1;
                    collection.Query.es.PageSize   = 8;

                    Assert.IsTrue(collection.Query.Load(), "Load 1");
                    Assert.AreEqual(8, collection.Count, "Count 1");

                    AggregateTest all0        = (AggregateTest)all[0];
                    AggregateTest collection0 = (AggregateTest)collection[0];
                    Assert.AreEqual(all0.Id.Value, collection0.Id.Value, "Compare 1");

                    collection.Query.es.PageNumber = 2;
                    Assert.IsTrue(collection.Query.Load(), "Load 2");
                    Assert.AreEqual(8, collection.Count, "Count 2");

                    all0        = (AggregateTest)all[8];
                    collection0 = (AggregateTest)collection[0];
                    Assert.AreEqual(all0.Id.Value, collection0.Id.Value, "Compare 2");

                    break;
                }
            }
        }
 public void Init2()
 {
     aggTestColl   = new AggregateTestCollection();
     aggTest       = new AggregateTest();
     aggTestQuery  = new AggregateTestQuery();
     aggCloneColl  = new AggregateTestCollection();
     aggClone      = new AggregateTest();
     aggCloneQuery = new AggregateTestQuery();
 }
Пример #7
0
        public void TestAddNewOnCollection()
        {
            aggTestColl = new AggregateTestCollection();
            Assert.IsFalse(aggTestColl.IsDirty);

            AggregateTest t = aggTestColl.AddNew();

            Assert.IsTrue(aggTestColl.IsDirty);
        }
        public void ChangeMetadata()
        {
            AggregateTest entity = new AggregateTest();

            Assert.IsTrue(entity.GetAutoKey() == true);
            entity.ToggleAutoKey();
            Assert.IsTrue(entity.GetAutoKey() == false);
            entity.ToggleAutoKey();
            Assert.IsTrue(entity.GetAutoKey() == true);
        }
        public void GetColumnWithAliasEntity()
        {
            AggregateTest entity = new AggregateTest();

            entity.Query.es.CountAll      = true;
            entity.Query.es.CountAllAlias = "Count";
            entity.Query.Load();

            Assert.AreEqual(30, Convert.ToInt32(entity.GetColumn("Count")));
        }
Пример #10
0
        public void TestRejectChangesOnCollection()
        {
            aggTestColl = new AggregateTestCollection();

            AggregateTest aggTest = aggTestColl.AddNew();

            aggTest.FirstName = "Mike";

            aggTestColl.RejectChanges();

            Assert.IsFalse(aggTestColl.IsDirty);
        }
Пример #11
0
        public void TestRejectChangesOnEntity1()
        {
            aggTest           = new AggregateTest();
            aggTest.FirstName = "Mike";
            aggTest.RejectChanges();

            Assert.IsFalse(aggTest.es.IsAdded);
            Assert.IsFalse(aggTest.es.IsDeleted);
            Assert.IsFalse(aggTest.es.IsModified);
            Assert.IsFalse(aggTest.es.IsDirty);
            Assert.IsTrue(aggTest.es.ModifiedColumns.Count == 0);
            Assert.IsTrue(aggTest.es.RowState == esDataRowState.Unchanged);
        }
Пример #12
0
        public void TestFailedTransaction()
        {
            switch (aggTest.es.Connection.Name)
            {
            case "SQLStoredProcEnterprise":
            case "SQLDynamicEnterprise":
            case "ORACLEStoredProcEnterprise":
            case "ORACLEDynamicEnterprise":
            case "VistaDBDynamic":
                Assert.Ignore("Using esTransactionScope only");
                break;

            default:
                try
                {
                    aggTest = new AggregateTest();
                    AggregateTest aggTest2  = new AggregateTest();
                    int           tempId1   = -1;
                    int           tempId2   = -1;
                    aggTest2.str().HireDate = "1/1/1";

                    using (esTransactionScope scope = new esTransactionScope())
                    {
                        try
                        {
                            aggTest.Save();
                            tempId1 = aggTest.Id.Value;
                            aggTest2.Save();
                            tempId2 = aggTest2.Id.Value;

                            throw new Exception();

                            scope.Complete();
                        }
                        catch
                        {
                        }
                    }
                    aggTest = new AggregateTest();
                    Assert.IsFalse(aggTest.LoadByPrimaryKey(tempId1));

                    aggTest = new AggregateTest();
                    Assert.IsFalse(aggTest.LoadByPrimaryKey(tempId2));
                }
                catch (Exception ex)
                {
                    Assert.Fail(ex.ToString());
                }
                break;
            }
        }
Пример #13
0
        public void PagingWithGroupBy()
        {
            AggregateTestCollection collection = new AggregateTestCollection();

            switch (collection.es.Connection.ProviderSignature.DataProviderName)
            {
            case "EntitySpaces.MSAccessProvider":
            case "EntitySpaces.SqlServerCeProvider":
            case "EntitySpaces.VistaDBProvider":
            case "EntitySpaces.VistaDB4Provider":
                Assert.Ignore("Paging Not supported");
                break;

            default:
                AggregateTestCollection all = new AggregateTestCollection();

                all.Query
                .Select(all.Query.LastName, all.Query.Salary.Avg())
                .Where(all.Query.IsActive == true)
                .GroupBy(all.Query.LastName)
                .OrderBy(all.Query.LastName, esOrderByDirection.Ascending);
                all.Query.Load();

                collection = new AggregateTestCollection();

                collection.Query
                .Select(collection.Query.LastName, collection.Query.Salary.Avg())
                .Where(collection.Query.IsActive == true)
                .GroupBy(collection.Query.LastName)
                .OrderBy(collection.Query.LastName, esOrderByDirection.Ascending);
                collection.Query.es.PageNumber = 1;
                collection.Query.es.PageSize   = 8;

                Assert.IsTrue(collection.Query.Load(), "Load 1");
                Assert.AreEqual(8, collection.Count, "Count 1");

                AggregateTest all0        = (AggregateTest)all[0];
                AggregateTest collection0 = (AggregateTest)collection[0];
                Assert.AreEqual(all0.LastName, collection0.LastName, "Compare 1");

                collection.Query.es.PageNumber = 2;
                Assert.IsTrue(collection.Query.Load(), "Load 2");
                Assert.AreEqual(2, collection.Count, "Count 2");

                all0        = (AggregateTest)all[8];
                collection0 = (AggregateTest)collection[0];
                Assert.AreEqual(all0.LastName, collection0.LastName, "Compare 2");

                break;
            }
        }
Пример #14
0
        public void TestDeleteOnCollection()
        {
            aggTestColl = new AggregateTestCollection();

            AggregateTest aggTest = aggTestColl.AddNew();

            aggTest.FirstName = "Mike";

            aggTestColl.AcceptChanges();
            Assert.IsFalse(aggTestColl.IsDirty);

            // Let's mark it as deleted
            aggTest.MarkAsDeleted();
            Assert.IsTrue(aggTestColl.IsDirty);
        }
        public void TestDateTimeMicroSeconds()
        {
            int           testId = -1;
            AggregateTest test   = new AggregateTest();

            switch (test.es.Connection.ProviderSignature.DataProviderName)
            {
            case "EntitySpaces.MSAccessProvider":
                Assert.Ignore("MS Access only resolves to MilliSeconds.");
                break;

            case "EntitySpaces.MySqlClientProvider":
                Assert.Ignore("Not supported.");
                break;

            case "EntitySpaces.SqlServerCeProvider":
            case "EntitySpaces.SqlServerCe4Provider":
            case "EntitySpaces.SqlClientProvider":
                Assert.Ignore("Requires SQL Server 2008 and datetime2 data type.");
                break;

            default:
                try
                {
                    using (esTransactionScope scope = new esTransactionScope())
                    {
                        test.HireDate = Convert.ToDateTime("1902-01-01 01:01:01.000001");
                        test.Save();
                        testId = test.Id.Value;

                        test = new AggregateTest();
                        Assert.IsTrue(test.LoadByPrimaryKey(testId));
                        Assert.AreEqual(Convert.ToDateTime("1902-01-01 01:01:01.000001"), test.HireDate.Value, "MicroSeconds");
                    }
                }
                finally
                {
                    // Clean up
                    test = new AggregateTest();
                    if (test.LoadByPrimaryKey(testId))
                    {
                        test.MarkAsDeleted();
                        test.Save();
                    }
                }
                break;
            }
        }
        public void CollectionFilterDate()
        {
            AggregateTestCollection aggTestColl = new AggregateTestCollection();

            aggTestColl.LoadAll();
            aggTestColl.Filter = aggTestColl.AsQueryable().OrderBy(s => s.Id);

            AggregateTest entity = (AggregateTest)aggTestColl[5];

            aggTestColl.Filter = aggTestColl.AsQueryable().Where(f => f.HireDate > entity.HireDate);

            Assert.AreEqual(4, aggTestColl.Count);

            aggTestColl.Filter = null;
            Assert.AreEqual(30, aggTestColl.Count);
        }
Пример #17
0
        public void TestAddNewOnEntity()
        {
            aggTest = new AggregateTest();
            Assert.IsTrue(aggTest.es.ModifiedColumns.Count == 0);
            // Assert.IsTrue(aggTest.es.RowState == esDataRowState.Detached);

            // We set a property which creates the DataTable
            aggTest.FirstName = "Mike";

            Assert.IsTrue(aggTest.es.IsAdded);
            Assert.IsFalse(aggTest.es.IsDeleted);
            Assert.IsFalse(aggTest.es.IsModified);
            Assert.IsTrue(aggTest.es.IsDirty);
            Assert.IsTrue(aggTest.es.ModifiedColumns.Count == 1);
            Assert.IsTrue(aggTest.es.RowState == esDataRowState.Added);
        }
Пример #18
0
        public void WhereLikeEscapedMultiWithSubOp()
        {
            int tempId = -1;
            AggregateTestCollection collection = new AggregateTestCollection();
            AggregateTest           aggTest    = new AggregateTest();

            switch (collection.es.Connection.ProviderSignature.DataProviderName)
            {
            case "EntitySpaces.MSAccessProvider":
                Assert.Ignore("Not supported.");
                break;

            default:
                try
                {
                    using (esTransactionScope scope = new esTransactionScope())
                    {
                        aggTest.LastName = "a 10% name";
                        aggTest.Save();
                        tempId = aggTest.Id.Value;

                        collection.Query
                        .Select()
                        .Where
                        (
                            collection.Query.LastName.Trim().Like("%10!%%", '!'),
                            collection.Query.LastName.Like("%a%")
                        );
                        Assert.IsTrue(collection.Query.Load());
                        Assert.AreEqual(1, collection.Count);
                    }
                }
                finally
                {
                    // Clean up
                    aggTest = new AggregateTest();
                    if (aggTest.LoadByPrimaryKey(tempId))
                    {
                        aggTest.MarkAsDeleted();
                        aggTest.Save();
                    }
                }
                break;
            }
        }
        public void AggregateInOrderBy()
        {
            switch (aggTestColl.es.Connection.ProviderSignature.DataProviderName)
            {
            case "EntitySpaces.MSAccessProvider":
                Assert.Ignore("Not supported");
                break;

            default:
                aggTestColl.Query
                .Select
                (
                    aggTestColl.Query.DepartmentID,
                    aggTestColl.Query.Salary.Min()
                )
                .OrderBy
                (
                    aggTestColl.Query.Salary.Descending
                )
                .GroupBy
                (
                    aggTestColl.Query.DepartmentID
                );
                aggTestColl.Query.Load();
                break;
            }

            AggregateTest test = new AggregateTest();

            switch (aggTestColl.es.Connection.ProviderSignature.DataProviderName)
            {
            case "EntitySpaces.NpgsqlProvider":
            case "EntitySpaces.Npgsql2Provider":
            case "EntitySpaces.OracleClientProvider":
                test = (AggregateTest)aggTestColl[1];
                break;

            default:
                test = (AggregateTest)aggTestColl[0];
                break;
            }

            Assert.AreEqual(4, test.DepartmentID.Value);
            Assert.AreEqual(18.44, Math.Round(test.Salary.Value, 2));
        }
Пример #20
0
        public void TestTrueIsDirtyLogicOnEntity()
        {
            aggTest           = new AggregateTest();
            aggTest.FirstName = "Mike";
            aggTest.AcceptChanges();

            Assert.IsFalse(aggTest.es.IsAdded);
            Assert.IsFalse(aggTest.es.IsDeleted);
            Assert.IsFalse(aggTest.es.IsModified);
            Assert.IsFalse(aggTest.es.IsDirty);
            Assert.IsTrue(aggTest.es.ModifiedColumns.Count == 0);
            Assert.IsTrue(aggTest.es.RowState == esDataRowState.Unchanged);

            // Let's change it
            aggTest.FirstName = "Joe";

            Assert.IsFalse(aggTest.es.IsAdded);
            Assert.IsFalse(aggTest.es.IsDeleted);
            Assert.IsTrue(aggTest.es.IsModified);
            Assert.IsTrue(aggTest.es.IsDirty);
            Assert.IsTrue(aggTest.es.ModifiedColumns.Count == 1);
            Assert.IsTrue(aggTest.es.RowState == esDataRowState.Modified);

            // Now let's set it back to it's original value
            aggTest.FirstName = "Mike";

            Assert.IsFalse(aggTest.es.IsAdded);
            Assert.IsFalse(aggTest.es.IsDeleted);
            Assert.IsFalse(aggTest.es.IsModified);
            Assert.IsFalse(aggTest.es.IsDirty);
            Assert.IsTrue(aggTest.es.ModifiedColumns.Count == 0);
            Assert.IsTrue(aggTest.es.RowState == esDataRowState.Unchanged);

            // Let's change it again, notice we are no longer dirty now
            aggTest.FirstName = "Joe";

            Assert.IsFalse(aggTest.es.IsAdded);
            Assert.IsFalse(aggTest.es.IsDeleted);
            Assert.IsTrue(aggTest.es.IsModified);
            Assert.IsTrue(aggTest.es.IsDirty);
            Assert.IsTrue(aggTest.es.ModifiedColumns.Count == 1);
            Assert.IsTrue(aggTest.es.RowState == esDataRowState.Modified);
        }
Пример #21
0
        public void TestTransactions()
        {
            switch (aggTest.es.Connection.Name)
            {
            case "SQLStoredProcEnterprise":
            case "SQLDynamicEnterprise":
            case "ORACLEStoredProcEnterprise":
            case "ORACLEDynamicEnterprise":
            case "VistaDBDynamic":
                Assert.Ignore("Using esTransactionScope only");
                break;

            default:
                int tempId1 = 0;
                int tempId2 = 0;

                aggTest = new AggregateTest();
                AggregateTest aggTest2 = new AggregateTest();

                using (esTransactionScope scope = new esTransactionScope())
                {
                    aggTest.Save();
                    tempId1 = aggTest.Id.Value;
                    aggTest2.Save();
                    tempId2 = aggTest2.Id.Value;

                    scope.Complete();
                }

                aggTest = new AggregateTest();
                Assert.IsTrue(aggTest.LoadByPrimaryKey(tempId1));
                aggTest.MarkAsDeleted();
                aggTest.Save();

                aggTest = new AggregateTest();
                Assert.IsTrue(aggTest.LoadByPrimaryKey(tempId2));
                aggTest.MarkAsDeleted();
                aggTest.Save();

                break;
            }
        }
Пример #22
0
        public void TestEsUtilityClass()
        {
            switch (aggTestColl.es.Connection.ProviderSignature.DataProviderName)
            {
            case "EntitySpaces.SqlClientProvider":
                if (aggTestColl.es.Connection.SqlAccessType != esSqlAccessType.StoredProcedure)
                {
                    Assert.Ignore("Stored procedure test only.");
                }

                aggTestColl.LoadAll();
                AggregateTest entity     = (AggregateTest)aggTestColl[0];
                string        entityName = aggTestColl.GetFullName(entity.Id.Value);

                EntitySpaces.Core.esUtility util =
                    new EntitySpaces.Core.esUtility();

                util.es.Connection.Catalog = "AggregateDb";
                util.es.Connection.Schema  = "dbo";

                EntitySpaces.Interfaces.esParameters parms =
                    new EntitySpaces.Interfaces.esParameters();

                parms.Add("ID", entity.Id.Value);
                parms.Add("FullName",
                          EntitySpaces.Interfaces.esParameterDirection.Output,
                          System.Data.DbType.String, 40);

                util.ExecuteNonQuery(
                    EntitySpaces.DynamicQuery.esQueryType.StoredProcedure,
                    "proc_GetEmployeeFullName", parms);

                string name = parms["FullName"].Value as string;
                Assert.AreEqual(entityName, name);
                break;

            default:
                Assert.Ignore("Tested on SQL Server only");
                break;
            }
        }
        public void TestHasData()
        {
            Assert.IsFalse(aggTestColl.HasData);

            Assert.IsTrue(aggTestColl.LoadAll());
            Assert.AreEqual(30, aggTestColl.Count);
            Assert.IsTrue(aggTestColl.HasData);

            aggTestColl = new AggregateTestCollection();
            Assert.IsFalse(aggTestColl.HasData);
            Assert.IsFalse(aggTest.es.HasData);

            aggTest = aggTestColl.AddNew();
            Assert.IsTrue(aggTestColl.HasData);
            Assert.IsTrue(aggTest.es.HasData);

            aggTest = new AggregateTest();
            Assert.IsFalse(aggTest.es.HasData);
            aggTest.Age = 40;
            Assert.IsTrue(aggTest.es.HasData);
        }
        public void SerializeDeserializeNewEntityBinary()
        {
            if (aggTest.es.Connection.Name == "SqlCe")
            {
                Assert.Ignore("Not tested for SqlCe.");
            }
            else
            {
                aggTest.LastName = "Griffinski";

                BinaryFormatter bf = new BinaryFormatter();
                MemoryStream    ms = new MemoryStream();
                bf.Serialize(ms, aggTest);

                ms.Position = 0;
                aggClone    = (AggregateTest)bf.Deserialize(ms);
                ms.Close();

                Assert.AreEqual("Griffinski", aggClone.str().LastName);
            }
        }
        public void TestDateTime()
        {
            int testId = -1;
            AggregateTestCollection aggTestColl = new AggregateTestCollection();
            AggregateTest           test        = new AggregateTest();

            try
            {
                using (EntitySpaces.Interfaces.esTransactionScope scope =
                           new EntitySpaces.Interfaces.esTransactionScope())
                {
                    aggTestColl.Query.Load();
                    aggTestColl.Filter = aggTestColl.AsQueryable().OrderBy(s => s.Id);
                    test = (AggregateTest)aggTestColl[0];
                    DateTime date = test.HireDate.Value;
                    Assert.AreEqual(Convert.ToDateTime("02/16/2000 05:59:31"), date);

                    test          = new AggregateTest();
                    test.HireDate = Convert.ToDateTime("12/31/9999");
                    test.Save();
                    testId = test.Id.Value;

                    test = new AggregateTest();
                    Assert.IsTrue(test.LoadByPrimaryKey(testId));
                    Assert.AreEqual(Convert.ToDateTime("12/31/9999"), test.HireDate.Value);
                    test.MarkAsDeleted();
                    test.Save();
                }
            }
            finally
            {
                // Clean up
                test = new AggregateTest();
                if (test.LoadByPrimaryKey(testId))
                {
                    test.MarkAsDeleted();
                    test.Save();
                }
            }
        }
        public void CollectionFindByPrimaryKey()
        {
            AggregateTest aggTest = new AggregateTest();

            aggTest.Query
            .Select()
            .Where
            (
                aggTest.Query.FirstName.Equal("Sarah"),
                aggTest.Query.LastName.Equal("Doe")
            );
            Assert.IsTrue(aggTest.Query.Load());
            int primaryKey = aggTest.Id.Value;

            AggregateTestCollection aggCloneColl = new AggregateTestCollection();

            aggCloneColl.LoadAll();
            AggregateTest aggClone = aggCloneColl.FindByPrimaryKey(primaryKey);

            Assert.AreEqual("Doe", aggClone.str().LastName);
            Assert.AreEqual("Sarah", aggClone.str().FirstName);
        }
        public void TransferMoney_LowBalanceSendNotification_Suscessfully()
        {
            Account toAccount   = new Account(Guid.NewGuid(), new User(Guid.NewGuid(), "alice", "*****@*****.**"), 100m, 90m, 0m);
            Account fromAccount = new Account(Guid.NewGuid(), new User(Guid.NewGuid(), "bob", "*****@*****.**"), toAccount.NotificationThresold, 80m, 0m);


            toAccount.TransferMoney(fromAccount, 150);

            AggregateTest.AssertSingleDomainEvent <AccountWithdrawnDomainEvent>(fromAccount, x => {
                Assert.Equal(150m, x.Amount);
                Assert.Equal(fromAccount, x.Account);
            });

            AggregateTest.AssertSingleDomainEvent <FundsLowDomainEvent>(fromAccount, x => {
                Assert.Equal(fromAccount, x.Account);
            });

            /*
             * Assert.Collection(fromAccount.DomainEvents,
             * x => Assert.Equal(typeof(AccountWithdrawnDomainEvent), x.GetType()),
             * x => Assert.Equal(typeof(FundsLowDomainEvent), x.GetType()));*/
        }
Пример #28
0
        public void TestTrueIsDirtyLogicOnCollection()
        {
            aggTestColl = new AggregateTestCollection();

            AggregateTest aggTest = aggTestColl.AddNew();

            aggTest.FirstName = "Mike";

            aggTestColl.AcceptChanges();
            Assert.IsFalse(aggTestColl.IsDirty);

            // Let's change it
            aggTest.FirstName = "Joe";
            Assert.IsTrue(aggTestColl.IsDirty);

            // Now let's set it back to it's original value
            aggTest.FirstName = "Mike";
            Assert.IsFalse(aggTestColl.IsDirty);

            // Let's change it again, notice we are no longer dirty now
            aggTest.FirstName = "Joe";
            Assert.IsTrue(aggTestColl.IsDirty);
        }
        public void TransferMoney_ApprocahingPaidInSendNotification_Suscessfully()
        {
            Account fromAccount = new Account(Guid.NewGuid(), new User(Guid.NewGuid(), "bob", "*****@*****.**"), 80m, 80m, 0m);
            Account toAccount   = new Account(Guid.NewGuid(), new User(Guid.NewGuid(), "alice", "*****@*****.**"), 100m, 90m, fromAccount.PayInLimit - 10);


            toAccount.TransferMoney(fromAccount, 5);

            AggregateTest.AssertSingleDomainEvent <AccountPaidInDomainEvent>(toAccount, x => {
                Assert.Equal(5m, x.Amount);
                Assert.Equal(toAccount, x.Account);
            });

            AggregateTest.AssertSingleDomainEvent <ApproachingPayInLimitDomainEvent>(toAccount, x => {
                Assert.Equal(toAccount, x.Account);
            });

            /*
             * Assert.Collection(toAccount.DomainEvents,
             * x => Assert.Equal(typeof(AccountPaidInDomainEvent), x.GetType()),
             *    x => Assert.Equal(typeof(ApproachingPayInLimitDomainEvent), x.GetType()));
             */
        }
Пример #30
0
        public void TestDeleteOnEntity()
        {
            aggTest           = new AggregateTest();
            aggTest.FirstName = "Mike";
            aggTest.AcceptChanges();

            Assert.IsFalse(aggTest.es.IsAdded);
            Assert.IsFalse(aggTest.es.IsDeleted);
            Assert.IsFalse(aggTest.es.IsModified);
            Assert.IsFalse(aggTest.es.IsDirty);
            Assert.IsTrue(aggTest.es.ModifiedColumns.Count == 0);
            Assert.IsTrue(aggTest.es.RowState == esDataRowState.Unchanged);

            // Let's mark it as deleted
            aggTest.MarkAsDeleted();

            Assert.IsFalse(aggTest.es.IsAdded);
            Assert.IsTrue(aggTest.es.IsDeleted);
            Assert.IsFalse(aggTest.es.IsModified);
            Assert.IsTrue(aggTest.es.IsDirty);
            Assert.IsTrue(aggTest.es.ModifiedColumns.Count == 0);
            Assert.IsTrue(aggTest.es.RowState == esDataRowState.Deleted);
        }