public async Task AddProductCategoryCommandHandler_AddsCategory()
        {
            //Arange
            AllMarktContextIM.Shops.Add(new AllMarkt.Entities.Shop
            {
                Address           = "dddd",
                Comments          = null,
                CUI               = "ddd",
                IBAN              = "dffddfdfd",
                Orders            = null,
                PhoneNumber       = "0123654789",
                ProductCategories = null,
                ShopCategoryLink  = null,
                SocialCapital     = 3
            });
            AllMarktContextIM.SaveChanges();
            var shop = AllMarktContextIM.Shops.FirstOrDefault();

            var addedProductCategory = new AddProductCategoryCommand
            {
                Name        = "testName",
                Description = "DescName",
                ShopId      = shop.Id
            };

            //Act
            await _addProductCategoryCommandHandler.Handle(addedProductCategory, CancellationToken.None);

            //Assert
            AllMarktContextIM.ProductCategories
            .Should()
            .Contain(productCategory => productCategory.Name == addedProductCategory.Name &&
                     productCategory.Description == addedProductCategory.Description);
        }
Ejemplo n.º 2
0
        public async Task EditCategoryCommandHandle_UpdatesExistingCategory()
        {
            //Arrange
            var category = new AllMarkt.Entities.Category
            {
                Name        = "TestName",
                Description = "TestDescription"
            };

            AllMarktContextIM.Categories.Add(category);
            AllMarktContextIM.SaveChanges();

            var existingCategory = AllMarktContextIM.Categories.First();

            var editCategoryCommand = new EditCategoryCommand
            {
                Id          = existingCategory.Id,
                Name        = "TestName_EDIT",
                Description = "TestDescription_EDIT"
            };

            //Act
            await _editCategoryCommandHandler.Handle(editCategoryCommand, CancellationToken.None);

            //Assert
            AllMarktContextIM.Categories.Should().Contain(x => x.Id == editCategoryCommand.Id);

            category.Name.Should().Be(editCategoryCommand.Name);
            category.Description.Should().Be(editCategoryCommand.Description);
        }
Ejemplo n.º 3
0
        public async Task AddProductCommandHandle_AddsProduct()
        {
            //Arrange
            var productCategory = new AllMarkt.Entities.ProductCategory {
                Name = "category", Description = "description"
            };

            AllMarktContextIM.ProductCategories.Add(productCategory);
            AllMarktContextIM.SaveChanges();

            var addProductCommand = new AddProductCommand
            {
                Name              = "Test Name1",
                Description       = "Test Description1",
                Price             = 10,
                ImageURI          = "",
                State             = true,
                ProductCategoryId = productCategory.Id
            };

            //Act
            await _addProductCommandHandler.Handle(addProductCommand, CancellationToken.None);

            //Assert
            AllMarktContextIM.Products.Should()
            .Contain(product =>
                     product.Name == addProductCommand.Name &&
                     product.Description == addProductCommand.Description &&
                     product.Price == addProductCommand.Price &&
                     product.ImageURI == addProductCommand.ImageURI &&
                     product.State == addProductCommand.State &&
                     product.ProductCategory.Id == addProductCommand.ProductCategoryId);
        }
Ejemplo n.º 4
0
        public async Task AddProductCommentCommandHandle_AddsShopComment()
        {
            //Arrange
            var productCategory = new AllMarkt.Entities.ProductCategory {
                Name = "category", Description = "description"
            };

            AllMarktContextIM.ProductCategories.Add(productCategory);
            AllMarktContextIM.SaveChanges();

            var user = new AllMarkt.Entities.User {
                Email       = "*****@*****.**",
                Password    = "******",
                DisplayName = "UserTest"
            };

            var product = new AllMarkt.Entities.Product
            {
                Name            = "testProduct",
                Description     = "testDescription",
                Price           = 20,
                ImageURI        = "",
                State           = true,
                ProductCategory = productCategory
            };

            AllMarktContextIM.Users.Add(user);
            AllMarktContextIM.Products.Add(product);
            await AllMarktContextIM.SaveChangesAsync();

            var addProductCommentCommand = new AddProductCommentCommand
            {
                Rating        = 5,
                Text          = "cel mai bun produs",
                ProductId     = product.Id,
                AddedByUserId = user.Id
            };

            //Act
            await _addProductCommentCommandHandler.Handle(addProductCommentCommand, CancellationToken.None);

            //Assert
            AllMarktContextIM.ProductComments
            .Should()
            .Contain(productComment =>
                     productComment.Rating == addProductCommentCommand.Rating &&
                     productComment.Text == addProductCommentCommand.Text &&
                     productComment.AddedBy.Id == addProductCommentCommand.AddedByUserId &&
                     productComment.Product.Id == addProductCommentCommand.ProductId);
        }
Ejemplo n.º 5
0
        public async Task DeleteShopCategoryLinkCommandHandlre_Deleting_ShopCategory()
        {
            //Arrange
            AllMarktContextIM.Shops.Add(new AllMarkt.Entities.Shop
            {
                Address           = "dddd",
                Comments          = null,
                CUI               = "ddd",
                IBAN              = "dffddfdfd",
                Orders            = null,
                PhoneNumber       = "0123654789",
                ProductCategories = null,
                ShopCategoryLink  = null,
                SocialCapital     = 3
            });
            AllMarktContextIM.SaveChanges();
            var shop = AllMarktContextIM.Shops.FirstOrDefault();

            AllMarktContextIM.Categories.Add(new AllMarkt.Entities.Category
            {
                Name        = "Categ 1",
                Description = "Description"
            });

            AllMarktContextIM.SaveChanges();
            var category = AllMarktContextIM.Categories.FirstOrDefault();

            AllMarktContextIM.ShopCategories.Add(new AllMarkt.Entities.ShopCategory
            {
                ShopId     = shop.Id,
                CategoryId = category.Id
            });
            AllMarktContextIM.SaveChanges();

            var deleteShopCategoryLink = new DeleteShopCategoryLinkCommand
            {
                ShopId     = shop.Id,
                CategoryId = category.Id
            };

            //Act
            await _deleteShopCategoryLinkHandler.Handle(deleteShopCategoryLink, CancellationToken.None);

            //Assert
            AllMarktContextIM.ShopCategories
            .Should()
            .NotContain(sc => sc.ShopId == deleteShopCategoryLink.ShopId && sc.CategoryId == deleteShopCategoryLink.CategoryId);
        }
Ejemplo n.º 6
0
        public async Task GetAllProductsByProductCategoryQueryHandler_ReturnsEmpty()
        {
            //Arrange
            var productCategory = new AllMarkt.Entities.ProductCategory {
                Name = "category", Description = "description"
            };

            AllMarktContextIM.ProductCategories.Add(productCategory);
            AllMarktContextIM.SaveChanges();

            //Act
            var result = await _getAllProductsQueryHandler.Handle(new GetAllProductsByProductCategoryQuery(productCategory.Id), CancellationToken.None);

            //Assert
            result.Should().BeEmpty();
        }
Ejemplo n.º 7
0
        public async Task EditProductCategoryCommandHandler_EditExistingProductCategory()
        {
            //Arange
            AllMarktContextIM.Shops.Add(new AllMarkt.Entities.Shop
            {
                Address           = "Address1",
                Comments          = null,
                CUI               = "CUI1",
                IBAN              = "IBAN",
                Orders            = null,
                PhoneNumber       = "0123654789",
                ProductCategories = null,
                ShopCategoryLink  = null,
                SocialCapital     = 3
            });

            AllMarktContextIM.SaveChanges();
            var shop = AllMarktContextIM.Shops.FirstOrDefault();

            AllMarktContextIM.ProductCategories.Add(new AllMarkt.Entities.ProductCategory
            {
                Name        = "firstName",
                Description = "FirstDec",
                Shop        = shop
            });
            AllMarktContextIM.SaveChanges();

            var existedProductCategory = AllMarktContextIM.ProductCategories.FirstOrDefault();
            var newProductCategory     = new EditProductCategoryCommand
            {
                Id          = existedProductCategory.Id,
                Name        = "editedName",
                Description = "editedDesc",
            };

            //Act
            await _editProductCategoryCommandHandler.Handle(newProductCategory, CancellationToken.None);

            //Assert
            AllMarktContextIM.ProductCategories
            .Should()
            .Contain(x => x.Id == newProductCategory.Id &&
                     x.Name == newProductCategory.Name &&
                     x.Description == newProductCategory.Description);
        }
Ejemplo n.º 8
0
        public async Task GetAllProductsByProductCategoryQueryHandler_ReturnsExistingProducts()
        {
            //Arrange
            var productCategory = new AllMarkt.Entities.ProductCategory {
                Name = "category", Description = "description"
            };

            AllMarktContextIM.ProductCategories.Add(productCategory);
            AllMarktContextIM.SaveChanges();

            AllMarktContextIM.Products.Add(new AllMarkt.Entities.Product
            {
                Name            = "Test Name1",
                Description     = "Test Description1",
                Price           = 10,
                ImageURI        = "",
                State           = true,
                ProductCategory = productCategory
            });

            AllMarktContextIM.Products.Add(new AllMarkt.Entities.Product
            {
                Name            = "Test Name2",
                Description     = "Test Description2",
                Price           = 10,
                ImageURI        = "",
                State           = true,
                ProductCategory = productCategory
            });

            AllMarktContextIM.SaveChanges();

            //Act
            var result = await _getAllProductsQueryHandler.Handle(new GetAllProductsByProductCategoryQuery(productCategory.Id), CancellationToken.None);

            //Assert

            result.Count().Should().Be(2);
        }
        public async Task DeleteProductCategoryCommandHandle_DeletingCategory()
        {
            //Arrange
            AllMarktContextIM.Shops.Add(new AllMarkt.Entities.Shop
            {
                Address           = "dddd",
                Comments          = null,
                CUI               = "ddd",
                IBAN              = "dffddfdfd",
                Orders            = null,
                PhoneNumber       = "0123654789",
                ProductCategories = null,
                ShopCategoryLink  = null,
                SocialCapital     = 3
            });
            AllMarktContextIM.SaveChanges();
            var shop = AllMarktContextIM.Shops.First();

            AllMarktContextIM.ProductCategories.Add(new AllMarkt.Entities.ProductCategory
            {
                Name        = "TestName",
                Description = "TestDescription",
                Shop        = shop,
                Products    = null
            });
            AllMarktContextIM.SaveChanges();
            var existentProductCategory = AllMarktContextIM.ProductCategories.First();
            var deletedProductCategory  = new DeleteProductCategoryCommand {
                Id = existentProductCategory.Id
            };

            //Act
            await _deleteProductCategoryHandler.Handle(deletedProductCategory, CancellationToken.None);

            //Assert
            AllMarktContextIM.ProductCategories
            .Should()
            .NotContain(productCategory => productCategory.Id == deletedProductCategory.Id);
        }
Ejemplo n.º 10
0
        public async Task GetAllCategoriesQueryHandler_ReturnsExistingCategories()
        {
            //Arrange
            AllMarktContextIM.Categories.Add(new AllMarkt.Entities.Category
            {
                Name        = "Test Name1",
                Description = "Test Description1"
            });

            AllMarktContextIM.Categories.Add(new AllMarkt.Entities.Category
            {
                Name        = "Test Name2",
                Description = "Test Description2"
            });

            AllMarktContextIM.SaveChanges();

            //Act
            var result = await _getAllCategoriesQueryHandler.Handle(new GetAllCategoriesQuery(), CancellationToken.None);

            //Assert
            result.Count().Should().Be(2);
        }
Ejemplo n.º 11
0
        public async Task DeleteCategoryCommandHandle_DeletesExistingCategory()
        {
            //Arrange
            AllMarktContextIM.Categories.Add(new AllMarkt.Entities.Category
            {
                Name        = "TestName",
                Description = "TestDescription"
            });
            AllMarktContextIM.SaveChanges();
            var existingCategory = AllMarktContextIM.Categories.First();

            var deleteCategoryCommand = new DeleteCategoryCommand {
                Id = existingCategory.Id
            };

            //Act
            await _deleteCategoryCommandHandler.Handle(deleteCategoryCommand, CancellationToken.None);

            //Assert
            AllMarktContextIM.Categories
            .Should()
            .NotContain(category => category.Id == deleteCategoryCommand.Id);
        }