예제 #1
0
        public async Task <IPageResult <BookPrice> > GetPriceList(PriceSpecification priceSpecification, int index, int pageSize)
        {
            Guard.Against.NegativeIndexPage(pageSize, index);

            var bookPrice = await _priceRepository.GetListAsync(priceSpecification);

            return(new PageResult <BookPrice>(bookPrice, index, pageSize));
        }
예제 #2
0
        public async Task GetBooksPrice_Should_GetList(PriceSpecification specification, int index, int pageSize, int count)
        {
            _repository.Setup(s => s.GetListAsync(It.IsAny <Expression <Func <BookPrice, bool> > >(), It.IsAny <Func <IQueryable <BookPrice>, IOrderedQueryable <BookPrice> > >(), It.IsAny <Expression <Func <BookPrice, object> > >()))
            .ReturnsAsync(DataSeed.BookPrices.AsQueryable().Where(specification));
            IPageResult <BookPrice> price = await _priceService.GetPriceList(specification, index, pageSize);

            Assert.NotNull(price);
            Assert.Equal(count, price.Total);
            int pageCount = count - pageSize * index;

            Assert.Equal(pageCount >= pageSize ? pageSize : (pageCount > 0 ? count : 0), price.Data.Count());
        }
예제 #3
0
        public void IsSatisfiedBy_NoOperator_False()
        {
            // Arrange
            var alertCriteria = new AlertCriteria();
            var spec          = new PriceSpecification(alertCriteria);
            var message       = new AlertEvaluationMessage();

            // Act
            var result = spec.IsSatisfiedBy(message);

            // Assert
            result.Should().BeFalse();
        }
예제 #4
0
        public void TestAndSpecification()
        {
            var product = new Product {
                ProductName = "p2", Amount = 10, Price = 11.3
            };
            var nameSpec   = new NameEqualSpecification("p1");
            var amountSpec = new AmountSpecification();
            var priceSpec  = new PriceSpecification();
            var andSpec    = nameSpec.And(amountSpec).And(priceSpec);

            bool isSatisfiedBy = andSpec.IsSatisfiedBy(product);

            isSatisfiedBy.ShouldBeTrue();
        }
예제 #5
0
        public void TestFindByPrice()
        {
            // Arrange
            PriceSpecification priceSpecification = new PriceSpecification(8.95M);

            // Act
            ReadOnlyCollection <Product> foundProducts = this._finder.SelectBy(priceSpecification);

            // Assert
            Assert.AreEqual(2, foundProducts.Count, "found products that cost $8.95");

            foreach (Product foundProduct in foundProducts)
            {
                Assert.AreEqual(8.95M, foundProduct.GetPrice());
            }
        }
예제 #6
0
        public async Task PriceSpecification_IsSatisfied_WithAll(string bookTitle, string isbn)
        {
            List <Guid> bookIds = DataSeed.Books.Where(b =>
                                                       (string.IsNullOrWhiteSpace(bookTitle) || b.Title.Contains(bookTitle)) &&
                                                       (string.IsNullOrWhiteSpace(isbn) || b.ISBN == isbn))
                                  .Select(b => b.Id).ToList();

            var satisfiedList = from bookPrice in DataSeed.BookPrices
                                where bookIds.Contains(bookPrice.BookId)
                                select bookPrice;

            foreach (BookPrice price in satisfiedList)
            {
                bool isSatisfied = new PriceSpecification(bookIds).IsSatisfiedBy(price);
                Assert.True(isSatisfied);
            }
        }
예제 #7
0
        public void IsSatisfiedBy_LessThanOrEqual_LastPriceEqualLevel_PrevLastPriceGreaterThanLevel_True()
        {
            // Arrange
            var alertCriteria = new AlertCriteria {
                Operator = CriteriaOperator.LessThanOrEqualTo, Level = 50
            };
            var spec    = new PriceSpecification(alertCriteria);
            var message = new AlertEvaluationMessage {
                LastPrice = 50, PreviousLastPrice = 50.1M
            };

            // Act
            var result = spec.IsSatisfiedBy(message);

            // Assert
            result.Should().BeTrue();
        }
예제 #8
0
        public void IsSatisfiedBy_EqualTo_LastPriceLessThanLevel_PrevLastPriceEqualLevel_False()
        {
            // Arrange
            var alertCriteria = new AlertCriteria {
                Operator = CriteriaOperator.Equals, Level = 50
            };
            var spec    = new PriceSpecification(alertCriteria);
            var message = new AlertEvaluationMessage {
                LastPrice = 49, PreviousLastPrice = 50
            };

            // Act
            var result = spec.IsSatisfiedBy(message);

            // Assert
            result.Should().BeFalse();
        }
 /// <summary>
 /// MonetaryAmountOrPriceSpecification as a PriceSpecification.
 /// </summary>
 /// <param name="priceSpecification">MonetaryAmountOrPriceSpecification as a PriceSpecification.</param>
 public MonetaryAmountOrPriceSpecification(PriceSpecification priceSpecification)
 {
     AsPriceSpecification = priceSpecification;
 }