public void ErrorSetsViewBagAndReturnsPage() { var connector = new ConnectorViewModel { Id = id, Name = "abc" }; var errors = new Dictionary <string, string>() { { "error", "val" } }; var repo = new Mock <IConnectorRepo>(); repo.Setup(c => c.Validate(connector, errors)).Verifiable(); var page = new ConnectorForm(repo.Object, Mock.Of <ILayoutPage>()); page.LoggingService = Logging; var privateObj = new PrivateObject(page); privateObj.SetField("model", connector); privateObj.SetField("errors", errors); var dispatcher = page.Save(); Assert.AreEqual(0, Logging.LogCount); Assert.IsInstanceOfType(dispatcher, typeof(RazorPageDispatcher)); Assert.AreEqual(page, new PrivateObject(dispatcher).GetField("_page")); Assert.AreEqual(connector, page.ViewBag["model"]); repo.Verify(c => c.Insert(It.IsAny <ConnectorViewModel>()), Times.Never); repo.Verify(c => c.Save(It.IsAny <ConnectorViewModel>()), Times.Never); repo.Verify(); }
public void SetFormValuesMapping() { var formValues = new Dictionary <string, string[]> { { "id", new[] { id.ToString() } }, { "connectorName", new[] { "name1" } }, { "serverName", new[] { "serv" } }, { "databaseName", new[] { "db1" } }, { "schema", new[] { "sch1" } }, { "resourceType", new[] { "type1" } }, { "userId", new[] { "id1" } }, { "password", new[] { "pass1" } }, { "recordLimit", new[] { "100" } }, { "isEnabled", new[] { "true" } }, }; var page = new ConnectorForm(Mock.Of <IConnectorRepo>(), Mock.Of <ILayoutPage>()); page.SetForm(formValues); var model = (ConnectorViewModel) new PrivateObject(page).GetField("model"); Assert.AreEqual(id, model.Id); Assert.AreEqual("type1", model.ResourceType); Assert.AreEqual("name1", model.Name); Assert.AreEqual("serv", model.DataSource); Assert.AreEqual("db1", model.InitialCatalog); Assert.AreEqual("sch1", model.Schema); Assert.AreEqual("id1", model.UserId); Assert.AreEqual("pass1", model.Password); Assert.AreEqual(100, model.RecordLimit); Assert.AreEqual(true, model.IsActive); }
public void UpdateLogsAndRedirects() { var connector = new ConnectorViewModel { Id = id, Name = "abc" }; var repo = new Mock <IConnectorRepo>(); repo.Setup(c => c.Save(connector)).Returns(id); repo.Setup(c => c.Validate(connector, new Dictionary <string, string>())).Verifiable(); var page = new ConnectorForm(repo.Object, Mock.Of <ILayoutPage>()); page.LoggingService = Logging; var privateObj = new PrivateObject(page); privateObj.SetField("model", connector); var dispatcher = page.Save(); Assert.AreEqual(1, Logging.LogCount); Assert.AreEqual("PUT", Logging.PublicRequests.First().RequestType); Assert.IsInstanceOfType(dispatcher, typeof(RedirectDispatcher)); Assert.AreEqual($"/Connectors/Connector/{id}", new PrivateObject(dispatcher).GetField("_location")); }
public JsonResult Form(ConnectorForm form) { form.ByUserID = UserSession.UserID; var score = Facade <ConnectorFacade>().AddConnector(form); return(Json(score, JsonRequestBehavior.AllowGet)); }
public RedirectResult Read(int id, string url, int seriesID = 0, IList <int> listIDs = null) { var session = UserSession; // mark as read var readForm = new ReadForm { UserID = session.UserID, SourceID = id, SourceTable = R.SourceTable.RELEASE }; Facade <UserActionFacade>().Reading(readForm); // add series to list if (seriesID > 0 && listIDs != null) { foreach (var listID in listIDs) { var form = new ConnectorForm { ByUserID = UserSession.UserID, ConnectorType = R.ConnectorType.SERIES_USERLIST, SourceID = seriesID, TargetID = listID }; Facade <ConnectorFacade>().AddConnector(form); } } return(RedirectPermanent(url)); }
public void NewConnectorIsActive() { var page = new ConnectorForm(Mock.Of <IConnectorRepo>(), Mock.Of <ILayoutPage>()); page.NewConnector(); Assert.IsTrue(((ConnectorViewModel)page.ViewBag["model"]).IsActive); }
public int AddConnector(ConnectorForm form) { using (var uow = UnitOfWorkFactory.Create <NovelContext>()) { var service = new ConnectorService(uow); var id = service.SaveChanges(form); return(id); } }
public int SaveChanges(ConnectorForm form) { var tConnector = Table <Connector>(); var connector = tConnector.GetOrAdd(w => w.ID == form.ID || (form.ID == 0 && w.ConnectorType == form.ConnectorType && w.SourceID == form.SourceID && w.TargetID == form.TargetID)); MapProperty(form, connector, form.InlineEditProperty); UpdateAuditFields(connector, form.ByUserID); // save SaveChanges(); return(connector.ID); }
public void SetViewBagToConnectorById() { var connector = new ConnectorViewModel { Id = id, Name = "abc" }; var repo = new Mock <IConnectorRepo>(); repo.Setup(c => c.GetById(id)).Returns(connector); var page = new ConnectorForm(repo.Object, Mock.Of <ILayoutPage>()); page.GetById(id); Assert.AreEqual(connector, page.ViewBag["model"]); }
//-----------------------------------------------------------------// //--- Call to edit the selected connector item in the list view ---// //-----------------------------------------------------------------// private void btnEditConnector_Click(object sender, EventArgs e) { if (lvConnectors.SelectedItems.Count > 0) { var form = new ConnectorForm(); var connector = (Connector)lvConnectors.SelectedItems[0].Tag; form.Connector = connector; form.TopLevel = true; form.Closed += delegate { if (DialogResult.OK == form.DialogResult) { ListViewItem item = lvConnectors.SelectedItems[0]; lvConnectors.UpdateConnector(item, form.Connector); lvPins.Connector = (Connector)lvConnectors.SelectedItems[0].Tag; } }; form.Show(); } }
//---------------------------------------------------------// //--- Call to add a new connector item to the list view ---// //---------------------------------------------------------// private void btnAddConnector_Click(object sender, EventArgs e) { var form = new ConnectorForm(); var connector = new Connector(); form.Connector = connector; form.TopLevel = true; form.Closed += delegate { if (DialogResult.OK == form.DialogResult) { connector = form.Connector; lvConnectors.AddConnector(connector); //if (_physicalInterfaceConnectors.Connector == null) // _physicalInterfaceConnectors.Connector = new List<Connector>(); //_physicalInterfaceConnectors.Connector.Add( connector ); } }; form.Show(); }
public int AddGroup(GroupForm form) { using (var uow = UnitOfWorkFactory.Create <NovelContext>()) { var service = new GroupService(uow); var id = service.SaveChanges(form); var connectorService = new ConnectorService(uow); if (form.Feeds != null || form.InlineEditProperty == form.PropertyName(m => m.Feeds)) { var feedService = new FeedService(uow); foreach (var feed in form.Feeds) { feed.UrlHash = feed.Url.GetIntHash(); feed.Status = feed.Status == 0 ? R.FeedStatus.ACTIVE : feed.Status; feed.LastSuccessDate = DateTime.Now.AddYears(-10); var feedForm = new GenericForm <Feed> { ByUserID = form.ByUserID, DataModel = feed }; var feedID = feedService.SaveChanges(feedForm); // add to connector only if it a new feed if (feed.ID == 0) { // connect series to feed var connectorForm = new ConnectorForm() { ByUserID = form.ByUserID, ConnectorType = R.ConnectorType.GROUP_FEED, SourceID = id, TargetID = feedID }; connectorService.SaveChanges(connectorForm); } } } if (form.Glossaries != null && form.InlineEditProperty == form.PropertyName(m => m.Glossaries)) { foreach (var glossary in form.Glossaries) { var glossaryService = new GlossaryService(uow); var glossaryForm = new GlossaryForm(); new PropertyMapper <Glossary, GlossaryForm>(glossary, glossaryForm).Map(); glossaryForm.ByUserID = form.ByUserID; var glossaryID = glossaryService.SaveChanges(glossaryForm); // connect group to glossary var connectorForm = new ConnectorForm() { ByUserID = form.ByUserID, ConnectorType = R.ConnectorType.GROUP_GLOSSARY, SourceID = id, TargetID = glossaryID }; connectorService.SaveChanges(connectorForm); } } return(id); } }
public int AddSeries(SeriesForm form) { using (var uow = UnitOfWorkFactory.Create <NovelContext>()) { var service = new SeriesService(uow); var id = service.SaveChanges(form); var connectorService = new ConnectorService(uow); if (form.Categories != null || form.InlineEditProperty == form.PropertyName(m => m.Categories)) { form.Categories = form.Categories ?? new List <int>(); var connectorForm = new GenericForm <Connector> { ByUserID = form.ByUserID, DataModel = new Connector { ConnectorType = R.ConnectorType.SERIES_TAGCATEGORY, SourceID = id } }; connectorService.Connect(connectorForm, form.Categories); } if (form.Genres != null || form.InlineEditProperty == form.PropertyName(m => m.Genres)) { form.Genres = form.Genres ?? new List <int>(); var connectorForm = new GenericForm <Connector> { ByUserID = form.ByUserID, DataModel = new Connector { ConnectorType = R.ConnectorType.SERIES_TAGGENRE, SourceID = id } }; connectorService.Connect(connectorForm, form.Genres); } if (form.Contains != null || form.InlineEditProperty == form.PropertyName(m => m.Contains)) { form.Contains = form.Contains ?? new List <int>(); var connectorForm = new GenericForm <Connector> { ByUserID = form.ByUserID, DataModel = new Connector { ConnectorType = R.ConnectorType.SERIES_TAGCONTAIN, SourceID = id } }; connectorService.Connect(connectorForm, form.Contains); } if (form.Feeds != null || form.InlineEditProperty == form.PropertyName(m => m.Feeds)) { var feedService = new FeedService(uow); foreach (var feed in form.Feeds) { feed.UrlHash = feed.Url.GetIntHash(); feed.Status = feed.Status == 0 ? R.FeedStatus.ACTIVE : feed.Status; feed.LastSuccessDate = feed.LastSuccessDate == DateTime.MinValue ? DateTime.Now : feed.LastSuccessDate; var feedForm = new GenericForm <Feed> { ByUserID = form.ByUserID, DataModel = feed }; var feedID = feedService.SaveChanges(feedForm); // add to connector only if it a new feed if (feed.ID == 0) { // connect series to feed var connectorForm = new ConnectorForm() { ByUserID = form.ByUserID, ConnectorType = R.ConnectorType.SERIES_FEED, SourceID = id, TargetID = feedID }; connectorService.SaveChanges(connectorForm); } } } if (form.Groups != null || form.InlineEditProperty == form.PropertyName(m => m.Groups)) { foreach (var group in form.Groups) { // connect series to feed var connectorForm = new ConnectorForm() { ByUserID = form.ByUserID, ConnectorType = R.ConnectorType.SERIES_GROUP, SourceID = id, TargetID = group.ID }; connectorService.SaveChanges(connectorForm); } } if (form.Authors != null || form.InlineEditProperty == form.PropertyName(m => m.Authors)) { foreach (var author in form.Authors) { // connect series to feed var connectorForm = new ConnectorForm() { ByUserID = form.ByUserID, ConnectorType = R.ConnectorType.SERIES_AUTHOR, SourceID = id, TargetID = author.ID }; connectorService.SaveChanges(connectorForm); } } if (form.Akas != null || form.InlineEditProperty == form.PropertyName(m => m.Akas)) { var akaService = new AkaService(uow); foreach (var aka in form.Akas) { var akaForm = new AkaForm { ByUserID = form.ByUserID, SourceID = form.ID, SourceTable = R.SourceTable.SERIES }; new PropertyMapper <Aka, AkaForm>(aka, akaForm).Map(); var akaID = akaService.SaveChanges(akaForm); } } return(id); } }