public void ReturnsStoreWithId10_GivenStoreByIdSpec()
        {
            var spec = new StoreByIdSpec(10);

            var store = spec.Evaluate(StoreSeed.Get()).FirstOrDefault();

            store?.Id.Should().Be(10);
        }
        public void ReturnsOrderStoresByNameDescThenByIdForCompanyWithId2_GivenStoresByCompanyOrderedDescByNameThenByIdSpec()
        {
            var spec = new StoresByCompanyOrderedDescByNameThenByIdSpec(2);

            var stores = spec.Evaluate(StoreSeed.Get());

            stores.First().Id.Should().Be(99);
            stores.Last().Id.Should().Be(98);
        }
        public void ReturnsOrderStoresByNameDescForCompanyWithId2_GivenStoresByCompanyOrderedDescByNameSpec()
        {
            var spec = new StoresByCompanyOrderedDescByNameSpec(2);

            var stores = spec.Evaluate(StoreSeed.Get());

            stores.First().Id.Should().Be(StoreSeed.ORDERED_BY_NAME_DESC_FOR_COMPANY2_FIRST_ID);
            stores.Last().Id.Should().Be(StoreSeed.ORDERED_BY_NAME_DESC_FOR_COMPANY2_LAST_ID);
        }
        public void ReturnsOrderedStores_GivenStoresOrderedDescendingByNameSpec()
        {
            var spec = new StoresOrderedDescendingByNameSpec();

            var stores = spec.Evaluate(StoreSeed.Get());

            stores.First().Id.Should().Be(StoreSeed.ORDERED_BY_NAME_DESC_FIRST_ID);
            stores.Last().Id.Should().Be(StoreSeed.ORDERED_BY_NAME_DESC_LAST_ID);
        }
        public void ThrowsDuplicateOrderChainException_GivenSpecWithMultipleOrderChains()
        {
            var spec = new StoresOrderedTwoChainsSpec();

            Action sutAction = () => spec.Evaluate(StoreSeed.Get());

            sutAction.Should()
            .Throw <DuplicateOrderChainException>()
            .WithMessage("The specification contains more than one Order chain!");
        }
        public void ReturnsStoreWithIdFrom15To30_GivenStoresByIdListSpec()
        {
            var ids  = Enumerable.Range(15, 16);
            var spec = new StoresByIdListSpec(ids);

            var stores = spec.Evaluate(StoreSeed.Get());

            stores.Count().Should().Be(16);
            stores.OrderBy(x => x.Id).First().Id.Should().Be(15);
            stores.OrderBy(x => x.Id).Last().Id.Should().Be(30);
        }
Esempio n. 7
0
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);

            modelBuilder.Entity <Store>().HasOne(x => x.Address).WithOne(x => x !.Store !).HasForeignKey <Address>(x => x.StoreId);

            modelBuilder.Entity <Country>().HasData(CountrySeed.Get());
            modelBuilder.Entity <Company>().HasData(CompanySeed.Get());
            modelBuilder.Entity <Address>().HasData(AddressSeed.Get());
            modelBuilder.Entity <Store>().HasData(StoreSeed.Get());
            modelBuilder.Entity <Product>().HasData(ProductSeed.Get());
        }
        public void ReturnsSecondPageOfStoresForCompanyWithId2_GivenStoresByCompanyPaginatedOrderedDescByNameSpec()
        {
            int take = 10;           // pagesize 10
            int skip = (2 - 1) * 10; // page 2

            var spec = new StoresByCompanyPaginatedOrderedDescByNameSpec(2, skip, take);

            var stores = spec.Evaluate(StoreSeed.Get());

            stores.Count().Should().Be(take);
            stores.First().Id.Should().Be(StoreSeed.ORDERED_BY_NAME_DESC_FOR_COMPANY2_PAGE2_FIRST_ID);
            stores.Last().Id.Should().Be(StoreSeed.ORDERED_BY_NAME_DESC_FOR_COMPANY2_PAGE2_LAST_ID);
        }
        public void ReturnsSecondPageOfStores_GivenStoresPaginatedSpec()
        {
            int take = 10;           // pagesize 10
            int skip = (2 - 1) * 10; // page 2

            var spec = new StoresPaginatedSpec(skip, take);

            var stores = spec.Evaluate(StoreSeed.Get());

            stores.Count().Should().Be(take);
            stores.OrderBy(x => x.Id).First().Id.Should().Be(11);
            stores.OrderBy(x => x.Id).Last().Id.Should().Be(20);
        }
        public void ReturnsSecondPageOfStoreNames_GivenStoreNamesPaginatedSpec()
        {
            int take = 10;           // pagesize 10
            int skip = (2 - 1) * 10; // page 2

            var spec = new StoreNamesPaginatedSpec(skip, take);

            var storeNames = spec.Evaluate(StoreSeed.Get());

            storeNames.Count().Should().Be(take);
            storeNames.First().Should().Be("Store 11");
            storeNames.Last().Should().Be("Store 20");
        }
Esempio n. 11
0
        protected override void Seed(TestDbContext context)
        {
            base.Seed(context);

            var companies = CompanySeed.Get();

            context.Addresses.AddRange(AddressSeed.Get());
            context.Countries.AddRange(CountrySeed.Get());
            context.Companies.AddRange(CompanySeed.Get());
            context.Products.AddRange(ProductSeed.Get());
            context.Stores.AddRange(StoreSeed.Get());

            context.SaveChanges();
        }
        public void ThrowsDuplicateOrderChainException_GivenSpecWithMultipleOrderChains()
        {
            var spec = new StoresOrderedTwoChainsSpec();

            Assert.Throws <DuplicateOrderChainException>(() => spec.Evaluate(StoreSeed.Get()));
        }