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 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 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 GetAllSentPrivateMessagesQueryHandler_ReturnsEmpty()
        {
            //Arrange
            await Setup_Add2UsersForPrivateMessagesTest();

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

            //Act
            var result = await _getAllSentPrivateMessagesWithUserIdQueryHandler.Handle(new GetAllSentPrivateMessagesByUserQuery(user1.Id), CancellationToken.None);

            //Assert
            result.Count().Should().Be(0);
        }
Ejemplo n.º 5
0
        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);
        }
        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);
        }
Ejemplo n.º 7
0
        public async Task GetPrivateMessageByIdQueryHandler_ReturnsExisting_PrivateMessageById()
        {
            //Arrange
            await Setup_Add2UsersForPrivateMessagesTest();

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

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

            var message = new AllMarkt.Entities.PrivateMessage
            {
                Title     = "Title 1",
                Text      = "Text 1",
                DateSent  = DateTime.Now,
                DateRead  = null,
                Sender    = user1,
                Receiver  = user2,
                DeletedBy = DeletedBy.Receiver
            };

            await AllMarktContextIM.PrivateMessages.AddAsync(message);

            await AllMarktContextIM.SaveChangesAsync();

            var idAndDisplayNameUser1 = new IdAndDisplayNameUserViewModel(user1);
            var idAndDisplayNameUser2 = new IdAndDisplayNameUserViewModel(user2);

            //Act
            var result = await _getPrivateMessageByIdQueryHandler.Handle(new GetPrivateMessageByIdQuery { Id = message.Id }, CancellationToken.None);

            //Assert
            result.Title.Should().Be("Title 1");
            result.Text.Should().Be("Text 1");
            result.DateRead.Should().Be(null);
            result.Sender.Should().BeEquivalentTo(idAndDisplayNameUser1);
            result.Receiver.Should().BeEquivalentTo(idAndDisplayNameUser2);
            result.DeletedBy.Should().Be(DeletedBy.Receiver);
        }
Ejemplo n.º 8
0
        public async Task GetUserByIdQueryHandler_ReturnsExisting_UserById()
        {
            //Arrange
            var user = new AllMarkt.Entities.User
            {
                Email       = "*****@*****.**",
                Password    = "******",
                DisplayName = "name1",
                UserRole    = UserRole.Shop
            };

            await AllMarktContextIM.Users.AddAsync(user);

            await AllMarktContextIM.SaveChangesAsync();

            //Act
            var result = await _getUserByIdQueryHandler.Handle(new GetUserByIdQuery { Id = user.Id }, CancellationToken.None);

            //Assert
            result.Email.Should().Be("*****@*****.**");
            result.DisplayName.Should().Be("name1");
            result.UserRole.Should().Be(nameof(UserRole.Shop));
        }
        public async Task GetAllSentPrivateMessagesQueryHandler_ReturnsExistingPrivateMessagesForUser()
        {
            //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 == "*****@*****.**");

            AllMarktContextIM.PrivateMessages.Add(new AllMarkt.Entities.PrivateMessage
            {
                Title    = "Title 1",
                Text     = "Text 1",
                DateSent = DateTime.Now,
                DateRead = DateTime.Now,
                Sender   = user1,
                Receiver = user2
            });

            AllMarktContextIM.PrivateMessages.Add(new AllMarkt.Entities.PrivateMessage
            {
                Title    = "Title 2",
                Text     = "Text 2",
                DateSent = DateTime.Now,
                DateRead = DateTime.Now,
                Sender   = user2,
                Receiver = user2
            });

            await AllMarktContextIM.SaveChangesAsync();

            //Act
            var result = await _getAllSentPrivateMessagesWithUserIdQueryHandler.Handle(new GetAllSentPrivateMessagesByUserQuery(user1.Id), CancellationToken.None);

            //Assert
            result.Count().Should().Be(1);
        }