コード例 #1
0
        public void GetAllCustomersShouldReturnAllDataWhenDefaultValuesUsed()
        {
            // Arrange
            var interceptors = new DefaultRepositoryInterceptors(new NorthwindQueryRepositoryInterceptor());
            var repository = new InMemoryRepository(interceptors);

            for (int i = 0; i < 15; i++)
            {
                repository.Add(EntityGenerator.Create<Customer>(
                    p => p.CompanyName = p.CompanyName + i,
                    p => p.CustomerID = i.ToString(),
                    p => p.Orders.First().OrderDetails.First().Quantity = (short)i,
                    p => p.Orders.First().OrderDetails.First().UnitPrice = 100.0M));
            }

            // Act
            var ordersController = new OrdersController(repository);
            var results = ordersController.GetAllCustomers().Result;

            // Assert
            results.Count().ShouldEqual(15);
            for (int i = 0; i < 15; i++)
            {
                results.ElementAt(i).CustomerId.ShouldEqual(i.ToString());
                results.ElementAt(i).CompanyName.ShouldEqual("CompanyName" + i);
                results.ElementAt(i).CombinedOrderValue.ShouldEqual(100 * i);
            }
        }
コード例 #2
0
        public void InsertCategoryShouldSaveToRepository()
        {
            // Arrange
            var events = new RecordedRepositoryEvents();
            var repository = new InMemoryRepository(events);

            // Act
            var salesController = new SalesController(repository);
            salesController.PostCategory(new SalesCategory
            {
                CategoryName = "NewCat",
                CategoryDescription = "NewDescription"
            });

            // Check category values
            var savedCategory = repository.GetEntity<Category>(p => p.Id == 0);
            savedCategory.Id.ShouldEqual(0);
            savedCategory.CategoryName.ShouldEqual("NewCat");
            savedCategory.Description.ShouldEqual("NewDescription");

            // As we are using an in memory implementation we need to check that the modify and save
            // methods are called
            events.AddedEvents.Count().ShouldEqual(1);
            events.ModifiedEvents.Count().ShouldEqual(0);
            events.DeletedEvents.Count().ShouldEqual(0);
            events.SavedEvents.Count().ShouldEqual(1);
        }
コード例 #3
0
        public void GetSalesCategoriesShouldReturnDataRetrievedFromInterceptorThroughProjection()
        {
            // Arrange
            var events = new RecordedRepositoryEvents();
            var repository = new InMemoryRepository(
                events,
                new DefaultRepositoryInterceptors(new NorthwindQueryRepositoryInterceptor()));

            // Act
            var salesController = new SalesController(repository);
            var items = salesController.GetSalesCategories().Result;

            // Check we are getting the necessary data from the stored proc call.
            items.Count().ShouldEqual(2);
            items.Count().ShouldEqual(TestsEntityFrameworkRepositoryExtensions.SalesCategories.Count());
            items.First().ShouldEqual(TestsEntityFrameworkRepositoryExtensions.SalesCategories.First());
            items.Second().ShouldEqual(TestsEntityFrameworkRepositoryExtensions.SalesCategories.Second());
        }
コード例 #4
0
        public void GetAllCustomersQueryShouldUseCorrectStrategies(int take, int skip, string orderBy, bool ascending, decimal? minOrderValue)
        {
            // Arrange
            var events = new RecordedRepositoryEvents();
            var repository = new InMemoryRepository(events);

            // Act
            var notUsed = new OrdersController(repository).GetAllCustomers(take, skip, orderBy, ascending, minOrderValue).Result;

            // Assert
            var allStrategies = events.QueryEvents.Single().GetQueryStrategies();
            allStrategies.Count().ShouldEqual(4);

            allStrategies.First().GetType().ShouldEqual(typeof(DefaultSpecificationQueryStrategy<AggregateCustomerSales>));
            allStrategies.Second().GetType().ShouldEqual(typeof(ConditionalQueryStrategy));
            allStrategies.Third().GetType().ShouldEqual(typeof(ConditionalQueryStrategy));
            allStrategies.Fourth().GetType().ShouldEqual(typeof(ConditionalQueryStrategy));
        }
コード例 #5
0
        public void GetAllCustomersShouldReturnCorrectDataWhenMinOrderSupplied()
        {
            // Arrange
            var interceptors = new DefaultRepositoryInterceptors(new NorthwindQueryRepositoryInterceptor());
            var repository = new InMemoryRepository(interceptors);

            for (int i = 0; i < 15; i++)
            {
                repository.Add(EntityGenerator.Create<Customer>(
                    p => p.CompanyName = p.CompanyName + i,
                    p => p.CustomerID = i.ToString(),
                    p => p.Orders.First().OrderDetails.First().Quantity = (short)i,
                    p => p.Orders.First().OrderDetails.First().UnitPrice = 100.0M));
            }

            // Act
            var ordersController = new OrdersController(repository);

            // Assert
            var results = ordersController.GetAllCustomers(minOrderValue: 100 * 10).Result;
            results.Count().ShouldEqual(5);
        }
コード例 #6
0
        public void UpdateCategoryShouldSaveToRepository()
        {
            // Arrange
            var events = new RecordedRepositoryEvents();
            var repository = new InMemoryRepository(events);

            var newCategory = EntityGenerator.Create<Category>(p => p.Id = 999);
            repository.Add(newCategory);
            events.Reset();

            // Act
            var salesController = new SalesController(repository);
            salesController.PutCategory(new SalesCategory
            {
                Id = newCategory.Id,
                CategoryName = "NewCat",
                CategoryDescription = "NewDescription"
            });

            // Check category values
            var savedCategory = repository.GetEntity<Category>(p => p.Id == newCategory.Id);
            savedCategory.Id.ShouldEqual(savedCategory.Id);
            savedCategory.CategoryName.ShouldEqual("NewCat");
            savedCategory.Description.ShouldEqual("NewDescription");

            // As we are using an in memory implementation we need to check that the modify and save
            // methods are called
            events.AddedEvents.Count().ShouldEqual(0);
            events.ModifiedEvents.Count().ShouldEqual(1);
            events.DeletedEvents.Count().ShouldEqual(0);
            events.SavedEvents.Count().ShouldEqual(1);

            // If required we can drill down into each event and look at all aspects
            // of the event. Here we are check that the same reference is updated.
            var entityModified = (Category)events.ModifiedEvents.First().Entity;
            entityModified.ShouldEqual(savedCategory);
            entityModified.ShouldEqual(newCategory);
        }
コード例 #7
0
        public void GetAllCustomersShouldReturnCorrectDataWhenOrderedByDesc()
        {
            // Arrange
            var interceptors = new DefaultRepositoryInterceptors(new NorthwindQueryRepositoryInterceptor());
            var repository = new InMemoryRepository(interceptors);

            for (int i = 0; i < 15; i++)
            {
                repository.Add(EntityGenerator.Create<Customer>(
                    p => p.CompanyName = p.CompanyName + i,
                    p => p.CustomerID = i.ToString(),
                    p => p.Orders.First().OrderDetails.First().Quantity = (short)i,
                    p => p.Orders.First().OrderDetails.First().UnitPrice = 100.0M));
            }

            // Act
            var ordersController = new OrdersController(repository);
            var results = ordersController.GetAllCustomers(take: 1, skip: 0, ascending: false).Result;

            // Assert
            results.Single().CustomerId.ShouldEqual("14");
        }
コード例 #8
0
        public void GetVeryImportantCustomersShouldReturnCorrectData()
        {
            // Arrange
            var events = new RecordedRepositoryEvents();
            var repository = new InMemoryRepository(events);
            var customerSales = Enumerable.Repeat(EntityGenerator.Create<AggregateCustomerSales>(), 20).ToList();
            customerSales.ForEach(repository.Add);

            // Act
            var ordersController = new OrdersController(repository);
            var results = ordersController.GetVeryImportantCustomers().Result;

            // Assert
            results.Count().ShouldEqual(10);
            var allStrategies = events.QueryEvents.Single().GetQueryStrategies();

            // check the strategies used in this call
            allStrategies.Count().ShouldEqual(2);
            allStrategies.First().GetType().ShouldEqual(typeof(DefaultSpecificationQueryStrategy<AggregateCustomerSales>));
            allStrategies.Second().GetType().ShouldEqual(typeof(FindVeryImportantCustomersQueryStrategy));
        }
コード例 #9
0
        public void GetCustomerOrderHistoryShouldReturnCorrectDataWhenFilteredByProductName()
        {
            // Arrange
            var repository = new InMemoryRepository();

            // Act
            var ordersController = new OrdersController(repository);
            var result = ordersController.GetCustomerOrderHistory("NotUsed", "2").Result;

            // Assert
            result.Count().ShouldEqual(1);
            result.First().ProductName.ShouldEqual("ProductName2");
        }
コード例 #10
0
        public void GetCustomerOrderHistoryShouldReturnCorrectData()
        {
            // Arrange
            var events = new RecordedRepositoryEvents();
            var repository = new InMemoryRepository(events);

            // Act
            var ordersController = new OrdersController(repository);
            var result = ordersController.GetCustomerOrderHistory("NotUsed").Result;

            result.Count().ShouldEqual(TestsEntityFrameworkRepositoryExtensions.CustomerOrderHistories.Count());

            var allStrategies = events.QueryEvents.Single().GetQueryStrategies();
            allStrategies.Count().ShouldEqual(3);

            allStrategies.First().GetType().ShouldEqual(typeof(DefaultSpecificationQueryStrategy<CustomerOrderHistory>));
            allStrategies.Second().GetType().ShouldEqual(typeof(CustomerOrderHistoryStoredProcQueryStrategy));
            allStrategies.Third().GetType().ShouldEqual(typeof(ConditionalQueryStrategy));
        }