예제 #1
0
        public void GetAllDefault()
        {
            // setting up the expectation
            var activeLawyerRecords = Lawyers.Where(l => l.Active == true).ToList();

            // test that GetAll() fetches the Lawyers list
            using (LawyerService lawyerService = new LawyerService(MockContext.Object))
            {
                var actual = lawyerService.GetAll();
                CollectionAssert.AreEqual(activeLawyerRecords, actual.ToList());
            }
        }
예제 #2
0
        public void GetAllWithParameters()
        {
            // setting up the expectation
            var defaultParams            = Doubles.GetParameters(); // nothing included and no search by name or surname
            var defaultParamsExpectation = Lawyers.Where(l => l.Active == true).ToList();

            var includeGender            = Doubles.GetParameters(IncludeGender: true);
            var includeGenderExpectation = Lawyers.Where(l => l.Active == true).Select(l =>
            {
                l.Gender = Doubles.GetById(Genders, l.GenderRefId);
                return(l);
            }).ToList();

            var includeTitle            = Doubles.GetParameters(IncludeTitle: true);
            var includeTitleExpectation = Lawyers.Where(l => l.Active == true).Select(l =>
            {
                if (l.TitleRefId.HasValue)
                {
                    l.Title = Doubles.GetById(Titles, l.TitleRefId.Value);
                }
                return(l);
            }).ToList();

            var includeInactive            = Doubles.GetParameters(IncludeInactive: true);
            var includeInactiveExpectation = Lawyers.ToList();

            var searchNameInDefaults            = Doubles.GetParameters(Name: "Elp");
            var searchNameInDefaultsExpectation = Lawyers.Where(l => l.Active == true && l.Name.ToLower().Contains("Elp".ToLower())).ToList();

            var searchSurnameInDefaults            = Doubles.GetParameters(Surname: "Tromp");
            var searchSurnameInDefaultsExpectation = Lawyers.Where(l => l.Active == true && l.Surname.ToLower().Contains("Tromp".ToLower())).ToList();

            var searchNameInAll            = Doubles.GetParameters(Name: "Elp", IncludeInactive: true);
            var searchNameInAllExpectation = Lawyers.Where(l => l.Name.ToLower().Contains("Elp".ToLower())).ToList();

            var searchSurnameInAll            = Doubles.GetParameters(Surname: "Tromp", IncludeInactive: true);
            var searchSurnameInAllExpectation = Lawyers.Where(l => l.Surname.ToLower().Contains("Tromp".ToLower())).ToList();

            using (LawyerService lawyerService = new LawyerService(MockContext.Object))
            {
                var actual = lawyerService.GetAll(defaultParams);
                CollectionAssert.AreEqual(defaultParamsExpectation, actual.ToList());

                actual = lawyerService.GetAll(includeGender);
                CollectionAssert.AreEqual(includeGenderExpectation, actual.ToList());

                actual = lawyerService.GetAll(includeTitle);
                CollectionAssert.AreEqual(includeTitleExpectation, actual.ToList());

                actual = lawyerService.GetAll(includeInactive);
                CollectionAssert.AreEqual(includeInactiveExpectation, actual.ToList());

                actual = lawyerService.GetAll(searchNameInDefaults);
                CollectionAssert.AreEqual(searchNameInDefaultsExpectation, actual.ToList());

                actual = lawyerService.GetAll(searchSurnameInDefaults);
                CollectionAssert.AreEqual(searchSurnameInDefaultsExpectation, actual.ToList());

                actual = lawyerService.GetAll(searchNameInAll);
                CollectionAssert.AreEqual(searchNameInAllExpectation, actual.ToList());

                actual = lawyerService.GetAll(searchSurnameInAll);
                CollectionAssert.AreEqual(searchSurnameInAllExpectation, actual.ToList());
            }
        }