Ejemplo n.º 1
0
        public async Task GetShopOrdersQueryHandle_Returns_ExistingOrders()
        {
            //Arrange
            AllMarkt.Entities.Shop seller = new AllMarkt.Entities.Shop
            {
                Address           = "aaaaa",
                Comments          = null,
                CUI               = "aaaaddd",
                IBAN              = "aaaaa",
                Orders            = null,
                PhoneNumber       = "0123654789",
                ProductCategories = null,
                ShopCategoryLink  = null,
                SocialCapital     = 4
            };
            AllMarktContextIM.Shops.Add(seller);
            await AllMarktContextIM.SaveChangesAsync();

            AllMarkt.Entities.Order order = new AllMarkt.Entities.Order()
            {
                Seller = seller
            };
            AllMarktContextIM.Orders.Add(order);
            await AllMarktContextIM.SaveChangesAsync();

            //Act
            var result = await _getShopOrdersQueryHandler
                         .Handle(new GetShopOrdersQuery()
            {
                ShopId = seller.Id
            }, CancellationToken.None);

            //Assert
            result.Count().Should().Be(1);
        }
        public async Task GetShopsByCategoryIdQueryHandler_Returns_ExistingShops()
        {
            //Arrange
            var user = new AllMarkt.Entities.User
            {
                Email       = "*****@*****.**",
                Password    = "******",
                DisplayName = "name1",
                UserRole    = UserRole.Shop
            };

            await AllMarktContextIM.Users.AddAsync(user);

            await AllMarktContextIM.SaveChangesAsync();

            var shop = new AllMarkt.Entities.Shop
            {
                ProductCategories = null,
                User          = user,
                Address       = "address",
                Comments      = null,
                CUI           = "RO123456789c",
                IBAN          = new string('8', 24),
                PhoneNumber   = "01234567891",
                SocialCapital = 23
            };

            var category = new AllMarkt.Entities.Category
            {
                Description = "Desc",
                Name        = "Category1"
            };

            await AllMarktContextIM.Shops.AddAsync(shop);

            await AllMarktContextIM.Categories.AddAsync(category);

            await AllMarktContextIM.SaveChangesAsync();

            var link = new AllMarkt.Entities.ShopCategory
            {
                Shop       = shop,
                ShopId     = shop.Id,
                Category   = category,
                CategoryId = category.Id
            };
            await AllMarktContextIM.ShopCategories.AddAsync(link);

            await AllMarktContextIM.SaveChangesAsync();

            shop.ShopCategoryLink.Add(link);
            category.ShopCategoryLink.Add(link);
            await AllMarktContextIM.SaveChangesAsync();

            //Act
            var shopList = await _getShopsByCategoryIdQueryHandler.Handle(new GetShopsByCategoryIdQuery { Id = category.Id }, CancellationToken.None);

            //Assert
            shopList.Count().Should().Be(1);
        }
        public async Task GetUserByIdQueryHandler_ReturnsExisting_UserById()
        {
            //Arrange
            var user1 = new AllMarkt.Entities.User
            {
                Email       = "*****@*****.**",
                Password    = "******",
                DisplayName = "name1",
                UserRole    = UserRole.Shop
            };
            var shop = new AllMarkt.Entities.Shop
            {
                CUI               = "3333",
                Address           = "address1",
                PhoneNumber       = "0147852369",
                Comments          = null,
                IBAN              = "SE3550000000054910000003",
                Orders            = null,
                ProductCategories = null,
                SocialCapital     = 3,
                User              = user1,
                UserId            = user1.Id
            };

            await AllMarktContextIM.Users.AddAsync(user1);

            await AllMarktContextIM.Shops.AddAsync(shop);

            await AllMarktContextIM.SaveChangesAsync();

            //Act
            var result = await _getShopByUserIdQueryHandler.Handle(new GetShopByUserIdQuery { UserId = user1.Id }, CancellationToken.None);

            //Assert
            result.UserDisplayName.Should().Be("name1");
            result.Address.Should().Be("address1");
            result.PhoneNumber.Should().Be("0147852369");
            result.IBAN.Should().Be("SE3550000000054910000003");
            result.SocialCapital.Equals(3);
        }