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); }
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); }
public void Add(WebsiteCategoryDto websiteCategoryDto) { var entity = Mapper.Map <WebsiteCategories>(websiteCategoryDto); using (var unitOfWork = UnitOfWorkFactory.GetUnitOfWork()) { unitOfWork.Queue(new EntityCommand <WebsiteCategories>(CommandType.CREATE, entity)); } }
public WebsiteCategoryDto GetOrCreateWebsiteCategory(WebsiteEntry websiteEntry) { var websiteCategory = WebsiteCategoryRepository.GetWebsiteCategory(websiteEntry.GovernmentType, websiteEntry.Agency, websiteEntry.Organization, websiteEntry.City, websiteEntry.State); if (websiteCategory == null) { websiteCategory = new WebsiteCategoryDto() { Id = GetNextId(), GovernmentType = (int)websiteEntry.GovernmentType, Agency = websiteEntry.Agency, Organization = websiteEntry.Organization, State = websiteEntry.State, City = websiteEntry.City }; WebsiteCategoryRepository.Add(websiteCategory); } return websiteCategory; }
public void WebsiteCategoryRepository_Add() { //Arrange var websiteCategoryDto = new WebsiteCategoryDto() { Id = 7216, GovernmentType = (int)GovernmentType.FEDERAL_JUDICIAL, Agency = "The Supreme Court", Organization = "Supreme Court of the United States", City = "Washington", State = "DC" }; var unitOfWork = new UnitOfWork(Database); var unitOfWorkFactory = new Mock <IUnitOfWorkFactory>(); unitOfWorkFactory.Setup(x => x.GetUnitOfWork()).Returns(unitOfWork); var repository = new WebsiteCategoryRepository(new DatabaseFactory(Database)) { UnitOfWorkFactory = unitOfWorkFactory.Object }; //Act repository.Add(websiteCategoryDto); var entityToAssert = Database.WebsiteCategories.Find(7216); //Assert Assert.IsNotNull(entityToAssert); Assert.AreEqual(7216, entityToAssert.Id); Assert.AreEqual(6, entityToAssert.GovernmentType); Assert.AreEqual("The Supreme Court", entityToAssert.Agency); Assert.AreEqual("Supreme Court of the United States", entityToAssert.Organization); Assert.AreEqual("DC", entityToAssert.State); Assert.AreEqual("Washington", entityToAssert.City); }