public StatisticsDTO GetStatistics(int userId, StatisticsRequestDTO dto)
        {
            if (dto == null)
            {
                throw new ArgumentNullException("dto");
            }

            var key = _keyFactory
                .CreateKey()
                .Add("statistics")
                .AddTag("expence", "create", userId)
                .AddTag("expence", "update", userId)
                .AddTag("expence", "delete", userId)
                .Add("from").Add(dto.From.ToShortDateString())
                .Add("to").Add(dto.To.ToShortDateString())
                .GetKey();

            var resultDTO = _cache.Get<StatisticsDTO>(key);
            if (resultDTO == null)
            {
                var spec = new AndSpecification<Expence>(
                    ExpenceSpecifications.ByUserId(userId),
                    ExpenceSpecifications.DateFilter(dto.From, dto.To));

                //TODO: make async calls
                var summary = _statsRepostiory
                    .GetSummary(spec);

                var topCategories = _statsRepostiory
                    .GetCategoriesRating(spec)
                    .Take(5);

                resultDTO =
                    new StatisticsDTO
                    {
                        Summary =
                            new SummaryStatisticsDTO
                            {
                                Total = summary.Total
                            },
                        TopCategories =
                            topCategories.Select(c =>
                                new CategorySummaryDTO
                                {
                                    Name = c.CategoryName,
                                    Total = c.Total
                                })
                    };

                _cache.Set(
                    key,
                    resultDTO,
                    new System.Runtime.Caching.CacheItemPolicy
                    {
                        SlidingExpiration = TimeSpan.FromDays(1)
                    });
            }

            return resultDTO;
        }
		public void Test_And_AllTrue()
		{
			AndSpecification s = new AndSpecification();
			s.Add(AlwaysTrue);
			s.Add(AlwaysTrue);
			Assert.IsTrue(s.Test(null).Success);
		}
        public void CreateAndSpecificationTest()
        {
            //Arrange
            DirectSpecification<SampleEntity> leftAdHocSpecification;
            DirectSpecification<SampleEntity> rightAdHocSpecification;

            var identifier = Guid.NewGuid();
            Expression<Func<SampleEntity, bool>> leftSpec = s => s.Id == identifier;
            Expression<Func<SampleEntity, bool>> rightSpec = s => s.SampleProperty.Length > 2;

            leftAdHocSpecification = new DirectSpecification<SampleEntity>(leftSpec);
            rightAdHocSpecification = new DirectSpecification<SampleEntity>(rightSpec);

            //Act
            AndSpecification<SampleEntity> composite = new AndSpecification<SampleEntity>(leftAdHocSpecification, rightAdHocSpecification);

            //Assert
            Assert.IsNotNull(composite.SatisfiedBy());
            Assert.ReferenceEquals(leftAdHocSpecification, composite.LeftSideSpecification);
            Assert.ReferenceEquals(rightAdHocSpecification, composite.RightSideSpecification);

            var list = new List<SampleEntity>();
            var sampleA = new SampleEntity() {  SampleProperty = "1" };
            sampleA.ChangeCurrentIdentity(identifier);

            var sampleB = new SampleEntity() { SampleProperty = "the sample property" };
            sampleB.ChangeCurrentIdentity(identifier);

            list.AddRange(new SampleEntity[] { sampleA, sampleB });
            

            var result = list.AsQueryable().Where(composite.SatisfiedBy()).ToList();

            Assert.IsTrue(result.Count == 1);
        }
		public void Test_And_Mixed()
		{
			AndSpecification s = new AndSpecification();
			s.Add(AlwaysFalse);
			s.Add(AlwaysTrue);
			Assert.IsFalse(s.Test(null).Success);
		}
            public void TwoPassingSpecsShouldPass()
            {
                var sut = new AndSpecification<int>(new FunctionSpecification<int>(i => i > 0), new FunctionSpecification<int>(i => i > 0));

                var result = sut.IsSatisfiedBy(1);

                result.Should().BeTrue();
            }
        public void IsSatisfiedByReturnsFalseIBothArentSatisfied()
        {
            _left = SpecificationGenerator.GetSpecification(false);
            _right = SpecificationGenerator.GetSpecification(false);
            var andSpecification = new AndSpecification<object>(_left, _right);

            Assert.False(andSpecification.IsSatisfiedBy(string.Empty));
        }
 /// <summary>
 ///     获取登录用户信息
 /// </summary>
 /// <param name="userName"></param>
 /// <param name="password"></param>
 /// <returns></returns>
 public EmployeeDataObject GetLoginEmployee(string userName, string password)
 {
     ISpecification<Employee> specification = new AndSpecification<Employee>(new EmployeeUserNameEqualSpecification(userName),
         new EmployeePasswordEqualSpecification(password));
     
     Employee entity = this._employeeRepository.Find(specification);
     return Mapper.Map<Employee, EmployeeDataObject>(entity);
 }
        public void IsSatisfiedByReturnsTrueIfBothAreSatisfiedBy()
        {
            _left = SpecificationGenerator.GetSpecification(true);
            _right = SpecificationGenerator.GetSpecification(true);
            var andSpecification = new AndSpecification<object>(_left, _right);

            Assert.True(andSpecification.IsSatisfiedBy(string.Empty));
        }
            public void TwoFailingSpecsShouldFail()
            {
                var sut = new AndSpecification<int>(new FunctionSpecification<int>(i => i > 0), new FunctionSpecification<int>(i => i > 0));

                var result = sut.IsSatisfiedBy(0);

                result.Should().BeFalse();
            }
        public void WhenSpecificationsAreDefinedThenResultIsAndSpecification()
        {
            var hasDrm = new HasDrmSpecification();
            var hasEps = new HasAtLeaseOneEpisodeSpecification();
            var sut = new AndSpecification<TvShow>(hasDrm, hasEps);

            Assert.IsInstanceOf<AndSpecification<TvShow>>(sut);
            Assert.IsTrue(sut.IsSatisfiedBy(new TvShow { Drm = true, EpisodeCount = 1 }));
        }
示例#11
0
        public void Should_Be_Fine_If_None_Are_Null()
        {
            var p1 = new PredicateSpecification<int>(x => x == 5);
            var p2 = new PredicateSpecification<int>(x => x >= 5);

            var spec = new AndSpecification<int>(p1, p2);

            Assert.AreEqual(spec.Left, p1);
            Assert.AreEqual(spec.Right, p2);
        }
示例#12
0
        public void AndMethodWithValidArgumentsShouldReturnAndSpecification()
        {
            Specification<object> spec1 = SpecificationUtils.CreateSatisfiedSpecification();
            Specification<object> spec2 = SpecificationUtils.CreateSatisfiedSpecification();
            Specification<object> expectedResult = new AndSpecification<object>(spec1, spec2);

            Specification<object> result = spec1.And(spec2);

            Assert.AreEqual(expectedResult, result);
        }
示例#13
0
        public void AndTestCase3()
        {
            var left = new ExpressionSpecification<String>( x => false );
            var right = new ExpressionSpecification<String>( x => true );
            var target = new AndSpecification<String>( left, right );

            var actual = target.And( new ExpressionSpecification<String>( x => false ) );
            var result = actual.IsSatisfiedBy( String.Empty );
            Assert.IsFalse( result );
        }
示例#14
0
        public void AndTestCaseNullCheck()
        {
            var left = new ExpressionSpecification<String>( x => false );
            var right = new ExpressionSpecification<String>( x => true );
            var target = new AndSpecification<String>( left, right );

            ExpressionSpecification<String> other = null;
            Action test = () => target.And( other );

            test.ShouldThrow<ArgumentNullException>();
        }
        public bool Match(MethodInfo method)
        {
            TypeInformationExtractor typeExtractor = new TypeInformationExtractor(_parameter);

            ISpecification<MethodInfo> exactlyOneParameter = new ExactlyOneMethodParameterSpecification();
            ISpecification<MethodInfo> parameterTypeMatch = new FirstMethodParameterTypeSpecification(typeExtractor.ExtractType());

            ISpecification<MethodInfo> exactlyOneParameterAndParameterTypeMatch = new AndSpecification<MethodInfo>(exactlyOneParameter, parameterTypeMatch);

            return exactlyOneParameterAndParameterTypeMatch.IsSatisfiedBy(method);
        }
示例#16
0
        public void CriaAndSpecificationComLambdaRightNullEThrowArgumentNullExceptionTest()
        {
            //Arrange
            CompositeSpecification<ClienteStub> compoSpecification;
            Expression<Func<ClienteStub, bool>> lambda = s => s.Nome != string.Empty;

            DirectSpecification<ClienteStub> direct = new DirectSpecification<ClienteStub>(lambda);

            //Act
            compoSpecification = new AndSpecification<ClienteStub>(direct, null);
        }
示例#17
0
        public void AndSpecificationSatisfiedTest()
        {
            // Arrange
            var specification = new AndSpecification<int>(
                new Specification<int>(x => x > 0), new Specification<int>(y => y < 10));

            // Act
            var sut = specification.IsSatisfiedBy().Compile().Invoke(5);

            // Assert
            Assert.True(sut);
        }
 private void AssertIsSatisfiedBy(bool leftSpecificationIsSatisfiedBy, bool rightSpecificationIsSatisfiedBy,
     bool expected)
 {
     var mockRepository = new MockRepository(MockBehavior.Strict);
     var leftSpecification = mockRepository.CreateSpecificationMock<string>(leftSpecificationIsSatisfiedBy);
     var rightSpecification = !leftSpecificationIsSatisfiedBy
                                  ? mockRepository.CreateSpecificationMock<string>()
                                  : mockRepository.CreateSpecificationMock<string>(
                                      rightSpecificationIsSatisfiedBy);
     var specification = new AndSpecification<string>(leftSpecification, rightSpecification);
     Assert.AreEqual(expected, specification.IsSatisfiedBy("test"));
     mockRepository.VerifyAll();
 }
示例#19
0
        public void CreateAndSpecificationTest()
        {
            var leftAdHocSpecification = new DirectSpecification<SampleEntity>(s => s.Name == EntityName);
            var rightAdHocSpecification = new DirectSpecification<SampleEntity>(s => s.Order > 1);

            var composite = new AndSpecification<SampleEntity>(leftAdHocSpecification, rightAdHocSpecification);

            Assert.IsNotNull(composite.SatisfiedBy());
            Assert.AreEqual(leftAdHocSpecification, composite.LeftSideSpecification);
            Assert.AreEqual(rightAdHocSpecification, composite.RightSideSpecification);

            var result = EntityList.AsQueryable().Where(composite.SatisfiedBy()).ToList();

            Assert.AreEqual(1, result.Count);
        }
示例#20
0
        public void CreateAndSpecificationNullRightSpecThrowArgumentNullExceptionTest()
        {
            //Arrange
            DirectSpecification<SampleEntity> leftAdHocSpecification;
            DirectSpecification<SampleEntity> rightAdHocSpecification;

            Expression<Func<SampleEntity, bool>> rightSpec = s => s.Id == IdentityGenerator.NewSequentialGuid();
            Expression<Func<SampleEntity, bool>> leftSpec = s => s.SampleProperty.Length > 2;

            leftAdHocSpecification = new DirectSpecification<SampleEntity>(leftSpec);
            rightAdHocSpecification = new DirectSpecification<SampleEntity>(rightSpec);

            //Act
            AndSpecification<SampleEntity> composite = new AndSpecification<SampleEntity>(leftAdHocSpecification, null);
        }
        public void AndSpecification_Creation_NullRightSpecThrowArgumentNullException_Test()
        {
            //Arrange
            DirectSpecification<TEntity> leftAdHocSpecification;
            DirectSpecification<TEntity> rightAdHocSpecification;

            Expression<Func<TEntity, bool>> rightSpec = s=>s.Id==0;
            Expression<Func<TEntity, bool>> leftSpec = s => s.SampleProperty.Length > 2;

            leftAdHocSpecification = new DirectSpecification<TEntity>(leftSpec);
            rightAdHocSpecification = new DirectSpecification<TEntity>(rightSpec);

            //Act
            AndSpecification<TEntity> composite = new AndSpecification<TEntity>(leftAdHocSpecification, null);
        }
        public void TestColorAndSizeFilter()
        {
            Size size = Size.Large;
            Color color = Color.Red;
            var spec1 = new SizeSpecification(size);
            var spec2 = new ColorSpecification(color);
            var andSizeSpecification = new AndSpecification(spec1, spec2);

            IList<IProduct> filterList = filter.Filter(_productList, andSizeSpecification);
            foreach (var product in filterList)
            {
                bool matched = (product.Color == color) && (product.Size == size);
                Assert.IsTrue(matched);
            }
        }
                public When_First_Option_Is_True()
                {
                    subject = new object();
                    option = new AndSpecification(
                        new TrueSpecification(),
                        new Specification(
                            s => {
                                funcSubject = s;
                                funcCalled = true;
                                return false;
                            }
                        )
                    );

                    option.IsSatisfiedBy(subject);
                }
                public When_Invoked()
                {
                    subject = new object();

                    option = new AndSpecification(
                        new Specification(
                            s => {
                                option1Subject = s;
                                option1Called = true;
                                return false;
                            }
                        ),
                        new NoSpecification()
                    );

                    option.IsSatisfiedBy(subject);
                }
示例#25
0
        public void And_Should_Return_True_If_Both_Arguments_Are_True()
        {
            var mocks = new MockRepository();
            var s1 = mocks.StrictMock<ISpecification<int>>();
            var s2 = mocks.StrictMock<ISpecification<int>>();

            Expect.Call(s1.IsSatisfiedBy(5)).Return(true);
            Expect.Call(s2.IsSatisfiedBy(5)).Return(true);

            mocks.ReplayAll();

            var andSpecification = new AndSpecification<int>(s1, s2);

            Assert.AreEqual(andSpecification.IsSatisfiedBy(5), true);

            mocks.VerifyAll();
        }
        public void testAndIsSatisifedBy()
        {
            AlwaysTrueSpec trueSpec = new AlwaysTrueSpec();
            AlwaysFalseSpec falseSpec = new AlwaysFalseSpec();

            AndSpecification<object> andSpecification = new AndSpecification<object>(trueSpec, trueSpec);
            Assert.True(andSpecification.isSatisfiedBy(new object()));

            andSpecification = new AndSpecification<object>(falseSpec, trueSpec);
            Assert.False(andSpecification.isSatisfiedBy(new object()));

            andSpecification = new AndSpecification<object>(trueSpec, falseSpec);
            Assert.False(andSpecification.isSatisfiedBy(new object()));

            andSpecification = new AndSpecification<object>(falseSpec, falseSpec);
            Assert.False(andSpecification.isSatisfiedBy(new object()));
        }
示例#27
0
        public void CriaAndSpecificationTest()
        {
            Expression<Func<ClienteStub, bool>> leftLambda = s => string.IsNullOrWhiteSpace(s.Nome) == false;
            Expression<Func<ClienteStub, bool>> rightLambda = s => s.Nome.ToUpper() != "MARCUS";

            var leftSpecification = new DirectSpecification<ClienteStub>(leftLambda);
            var rightSpecification = new DirectSpecification<ClienteStub>(rightLambda);

            CompositeSpecification<ClienteStub> andSpec = new AndSpecification<ClienteStub>(leftSpecification, rightSpecification);

            List<ClienteStub> listaCliente = new List<ClienteStub>();

            listaCliente.Add(new ClienteStub() { Nome = "luiz" });

            var result = listaCliente.AsQueryable().Where(andSpec.SatisfiedBy()).ToList();

            Assert.IsTrue(result.Count == 1);
        }
		public void ItShouldReturnTheCorrectValueForAllPossibleLHSAndRHSCombinations(bool lhsResult, bool rhsResult, bool expected)
		{
			// Arrange
			var item = new TestType();

			var lhs = A.Fake<ISpecification<TestType>>();
			A.CallTo(() => lhs.IsSatisfiedBy(item)).Returns(lhsResult);

			var rhs = A.Fake<ISpecification<TestType>>();
			A.CallTo(() => rhs.IsSatisfiedBy(item)).Returns(rhsResult);

			var sut = new AndSpecification<TestType>(lhs, rhs);

			// Act
			var result = sut.IsSatisfiedBy(item);

			// Assert
			result.Should().Be(expected);
		}
        public void Filter_GetLargeBlackProducts_ReturnListWithSingleElement()
        {
            IEnumerable <Product> products = new List <Product>()
            {
                new Product("Polo Shirt", ProductColor.Black, ProductSize.L),
                new Product("T-Shirt", ProductColor.Blue, ProductSize.XS),
                new Product("T-Shirt", ProductColor.Red, ProductSize.S),
                new Product("Jeans", ProductColor.Blue, ProductSize.XL),
                new Product("Jeans", ProductColor.Black, ProductSize.XL),
            };
            var betterFilter     = new BetterFilter();
            var andSpecification = new AndSpecification <Product>(
                new ColorSpecification(ProductColor.Black),
                new SizeSpecification(ProductSize.L));

            var filteredProducts = betterFilter.Filter(products, andSpecification).ToList();

            Assert.That(filteredProducts.Count, Is.EqualTo(1));
            return;
        }
        public void AndSpecification_Creation_Test()
        {
            //Arrange
            DirectSpecification <TEntity> leftAdHocSpecification;
            DirectSpecification <TEntity> rightAdHocSpecification;

            Expression <Func <TEntity, bool> > leftSpec  = s => s.Id == 0;
            Expression <Func <TEntity, bool> > rightSpec = s => s.SampleProperty.Length > 2;

            leftAdHocSpecification  = new DirectSpecification <TEntity>(leftSpec);
            rightAdHocSpecification = new DirectSpecification <TEntity>(rightSpec);

            //Act
            AndSpecification <TEntity> composite = new AndSpecification <TEntity>(leftAdHocSpecification, rightAdHocSpecification);

            //Assert
            Assert.IsNotNull(composite.SatisfiedBy());
            Assert.ReferenceEquals(leftAdHocSpecification, composite.LeftSideSpecification);
            Assert.ReferenceEquals(rightAdHocSpecification, composite.RightSideSpecification);
        }
        public void ResolveValueRefsError()
        {
            SpecificationValue refValue = SpecificationValue.Ref("qwe");
            AndSpecification   and      = new AndSpecification(
                new EqualSpecification("qwe", SpecificationValue.Single(1)),
                new LessOrEqualSpecification("qwe", refValue));

            Dictionary <string, object> values = new Dictionary <string, object> {
                { "qwe", TimeSpan.FromDays(1) }
            };
            AndSpecification resolved = and.ResolveValueRefs(
                values,
                new ReferenceResolutionSettings {
                ThrowValueErrors = false
            });
            var kv = Assert.IsType <LessOrEqualSpecification>(resolved.Specifications.Last());

            Assert.True(kv.Value.IsReference);
            Assert.Same(refValue, kv.Value);
        }
示例#32
0
        //[ExpectedException(typeof(ArgumentNullException))]
        public void CreateAndSpecificationNullRightSpecThrowArgumentNullExceptionTest()
        {
            //Arrange
            DirectSpecification <SampleEntity> leftAdHocSpecification;
            DirectSpecification <SampleEntity> rightAdHocSpecification;

            Expression <Func <SampleEntity, bool> > rightSpec = s => s.Id == Guid.NewGuid();
            Expression <Func <SampleEntity, bool> > leftSpec  = s => s.SampleProperty.Length > 2;

            leftAdHocSpecification  = new DirectSpecification <SampleEntity>(leftSpec);
            rightAdHocSpecification = new DirectSpecification <SampleEntity>(rightSpec);

            //Act
            AndSpecification <SampleEntity> composite = new AndSpecification <SampleEntity>(leftAdHocSpecification, null);

            Assert.IsTrue(composite.IsSatisfiedBy(new SampleEntity()
            {
                SampleProperty = "asdasd"
            }));
        }
示例#33
0
        public void And_Should_Return_False_If_Different_Or_Both_Are_False()
        {
            var mocks = new MockRepository();
            var s1    = mocks.StrictMock <ISpecification <int> >();
            var s2    = mocks.StrictMock <ISpecification <int> >();

            Expect.Call(s1.IsSatisfiedBy(5)).Return(true);
            Expect.Call(s2.IsSatisfiedBy(5)).Return(false);

            Expect.Call(s1.IsSatisfiedBy(5)).Return(false);

            mocks.ReplayAll();

            var andSpecification = new AndSpecification <int>(s1, s2);

            Assert.AreEqual(andSpecification.IsSatisfiedBy(5), false);
            Assert.AreEqual(andSpecification.IsSatisfiedBy(5), false);

            mocks.VerifyAll();
        }
示例#34
0
        public DTO.ClientDTOList GetAll(string keywords = "", Guid?departmentId = null)
        {
            var clients = new ClientDTOList();
            ISpecification <Client> spec = Specification <Client> .Eval(item => true);

            spec = new AndSpecification <Client>(spec,
                                                 Specification <Client> .Eval(item =>
                                                                              keywords == "" ||
                                                                              item.Name.Contains(keywords)));
            spec = new AndSpecification <Client>(spec,
                                                 Specification <Client> .Eval(item =>
                                                                              !departmentId.HasValue ||
                                                                              item.DepartmentId == departmentId.Value));

            this._IClientRepository.GetAll(spec).ToList().ForEach(item =>
                                                                  clients.Add(AutoMapper.Mapper.Map <Client, ClientDTO>(item))
                                                                  );
            this.AppendUserInfo(clients, this._IUserRepository.Data);
            return(clients);
        }
示例#35
0
        public F_UserDTOList GetUsers(bool?isActive = true, string keywords = "", F_UserTypeEnum?userType = null, string sort = "createddate_desc")
        {
            var userDTOList = new F_UserDTOList();

            ISpecification <F_User> spec = Specification <F_User> .Eval(user => true);

            spec = new AndSpecification <F_User>(spec,
                                                 Specification <F_User> .Eval(user => isActive == null || user.IsActive == isActive.Value));
            spec = new AndSpecification <F_User>(spec,
                                                 Specification <F_User> .Eval(user => (keywords == "") || user.UserName.Contains(keywords)));

            spec = new AndSpecification <F_User>(spec,
                                                 Specification <F_User> .Eval(user => (userType == null) || user.UserType == userType));


            this._IF_UserRepository.GetAll(spec, sort).ToList().ForEach(item =>
                                                                        userDTOList.Add(Mapper.Map <F_User, F_UserDTO>(item)));
            this.F_AppendUserInfo(userDTOList, this._IF_UserRepository.Data);
            return(userDTOList);
        }
示例#36
0
        public static void Main(string[] args)
        {
            var mobiles = new List<Mobile>() {
                new Mobile(MobileBrand.Apple, MobileType.Smart),
                new Mobile(MobileBrand.Samsung, MobileType.Smart),
                new Mobile(MobileBrand.Samsung, MobileType.Basic)
            };

            var smartSpecification = new ExpressionSpecification<Mobile>(mobile => mobile.Type == MobileType.Smart);
            var appleSpecification = new ExpressionSpecification<Mobile>(mobile => mobile.Brand == MobileBrand.Apple);
            // find all smart mobiles;
            var smartMobiles = mobiles.FindAll(mobile => smartSpecification.IsSatisfiedBy(mobile));
            // find all apple smart mobiles;
            var andSpecification = new AndSpecification<Mobile>(smartSpecification, appleSpecification);
            var appleSmartMobiles = mobiles.FindAll(mobile => andSpecification.IsSatisfiedBy(mobile));

            Console.WriteLine("Hello World!");

            Console.ReadKey();
        }
        public void AndSpecification_Creation_Test()
        {
            //Arrange
            DirectSpecification<TEntity> leftAdHocSpecification;
            DirectSpecification<TEntity> rightAdHocSpecification;

            Expression<Func<TEntity, bool>> leftSpec = s => s.Id == 0;
            Expression<Func<TEntity, bool>> rightSpec = s => s.SampleProperty.Length > 2;

            leftAdHocSpecification = new DirectSpecification<TEntity>(leftSpec);
            rightAdHocSpecification = new DirectSpecification<TEntity>(rightSpec);

            //Act
            AndSpecification<TEntity> composite = new AndSpecification<TEntity>(leftAdHocSpecification, rightAdHocSpecification);

            //Assert
            Assert.IsNotNull(composite.SatisfiedBy());
            Assert.ReferenceEquals(leftAdHocSpecification, composite.LeftSideSpecification);
            Assert.ReferenceEquals(rightAdHocSpecification, composite.RightSideSpecification);
        }
示例#38
0
        /// <summary>
        /// 根据银行编码获取银行用户
        /// </summary>
        /// <param name="bankCode">银行编码</param>
        /// <returns></returns>
        public List <G_UserDetailDTO> GetUserByBank(string bankCode)
        {
            ISpecification <G_UserDetail> spec = Specification <G_UserDetail> .Eval(item => true);

            spec = new AndSpecification <G_UserDetail>(spec,
                                                       Specification <G_UserDetail> .Eval(item =>
                                                                                          bankCode == null || bankCode == "" || item.BankCode.Equals(bankCode)
                                                                                          ));
            spec = new AndSpecification <G_UserDetail>(spec,
                                                       Specification <G_UserDetail> .Eval(item =>
                                                                                          item.G_User.UserType == G_UserTypeEnum.BC ||
                                                                                          item.G_User.UserType == G_UserTypeEnum.BM
                                                                                          ));

            var list = new List <G_UserDetailDTO>();

            this._IG_UserDetailRepository.GetAll(spec).ToList().ForEach(item =>
                                                                        list.Add(Mapper.Map <G_UserDetail, G_UserDetailDTO>(item))
                                                                        );
            return(list);
        }
示例#39
0
        public List <F_ActivityDTO> GetAll(Guid?referenceId, bool?isRead, bool?isGlobal)
        {
            ISpecification <F_Activity> spec = Specification <F_Activity> .Eval(item => true);

            spec = new AndSpecification <F_Activity>(spec,
                                                     Specification <F_Activity> .Eval(item =>
                                                                                      referenceId == null || item.ReferenceId.Equals(referenceId.Value)));
            spec = new AndSpecification <F_Activity>(spec,
                                                     Specification <F_Activity> .Eval(item =>
                                                                                      isRead == null || item.IsRead.Equals(isRead.Value)));
            spec = new AndSpecification <F_Activity>(spec,
                                                     Specification <F_Activity> .Eval(item =>
                                                                                      isGlobal == null || item.IsGlobal.Equals(isGlobal.Value)));

            var list = new List <F_ActivityDTO>();

            this._IF_ActivityRepository.GetAll(spec).ToList().ForEach(item =>
                                                                      list.Add(Mapper.Map <F_Activity, F_ActivityDTO>(item))
                                                                      );
            return(list);
        }
示例#40
0
        public List <F_BankOptionDTO> GetAll(bool?isAdmin = null, string sort = "order_desc")
        {
            ISpecification <F_BankOption> spec = Specification <F_BankOption> .Eval(item => true);

            spec = new AndSpecification <F_BankOption>(spec,
                                                       Specification <F_BankOption> .Eval(item => item.F_Bank.IsActive));
            if (isAdmin != null)
            {
                spec = new AndSpecification <F_BankOption>(spec,
                                                           Specification <F_BankOption> .Eval(item =>
                                                                                              isAdmin == null || isAdmin.HasValue || item.F_Bank.IsAdmin.Equals(isAdmin.Value)
                                                                                              ));
            }

            var list = new List <F_BankOptionDTO>();

            this._IF_BankOptionRepository.GetAll(spec, sort).ToList().ForEach(item =>
                                                                              list.Add(Mapper.Map <F_BankOption, F_BankOptionDTO>(item))
                                                                              );
            return(list);
        }
示例#41
0
        public void IsSatisfiedBy_04()
        {
            // arrange:
            object candidate             = new object();
            ISpecification <object> left = MockRepository.GenerateMock <ISpecification <object> >();

            left.Expect(s => s.IsSatisfiedBy(candidate)).Return(false);
            ISpecification <object> right = MockRepository.GenerateMock <ISpecification <object> >();

            right.Expect(s => s.IsSatisfiedBy(candidate)).Return(false);


            // act:
            ISpecification <object> target = new AndSpecification <object>(left, right);
            bool satisfied = target.IsSatisfiedBy(candidate);

            // assert:
            Assert.IsFalse(satisfied);
            left.VerifyAllExpectations();
            right.AssertWasNotCalled(s => s.IsSatisfiedBy(candidate));
        }
        public void ResolveSpecRefGeneric()
        {
            AndSpecification and = new AndSpecification(
                new EqualSpecification("qwe", SpecificationValue.Single(1)),
                new ReferenceSpecification("qwe"));

            LessOrEqualSpecification    specification = new LessOrEqualSpecification("qwe", SpecificationValue.Single(1));
            Dictionary <string, object> values        =
                new Dictionary <string, object>
            {
                {
                    "qwe",
                    specification
                }
            };

            AndSpecification resolved = and.ResolveSpecificationRefs(values);
            var kv = Assert.IsType <LessOrEqualSpecification>(resolved.Specifications.Last());

            Assert.Same(specification, kv);
        }
示例#43
0
        public void CriaAndSpecificationTest()
        {
            Expression <Func <ClienteStub, bool> > leftLambda  = s => string.IsNullOrWhiteSpace(s.Nome) == false;
            Expression <Func <ClienteStub, bool> > rightLambda = s => s.Nome.ToUpper() != "MARCUS";

            var leftSpecification  = new DirectSpecification <ClienteStub>(leftLambda);
            var rightSpecification = new DirectSpecification <ClienteStub>(rightLambda);

            CompositeSpecification <ClienteStub> andSpec = new AndSpecification <ClienteStub>(leftSpecification, rightSpecification);

            List <ClienteStub> listaCliente = new List <ClienteStub>();

            listaCliente.Add(new ClienteStub()
            {
                Nome = "luiz"
            });

            var result = listaCliente.AsQueryable().Where(andSpec.SatisfiedBy()).ToList();

            Assert.IsTrue(result.Count == 1);
        }
示例#44
0
        public List <G_NewsDTO> GetAll(string code = "", string title = "")
        {
            ISpecification <G_News> spec = Specification <G_News> .Eval(item => true);

            spec = new AndSpecification <G_News>(spec,
                                                 Specification <G_News> .Eval(item =>
                                                                              code == "" || item.Code.Equals(code)));

            spec = new AndSpecification <G_News>(spec,
                                                 Specification <G_News> .Eval(item =>
                                                                              title == "" || item.Title.Contains(title)));

            spec = new AndSpecification <G_News>(spec,
                                                 Specification <G_News> .Eval(item => item.IsActive));

            var list = new List <G_NewsDTO>();

            this._IG_NewsRepository.GetAll(spec).ToList().ForEach(item =>
                                                                  list.Add(Mapper.Map <G_News, G_NewsDTO>(item))
                                                                  );
            return(list);
        }
        public void GetTotalAmountForCategory_ReturnsCorrectTotal()
        {
            // Arrange
            var manualEntryManager = GenerateManualEntryManager();

            manualEntryManager.Add(DateTime.ParseExact("01/02/2017", "dd/MM/yyyy", CultureInfo.InvariantCulture),
                                   "petrol",
                                   2000,
                                   "testDescription");

            var startDate = DateTime.ParseExact("01/01/2017", "dd/MM/yyyy", CultureInfo.InvariantCulture);
            var endDate   = DateTime.ParseExact("01/01/2018", "dd/MM/yyyy", CultureInfo.InvariantCulture);

            var specifications = new AndSpecification <Entry>(new EntryDateSpecification(startDate, endDate),
                                                              new EntryCategorySpecification("petrol"));

            // Act
            var total = manualEntryManager.GetTotal(specifications);

            // Assert
            Assert.AreEqual(2500, actual: total);
        }
        public void Filter_Based_On_AlbumSongSpecification_And_FilterSongSpecification()
        {
            var specification = new AndSpecification <Song>(new AlbumSongSpecification(2), new FilterSongSpecification
            {
                GenreIdsToInclude = new List <int> {
                    1, 2, 3
                },
                AlbumIdsToinclude = new List <int> {
                    1, 2, 3, 5
                },
                ArtistsToInclude = new List <string> {
                    "Eagles", "Michael Jackson", "Pink Floyd"
                },
                TitleFilter = "Th",
                MinRating   = 4
            });

            var songs = new SongRepository().Read(specification);

            Assert.Single(songs);
            Assert.Equal("Thriller", songs.First().Title);
        }
示例#47
0
        //-------------------------------------------------------------------------

        private void RefreshProfilingInformation()
        {
            double totalExpenditure = _infoCollection.ManualEntriesInfo.GetTotal(new EntryMonthSpecification(endDatePicker.Value.Date));
            double totalBudget      = _infoCollection.CategoriesInfo.GetTotalBudgetAmount();

            totalsOutput.Text      = Convert.ToString(totalExpenditure, CultureInfo.InvariantCulture);
            totalsOutput.BackColor = totalExpenditure > totalBudget ? Color.Red : Color.Green;

            budgetTotalOutput.Text = Convert.ToString(totalBudget, CultureInfo.InvariantCulture);

            totalsTable.Rows.Clear();

            foreach (var category in _infoCollection.CategoriesInfo.GetCategoryNames())
            {
                var specifications = new AndSpecification <Entry>(new EntryMonthSpecification(endDatePicker.Value.Date),
                                                                  new EntryCategorySpecification(category));

                var index = totalsTable.Rows.Add();
                totalsTable.Rows[index].Cells["totalsCategory"].Value = category;
                totalsTable.Rows[index].Cells["totalsAmount"].Value   = _infoCollection.ManualEntriesInfo.GetTotal(specifications);
            }
        }
        public void ResolveValueRefPartial()
        {
            AndSpecification and = new AndSpecification(
                new EqualSpecification("qwe", SpecificationValue.Single(1)),
                new LessOrEqualSpecification("qwe", SpecificationValue.Ref("qwe")));

            Dictionary <string, object> values = new Dictionary <string, object>
            {
                { "qwe", SpecificationValue.Ref("qwe2") },
            };
            ReferenceResolutionSettings settings = new ReferenceResolutionSettings();

            settings.AllowedUnresolvedValueReferenceKeys.Add("qwe2");

            AndSpecification resolved = and.ResolveValueRefs(
                values,
                settings);
            var kv = Assert.IsType <LessOrEqualSpecification>(resolved.Specifications.Last());

            Assert.True(kv.Value.IsReference);
            Assert.Equal("qwe2", kv.Value.Values.Single());
        }
示例#49
0
        public DTO.ContractDTOList GetAll(string keywords = "", Guid?clientId = null, Guid?userId = null, Guid?departmentId = null)
        {
            var Contracts = new ContractDTOList();
            ISpecification <Contract> spec = Specification <Contract> .Eval(item => true);

            spec = new AndSpecification <Contract>(spec,
                                                   Specification <Contract> .Eval(item =>
                                                                                  !userId.HasValue ||
                                                                                  item.OwnerId == userId.Value));
            spec = new AndSpecification <Contract>(spec,
                                                   Specification <Contract> .Eval(item =>
                                                                                  !departmentId.HasValue ||
                                                                                  item.DepartmentId == userId.Value));
            spec = new AndSpecification <Contract>(spec,
                                                   Specification <Contract> .Eval(item =>
                                                                                  !clientId.HasValue ||
                                                                                  item.ClientId == clientId.Value));

            spec = new AndSpecification <Contract>(spec,
                                                   Specification <Contract> .Eval(item =>
                                                                                  keywords == "" ||
                                                                                  item.Title.Contains(keywords)));


            this._IContractRepository.GetAll(spec).ToList().ForEach(item =>
                                                                    Contracts.Add(AutoMapper.Mapper.Map <Contract, ContractDTO>(item))
                                                                    );
            foreach (var item in Contracts)
            {
                item.Department = this._IDepartmentService.GetByKey(item.DepartmentId);
                item.Owner      = this._IUserService.GetByKey(item.OwnerId);
                if (item.PrincipalId.HasValue)
                {
                    item.Principal = this._IUserService.GetByKey(item.PrincipalId.Value);
                }
            }
            return(Contracts);
        }
示例#50
0
        public G_ActivityDTOListWithPagination GetAll(int pageIndex, int pageSize, Guid?referenceId, bool?isRead, bool?isGlobal, string sort = "createddate_desc")
        {
            ISpecification <G_Activity> spec = Specification <G_Activity> .Eval(item => true);

            spec = new AndSpecification <G_Activity>(spec,
                                                     Specification <G_Activity> .Eval(item =>
                                                                                      referenceId == null || item.ReferenceId.Equals(referenceId.Value)));
            spec = new AndSpecification <G_Activity>(spec,
                                                     Specification <G_Activity> .Eval(item =>
                                                                                      isRead == null || item.IsRead.Equals(isRead.Value)));
            spec = new AndSpecification <G_Activity>(spec,
                                                     Specification <G_Activity> .Eval(item =>
                                                                                      isGlobal == null || item.IsGlobal.Equals(isGlobal.Value)));

            var list   = new List <G_ActivityDTO>();
            var result = this._IG_ActivityRepository.GetAll(pageIndex, pageSize, spec, sort);

            int totalPages   = 0;
            int totalRecords = 0;

            if (result != null)
            {
                result.Data.ForEach(item =>
                                    list.Add(Mapper.Map <G_Activity, G_ActivityDTO>(item))
                                    );
                totalPages   = result.TotalPages;
                totalRecords = result.TotalRecords;
            }

            return(new G_ActivityDTOListWithPagination
            {
                TotalRecords = totalRecords,
                PageSize = pageSize,
                PageIndex = pageIndex,
                TotalPages = totalPages,
                Data = list
            });
        }
        public void IsSatisfiedByExample()
        {
            // Our model to test on
            var p = new Person {
                Name = "Hilton", Surname = "Goosen"
            };

            // Build up two specifications to AND together
            var nameSpecification    = new PredicateSpecification <Person>(x => x.Name == "Hilton");
            var surnameSpecification = new PredicateSpecification <Person>(x => x.Surname == "Goosen");

            // Create a new And Specification
            var specification = new AndSpecification <Person>(nameSpecification, surnameSpecification);

            Assert.IsTrue(specification.IsSatisfiedBy(p));

            // Set the surname to something else
            surnameSpecification = new PredicateSpecification <Person>(x => x.Surname == "Hanekom");
            specification        = new AndSpecification <Person>(nameSpecification, surnameSpecification);

            // Surname specification is not satisfied by this person
            Assert.IsFalse(specification.IsSatisfiedBy(p));
        }
示例#52
0
        public void AndSpecificationTestAndSpecification()
        {
            // arrange
            var specFirstName = new AdHocSpecification <Sample>(x => x.FirstName.StartsWith("J"));
            var specLastName  = new AdHocSpecification <Sample>(x => x.LastName.StartsWith("R"));
            var spec          = new AndSpecification <Sample>(specFirstName, specLastName);

            // act
            var resultFirstName = TestData.List.Where(specFirstName.IsSatisfied()).OrderBy(c => c.FirstName);
            var resultLastName  = TestData.List.Where(specLastName.IsSatisfied()).OrderBy(c => c.FirstName);
            var result          = TestData.List.Where(spec.IsSatisfied()).OrderBy(c => c.FirstName);

            // assert
            Assert.That(resultFirstName.Count(), Is.EqualTo(2));
            Assert.That(resultFirstName.First().FirstName, Is.EqualTo("Jose"));
            Assert.That(resultFirstName.Last().FirstName, Is.EqualTo("Julian"));
            Assert.That(resultLastName.Count(), Is.EqualTo(2));
            Assert.That(resultLastName.First().LastName, Is.EqualTo("Rodriguez"));
            Assert.That(resultLastName.Last().LastName, Is.EqualTo("Rivera"));
            Assert.That(result.Count(), Is.EqualTo(1));
            Assert.That(result.First().FirstName, Is.EqualTo("Jose"));
            Assert.That(result.First().LastName, Is.EqualTo("Rodriguez"));
        }
示例#53
0
        public IEnumerable <Product> Filter(IEnumerable <Product> unfilteredProducts,
                                            Group group, Subgroup subgroup, string name, string sequence)
        {
            var specsList = new List <ISpecification <Product> >
            {
                new ProductNameSpecification(name),
                new ProductSequenceSpecification(sequence)
            };

            if (group != null)
            {
                specsList.Add(new ProductGroupSpecification(group));
            }
            if (subgroup != null)
            {
                specsList.Add(new ProductSubgroupSpecification(subgroup));
            }

            var andSpecification     = new AndSpecification <Product>(specsList);
            var specificationChecker = new SpecificationChecker <Product>();

            return(specificationChecker.Filter(unfilteredProducts, andSpecification));
        }
        private static Specification <T> CreateExpression <T>(FilterDefinition filterdata, FilterMetadata metadata)
        {
            Specification <T> spec = null;

            if (filterdata is SimpleFilterDefinition)
            {
                var data = filterdata as SimpleFilterDefinition;
                spec = new FieldSpecification <T>(data, metadata.GetTypeCodeOfField(data.FieldName));
            }
            else if (filterdata is ComplexFilterDefinition)
            {
                var data = filterdata as ComplexFilterDefinition;
                if (data.FiltersConnector == ComplexFilterDefinition.Connector.And)
                {
                    spec = new AndSpecification <T>(CreateExpression <T>(data.LeftFilter, metadata), CreateExpression <T>(data.RightFilter, metadata));
                }
                else
                {
                    spec = new OrSpecification <T>(CreateExpression <T>(data.LeftFilter, metadata), CreateExpression <T>(data.RightFilter, metadata));
                }
            }
            return(spec);
        }
示例#55
0
        public List <G_BankDTO> GetBanks(string bankCode = "", bool?isAdmin = null, string sort = "order")
        {
            ISpecification <G_Bank> spec = Specification <G_Bank> .Eval(item => true);

            spec = new AndSpecification <G_Bank>(spec,
                                                 Specification <G_Bank> .Eval(item =>
                                                                              bankCode == null || bankCode == "" || item.Code.Equals(bankCode)
                                                                              ));
            spec = new AndSpecification <G_Bank>(spec,
                                                 Specification <G_Bank> .Eval(item =>
                                                                              isAdmin == null || item.IsAdmin.Equals(isAdmin.Value)
                                                                              ));

            spec = new AndSpecification <G_Bank>(spec,
                                                 Specification <G_Bank> .Eval(item => item.IsActive));

            var list = new List <G_BankDTO>();

            this._IG_BankRepository.GetAll(spec, sort).ToList().ForEach(item =>
                                                                        list.Add(Mapper.Map <G_Bank, G_BankDTO>(item))
                                                                        );
            return(list);
        }
示例#56
0
        public F_OrderDTO GetComplexOrder(Guid id)
        {
            ISpecification <F_Order> spec = Specification <F_Order> .Eval(item => true);

            spec = new AndSpecification <F_Order>(spec,
                                                  Specification <F_Order> .Eval(item =>
                                                                                item.Id.Equals(id)));

            var order = this._IF_OrderRepository.GetAll(1, int.MaxValue, spec).ToList().FirstOrDefault();

            if (order == null)
            {
                return(null);
            }
            var result          = Mapper.Map <ComplexOrder, F_OrderDTO>(order);
            var orderRecordList = new List <F_OrderRecordDTO>();

            this._IF_OrderRecordRepository.GetOrderRecordByOrderId(order.Id).OrderByDescending(item => item.CreatedDate).ToList().ForEach(item =>
                                                                                                                                          orderRecordList.Add(Mapper.Map <ComplexOrderRecord, F_OrderRecordDTO>(item))
                                                                                                                                          );
            result.OrderRecordList = orderRecordList;
            result.Files           = this._IF_FileService.GetFilesByReferenceId(result.Id);
            return(result);
        }
        public static IEnumerable <TestCaseData> SpecificationExtensionsTestIsSameCaseSource()
        {
            // single spec types
            var specFirstNull             = new FirstNameSpec(null);
            var specFirstNull2            = new FirstNameSpec(null);
            var specFirstBob              = new FirstNameSpec("bob");
            var specFirstBob2             = new FirstNameSpec("bob");
            var specFirstBobbette         = new FirstNameSpec("bobbette");
            var specFirstAndLastBob       = new FirstAndLastNameSpec("bob", "le");
            var specFirstAndLastBob2      = new FirstAndLastNameSpec("bob", "le");
            var specFirstAndLastBobbbette = new FirstAndLastNameSpec("bobbette", "le");
            var specLastBob = new LastNameSpec("bob");

            yield return(new TestCaseData("Check on null type", specFirstBob, null, false));

            yield return(new TestCaseData("Check non reference type", specFirstBob, "dinge", false));

            yield return(new TestCaseData("SameReference", specFirstBob, specFirstBob, true));

            yield return(new TestCaseData("Different type", specFirstBob, specLastBob, false));

            yield return(new TestCaseData("Same single content (null)", specFirstNull, specFirstNull2, true));

            yield return(new TestCaseData("Same single content", specFirstBob, specFirstBob2, true));

            yield return(new TestCaseData("Same multiple content", specFirstAndLastBob, specFirstAndLastBob2, true));

            yield return(new TestCaseData("Different single content", specFirstBob, specFirstBobbette, false));

            // operator specs
            var orSpecBob   = new OrSpecification <Sample>(specFirstBob, specFirstBob2);
            var orSpecBob2  = new OrSpecification <Sample>(specFirstBob, specFirstBob2);
            var orSpecBob3  = new OrSpecification <Sample>(specFirstBob, specLastBob);
            var andSpecBob  = new AndSpecification <Sample>(specFirstBob, specFirstBob);
            var andSpecBob2 = new AndSpecification <Sample>(specFirstBob, specFirstBob2);
            var andSpecBob3 = new AndSpecification <Sample>(specFirstBob, specLastBob);

            yield return(new TestCaseData("OR Same containing specs", orSpecBob, orSpecBob2, true));

            yield return(new TestCaseData("Or Different containing specs", orSpecBob, orSpecBob3, false));

            yield return(new TestCaseData("And Same containing specs", andSpecBob, andSpecBob2, true));

            yield return(new TestCaseData("And Different containing specs", andSpecBob, andSpecBob3, false));

            // array specs: value compares
            var array         = new int[] { 1, 2, 3 };
            var arraySpecNull = new ArraySpec <int>(null);
            var arraySpec     = new ArraySpec <int>(array);
            var arraySpec2    = new ArraySpec <int>(array);
            var arraySpec3    = new ArraySpec <int>(new int[] { 1, 2, 3 });
            var arraySpec4    = new ArraySpec <int>(new int[] { 1, 2, 3, 4 });

            yield return(new TestCaseData("Array - same array", arraySpec, arraySpec2, true));

            yield return(new TestCaseData("Array - different array - same content", arraySpec, arraySpec3, true));

            yield return(new TestCaseData("Array - different array - different content", arraySpec, arraySpec4, false));

            yield return(new TestCaseData("Array - different array - different content (null)", arraySpec, arraySpecNull, false));

            yield return(new TestCaseData("Array(obj) - same array", arraySpec, arraySpec2, true));

            // array specs: object compares
            var sample               = new Sample("le", "bob");
            var arraySpecSample      = new ArraySpec <Sample>(new Sample[] { sample, sample });
            var arraySpecSample2     = new ArraySpec <Sample>(new Sample[] { sample, sample });
            var arraySpecSampleNull  = new ArraySpec <Sample>(new Sample[] { sample, null, sample });
            var arraySpecSampleNull2 = new ArraySpec <Sample>(new Sample[] { sample, null, sample });
            var arraySpecObject      = new ArraySpec <object>(new object[] { "a", 1 });
            var arraySpecObject2     = new ArraySpec <object>(new object[] { "a", "b" });
            var arraySpecObject3     = new ArraySpec <object>(new object[] { "a", "c" });
            var arraySpecObjectnull  = new ArraySpec <object>(null);

            yield return(new TestCaseData("Array(obj) - different array - same content", arraySpecSample, arraySpecSample2, true));

            yield return(new TestCaseData("Array(obj) - different array - different content (null)", arraySpecSampleNull, arraySpecSampleNull2, false));

            yield return(new TestCaseData("Array(obj) - different array - different content (type)", arraySpecObject, arraySpecObject2, false));

            yield return(new TestCaseData("Array(obj) - different array - different content (value)", arraySpecObject3, arraySpecObject2, false));

            yield return(new TestCaseData("Array(obj) - different array - one is null", arraySpecObject3, arraySpecObjectnull, false));
        }
        public OutageReport Generate(ReportOptions options)
        {
            bool isScope = false;
            List <Specification <ConsumerHistorical> > specs = new List <Specification <ConsumerHistorical> >();

            if (options.StartDate.HasValue)
            {
                specs.Add(new HistoricalConsumerStartDateQuery(options.StartDate.Value));
            }

            if (options.EndDate.HasValue)
            {
                specs.Add(new HistoricalConsumerEndDateQuery(options.EndDate.Value));
            }

            if (options.ElementId != null)
            {
                specs.Add(new HistoricalConsumerElementIdQuery((long)options.ElementId));
                isScope = true;
            }

            specs.Add(new HistoricalConsumerOperationQuery(DatabaseOperation.DELETE));

            IEnumerable <ConsumerHistorical> outages;

            if (specs.Count > 1)
            {
                AndSpecification <ConsumerHistorical> andQuery = new AndSpecification <ConsumerHistorical>(specs);
                outages = _outageRepository.Find(andQuery.IsSatisfiedBy).ToList();
            }
            else if (specs.Count == 1)
            {
                outages = _outageRepository.Find(specs[0].IsSatisfiedBy).ToList();
            }
            else
            {
                outages = _outageRepository.GetAll().ToList();
            }

            var type = DateHelpers.GetType(options.StartDate, options.EndDate);
            var outageReportGrouping = outages.GroupBy(o => type == "Monthly" ? o.OperationTime.Month : o.OperationTime.Year).Select(o => o).ToList();

            var numOfConsumers = 1;

            if (!isScope)
            {
                numOfConsumers = _consumerRepository.GetAll().Count();
            }

            var reportData = new Dictionary <string, float>();

            foreach (var outage in outageReportGrouping)
            {
                var outageCount = outage.Count();
                reportData.Add(type == "Monthly" ? DateHelpers.Months[outage.Key] : outage.Key.ToString(), (float)outageCount / (float)numOfConsumers);;
            }

            return(new OutageReport
            {
                Type = type,
                Data = reportData
            });
        }
示例#59
0
 public ISpecificationBuilder <T> And(ISpecification <T> specification)
 {
     _criteria = new AndSpecification <T>(_criteria, specification);
     return(this);
 }
        public void AndToString()
        {
            AndSpecification and = new AndSpecification(ConstantSpecification.True, ConstantSpecification.True);

            Assert.Equal("(true and true)", and.ToString());
        }