コード例 #1
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);
        }
コード例 #2
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());
        }
コード例 #3
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));
        }
コード例 #4
0
        //        [Test]
        public void CheckAddAndDeleteFoMongoUnitOfWorkCommandRepository()
        {
            var eventRecorder = new RecordedRepositoryEvents();

            var mongoDatabase = CreateEmptyMongoDatabase();
            var repository = new MongoDbUnitOfWorkRepository(mongoDatabase, eventRecorder);

            var account = new SimpleAccount("xyz");
            repository.GetEntities<SimpleAccount>(p => p.Name == account.Name).Any().ShouldEqual(false);
            repository.Add(account);
            repository.GetEntities<SimpleAccount>(p => p.Name == account.Name).Any().ShouldEqual(false);
            repository.Save();
            repository.GetEntities<SimpleAccount>(p => p.Name == account.Name).Any().ShouldEqual(true);
            repository.Delete(account);
            repository.GetEntities<SimpleAccount>(p => p.Name == account.Name).Any().ShouldEqual(true);
            repository.Save();
            repository.GetEntities<SimpleAccount>(p => p.Name == account.Name).Any().ShouldEqual(false);
        }
コード例 #5
0
        public void AddRange()
        {
            var events = new RecordedRepositoryEvents();
            var repository = new EntityFrameworkRepository(new FamilyDbContext(), events);
            var count = repository.GetEntities<Animal>().Count();

            var newAnimals = new Animal[]
            {
                new Rabitt{Name = "rabitty"},
                new Cat{Name = "catty"}
            };

            repository.AddRange(newAnimals);
            repository.Save();

            events.AddedEvents.Count.ShouldEqual(2);
            events.SavedEvents.Count.ShouldEqual(1);

            var repository2 = new EntityFrameworkRepository(new FamilyDbContext());
            var count2 = repository2.GetEntities<Animal>().Count();
            count2.ShouldEqual(count + 2);
        }
コード例 #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 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));
        }
コード例 #8
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));
        }