コード例 #1
0
ファイル: ModelTests.cs プロジェクト: docevaad/Chain
        public void CompiledDecomposeTest()
        {
            var ds = DataSource;

            var emp1 = new Employee() { FirstName = "Tom", LastName = "Jones", Title = "President" };
            var emp1Key = ds.Insert(EmployeeTableName, emp1).ToInt32().Execute();

            var emp2 = new Employee() { FirstName = "Lisa", LastName = "Green", Title = "VP Transportation", ManagerKey = emp1Key };
            var emp2Key = ds.Insert(EmployeeTableName, emp2).ToInt32().Execute();

            var echo = ds.From("HR.EmployeeWithManager", new { @EmployeeKey = emp2Key }).Compile().ToObject<EmployeeWithManager>().Execute();

            Assert.AreNotEqual(0, echo.EmployeeKey, "EmployeeKey was not set");
            Assert.AreEqual(emp2.FirstName, echo.FirstName, "FirstName");
            Assert.AreEqual(emp2.LastName, echo.LastName, "LastName");
            Assert.AreEqual(emp2.Title, echo.Title, "Title");

            Assert.AreNotEqual(0, echo.Manager.EmployeeKey, "Manager.EmployeeKey was not set");
            Assert.AreEqual(emp1.FirstName, echo.Manager.FirstName, "Manager.FirstName");
            Assert.AreEqual(emp1.LastName, echo.Manager.LastName, "Manager.LastName");
            Assert.AreEqual(emp1.Title, echo.Manager.Title, "Manager.Title");

            Assert.IsNotNull(echo.AuditInfo.CreatedDate, "CreatedDate via AuditInfo");
            Assert.IsNotNull(echo.Manager.AuditInfo.CreatedDate, "CreatedDate via Manager.AuditInfo");

        }
コード例 #2
0
ファイル: DeleteTests.cs プロジェクト: docevaad/Chain
        public void DeleteTests_Delete_Attribute(string assemblyName, string dataSourceName, DataSourceType mode)
        {

            var dataSource = DataSource(dataSourceName, mode);
            try
            {
                var original = new Employee()
                {
                    FirstName = "Test",
                    LastName = "Employee" + DateTime.Now.Ticks,
                    Title = "Mail Room"
                };

                var key = dataSource.Insert(EmployeeTableName, original).ToInt32().Execute();
                var inserted = dataSource.GetByKey(EmployeeTableName, key).ToObject<Employee>().Execute();

                dataSource.Delete(inserted).Execute();

                try
                {
                    dataSource.GetByKey(EmployeeTableName, key).ToObject<Employee>().Execute();
                    Assert.Fail("Expected a missing data exception");
                }
                catch (MissingDataException) { }
            }
            finally
            {
                Release(dataSource);
            }
        }
コード例 #3
0
ファイル: UpsertTests.cs プロジェクト: docevaad/Chain
        public void BasicUpsertTest(string assemblyName, string dataSourceName, DataSourceType mode)
        {

            var dataSource = DataSource(dataSourceName, mode);
            try
            {
                var original = new Employee()
                {
                    FirstName = "Test",
                    LastName = "Employee" + DateTime.Now.Ticks,
                    Title = "Mail Room"
                };

                var inserted = dataSource.Upsert(EmployeeTableName, original).ToObject<Employee>().Execute();

                inserted.FirstName = "Changed";
                inserted.Title = "Also Changed";

                var updated = dataSource.Upsert(EmployeeTableName, inserted).ToObject<Employee>().Execute();
                Assert.AreEqual(inserted.FirstName, updated.FirstName, "FirstName should't have changed");
                Assert.AreEqual(original.LastName, updated.LastName, "LastName shouldn't have changed");
                Assert.AreEqual(inserted.Title, updated.Title, "Title should have changed");

            }
            finally
            {
                Release(dataSource);
            }

        }
コード例 #4
0
        public void BasicCrud()
        {
            using (var trans = DataSource.BeginTransaction())
            {

                var repo = new Repository<Employee, int>(trans, EmployeeTableName);

                var emp1 = new Employee() { FirstName = "Tom", LastName = "Jones", Title = "President" };
                var echo1 = repo.Insert(emp1);

                Assert.AreNotEqual(0, echo1.EmployeeKey, "EmployeeKey was not set");
                Assert.AreEqual(emp1.FirstName, echo1.FirstName, "FirstName");
                Assert.AreEqual(emp1.LastName, echo1.LastName, "LastName");
                Assert.AreEqual(emp1.Title, echo1.Title, "Title");

                echo1.MiddleName = "G";
                repo.Update(echo1);

                var emp2 = new Employee() { FirstName = "Lisa", LastName = "Green", Title = "VP Transportation", ManagerKey = echo1.EmployeeKey };
                var echo2 = repo.Insert(emp2);
                Assert.AreNotEqual(0, echo2.EmployeeKey, "EmployeeKey was not set");
                Assert.AreEqual(emp2.FirstName, echo2.FirstName, "FirstName");
                Assert.AreEqual(emp2.LastName, echo2.LastName, "LastName");
                Assert.AreEqual(emp2.Title, echo2.Title, "Title");
                Assert.AreEqual(emp2.ManagerKey, echo2.ManagerKey, "ManagerKey");

                var list = repo.GetAll();
                Assert.IsTrue(list.Any(e => e.EmployeeKey == echo1.EmployeeKey), "Employee 1 is missing");
                Assert.IsTrue(list.Any(e => e.EmployeeKey == echo2.EmployeeKey), "Employee 2 is missing");

                var get1 = repo.Get(echo1.EmployeeKey.Value);
                Assert.AreEqual(echo1.EmployeeKey, get1.EmployeeKey);



                var whereSearch1 = repo.Query("FirstName = @FN", new { FN = "Tom" });
                Assert.IsTrue(whereSearch1.Any(x => x.EmployeeKey == echo1.EmployeeKey), "Emp1 should have been returned");
                Assert.IsTrue(whereSearch1.All(x => x.FirstName == "Tom"), "Checking for incorrect return values");

                var whereSearch2 = repo.Query(new { FirstName = "Tom" });
                Assert.IsTrue(whereSearch2.Any(x => x.EmployeeKey == echo1.EmployeeKey), "Emp1 should have been returned");
                Assert.IsTrue(whereSearch2.All(x => x.FirstName == "Tom"), "Checking for incorrect return values");


                repo.Delete(echo2.EmployeeKey.Value);
                repo.Delete(echo1.EmployeeKey.Value);

                var list2 = repo.GetAll();
                Assert.AreEqual(list.Count - 2, list2.Count);

                trans.Commit();
            }

        }
コード例 #5
0
ファイル: FromTests.cs プロジェクト: docevaad/Chain
        public void FromTests_ToImmutableObject()
        {
            var uniqueKey = Guid.NewGuid().ToString();

            var emp1 = new Employee() { FirstName = "A", LastName = "1", Title = uniqueKey };
            DataSource.Insert(EmployeeTableName, emp1).ToObject<Employee>().Execute();

            var lookup = DataSource.From(EmployeeTableName, new { Title = uniqueKey }).ToObject<EmployeeLookup>().WithConstructor<long, string, string>().Execute();

            Assert.AreEqual("A", lookup.FirstName);
            Assert.AreEqual("1", lookup.LastName);

        }
コード例 #6
0
        public void BasicCrud()
        {
            var repo = new RepositoryWithCaching<Employee, int>(DataSource, EmployeeTableName);

            var emp1 = new Employee() { FirstName = "Tom", LastName = "Jones", Title = "President" };
            var echo1 = repo.Insert(emp1);

            Assert.AreNotEqual(0, echo1.EmployeeKey, "EmployeeKey was not set");
            Assert.AreEqual(emp1.FirstName, echo1.FirstName, "FirstName");
            Assert.AreEqual(emp1.LastName, echo1.LastName, "LastName");
            Assert.AreEqual(emp1.Title, echo1.Title, "Title");

            echo1.MiddleName = "G";
            var updatedEcho1 = repo.Update(echo1);

            var cached1 = repo.Get(echo1.EmployeeKey.Value);
            Assert.AreSame(updatedEcho1, cached1, "Item should have been cached");

            var emp2 = new Employee() { FirstName = "Lisa", LastName = "Green", Title = "VP Transportation", ManagerKey = echo1.EmployeeKey };
            var echo2 = repo.Insert(emp2);
            Assert.AreNotEqual(0, echo2.EmployeeKey, "EmployeeKey was not set");
            Assert.AreEqual(emp2.FirstName, echo2.FirstName, "FirstName");
            Assert.AreEqual(emp2.LastName, echo2.LastName, "LastName");
            Assert.AreEqual(emp2.Title, echo2.Title, "Title");
            Assert.AreEqual(emp2.ManagerKey, echo2.ManagerKey, "ManagerKey");

            var list = repo.GetAll();
            Assert.IsTrue(list.Any(e => e.EmployeeKey == echo1.EmployeeKey), "Employee 1 is missing");
            Assert.IsTrue(list.Any(e => e.EmployeeKey == echo2.EmployeeKey), "Employee 2 is missing");

            var list2 = repo.GetAll();
            Assert.AreSame(list, list2, "GetAll should have been cached");

            var cached1b = repo.Get(echo1.EmployeeKey.Value);
            Assert.AreNotSame(echo1, cached1b, "Cached item was replaced");
            Assert.IsTrue(list.Contains(cached1b), "Single item should have been contained in the list we previously cached.");


            var get1 = repo.Get(echo1.EmployeeKey.Value);
            Assert.AreEqual(echo1.EmployeeKey, get1.EmployeeKey);

            repo.Delete(echo2.EmployeeKey.Value);
            repo.Delete(echo1.EmployeeKey.Value);

            var list3 = repo.GetAll();
            Assert.AreEqual(list.Count - 2, list3.Count);

        }
コード例 #7
0
ファイル: ModelTests.cs プロジェクト: docevaad/Chain
        public void CompiledTest()
        {
            var ds = DataSource;

            var emp1 = new Employee() { FirstName = "Tom", LastName = "Jones", Title = "President" };
            var emp1Key = ds.Insert(EmployeeTableName, emp1).ToInt32().Execute();

            var emp2 = new Employee() { FirstName = "Lisa", LastName = "Green", Title = "VP Transportation", ManagerKey = emp1Key };
            var emp2Key = ds.Insert(EmployeeTableName, emp2).ToInt32().Execute();

            var echo = ds.From("HR.EmployeeWithManager", new { @EmployeeKey = emp2Key }).Compile().ToObject<Employee>().Execute();
            var list = ds.From("HR.EmployeeWithManager", new { @EmployeeKey = emp2Key }).Compile().ToCollection<Employee>().Execute();


            Assert.AreNotEqual(0, echo.EmployeeKey, "EmployeeKey was not set");
            Assert.AreEqual(emp2.FirstName, echo.FirstName, "FirstName");
            Assert.AreEqual(emp2.LastName, echo.LastName, "LastName");
            Assert.AreEqual(emp2.Title, echo.Title, "Title");
        }
コード例 #8
0
ファイル: DeleteTests.cs プロジェクト: docevaad/Chain
        public void DeleteTests_Delete(string assemblyName, string dataSourceName, DataSourceType mode)
        {

            var dataSource = DataSource(dataSourceName, mode);
            try
            {
                var original = new Employee()
                {
                    FirstName = "Test",
                    LastName = "Employee" + DateTime.Now.Ticks,
                    Title = "Mail Room"
                };

                var key = dataSource.Insert(EmployeeTableName, original).ToInt32().Execute();
                var inserted = dataSource.GetByKey(EmployeeTableName, key).ToObject<Employee>().Execute();

                dataSource.Delete(EmployeeTableName, inserted).Execute();
            }
            finally
            {
                Release(dataSource);
            }
        }
コード例 #9
0
 public Employee Update(Employee entity)
 {
     return Source.Update(TableName, entity).ToObject<Employee>().Cache(CacheKey(entity)).InvalidateCache(AllCacheKey).Execute();
 }
コード例 #10
0
 public Employee Insert(Employee entity)
 {
     return Source.Insert(TableName, entity).ToObject<Employee>().InvalidateCache(AllCacheKey).Cache((Employee x) => CacheKey(x), policy: Policy).Execute();
 }
コード例 #11
0
 protected string CacheKey(Employee entity)
 {
     return CacheKey(entity.EmployeeKey.Value);
 }
コード例 #12
0
ファイル: FromTests.cs プロジェクト: docevaad/Chain
        public void FromTests_GetByKey()
        {
            var emp1 = new Employee() { FirstName = "A", LastName = "1" };
            var emp2 = new Employee() { FirstName = "B", LastName = "2" };
            var emp3 = new Employee() { FirstName = "C", LastName = "3" };
            var emp4 = new Employee() { FirstName = "D", LastName = "4" };

            emp1 = DataSource.Insert(EmployeeTableName, emp1).ToObject<Employee>().Execute();
            emp2 = DataSource.Insert(EmployeeTableName, emp2).ToObject<Employee>().Execute();
            emp3 = DataSource.Insert(EmployeeTableName, emp3).ToObject<Employee>().Execute();
            emp4 = DataSource.Insert(EmployeeTableName, emp4).ToObject<Employee>().Execute();

            var find2 = DataSource.GetByKey(EmployeeTableName, emp2.EmployeeKey.Value).ToObject<Employee>().Execute();
            Assert.AreEqual(emp2.EmployeeKey, find2.EmployeeKey, "The wrong employee was returned");

            var list = DataSource.GetByKey(EmployeeTableName, emp2.EmployeeKey.Value, emp3.EmployeeKey.Value, emp4.EmployeeKey.Value).ToCollection<Employee>().Execute();
            Assert.AreEqual(3, list.Count, "GetByKey returned the wrong number of rows");
            Assert.IsTrue(list.Any(e => e.EmployeeKey == emp2.EmployeeKey));
            Assert.IsTrue(list.Any(e => e.EmployeeKey == emp3.EmployeeKey));
            Assert.IsTrue(list.Any(e => e.EmployeeKey == emp4.EmployeeKey));
        }
コード例 #13
0
ファイル: FromTests.cs プロジェクト: docevaad/Chain
        public void FromTests_ImmutableList()
        {
            var uniqueKey = Guid.NewGuid().ToString();

            var emp1 = new Employee() { FirstName = "A", LastName = "2", Title = uniqueKey };
            var emp2 = new Employee() { FirstName = "B", LastName = "2", Title = uniqueKey };
            var emp3 = new Employee() { FirstName = "C", LastName = "1", Title = uniqueKey };
            var emp4 = new Employee() { FirstName = "D", LastName = "1", Title = uniqueKey };

            emp1 = DataSource.Insert(EmployeeTableName, emp1).ToObject<Employee>().Execute();
            emp2 = DataSource.Insert(EmployeeTableName, emp2).ToObject<Employee>().Execute();
            emp3 = DataSource.Insert(EmployeeTableName, emp3).ToObject<Employee>().Execute();
            emp4 = DataSource.Insert(EmployeeTableName, emp4).ToObject<Employee>().Execute();

            var test1 = DataSource.From(EmployeeTableName, new { Title = uniqueKey }).WithSorting("FirstName").ToImmutableList<Employee>().Execute();
            Assert.AreEqual(emp1.EmployeeKey, test1[0].EmployeeKey);
            Assert.AreEqual(emp2.EmployeeKey, test1[1].EmployeeKey);
            Assert.AreEqual(emp3.EmployeeKey, test1[2].EmployeeKey);
            Assert.AreEqual(emp4.EmployeeKey, test1[3].EmployeeKey);

            var test2 = DataSource.From(EmployeeTableName, new { Title = uniqueKey }).WithSorting(new SortExpression("FirstName", SortDirection.Descending)).ToImmutableList<Employee>().Execute();
            Assert.AreEqual(emp4.EmployeeKey, test2[0].EmployeeKey);
            Assert.AreEqual(emp3.EmployeeKey, test2[1].EmployeeKey);
            Assert.AreEqual(emp2.EmployeeKey, test2[2].EmployeeKey);
            Assert.AreEqual(emp1.EmployeeKey, test2[3].EmployeeKey);

            var test3 = DataSource.From(EmployeeTableName, new { Title = uniqueKey }).WithSorting("LastName", "FirstName").ToImmutableList<Employee>().Execute();
            Assert.AreEqual(emp3.EmployeeKey, test3[0].EmployeeKey);
            Assert.AreEqual(emp4.EmployeeKey, test3[1].EmployeeKey);
            Assert.AreEqual(emp1.EmployeeKey, test3[2].EmployeeKey);
            Assert.AreEqual(emp2.EmployeeKey, test3[3].EmployeeKey);

        }
コード例 #14
0
ファイル: FromTests.cs プロジェクト: docevaad/Chain
        public void FromTests_ToDictionary()
        {
            var uniqueKey = Guid.NewGuid().ToString();

            var emp1 = new Employee() { FirstName = "A", LastName = "1", Title = uniqueKey };
            var emp2 = new Employee() { FirstName = "B", LastName = "2", Title = uniqueKey };
            var emp3 = new Employee() { FirstName = "C", LastName = "3", Title = uniqueKey };
            var emp4 = new Employee() { FirstName = "D", LastName = "4", Title = uniqueKey };

            emp1 = DataSource.Insert(EmployeeTableName, emp1).ToObject<Employee>().Execute();
            emp2 = DataSource.Insert(EmployeeTableName, emp2).ToObject<Employee>().Execute();
            emp3 = DataSource.Insert(EmployeeTableName, emp3).ToObject<Employee>().Execute();
            emp4 = DataSource.Insert(EmployeeTableName, emp4).ToObject<Employee>().Execute();

            var test1 = DataSource.From(EmployeeTableName, new { Title = uniqueKey }).ToDictionary<string, Employee>("FirstName").Execute();

            Assert.AreEqual("1", test1["A"].LastName);
            Assert.AreEqual("2", test1["B"].LastName);
            Assert.AreEqual("3", test1["C"].LastName);
            Assert.AreEqual("4", test1["D"].LastName);

            var test2 = DataSource.From(EmployeeTableName, new { Title = uniqueKey }).ToDictionary<int, Employee>(e => int.Parse(e.LastName)).Execute();

            Assert.AreEqual("A", test2[1].FirstName);
            Assert.AreEqual("B", test2[2].FirstName);
            Assert.AreEqual("C", test2[3].FirstName);
            Assert.AreEqual("D", test2[4].FirstName);

            var test3 = DataSource.From(EmployeeTableName, new { Title = uniqueKey }).ToDictionary<string, Employee, ConcurrentDictionary<string, Employee>>("FirstName").Execute();
            Assert.IsInstanceOfType(test3, typeof(ConcurrentDictionary<string, Employee>));
            Assert.AreEqual("1", test3["A"].LastName);
            Assert.AreEqual("2", test3["B"].LastName);
            Assert.AreEqual("3", test3["C"].LastName);
            Assert.AreEqual("4", test3["D"].LastName);

            var test4 = DataSource.From(EmployeeTableName, new { Title = uniqueKey }).ToDictionary<int, Employee, ConcurrentDictionary<int, Employee>>(e => int.Parse(e.LastName)).Execute();
            Assert.IsInstanceOfType(test4, typeof(ConcurrentDictionary<int, Employee>));
            Assert.AreEqual("A", test4[1].FirstName);
            Assert.AreEqual("B", test4[2].FirstName);
            Assert.AreEqual("C", test4[3].FirstName);
            Assert.AreEqual("D", test4[4].FirstName);

            var test5 = DataSource.From(EmployeeTableName, new { Title = uniqueKey }).ToImmutableDictionary<string, Employee>("FirstName").Execute();
            Assert.IsInstanceOfType(test3, typeof(ConcurrentDictionary<string, Employee>));
            Assert.AreEqual("1", test5["A"].LastName);
            Assert.AreEqual("2", test5["B"].LastName);
            Assert.AreEqual("3", test5["C"].LastName);
            Assert.AreEqual("4", test5["D"].LastName);

            var test6 = DataSource.From(EmployeeTableName, new { Title = uniqueKey }).ToImmutableDictionary<int, Employee>(e => int.Parse(e.LastName)).Execute();
            Assert.IsInstanceOfType(test4, typeof(ConcurrentDictionary<int, Employee>));
            Assert.AreEqual("A", test6[1].FirstName);
            Assert.AreEqual("B", test6[2].FirstName);
            Assert.AreEqual("C", test6[3].FirstName);
            Assert.AreEqual("D", test6[4].FirstName);

        }
コード例 #15
0
ファイル: RepositoryTests.cs プロジェクト: docevaad/Chain
        public void Upsert()
        {
            var repo = new Repository<Employee, int>(DataSource, EmployeeTableName);

            var emp1 = new Employee() { FirstName = "Tom", LastName = "Jones", Title = "President" };
            var echo1 = repo.Upsert(emp1);

            Assert.AreNotEqual(0, echo1.EmployeeKey, "EmployeeKey was not set");
            Assert.AreEqual(emp1.FirstName, echo1.FirstName, "FirstName");
            Assert.AreEqual(emp1.LastName, echo1.LastName, "LastName");
            Assert.AreEqual(emp1.Title, echo1.Title, "Title");

            echo1.MiddleName = "G";
            var echo2 = repo.Upsert(echo1);
            Assert.AreEqual("G", echo2.MiddleName);

            var echo3 = repo.Get(echo1.EmployeeKey.Value);
            Assert.AreEqual("G", echo3.MiddleName);

            repo.Delete(echo1.EmployeeKey.Value);
        }