Ejemplo n.º 1
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.º 2
0
        public async Task EditProduct_CommandHandle_UpdatesExistingProduct()
        {
            //Arrange
            var productCategory = new AllMarkt.Entities.ProductCategory
            {
                Name        = "category",
                Description = "description"
            };

            AllMarktContextIM.ProductCategories.Add(productCategory);
            await AllMarktContextIM.SaveChangesAsync();

            var product = new AllMarkt.Entities.Product
            {
                Name            = "Test Name1",
                Description     = "Test Description1",
                Price           = 10,
                ImageURI        = "",
                State           = true,
                ProductCategory = productCategory
            };

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

            var existingProduct = AllMarktContextIM.Products.First();

            var editProductCommand = new EditProductCommand
            {
                Id          = existingProduct.Id,
                Name        = "TestName_EDIT",
                Description = "TestDescription_EDIT",
                Price       = 11,
                ImageURI    = "abc",
                State       = false,
            };

            //Act
            await _editProductCommandHandler.Handle(editProductCommand, CancellationToken.None);

            //Assert
            AllMarktContextIM.Products.Should().Contain(x => x.Id == editProductCommand.Id);

            product.Name.Should().Be(editProductCommand.Name);
            product.Description.Should().Be(editProductCommand.Description);
            product.Price.Should().Be(editProductCommand.Price);
            product.ImageURI.Should().Be(editProductCommand.ImageURI);
            product.State.Should().Be(editProductCommand.State);
        }