Exemplo n.º 1
0
        public void TestGettingMoreThan10Videos()
        {
            // Arrange:
            List<Video> videos = new List<Video>();

            for(int i = 0; i < 13; i++)
            {
                videos.Add(new Video
                {
                    ID = i,
                    videoCategory = "Hasar",
                    videoTime = DateTime.Now.AddDays(i),
                    videoName = "Video " + i.ToString()
                });
            }

            var mockRepo = new Mocks.MockVideoRepository(videos);
            var controller = new MockVideoController(mockRepo);

            // Act:
            var result = controller.GetVideos(null, "");

            // Assert:
            var viewResult = (ViewResult)result;
            List<Video> model = (viewResult.Model as IEnumerable<Video>).ToList();

            Assert.IsTrue(model.Count == 10);
        }
Exemplo n.º 2
0
        public void TestGettingTranslationById()
        {
            // Arrange:
            List<Translation> translations = new List<Translation>();

            for (int i = 0; i < 15; i++)
            {
                translations.Add(new Translation
                {
                    ID = i,
                    vID = i % 3,
                    translationName = "Hackers",
                    translationCategory = "Hasar",
                    translationDescription = "Lorem ipsum",
                    translationLanguage = "English" + i.ToString(),
                    translationText = "Lorem ipsum",
                    averageVotes = Convert.ToDouble(i),
                    translationTime = DateTime.Now.AddDays(i)
                });
            }
            var mockRepo = new Mocks.MockTranslationRepository(translations);
            var controller = new MockVideoController(mockRepo);

            // Act:
            // Get translation with id == 7.
            var result = controller.GetTranslationById(7);

            // Assert:
            var viewResult = (ViewResult)result;
            List<Translation> model = (viewResult.Model as IEnumerable<Translation>).ToList();

            Assert.IsTrue(model.Count == 1);
            Assert.IsTrue(model[0].ID == 7);
        }
Exemplo n.º 3
0
        public void TryToGetMoreThan10Translations()
        {
            // Arrange:
            List<Translation> translations = new List<Translation>();

            for(int i = 0; i < 13; i++)
            {
                translations.Add(new Translation
                {
                    ID = i,
                    vID = i % 3,
                    translationName = "Hackers",
                    translationCategory = "Hasar",
                    translationDescription = "Lorem ipsum",
                    translationLanguage = "English",
                    translationText = "Lorem ipsum",
                    translationTime = DateTime.Now.AddDays(i)
                });
            }

            var mockRepo = new Mocks.MockTranslationRepository(translations);
            var controller = new MockVideoController(mockRepo);

            // Act:
            // Get the translations with vId == 2.
            var result = controller.GetTranslationByVideoId(2, null, "");

            // Assert:
            var viewResult = (ViewResult)result;
            List<Translation> model = (viewResult.Model as IEnumerable<Translation>).ToList();

            foreach(var item in model)
            {
                Assert.IsTrue(item.vID == 2);
            }

            Assert.IsTrue(model.Count == 4);
        }
Exemplo n.º 4
0
        public void TestSearchingForUpperAndLowerCaseNames()
        {
            // Arrange:
            List<Video> videos = new List<Video>();

            for (int i = 0; i < 20; i++)
            {
                videos.Add(new Video
                {
                    ID = i,
                    videoCategory = "Hasar" + (i % 3).ToString(),
                    videoTime = DateTime.Now.AddDays(i),
                    videoName = i % 2 == 0 ? "Hackers" : "hackers"

                });
            }

            var mockRepo = new Mocks.MockVideoRepository(videos);
            var controller = new MockVideoController(mockRepo);

            // Act:
            var result = controller.SearchEngine("hackers", "", null, "");

            // Assert:
            var viewResult = (ViewResult)result;
            List<Video> model = (viewResult.Model as IEnumerable<Video>).ToList();

            foreach (var item in model)
            {
                Assert.IsTrue(item.videoName.ToLower() == "hackers");
            }
        }
Exemplo n.º 5
0
        public void TestOrderingVideosByNameDescending()
        {
            // Arrange:
            List<Video> videos = new List<Video>();

            for (int i = 0; i < 10; i++)
            {
                videos.Add(new Video
                {
                    ID = i,
                    videoCategory = "Hasar",
                    videoTime = DateTime.Now.AddDays(i),
                    videoName = "Video " + i.ToString()
                });
            }

            var mockRepo = new Mocks.MockVideoRepository(videos);
            var controller = new MockVideoController(mockRepo);

            // Act:
            // Get videos ordered by name descending.
            var result = controller.GetVideos(null, "name_desc");

            // Assert:
            var viewResult = (ViewResult)result;
            List<Video> model = (viewResult.Model as IEnumerable<Video>).ToList();

            for (int i = 0; i < model.Count - 1; i++)
            {
                int compare = String.Compare(model[i].videoName, model[i + 1].videoName);
                Assert.IsTrue(compare >= 0);
            }
        }
Exemplo n.º 6
0
        public void TestIfTranslationsAreOrderedByLanguageDescending()
        {
            // Arrange:
            List<Translation> translations = new List<Translation>();

            for (int i = 0; i < 30; i++)
            {
                translations.Add(new Translation
                {
                    ID = i,
                    vID = i % 3,
                    translationName = "Hackers",
                    translationCategory = "Hasar",
                    translationDescription = "Lorem ipsum",
                    translationLanguage = "English" + i.ToString(),
                    translationText = "Lorem ipsum",
                    translationTime = DateTime.Now.AddDays(i)
                });
            }
            var mockRepo = new Mocks.MockTranslationRepository(translations);
            var controller = new MockVideoController(mockRepo);

            // Act:
            // Get translations ordered by language descending.
            var result = controller.GetTranslationByVideoId(1, null, "lang_desc");

            // Assert:
            var viewResult = (ViewResult)result;
            List<Translation> model = (viewResult.Model as IEnumerable<Translation>).ToList();

            for (int i = 0; i < model.Count - 1; i++)
            {
                int compare = String.Compare(model[i].translationLanguage, model[i + 1].translationLanguage);
                Assert.IsTrue(compare >= 0);
            }
        }
Exemplo n.º 7
0
        public void TestIfTranslationsAreOrderedByDownloadCountAscending()
        {
            // Arrange:
            List<Translation> translations = new List<Translation>();

            for (int i = 0; i < 30; i++)
            {
                translations.Add(new Translation
                {
                    ID = i,
                    vID = i % 3,
                    translationName = "Hackers",
                    translationCategory = "Hasar",
                    translationDescription = "Lorem ipsum",
                    translationLanguage = "English" + i.ToString(),
                    translationText = "Lorem ipsum",
                    downloadCount = i,
                    translationTime = DateTime.Now.AddDays(i)
                });
            }
            var mockRepo = new Mocks.MockTranslationRepository(translations);
            var controller = new MockVideoController(mockRepo);

            // Act:
            // Get translations ordered by count ascending.
            var resultAscending = controller.GetTranslationByVideoId(1, null, "Count");

            // Assert:
            var viewResultAscending = (ViewResult)resultAscending;
            List<Translation> modelAscending = (viewResultAscending.Model as IEnumerable<Translation>).ToList();

            for (int i = 0; i < modelAscending.Count - 1; i++)
            {
                Assert.IsTrue(modelAscending[i].downloadCount <= modelAscending[i + 1].downloadCount);
            }
        }
Exemplo n.º 8
0
        public void TestGettingVideoByCategory()
        {
            // Arrange:
            List<Video> videos = new List<Video>();

            for (int i = 0; i < 20; i++)
            {
                videos.Add(new Video
                {
                    ID = i,
                    videoCategory = "Hasar" + (i % 3).ToString(),
                    videoTime = DateTime.Now.AddDays(i),
                    videoName = "Video " + i.ToString()
                });
            }

            var mockRepo = new Mocks.MockVideoRepository(videos);
            var controller = new MockVideoController(mockRepo);

            // Act:
            // Get videos with category == Hasar1.
            var result = controller.GetVideoByCategory("Hasar1", null, "");

            // Assert:
            var viewResult = (ViewResult)result;
            List<Video> model = (viewResult.Model as IEnumerable<Video>).ToList();

            foreach(var item in model)
            {
                Assert.IsTrue(item.videoCategory == "Hasar1");
            }
        }