Beispiel #1
0
        public async Task DeleteOrderCommandHandler_DeletesExistingOrder()
        {
            //Arrange
            var order = new AllMarkt.Entities.Order
            {
                DeliveryAddress = "Test Address",
                AWB             = "Test AWB"
            };

            AllMarktContextIM.Orders.Add(order);
            await AllMarktContextIM.SaveChangesAsync();

            var existingOrder      = AllMarktContextIM.Orders.First();
            var deleteOrderCommand = new DeleteOrderCommand
            {
                Id = existingOrder.Id
            };

            //Act
            await _deleteOrderCommandHandler.Handle(deleteOrderCommand, CancellationToken.None);

            //Assert
            AllMarktContextIM.Orders
            .Should().NotContain(x => x.Id == existingOrder.Id);
        }
        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);
        }
Beispiel #3
0
        public async Task EditCustomer_CommandHandle_UpdatesExistingCustomer()
        {
            //Arrange
            var customer = new AllMarkt.Entities.Customer
            {
                Address     = "address",
                PhoneNumber = "0123654789"
            };

            AllMarktContextIM.Customers.Add(customer);
            await AllMarktContextIM.SaveChangesAsync();

            var existingCustomer = AllMarktContextIM.Customers.First();

            var editCustomerCommand = new EditCustomerCommand
            {
                Id          = existingCustomer.Id,
                Address     = "editedAddress",
                PhoneNumber = "0147852369"
            };

            //Act
            await _editCustomerCommandHandler.Handle(editCustomerCommand, CancellationToken.None);

            //Assert
            AllMarktContextIM.Customers.Should().Contain(x => x.Id == editCustomerCommand.Id);

            customer.Address.Should().Be(editCustomerCommand.Address);
            customer.PhoneNumber.Should().Be(editCustomerCommand.PhoneNumber);
        }
Beispiel #4
0
        public async Task EditShop_CommandHandle_UpdatesExistingShop()
        {
            //Arrange
            var shop = new AllMarkt.Entities.Shop
            {
                Address     = "address",
                PhoneNumber = "0123654789",
                IBAN        = "SE3550000000054910000003"
            };

            AllMarktContextIM.Shops.Add(shop);
            await AllMarktContextIM.SaveChangesAsync();

            var existingShop = AllMarktContextIM.Shops.First();

            var editShopCommand = new EditShopCommand
            {
                Id          = existingShop.Id,
                Address     = "editedAddress",
                IBAN        = "RO3550000000054910000003",
                PhoneNumber = "0147852369"
            };

            //Act
            await _editShopCommandHandler.Handle(editShopCommand, CancellationToken.None);

            //Assert
            AllMarktContextIM.Shops.Should().Contain(x => x.Id == editShopCommand.Id);

            shop.Address.Should().Be(editShopCommand.Address);
            shop.PhoneNumber.Should().Be(editShopCommand.PhoneNumber);
            shop.IBAN.Should().Be(editShopCommand.IBAN);
        }
        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);
        }
        public async Task EditProductCommentCommandHandle_UpdatesExistingProductComment()
        {
            //Arrange
            var productComment = new AllMarkt.Entities.ProductComment
            {
                Rating = 3,
                Text   = "test"
            };

            await AllMarktContextIM.ProductComments.AddAsync(productComment);

            await AllMarktContextIM.SaveChangesAsync();

            var existingProductComments = await AllMarktContextIM.ProductComments.FirstAsync();

            var editProductCommentsCommand = new EditProductCommentCommand
            {
                Id   = existingProductComments.Id,
                Text = "test_edit"
            };

            //Act
            await _editProductCommentCommandHandler.Handle(editProductCommentsCommand, CancellationToken.None);

            //Assert
            AllMarktContextIM.ProductComments
            .Should()
            .Contain(x => x.Id == editProductCommentsCommand.Id && x.Text == editProductCommentsCommand.Text);
        }
        public async Task EditUserCommandHandler_Change_ShopUser_Into_AdminUser()
        {
            //Arrange
            var user = await CreateUserWithRoleAsync(UserRole.Shop);

            var shop = new Shop
            {
                User = user
            };
            await AllMarktContextIM.Shops.AddAsync(shop);

            await AllMarktContextIM.SaveChangesAsync();

            var editUserCommand = CreateEditUserCommand(user.Id, "Admin");

            //Act
            await _editUserCommandHandler.Handle(editUserCommand, CancellationToken.None);

            //Assert
            AllMarktContextIM.Users.Should()
            .Contain(u =>
                     u.Email == editUserCommand.Email &&
                     u.DisplayName == editUserCommand.DisplayName &&
                     u.UserRole == (UserRole)Enum.Parse(typeof(UserRole), editUserCommand.UserRole)
                     );
            var shopFound = await AllMarktContextIM.Shops.FindAsync(user.Id);

            shopFound.Should().BeNull();

            AllMarktContextIM.Admins.Should().Contain(a => a.UserId == user.Id);
        }
        public async Task EditOrderCommandHandler_UpdatesExistingOrder()
        {
            //Arrange
            Shop     seller = new Shop();
            Customer buyer  = new Customer();

            AllMarktContextIM.Shops.Add(seller);
            AllMarktContextIM.Customers.Add(buyer);
            await AllMarktContextIM.SaveChangesAsync();

            var order = new AllMarkt.Entities.Order
            {
                Seller              = seller,
                Buyer               = buyer,
                AdditionalNotes     = "Test Notes",
                DeliveryAddress     = "Test Address",
                DeliveryPhoneNumber = "01234567890",
                TotalPrice          = 1,
                TimeOfOrder         = DateTime.Now,
                OrderStatus         = Status.Registered,
                AWB = "Test AWB",
            };

            OrderItem orderItem = new OrderItem
            {
                Order = order
            };

            order.OrderItems = new List <OrderItem> {
                orderItem
            };

            AllMarktContextIM.Orders.Add(order);
            AllMarktContextIM.OrderItems.Add(orderItem);
            await AllMarktContextIM.SaveChangesAsync();

            var existingOrder = AllMarktContextIM.Orders.Where(o => o.Id == order.Id).FirstOrDefault();

            var editOrderCommand = new EditOrderCommand
            {
                Id = existingOrder.Id,
                AdditionalNotes     = "Test Notes",
                DeliveryAddress     = "Edit Address",
                DeliveryPhoneNumber = "0123456789",
                TotalPrice          = 1,
                OrderStatus         = Status.Registered,
                AWB = "Edit AWB"
            };


            //Act
            await _editOrderCommandHandler.Handle(editOrderCommand, CancellationToken.None);

            //
            AllMarktContextIM.Orders.Should().Contain(x =>
                                                      x.Id == editOrderCommand.Id);

            order.DeliveryAddress.Should().Be(editOrderCommand.DeliveryAddress);
            order.AWB.Should().Be(editOrderCommand.AWB);
        }
        public async Task DeleteProduct_CommandHandle_DeletesExistingProducty()
        {
            //Arrange
            var productCategory = new AllMarkt.Entities.ProductCategory {
                Name = "category", Description = "description"
            };

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

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

            var existingProduct = AllMarktContextIM.Products.First();

            var deleteProductCommand = new DeleteProductCommand {
                Id = existingProduct.Id
            };

            //Act
            await _deleteProductCommandHandler.Handle(deleteProductCommand, CancellationToken.None);

            //Assert
            AllMarktContextIM.Products
            .Should()
            .NotContain(product => product.Id == deleteProductCommand.Id);
        }
Beispiel #10
0
        public async Task Setup_Add2UsersForPrivateMessagesTest()
        {
            if (!AllMarktContextIM.Users.Any(user => user.Email == "*****@*****.**"))
            {
                AllMarktContextIM.Users.Add(new AllMarkt.Entities.User
                {
                    Email            = "*****@*****.**",
                    Password         = "******",
                    DisplayName      = "user1",
                    ReceivedMessages = new List <AllMarkt.Entities.PrivateMessage>(),
                    SentMessages     = new List <AllMarkt.Entities.PrivateMessage>()
                });
            }

            if (!AllMarktContextIM.Users.Any(user => user.Email == "*****@*****.**"))
            {
                AllMarktContextIM.Users.Add(new AllMarkt.Entities.User
                {
                    Email            = "*****@*****.**",
                    Password         = "******",
                    DisplayName      = "user2",
                    ReceivedMessages = new List <AllMarkt.Entities.PrivateMessage>(),
                    SentMessages     = new List <AllMarkt.Entities.PrivateMessage>()
                });
            }

            await AllMarktContextIM.SaveChangesAsync();
        }
        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);
        }
Beispiel #12
0
        public async Task GetAllCustomersQueryHandler_ReturnsCustomers()
        {
            //Arrange
            var user = new AllMarkt.Entities.User
            {
                Email       = "*****@*****.**",
                DisplayName = "tets"
            };

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

            AllMarktContextIM.Customers.Add(new AllMarkt.Entities.Customer
            {
                User        = user,
                UserId      = user.Id,
                Address     = "address",
                PhoneNumber = "0123456789",
            });

            await AllMarktContextIM.SaveChangesAsync();

            //Act
            var customers = await _getAllCustomersQueryHandler.Handle(new GetAllCustomersQuery(), CancellationToken.None);

            //assert
            customers.Count().Should().Be(1);
        }
        public async Task DeleteShopCommentCommandHandle_DeletesExistingShopComment()
        {
            //Arrange
            AllMarktContextIM.ShopComments.Add(new AllMarkt.Entities.ShopComment
            {
                Rating = 5,
                Text   = "test"
            });

            await AllMarktContextIM.SaveChangesAsync();

            var existingShopComment = await AllMarktContextIM.ShopComments.FirstAsync();

            var deleteShopCommentCommand = new DeleteShopCommentCommand {
                Id = existingShopComment.Id
            };

            //Act
            await _deleteShopCommentCommandHandler.Handle(deleteShopCommentCommand, CancellationToken.None);

            //Assert
            AllMarktContextIM.ShopComments
            .Should()
            .NotContain(ShopComments => ShopComments.Id == deleteShopCommentCommand.Id);
        }
        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);
        }
Beispiel #15
0
        public async Task GetAllUsersQueryHandler_ReturnsExistingUsers()
        {
            //Arrange
            var user1 = new AllMarkt.Entities.User
            {
                Email       = "*****@*****.**",
                Password    = "******",
                DisplayName = "name1"
            };
            var user2 = new AllMarkt.Entities.User
            {
                Email       = "*****@*****.**",
                Password    = "******",
                DisplayName = "name2"
            };
            await AllMarktContextIM.Users.AddAsync(user1);

            await AllMarktContextIM.Users.AddAsync(user2);

            await AllMarktContextIM.SaveChangesAsync();

            //Act
            var result = await _getAllUsersQueryHandler.Handle(new GetAllUsersQuery(), CancellationToken.None);

            //Assert
            result.Count().Should().Be(2);
        }
        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);
        }
        public async Task GetCustomerByUserIdQueryHandler_ReturnsExisting_UserById()
        {
            //Arrange
            var user1 = new AllMarkt.Entities.User
            {
                Email       = "*****@*****.**",
                Password    = "******",
                DisplayName = "name1",
                UserRole    = UserRole.Customer
            };
            var customer = new AllMarkt.Entities.Customer
            {
                Address     = "address1",
                PhoneNumber = "0123654789",
                UserId      = user1.Id,
                User        = user1,
                Orders      = null
            };

            await AllMarktContextIM.Users.AddAsync(user1);

            await AllMarktContextIM.Customers.AddAsync(customer);

            await AllMarktContextIM.SaveChangesAsync();

            //Act
            var result = await _getCustomerByUserIdQueryHandler.Handle(new GetCustomerByUserIdQuery { Id = user1.Id }, CancellationToken.None);

            //Assert
            result.UserDisplayName.Should().Be("name1");
            result.Address.Should().Be("address1");
            result.PhoneNumber.Should().Be("0123654789");
        }
        public async Task DeleteUserCommandHandler_DeleteExistingUser_And_Asociated_UserRole_AdminObject()
        {
            //Arrange
            var newUser = GetNewUser();
            await AllMarktContextIM.Users.AddAsync(newUser);

            await AllMarktContextIM.SaveChangesAsync();

            var adminUser = new AllMarkt.Entities.Admin {
                User = newUser
            };
            await AllMarktContextIM.Admins.AddAsync(adminUser);

            await AllMarktContextIM.SaveChangesAsync();

            var existingUser      = AllMarktContextIM.Users.First();
            var deleteUserCommand = new DeleteUserCommand {
                Id = existingUser.Id
            };

            //Act
            await _deleteUserCommandHandler.Handle(deleteUserCommand, CancellationToken.None);

            //Assert
            AllMarktContextIM.Users
            .Should()
            .NotContain(u => u.Id == deleteUserCommand.Id);

            AllMarktContextIM.Admins
            .Should()
            .BeEmpty();
        }
        public async Task GetGetProductCommentsByProductIdQueryHandler_ReturnsExistingComments()
        {
            //Arrange
            var user = new AllMarkt.Entities.User
            {
                Email       = "*****@*****.**",
                Password    = "******",
                DisplayName = "UserTest"
            };

            var product1 = new AllMarkt.Entities.Product
            {
                Name        = "prodTest1",
                Description = "prodTestDescriere1",
                Price       = 20
            };
            var product2 = new AllMarkt.Entities.Product
            {
                Name        = "prodTest2",
                Description = "prodTestDescriere2",
                Price       = 20
            };

            AllMarktContextIM.Users.Add(user);
            AllMarktContextIM.Products.Add(product1);
            AllMarktContextIM.Products.Add(product2);
            await AllMarktContextIM.SaveChangesAsync();

            var productComment1 = new AllMarkt.Entities.ProductComment
            {
                Rating    = 2,
                Text      = "naspa rau",
                AddedBy   = user,
                Product   = product1,
                DateAdded = DateTime.UtcNow
            };

            var productComment2 = new AllMarkt.Entities.ProductComment
            {
                Rating    = 4,
                Text      = "super fain",
                AddedBy   = user,
                Product   = product2,
                DateAdded = DateTime.UtcNow
            };

            AllMarktContextIM.ProductComments.Add(productComment1);
            AllMarktContextIM.ProductComments.Add(productComment2);

            await AllMarktContextIM.SaveChangesAsync();

            //Act
            var result = await _getProductCommentsQueryHandler.Handle(new GetProductCommentsByProductIdQuery(product1.Id), CancellationToken.None);

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

            var shop = new AllMarkt.Entities.Shop
            {
                Address           = "aaaaa",
                Comments          = null,
                CUI               = "aaaaddd",
                IBAN              = "aaaaa",
                Orders            = null,
                PhoneNumber       = "0123654789",
                ProductCategories = null,
                ShopCategoryLink  = null,
                SocialCapital     = 4,
                User              = user
            };

            AllMarktContextIM.Users.Add(user);
            AllMarktContextIM.Shops.Add(shop);
            await AllMarktContextIM.SaveChangesAsync();

            AllMarktContextIM.ShopComments.Add(new AllMarkt.Entities.ShopComment
            {
                Rating  = 2,
                Text    = "naspa rau",
                AddedBy = user,
                Shop    = shop,
            });

            AllMarktContextIM.ShopComments.Add(new AllMarkt.Entities.ShopComment
            {
                Rating  = 5,
                Text    = "super fain",
                AddedBy = user,
                Shop    = shop
            });

            await AllMarktContextIM.SaveChangesAsync();

            //Act
            var result = await _getAllShopCommentsQueryHandler.Handle(new GetAllShopCommentsQuery(), CancellationToken.None);

            //Assert
            result.Count().Should().Be(2);
        }
        public async Task GetAllOrdersQueryHandler_Returns_ExistingOrders()
        {
            //Arrange
            AllMarkt.Entities.Order order = new AllMarkt.Entities.Order();
            AllMarktContextIM.Orders.Add(order);
            await AllMarktContextIM.SaveChangesAsync();

            //Act
            var result = await _getAllOrdersQueryHandler.Handle(new GetAllOrdersQuery(), CancellationToken.None);

            //Assert
            result.Count().Should().Be(1);
        }
        public async Task AddOrderCommandHandle_AddsOrder()
        {
            //Arrange
            Shop seller = new Shop
            {
                Address           = "aaaaa",
                Comments          = null,
                CUI               = "aaaaddd",
                IBAN              = "aaaaa",
                Orders            = null,
                PhoneNumber       = "0123654789",
                ProductCategories = null,
                ShopCategoryLink  = null,
                SocialCapital     = 4
            };
            Customer buyer = new Customer();

            AllMarktContextIM.Customers.Add(buyer);
            AllMarktContextIM.Shops.Add(seller);
            await AllMarktContextIM.SaveChangesAsync();

            var addOrderCommand = new AddOrderCommand
            {
                ShopId          = seller.Id,
                CustomerId      = buyer.Id,
                DeliveryAddress = "Test Address",
                AWB             = "Test AWB",
                OrderItems      = new List <OrderItemViewModel>()
                {
                    new OrderItemViewModel
                    {
                        Id     = 1,
                        Name   = "Test Item",
                        Amount = 1
                    }
                }
            };

            //Act
            await _addOrderCommandHandler.Handle(addOrderCommand, CancellationToken.None);

            //Assert
            AllMarktContextIM.Orders
            .Should()
            .Contain(order =>
                     order.Seller.Id == addOrderCommand.ShopId &&
                     order.Buyer.Id == addOrderCommand.CustomerId &&
                     order.DeliveryAddress == addOrderCommand.DeliveryAddress &&
                     order.AWB == addOrderCommand.AWB);
        }
Beispiel #23
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);
        }
Beispiel #24
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);
        }
        private async Task <AllMarkt.Entities.User> CreateUserWithRoleAsync(UserRole role)
        {
            var user1 = new AllMarkt.Entities.User
            {
                Email       = "*****@*****.**",
                Password    = "******",
                DisplayName = "Name",
                UserRole    = role
            };
            await AllMarktContextIM.Users.AddAsync(user1);

            await AllMarktContextIM.SaveChangesAsync();

            return(user1);
        }
Beispiel #26
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);
        }
Beispiel #27
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();
        }
        public async Task EditPrivateMessageCommandHandler_UpdatesExistingPrivateMessage()
        {
            //arrange
            await Setup_Add2UsersForPrivateMessagesTest();

            AllMarkt.Entities.User user1 = await AllMarktContextIM.Users.FirstOrDefaultAsync(user => user.Email == "*****@*****.**");

            AllMarkt.Entities.User user2 = await AllMarktContextIM.Users.FirstOrDefaultAsync(user => user.Email == "*****@*****.**");

            var privateMessage = new AllMarkt.Entities.PrivateMessage
            {
                Title     = "stock is best medi gun",
                Text      = "text",
                DateSent  = DateTime.Now,
                DateRead  = null,
                Sender    = user1,
                Receiver  = user2,
                DeletedBy = null
            };

            await AllMarktContextIM.PrivateMessages.AddAsync(privateMessage);

            await AllMarktContextIM.SaveChangesAsync();

            var existingPrivateMessage = await AllMarktContextIM.PrivateMessages.FirstOrDefaultAsync(PM => PM.Title == "stock is best medi gun");

            var editPrivateMessageCommand = new EditPrivateMessageCommand
            {
                Id         = existingPrivateMessage.Id,
                Title      = "kritzkrieg is best medi gun",
                Text       = existingPrivateMessage.Text,
                DateSent   = existingPrivateMessage.DateSent,
                DateRead   = existingPrivateMessage.DateRead,
                SenderId   = existingPrivateMessage.Sender.Id,
                ReceiverId = existingPrivateMessage.Receiver.Id,
                DeletedBy  = AllMarkt.Entities.DeletedBy.Receiver
            };

            //Act
            await _editPrivateMessageCommandHandler.Handle(editPrivateMessageCommand, CancellationToken.None);

            //Assert
            AllMarktContextIM.PrivateMessages.Should().Contain(PM => PM.Id == editPrivateMessageCommand.Id);

            privateMessage.Title.Should().Be(editPrivateMessageCommand.Title);
            privateMessage.DeletedBy.Should().Be(editPrivateMessageCommand.DeletedBy);
        }
Beispiel #29
0
        public async Task AddShopCommentCommandHandle_AddsShopComment()
        {
            //Arrange
            var user = new AllMarkt.Entities.User {
                Email       = "*****@*****.**",
                Password    = "******",
                DisplayName = "UserTest"
            };

            var shop = new AllMarkt.Entities.Shop
            {
                Address           = "aaaaa",
                Comments          = null,
                CUI               = "aaaaddd",
                IBAN              = "aaaaa",
                Orders            = null,
                PhoneNumber       = "0123654789",
                ProductCategories = null,
                ShopCategoryLink  = null,
                SocialCapital     = 4
            };

            AllMarktContextIM.Users.Add(user);
            AllMarktContextIM.Shops.Add(shop);
            await AllMarktContextIM.SaveChangesAsync();

            var addShopCommentCommand = new AddShopCommentCommand
            {
                Rating        = 5,
                Text          = "cel mai bun",
                ShopId        = shop.Id,
                AddedByUserId = user.Id
            };

            //Act
            await _addShopCommentCommandHandler.Handle(addShopCommentCommand, CancellationToken.None);

            //Assert
            AllMarktContextIM.ShopComments
            .Should()
            .Contain(shopComment =>
                     shopComment.Rating == addShopCommentCommand.Rating &&
                     shopComment.Text == addShopCommentCommand.Text &&
                     shopComment.AddedBy.Id == addShopCommentCommand.AddedByUserId &&
                     shopComment.Shop.Id == addShopCommentCommand.ShopId);
        }
Beispiel #30
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);
        }