public void TestEmptListThrowsExceptionOk()
        {
            using (var env = new MethodEnvironment(classEnv))
            {
                //SETUP             

                //ATTEMPT
                Assert.Throws<ArgumentException>( () =>  env.CompareAndLogList(new String[] { }, new String[] {}));

                //VERIFY
            }
        }
        public void TestSupportedSingleOk()
        {
            using (var env = new MethodEnvironment(classEnv))
            {
                //SETUP             

                //ATTEMPT
                env.CompareAndLogSingleton(1, 1);

                //VERIFY
                classEnv.GetLastMethodLog().State.ShouldEqual(LogStates.Supported);
            }
        }
        public void TestNoSupportedListResultsWrongOk()
        {
            using (var env = new MethodEnvironment(classEnv))
            {
                //SETUP

                //ATTEMPT
                Assert.Throws<AssertionException>(() => env.CompareAndLogList(new String[] { "fred" }, new String[] { }));

                //VERIFY
                classEnv.GetLastMethodLog().State.ShouldEqual(LogStates.NotSupported);
            }
        }
        public void TestNotSupportedSingleResultsWrongOk()
        {
            using (var env = new MethodEnvironment(classEnv))
            {
                //SETUP             

                //ATTEMPT
                Assert.Throws<AssertionException>(() => env.CompareAndLogSingleton(1,2));

                //VERIFY
                classEnv.GetLastMethodLog().State.ShouldEqual(LogStates.NotSupported);
            }
        }
        public void TestSupportedListOk()
        {
            using (var env = new MethodEnvironment(classEnv))
            {
                //SETUP             

                //ATTEMPT
                env.CompareAndLogList(new String[] { "fred" }, new String[] { "fred" });

                //VERIFY
                classEnv.GetLastMethodLog().State.ShouldEqual(LogStates.Supported);
            }
        }
        public async Task TestIntEqualsConstant()
        {
            using (var env = new MethodEnvironment(classEnv))
            {
                //SETUP
                var linq = await env.Db.EfParents.Select(x => x.ParentInt == 123).ToListAsync();

                //ATTEMPT
                env.AboutToUseDelegateDecompiler();
                var dd = await env.Db.EfParents.Select(x => x.IntEqualsConstant).DecompileAsync().ToListAsync();

                //VERIFY
                env.CompareAndLogList(linq, dd);
            }
        }
        public async Task TestBoolEqualsStaticVariableToArrayAsync()
        {
            using (var env = new MethodEnvironment(classEnv))
            {
                //SETUP
                var linq = await env.Db.EfParents.Select(x => x.ParentBool == staticBool).ToListAsync();

                //ATTEMPT
                env.AboutToUseDelegateDecompiler();
                var dd = await env.Db.EfParents.Select(x => x.BoolEqualsStaticVariable).DecompileAsync().ToListAsync();

                //VERIFY
                env.CompareAndLogList(linq, dd);
            }
        }
Exemplo n.º 8
0
        public void TestDateTimeWhereCompareWithStaticVariable()
        {
            using (var env = new MethodEnvironment(classEnv))
            {
                //SETUP
                var linq = env.Db.EfParents.Where(x => x.StartDate > dateConst).Select( x => x.StartDate).ToList();

                //ATTEMPT
                env.AboutToUseDelegateDecompiler();
                var dd = env.Db.EfParents.Where(x => x.StartDateGreaterThanStaticVar).Select( x => x.StartDate).Decompile().ToList();

                //VERIFY
                env.CompareAndLogList(linq, dd);
            }
        }
        public void TestIntEqualsStringLength()
        {
            using (var env = new MethodEnvironment(classEnv))
            {
                //SETUP
                var linq = env.Db.EfParents.Select(x => x.ParentInt == x.ParentString.Length).ToList();

                //ATTEMPT
                env.AboutToUseDelegateDecompiler();
                var dd = env.Db.EfParents.Select(x => x.IntEqualsStringLength).Decompile().ToList();

                //VERIFY
                env.CompareAndLogList(linq, dd);
            }
        }
Exemplo n.º 10
0
        public void TestWhereIntEqualsConstant()
        {
            using (var env = new MethodEnvironment(classEnv))
            {
                //SETUP
                var linq = env.Db.EfParents.Where(x => x.ParentInt == 123).Select(x => x.EfParentId).ToList();

                //ATTEMPT
                env.AboutToUseDelegateDecompiler();
                var dd = env.Db.EfParents.Where(x => x.IntEqualsConstant).Select(x => x.EfParentId).Decompile().ToList();

                //VERIFY
                env.CompareAndLogList(linq, dd);
            }
        }
Exemplo n.º 11
0
        public void TestAnyChildrenWithFilter()
        {
            using (var env = new MethodEnvironment(classEnv))
            {
                //SETUP
                var linq = env.Db.EfParents.Select(x => x.Children.Any( y => y.ChildInt == 123)).ToList();

                //ATTEMPT
                env.AboutToUseDelegateDecompiler();
                var dd = env.Db.EfParents.Select(x => x.AnyChildrenWithFilter).Decompile().ToList();

                //VERIFY
                env.CompareAndLogList(linq, dd);
            }
        }
Exemplo n.º 12
0
        public void TestNullableInit()
        {
            using (var env = new MethodEnvironment(classEnv))
            {
                //SETUP
                var linq = env.Db.EfParents.Select(x => new Nullable<int>()).ToList();

                //ATTEMPT
                env.AboutToUseDelegateDecompiler();
                var dd = env.Db.EfParents.Select(x => x.NullableInit).Decompile().ToList();

                //VERIFY
                env.CompareAndLogList(linq, dd);
            }
        }
Exemplo n.º 13
0
        public void TestWhereBoolEqualsStaticVariable()
        {
            using (var env = new MethodEnvironment(classEnv))
            {
                //SETUP
                var linq = env.Db.EfParents.Where(x => x.ParentBool == staticBool).Select(x => x.EfParentId).ToList();

                //ATTEMPT
                env.AboutToUseDelegateDecompiler();
                var dd = env.Db.EfParents.Where(x => x.BoolEqualsStaticVariable).Select(x => x.EfParentId).Decompile().ToList();

                //VERIFY
                env.CompareAndLogList(linq, dd);
            }
        }
Exemplo n.º 14
0
        public void TestSingletonAllFilter()
        {
            using (var env = new MethodEnvironment(classEnv))
            {
                //SETUP
                var linq = env.Db.EfParents.All(x => x.ParentInt == 123);

                //ATTEMPT
                env.AboutToUseDelegateDecompiler();
                var dd = env.Db.EfParents.Decompile().All(x => x.IntEqualsConstant);

                //VERIFY
                env.CompareAndLogSingleton(linq, dd);
            }
        }
Exemplo n.º 15
0
        public void TestConcatenatePersonNotHandleNull()
        {
            using (var env = new MethodEnvironment(classEnv))
            {
                //SETUP
                var linq = env.Db.EfPersons.Select(x => x.FirstName + " " + x.MiddleName + " " + x.LastName).ToList();

                //ATTEMPT
                env.AboutToUseDelegateDecompiler();
                var dd = env.Db.EfPersons.Select(x => x.FullNameNoNull).Decompile().ToList();

                //VERIFY
                env.CompareAndLogList(linq, dd);
            }
        }
Exemplo n.º 16
0
        public void TestSumCountInChildrenWhereChildrenCanBeNone()
        {
            using (var env = new MethodEnvironment(classEnv))
            {
                //SETUP

                var linq = env.Db.EfParents.Select(x => x.Children.Sum( y => (int?)y.ChildInt) ?? 0).ToList();

                //ATTEMPT
                env.AboutToUseDelegateDecompiler();
                var dd = env.Db.EfParents.Select(x => x.SumIntInChildrenWhereChildrenCanBeNone).Decompile().ToList();

                //VERIFY
                env.CompareAndLogList(linq, dd);
            }
        }
Exemplo n.º 17
0
        public void TestSingletonSumChildren()
        {
            using (var env = new MethodEnvironment(classEnv))
            {
                //SETUP

                var linq = env.Db.EfParents.Sum(x => x.Children.Count());

                //ATTEMPT
                env.AboutToUseDelegateDecompiler();
                var dd = env.Db.EfParents.Decompile().Sum(x => x.CountChildren);

                //VERIFY
                env.CompareAndLogSingleton(linq, dd);
            }
        }
Exemplo n.º 18
0
        public void TestOrderByChildrenCountThenByStringLength()
        {
            using (var env = new MethodEnvironment(classEnv))
            {
                //SETUP

                var linq = env.Db.EfParents.OrderBy(x => x.Children.Count).ThenBy( x => x.ParentString.Length).Select(x => x.EfParentId).ToList();

                //ATTEMPT
                env.AboutToUseDelegateDecompiler();
                var dd = env.Db.EfParents.OrderBy(x => x.CountChildren).ThenBy( x => x.GetStringLength).Select(x => x.EfParentId).Decompile().ToList();

                //VERIFY
                env.CompareAndLogList(linq, dd);
            }
        }
Exemplo n.º 19
0
        public void TestStringContainsConstantStringWithFilter()
        {
            using (var env = new MethodEnvironment(classEnv))
            {
                //SETUP
                var linq =
                    env.Db.EfParents.Where(x => x.ParentString.Contains("2")).Select(x => x.ParentString).ToList();

                //ATTEMPT
                env.AboutToUseDelegateDecompiler();
                var dd = env.Db.EfParents.Where(x => x.StringContainsConstantString).Select(x => x.ParentString).Decompile().ToList();

                //VERIFY
                env.CompareAndLogList(linq, dd);
            }
        }
Exemplo n.º 20
0
        public void TestCountChildren()
        {
            using (var env = new MethodEnvironment(classEnv))
            {
                //SETUP

                var linq = env.Db.EfParents.Select(x => x.Children.Count).ToList();

                //ATTEMPT
                env.AboutToUseDelegateDecompiler();
                var dd = env.Db.EfParents.Select(x => x.CountChildren).Decompile().ToList();

                //VERIFY
                env.CompareAndLogList(linq, dd);
            }
        }
Exemplo n.º 21
0
        public void TestWhereAnyChildrenThenOrderByThenSkipTake()
        {
            using (var env = new MethodEnvironment(classEnv))
            {
                //SETUP

                var linq = env.Db.EfParents.Where(x => x.Children.Any()).OrderBy(x => x.Children.Count).Select(x => x.EfParentId).Skip(1).Take(1).ToList();

                //ATTEMPT
                env.AboutToUseDelegateDecompiler();
                var dd = env.Db.EfParents.Where(x => x.AnyChildren).OrderBy(x => x.CountChildren).Select(x => x.EfParentId).Decompile().Skip(1).Take(1).ToList();

                //VERIFY
                env.CompareAndLogList(linq, dd);
            }
        }
Exemplo n.º 22
0
        public void TestConcatenatePersonHandleNameOrder()
        {
            using (var env = new MethodEnvironment(classEnv))
            {
                //SETUP
                var linq = env.Db.EfPersons.Select(x => x.NameOrder
                    ? x.LastName +", " + x.FirstName + (x.MiddleName == null ? "" : " ")
                    : x.FirstName + (x.MiddleName == null ? "" : " ") + x.MiddleName + " " + x.LastName).ToList();

                //ATTEMPT
                env.AboutToUseDelegateDecompiler();
                var dd = env.Db.EfPersons.Select(x => x.UseOrderToFormatNameStyle).Decompile().ToList();

                //VERIFY
                env.CompareAndLogList(linq, dd);
            }
        }
Exemplo n.º 23
0
        public void TestCountChildrenWithFilterByExternalClosure()
        {
            using (var env = new MethodEnvironment(classEnv))
            {
                //SETUP

                var i = 123;
                var linq = env.Db.EfParents.Select(x => x.Children.Count(y => y.ChildInt == i)).ToList();

                //ATTEMPT
                env.AboutToUseDelegateDecompiler();
                var dd = env.Db.EfParents.Select(x => x.GetCountChildrenWithFilterByExternalClosure(i)).Decompile().ToList();

                //VERIFY
                env.CompareAndLogList(linq, dd);
            }
        }
        public static void CompareAndLogSingleton <T>(this MethodEnvironment env, T linqResult, T ddResult,
                                                      [CallerLineNumber] int sourceLineNumber = 0)
        {
            if (typeof(T).IsSubclassOf(typeof(List)))
            {
                throw new ArgumentException("You should use CompareAndLogCollection for comparing lists.");
            }

            try
            {
                Assert.AreEqual(linqResult, ddResult);
            }
            catch (Exception)
            {
                env.LogFailer(sourceLineNumber);
                throw;
            }
            env.LogSuccess(sourceLineNumber);
        }
Exemplo n.º 25
0
        public void TestLinqExceptionOk()
        {
            try
            {
                using (var env = new MethodEnvironment(classEnv))
                {
                    //SETUP

                    //ATTEMPT
                    throw new Exception("Failed");
                }

            }
            catch
            {
                //VERIFY
                classEnv.GetLastMethodLog().State.ShouldEqual(LogStates.EvenLinqDidNotWork);
            }
        }
        public static void CompareAndLogList <T>(this MethodEnvironment env, IList <T> linqResult, IList <T> ddResult,
                                                 [CallerLineNumber] int sourceLineNumber = 0)
        {
            if (!linqResult.Any())
            {
                throw new ArgumentException("The linq result was empty, so this was not a fair test.");
            }

            try
            {
                CollectionAssert.AreEqual(linqResult, ddResult);
            }
            catch (Exception)
            {
                env.LogFailer(sourceLineNumber);
                throw;
            }
            env.LogSuccess(sourceLineNumber);
        }
Exemplo n.º 27
0
        public void TestDelegateDEcompilerExceptionOk()
        {
            try
            {
                using (var env = new MethodEnvironment(classEnv))
                {
                    //SETUP

                    //ATTEMPT
                    env.AboutToUseDelegateDecompiler();
                    throw new Exception("Failed");
                }

            }
            catch
            {
                //VERIFY
                classEnv.GetLastMethodLog().State.ShouldEqual(LogStates.NotSupported);
            }
        }
Exemplo n.º 28
0
        public void TestSingleIntEqualsUniqueValue()
        {
            using (var env = new MethodEnvironment(classEnv))
            {
                //SETUP
                var linq =
                    env.Db.EfParents.Select(x => new {x.EfParentId, x.ParentInt})
                        .Single(x => x.ParentInt == DatabaseHelpers.ParentIntUniqueValue).EfParentId;

                //ATTEMPT
                env.AboutToUseDelegateDecompiler();
                var dd =
                    env.Db.EfParents.Select(x => new {x.EfParentId, x.IntEqualsUniqueValue})
                        .Decompile()
                        .Single(x => x.IntEqualsUniqueValue)
                        .EfParentId;

                //VERIFY
                env.CompareAndLogSingleton(linq, dd);
            }
        }
Exemplo n.º 29
0
        public void TestSelectMethodWithoutComputedAttribute()
        {
            using (var env = new MethodEnvironment(classEnv))
            {
                //SETUP
                var linq = env.Db.EfPersons.Select(x => x.FirstName + " " + x.MiddleName + " " + x.LastName).ToList();

                //ATTEMPT
                env.AboutToUseDelegateDecompiler();
                var dd = env.Db.EfPersons.Select(x => x.GetFullNameNoAttibute()).Decompile().ToList();

                //VERIFY
                env.CompareAndLogList(linq, dd);
            }
        }