Example #1
0
        public void FilterBySearchWord(string searchWord)
        {
            // Arrange
            var mockedData = new Mock <IDearDiaryData>();
            var aims       = new List <Aim>
            {
                new Aim()
                {
                    Name = "Jump with parachute", OwnerUsername = "******"
                },
                new Aim()
                {
                    Name = "build a spacecraft", OwnerUsername = "******"
                },
                new Aim()
                {
                    Name = "visit china", OwnerUsername = "******"
                },
            }.AsQueryable();

            mockedData.Setup(x => x.Aims.All).Returns(aims);

            AimService service = new AimService(mockedData.Object);

            // Act
            var result = service.ExploreAims(searchWord, null, null);

            // Assert
            var expectedAims = aims.Where(x => x.Name.Contains(searchWord) || x.OwnerUsername.Contains(searchWord)).ToList();

            CollectionAssert.AreEquivalent(expectedAims, result);
        }
Example #2
0
        public void FilterByAimCategories(params int[] categoriesIds)
        {
            // Arrange
            var mockedData = new Mock <IDearDiaryData>();
            var aims       = new List <Aim>
            {
                new Aim()
                {
                    AimCategoryId = 1
                },
                new Aim()
                {
                    AimCategoryId = 2
                },
                new Aim()
                {
                    AimCategoryId = 8
                },
                new Aim()
                {
                    AimCategoryId = 1
                },
                new Aim()
                {
                    AimCategoryId = 2
                },
                new Aim()
                {
                    AimCategoryId = 1
                },
                new Aim()
                {
                    AimCategoryId = 2
                },
                new Aim()
                {
                    AimCategoryId = 2
                }
            }.AsQueryable();

            mockedData.Setup(x => x.Aims.All).Returns(aims);

            AimService service = new AimService(mockedData.Object);

            // Act
            var filteredAims = service.ExploreAims(null, categoriesIds, null);

            // Assert
            var expectedAims = aims.Where(x => categoriesIds.Contains(x.AimCategoryId)).ToList();

            CollectionAssert.AreEquivalent(expectedAims, filteredAims);
        }
Example #3
0
        public void FilteringAndOrderingSimultaneously()
        {
            // Arrange
            string searchWord    = "visit";
            var    categoriesIds = new int[] { 4, 3 };
            var    mockedData    = new Mock <IDearDiaryData>();

            var aims = new List <Aim>
            {
                new Aim()
                {
                    Name = "Jump with parachute", OwnerUsername = "******", AimCategoryId = 3
                },
                new Aim()
                {
                    Name = "build a spacecraft", OwnerUsername = "******", AimCategoryId = 4
                },
                new Aim()
                {
                    Name = "visit russia", OwnerUsername = "******", AimCategoryId = 3
                },
                new Aim()
                {
                    Name = "visit usa", OwnerUsername = "******", AimCategoryId = 1
                },
                new Aim()
                {
                    Name = "visit egypt", OwnerUsername = "******", AimCategoryId = 4
                }
            }.AsQueryable();

            mockedData.Setup(x => x.Aims.All).Returns(aims);

            AimService service = new AimService(mockedData.Object);

            // Act
            var filteredOrderedAims = service.ExploreAims(searchWord, categoriesIds, "name");

            // Assert
            var expectedAims = aims.Where(x => x.Name.Contains(searchWord) || x.OwnerUsername.Contains(searchWord))
                               .Where(x => categoriesIds.Contains(x.AimCategoryId))
                               .OrderBy(x => x.Name)
                               .ToList();

            CollectionAssert.AreEqual(expectedAims, filteredOrderedAims);
        }
Example #4
0
        public void GetTheCorrectAims_WhenPagingOptionsChosen()
        {
            int page       = 2;
            int perPage    = 2;
            var mockedData = new Mock <IDearDiaryData>();
            var aims       = new List <Aim>
            {
                new Aim()
                {
                    Name = "Jump with parachute", OwnerUsername = "******", AimCategoryId = 3
                },
                new Aim()
                {
                    Name = "build a spacecraft", OwnerUsername = "******", AimCategoryId = 4
                },
                new Aim()
                {
                    Name = "visit russia", OwnerUsername = "******", AimCategoryId = 3
                },
                new Aim()
                {
                    Name = "visit usa", OwnerUsername = "******", AimCategoryId = 1
                },
                new Aim()
                {
                    Name = "visit egypt", OwnerUsername = "******", AimCategoryId = 4
                }
            }.AsQueryable();

            mockedData.Setup(x => x.Aims.All).Returns(aims);

            AimService service = new AimService(mockedData.Object);

            // Act
            var pagingAims = service.ExploreAims(null, null, null, page, perPage);

            // Assert
            var expectedAims = aims.OrderBy(x => x.Name).Skip(2).Take(perPage);

            // has to take visit egypt & russia
            CollectionAssert.AreEqual(expectedAims, pagingAims);
        }
Example #5
0
        public void ReturnOrderedAimsByOwnerUsername()
        {
            // Arrange
            var mockedData = new Mock <IDearDiaryData>();

            var aims = new List <Aim>
            {
                new Aim()
                {
                    Name = "Jump with parachute", OwnerUsername = "******", AimCategoryId = 3
                },
                new Aim()
                {
                    Name = "build a spacecraft", OwnerUsername = "******", AimCategoryId = 4
                },
                new Aim()
                {
                    Name = "visit russia", OwnerUsername = "******", AimCategoryId = 3
                },
                new Aim()
                {
                    Name = "visit usa", OwnerUsername = "******", AimCategoryId = 1
                },
                new Aim()
                {
                    Name = "visit egypt", OwnerUsername = "******", AimCategoryId = 4
                }
            }.AsQueryable();

            mockedData.Setup(x => x.Aims.All).Returns(aims);

            AimService service = new AimService(mockedData.Object);

            // Act
            var filteredAndOrderedAims = service.ExploreAims(null, null, "ownerusername");

            // Assert
            var expectedAims = aims.OrderBy(x => x.OwnerUsername).ToList();

            CollectionAssert.AreEqual(expectedAims, filteredAndOrderedAims);
        }
Example #6
0
        public void ReturnAllAims_WhenNoParametersArePassed()
        {
            // Arrange
            var mockedData = new Mock <IDearDiaryData>();

            var aims = new List <Aim>
            {
                new Aim()
                {
                    Name = "Jump with parachute", OwnerUsername = "******", AimCategoryId = 3
                },
                new Aim()
                {
                    Name = "build a spacecraft", OwnerUsername = "******", AimCategoryId = 4
                },
                new Aim()
                {
                    Name = "visit russia", OwnerUsername = "******", AimCategoryId = 3
                },
                new Aim()
                {
                    Name = "visit usa", OwnerUsername = "******", AimCategoryId = 1
                },
                new Aim()
                {
                    Name = "visit egypt", OwnerUsername = "******", AimCategoryId = 4
                }
            }.AsQueryable();

            mockedData.Setup(x => x.Aims.All).Returns(aims);

            AimService service = new AimService(mockedData.Object);

            // Act
            var filteredAims = service.ExploreAims(null, null, null);

            // Assert
            CollectionAssert.AreEquivalent(aims.ToList(), filteredAims);
        }