コード例 #1
0
        public async Task ReturnPendingReports_WithSearch_When_ParamValid()
        {
            //Arrange
            var options   = Utils.GetOptions(nameof(ReturnPendingReports_WithSearch_When_ParamValid));
            var report1   = TestModelsSeeder.SeedReport();
            var industry1 = TestModelsSeeder.SeedIndustry();
            var user      = TestModelsSeeder.SeedUser();
            var tag       = TestModelsSeeder.SeedTag();
            var tag2      = TestModelsSeeder.SeedTag2();
            var tag3      = TestModelsSeeder.SeedTag3();
            var report2   = TestModelsSeeder.SeedReport2();
            var industry2 = TestModelsSeeder.SeedIndustry2();
            var report3   = TestModelsSeeder.SeedReport3();
            var industry3 = TestModelsSeeder.SeedIndustry3();

            report1.IsPending = true;
            report2.IsPending = true;

            using (var arrangeContext = new InsightHubContext(options))
            {
                await arrangeContext.Reports.AddAsync(report1);

                await arrangeContext.Tags.AddAsync(tag);

                await arrangeContext.Industries.AddAsync(industry1);

                await arrangeContext.Reports.AddAsync(report2);

                await arrangeContext.Tags.AddAsync(tag2);

                await arrangeContext.Industries.AddAsync(industry2);

                await arrangeContext.Reports.AddAsync(report3);

                await arrangeContext.Tags.AddAsync(tag3);

                await arrangeContext.Industries.AddAsync(industry3);

                await arrangeContext.Users.AddAsync(user);

                await arrangeContext.SaveChangesAsync();
            }
            //Act & Assert
            using var assertContext = new InsightHubContext(options);
            var sutTags = new TagServices(assertContext);
            var sut     = new ReportServices(assertContext, sutTags);
            var act     = await sut.GetPendingReports(null, "TestReport");

            var result = act.ToArray();

            Assert.AreEqual(2, result.Length);
            Assert.AreEqual(report1.Title, result[0].Title);
            Assert.AreEqual(report1.Summary, result[0].Summary);
            Assert.IsTrue(result[0].Title.Contains("TestReport"));
            Assert.AreEqual(report2.Title, result[1].Title);
            Assert.AreEqual(report2.Summary, result[1].Summary);
            Assert.IsTrue(result[1].Title.Contains("TestReport"));
        }
コード例 #2
0
        public async Task GetMostDownloadedReports_When_ParamsValid()
        {
            //Arrange
            var options   = Utils.GetOptions(nameof(GetMostDownloadedReports_When_ParamsValid));
            var report1   = TestModelsSeeder.SeedReport();
            var industry1 = TestModelsSeeder.SeedIndustry();
            var user      = TestModelsSeeder.SeedUser();
            var tag       = TestModelsSeeder.SeedTag();
            var tag2      = TestModelsSeeder.SeedTag2();
            var tag3      = TestModelsSeeder.SeedTag3();
            var report2   = TestModelsSeeder.SeedReport2();
            var industry2 = TestModelsSeeder.SeedIndustry2();
            var report3   = TestModelsSeeder.SeedReport3();
            var industry3 = TestModelsSeeder.SeedIndustry3();

            using (var arrangeContext = new InsightHubContext(options))
            {
                await arrangeContext.Reports.AddAsync(report1);

                await arrangeContext.Tags.AddAsync(tag);

                await arrangeContext.Industries.AddAsync(industry1);

                await arrangeContext.Reports.AddAsync(report2);

                await arrangeContext.Tags.AddAsync(tag2);

                await arrangeContext.Industries.AddAsync(industry2);

                await arrangeContext.Reports.AddAsync(report3);

                await arrangeContext.Tags.AddAsync(tag3);

                await arrangeContext.Industries.AddAsync(industry3);

                await arrangeContext.Users.AddAsync(user);

                await arrangeContext.SaveChangesAsync();
            }
            //Act & Assert
            using var assertContext = new InsightHubContext(options);
            var sutTags = new TagServices(assertContext);
            var sut     = new ReportServices(assertContext, sutTags);
            var act     = await sut.GetMostDownloadedReports();

            var result = act.ToArray();

            Assert.AreEqual(3, result.Length);
            Assert.AreEqual(report2.Title, result[0].Title);
            Assert.AreEqual(report2.Summary, result[0].Summary);
            Assert.IsTrue(result[0].DownloadsCount > result[1].DownloadsCount);
            Assert.AreEqual(report1.Title, result[1].Title);
            Assert.AreEqual(report1.Summary, result[1].Summary);
            Assert.IsTrue(result[1].DownloadsCount > result[2].DownloadsCount);
            Assert.AreEqual(report3.Title, result[2].Title);
            Assert.AreEqual(report3.Summary, result[2].Summary);
        }
コード例 #3
0
        public async Task ReturnNotDeletedReport_WithSortAndSearchAndIndustry_When_ParamValid()
        {
            //Arrange
            var options   = Utils.GetOptions(nameof(ReturnNotDeletedReport_WithSortAndSearchAndIndustry_When_ParamValid));
            var report1   = TestModelsSeeder.SeedReport();
            var industry1 = TestModelsSeeder.SeedIndustry();
            var user      = TestModelsSeeder.SeedUser();
            var tag       = TestModelsSeeder.SeedTag();
            var tag2      = TestModelsSeeder.SeedTag2();
            var tag3      = TestModelsSeeder.SeedTag3();
            var report2   = TestModelsSeeder.SeedReport2();
            var industry2 = TestModelsSeeder.SeedIndustry2();
            var report3   = TestModelsSeeder.SeedReport3();
            var industry3 = TestModelsSeeder.SeedIndustry3();

            using (var arrangeContext = new InsightHubContext(options))
            {
                await arrangeContext.Reports.AddAsync(report1);

                await arrangeContext.Tags.AddAsync(tag);

                await arrangeContext.Industries.AddAsync(industry1);

                await arrangeContext.Reports.AddAsync(report2);

                await arrangeContext.Tags.AddAsync(tag2);

                await arrangeContext.Industries.AddAsync(industry2);

                await arrangeContext.Reports.AddAsync(report3);

                await arrangeContext.Tags.AddAsync(tag3);

                await arrangeContext.Industries.AddAsync(industry3);

                await arrangeContext.Users.AddAsync(user);

                await arrangeContext.SaveChangesAsync();
            }
            //Act & Assert
            using var assertContext = new InsightHubContext(options);
            var sutTags = new TagServices(assertContext);
            var sut     = new ReportServices(assertContext, sutTags);
            var act     = await sut.GetReports("title_desc", "TestReport", null, "Industry", null);

            var result = act.ToList();

            Assert.AreEqual(3, result.Count());
            Assert.AreEqual(report3.Title, result[0].Title);
            Assert.IsTrue(result[0].Industry.Contains("Industry"));
            Assert.AreEqual(report2.Title, result[1].Title);
            Assert.IsTrue(result[1].Industry.Contains("Industry"));
            Assert.AreEqual(report1.Title, result[2].Title);
            Assert.IsTrue(result[2].Industry.Contains("Industry"));
        }
コード例 #4
0
        public async Task GetsCorrectReports_When_ParamsValid()
        {
            //Arrange
            var options   = Utils.GetOptions(nameof(GetsCorrectReports_When_ParamsValid));
            var report1   = TestModelsSeeder.SeedReport();
            var industry1 = TestModelsSeeder.SeedIndustry();
            var user      = TestModelsSeeder.SeedUser();
            var tag       = TestModelsSeeder.SeedTag();
            var tag2      = TestModelsSeeder.SeedTag2();
            var tag3      = TestModelsSeeder.SeedTag3();
            var report2   = TestModelsSeeder.SeedReport2();
            var industry2 = TestModelsSeeder.SeedIndustry2();
            var report3   = TestModelsSeeder.SeedReport3();
            var industry3 = TestModelsSeeder.SeedIndustry3();

            report1.IsDeleted = true;

            using (var arrangeContext = new InsightHubContext(options))
            {
                await arrangeContext.Reports.AddAsync(report1);

                await arrangeContext.Tags.AddAsync(tag);

                await arrangeContext.Industries.AddAsync(industry1);

                await arrangeContext.Reports.AddAsync(report2);

                await arrangeContext.Tags.AddAsync(tag2);

                await arrangeContext.Industries.AddAsync(industry2);

                await arrangeContext.Reports.AddAsync(report3);

                await arrangeContext.Tags.AddAsync(tag3);

                await arrangeContext.Industries.AddAsync(industry3);

                await arrangeContext.Users.AddAsync(user);

                await arrangeContext.SaveChangesAsync();
            }
            //Act & Assert
            using var assertContext = new InsightHubContext(options);
            var sutTags = new TagServices(assertContext);
            var sut     = new ReportServices(assertContext, sutTags);
            var result  = await sut.GetReports(null, null, null, null, null);

            Assert.AreEqual(2, result.Count);
        }
コード例 #5
0
        public async Task ThrowArgumentException_WhenTitleAlreadyExists()
        {
            //Arrange
            var options        = Utils.GetOptions(nameof(ThrowArgumentException_WhenTitleAlreadyExists));
            var newSummary     = "New Report Summary";
            var newDescription = "New Report Description";
            var newIndustry    = TestModelsSeeder.SeedIndustry2();
            var newImgURL      = "imageurl";
            var newTag         = TestModelsSeeder.SeedTag2();

            var report1   = TestModelsSeeder.SeedReport();
            var industry1 = TestModelsSeeder.SeedIndustry();
            var user      = TestModelsSeeder.SeedUser();
            var tag       = TestModelsSeeder.SeedTag();

            var report2   = TestModelsSeeder.SeedReport2();
            var industry2 = TestModelsSeeder.SeedIndustry3();
            var tag2      = TestModelsSeeder.SeedTag3();

            using (var arrangeContext = new InsightHubContext(options))
            {
                await arrangeContext.Users.AddAsync(user);

                await arrangeContext.Industries.AddAsync(industry1);

                await arrangeContext.Industries.AddAsync(industry2);

                await arrangeContext.Industries.AddAsync(newIndustry);

                await arrangeContext.Tags.AddAsync(tag);

                await arrangeContext.Tags.AddAsync(newTag);

                await arrangeContext.Tags.AddAsync(tag2);

                await arrangeContext.Reports.AddAsync(report1);

                await arrangeContext.Reports.AddAsync(report2);

                await arrangeContext.SaveChangesAsync();
            }
            //Act & Assert
            using var assertContext = new InsightHubContext(options);
            var sutTags    = new TagServices(assertContext);
            var sutReports = new ReportServices(assertContext, sutTags);
            await Assert.ThrowsExceptionAsync <ArgumentException>(() => sutReports.UpdateReport(1, report2.Title, newSummary, newDescription, newImgURL, newIndustry.Name, newTag.Name));
        }
コード例 #6
0
        public async Task ReturnAllUploadedReports()
        {
            //Arrange
            var options = Utils.GetOptions(nameof(ReturnAllUploadedReports));
            var user1   = TestModelsSeeder.SeedUser();
            var report1 = TestModelsSeeder.SeedReport();
            var report2 = TestModelsSeeder.SeedReport2();

            report1.AuthorId = user1.Id;
            report2.AuthorId = user1.Id;

            var tag1 = TestModelsSeeder.SeedTag();
            var tag2 = TestModelsSeeder.SeedTag2();

            var industry1 = TestModelsSeeder.SeedIndustry();
            var industry2 = TestModelsSeeder.SeedIndustry2();

            user1.IsPending   = false;
            report1.IsPending = false;
            report2.IsPending = false;
            //Act & Assert
            using (var arrangeContext = new InsightHubContext(options))
            {
                arrangeContext.Users.Add(user1);
                arrangeContext.Reports.Add(report1);
                arrangeContext.Reports.Add(report2);
                arrangeContext.Tags.Add(tag1);
                arrangeContext.Tags.Add(tag2);
                arrangeContext.Industries.Add(industry1);
                arrangeContext.Industries.Add(industry2);

                await arrangeContext.SaveChangesAsync();
            }

            using var assertContext = new InsightHubContext(options);
            var sut    = new UserServices(assertContext);
            var result = await sut.GetUploadedReports(user1.Id, null);

            Assert.AreEqual(2, result.Count);
        }