コード例 #1
0
        public void WebsiteFacade_AddWebsite()
        {
            //Arrange
            WebsiteDto dtoToAssert = null;

            var websiteEntry = DataCreationHelper.CreateStandardWebsiteEntry();

            var websiteCategory = new WebsiteCategoryDto()
            {
                Id = 239
            };

            var facade = Utils.Init <WebsiteFacade>();

            Mock.Get(facade.CsvService).Setup(x => x.ParseWebsiteCsvList("Fake CSV")).Returns(new[] { websiteEntry });
            Mock.Get(facade.WebsiteRepository).Setup(x => x.DoWebsitesExist(It.IsAny <List <string> >())).Returns(new Dictionary <string, bool>()
            {
                { "usa.gov", false }
            });
            Mock.Get(facade.WebsiteService).Setup(x => x.GetNextId()).Returns(34);
            Mock.Get(facade.WebsiteCategoryService).Setup(x => x.GetOrCreateWebsiteCategory(websiteEntry)).Returns(websiteCategory);
            Mock.Get(facade.WebsiteRepository).Setup(x => x.Add(It.IsAny <WebsiteDto>())).Callback((WebsiteDto websiteDto) =>
            {
                dtoToAssert = websiteDto;
            });

            //Act
            facade.AddWebsitesFromCsv("Fake CSV");

            //Assert
            Assert.AreEqual(34, dtoToAssert.Id);
            Assert.AreEqual("usa.gov", dtoToAssert.Hostname);
            Assert.AreEqual(DateTime.MinValue, dtoToAssert.LastScan);
            Assert.AreEqual(239, dtoToAssert.CategoryId);
        }
コード例 #2
0
        public void WebsiteCategoryService_GetOrCreateWebsiteCategory_CreateCategory()
        {
            //Arrange
            WebsiteCategoryDto dtoToAssert = null;
            var websiteEntry = DataCreationHelper.CreateStandardWebsiteEntry();

            var websiteCategoryService = Utils.Init <WebsiteCategoryService>();

            Mock.Get(websiteCategoryService.WebsiteCategoryRepository).Setup(x => x.GetLargestId()).Returns(20);
            Mock.Get(websiteCategoryService.WebsiteCategoryRepository).Setup(x => x.GetWebsiteCategory(GovernmentType.FEDERAL_EXECUTIVE, "General Services Administration", "Office of Citizen Services and Communications", "Washington", "DC")).Returns((WebsiteCategoryDto)null);
            Mock.Get(websiteCategoryService.WebsiteCategoryRepository).Setup(x => x.Add(It.IsAny <WebsiteCategoryDto>())).Callback((WebsiteCategoryDto websiteCategoryDto) =>
            {
                dtoToAssert = websiteCategoryDto;
            });

            //Act
            var websiteCategory = websiteCategoryService.GetOrCreateWebsiteCategory(websiteEntry);

            //Assert
            Assert.AreEqual(dtoToAssert, websiteCategory);
            Assert.AreEqual(21, dtoToAssert.Id);
            Assert.AreEqual("General Services Administration", dtoToAssert.Agency);
            Assert.AreEqual("Office of Citizen Services and Communications", dtoToAssert.Organization);
            Assert.AreEqual("Washington", dtoToAssert.City);
            Assert.AreEqual("DC", dtoToAssert.State);
        }
コード例 #3
0
        public void WebsiteFacade_AddWebsite_WebsiteAlreadyExists()
        {
            //Arrange
            var websiteEntry = DataCreationHelper.CreateStandardWebsiteEntry();

            var facade = Utils.Init <WebsiteFacade>();

            Mock.Get(facade.WebsiteRepository).Setup(x => x.DoWebsitesExist(It.IsAny <List <string> >())).Returns(new Dictionary <string, bool>()
            {
                { "usa.gov", true }
            });
            Mock.Get(facade.WebsiteRepository).Setup(x => x.Add(It.IsAny <WebsiteDto>())).Verifiable();
            Mock.Get(facade.CsvService).Setup(x => x.ParseWebsiteCsvList("Fake CSV")).Returns(new[] { websiteEntry });

            //Act
            facade.AddWebsitesFromCsv("Fake CSV");

            //Assert
            Mock.Get(facade.WebsiteRepository).Verify(x => x.Add(It.IsAny <WebsiteDto>()), Times.Never);
        }
コード例 #4
0
        public void WebsiteCategoryService_GetOrCreateWebsiteCategory_GetCategory()
        {
            //Arrange
            var websiteEntry = DataCreationHelper.CreateStandardWebsiteEntry();

            var websiteCategoryService = Utils.Init <WebsiteCategoryService>();

            Mock.Get(websiteCategoryService.WebsiteCategoryRepository).Setup(x => x.GetWebsiteCategory(GovernmentType.FEDERAL_EXECUTIVE, "General Services Administration", "Office of Citizen Services and Communications", "Washington", "DC")).Returns(DataCreationHelper.CreateStandardWebsiteCategoryDto());
            Mock.Get(websiteCategoryService.WebsiteCategoryRepository).Setup(x => x.Add(It.IsAny <WebsiteCategoryDto>())).Verifiable();

            //Act
            var websiteCategory = websiteCategoryService.GetOrCreateWebsiteCategory(websiteEntry);

            //Assert
            Mock.Get(websiteCategoryService.WebsiteCategoryRepository).Verify(x => x.Add(It.IsAny <WebsiteCategoryDto>()), Times.Never);

            Assert.AreEqual(21, websiteCategory.Id);
            Assert.AreEqual("General Services Administration", websiteCategory.Agency);
            Assert.AreEqual("Office of Citizen Services and Communications", websiteCategory.Organization);
            Assert.AreEqual("Washington", websiteCategory.City);
            Assert.AreEqual("DC", websiteCategory.State);
        }