public void SimpleContent_Constructor_Initialises_To_Known_Values_And_Properties_Work() { var instance = new SimpleContent(); TestUtilities.TestProperty(instance, r => r.Content, null, new byte[] { 0x01 }); TestUtilities.TestProperty(instance, r => r.HttpStatusCode, (HttpStatusCode)0, HttpStatusCode.OK); }
public void TestInitialise() { _Snapshot = Factory.TakeSnapshot(); _HtmlEnv = new MockOwinEnvironment(); _BndlEnv = new MockOwinEnvironment(); _LoopbackHost = TestUtilities.CreateMockImplementation <ILoopbackHost>(); _LoopbackContent = new Dictionary <string, string>(); _LoopbackHost.Setup(r => r.SendSimpleRequest(It.IsAny <string>(), _BndlEnv.Environment)).Returns((string path, IDictionary <string, object> env) => { var result = new SimpleContent(); if (!_LoopbackContent.TryGetValue(path, out string content)) { result.HttpStatusCode = HttpStatusCode.NotFound; } else { result.Content = Encoding.UTF8.GetBytes(content); result.HttpStatusCode = HttpStatusCode.OK; } return(result); }); _Config = Factory.Singleton.ResolveNewInstance <IBundlerConfiguration>(); }
public void ItemRemovesFromSiteMap() { //Assemble var content = new SimpleContent { Id = "Unmappable", Title = "DontMapMe", Content = "<b>not mapped</b>" }; s_repo.CreateContentAsync(content).GetAwaiter().GetResult(); s_mapRepo.AddItemToSiteMapAsync( new SiteMapEntry { ContentIdentifier = content.Id, Title = content.Title }); var controller = new ManageSimpleController(s_repo, s_mapRepo); //Act var result = controller.Remove(content.Id).GetAwaiter().GetResult() as ViewResult; var isEntryInMap = s_mapRepo.IsItemInSiteMapAsync(content.Id).GetAwaiter().GetResult(); var foundEntry = s_mapRepo.GetMapAsync().GetAwaiter().GetResult() .Entries.Where( (e) => e.ContentIdentifier == content.Id) .FirstOrDefault(); //Assert Assert.AreEqual <string>("SiteMapConfirm", result.ViewName, "Incorrect view returned"); Assert.IsFalse(isEntryInMap, "Map entry reported as in the site map"); Assert.IsNull(foundEntry, "Entry found manually in map"); }
public void TestInitialise() { _OriginalContainer = Factory.TakeSnapshot(); _WebServer = new Mock <IWebServer>() { DefaultValue = DefaultValue.Mock }.SetupAllProperties(); _Request = new Mock <IRequest>() { DefaultValue = DefaultValue.Mock }.SetupAllProperties(); _Response = new Mock <IResponse>() { DefaultValue = DefaultValue.Mock }.SetupAllProperties(); _InstallerSettingsStorage = TestUtilities.CreateMockImplementation <IInstallerSettingsStorage>(); _InstallerSettings = new InstallerSettings(); _InstallerSettingsStorage.Setup(m => m.Load()).Returns(_InstallerSettings); _SharedConfiguration = TestUtilities.CreateMockSingleton <ISharedConfiguration>(); _Configuration = new Configuration(); _Configuration.GoogleMapSettings.WebSiteReceiverId = 1; _Configuration.GoogleMapSettings.ClosestAircraftReceiverId = 1; _SharedConfiguration.Setup(r => r.Get()).Returns(_Configuration); _RuntimeEnvironment = TestUtilities.CreateMockSingleton <IRuntimeEnvironment>(); _RuntimeEnvironment.Setup(r => r.IsMono).Returns(false); _RuntimeEnvironment.Setup(r => r.ExecutablePath).Returns(TestContext.TestDeploymentDir); _BaseStationDatabase = new Mock <IBaseStationDatabase>() { DefaultValue = DefaultValue.Mock }.SetupAllProperties(); _AutoConfigBaseStationDatabase = TestUtilities.CreateMockSingleton <IAutoConfigBaseStationDatabase>(); _AutoConfigBaseStationDatabase.Setup(a => a.Database).Returns(_BaseStationDatabase.Object); _StandingDataManager = TestUtilities.CreateMockSingleton <IStandingDataManager>(); _UserManager = TestUtilities.CreateMockSingleton <IUserManager>(); _LoopbackHost = TestUtilities.CreateMockImplementation <ILoopbackHost>(); _LoopbackEnvironment = null; _LoopbackPathAndFile = null; _LoopbackResponse = new SimpleContent() { Content = new byte[0], HttpStatusCode = HttpStatusCode.OK, }; _LoopbackHost.Setup(r => r.SendSimpleRequest(It.IsAny <string>(), It.IsAny <IDictionary <string, object> >())).Returns((string p, IDictionary <string, object> e) => { _LoopbackPathAndFile = p; _LoopbackEnvironment = e; return(_LoopbackResponse); }); _FileSystemServerConfiguration = TestUtilities.CreateMockSingleton <IFileSystemServerConfiguration>(); _WebSite = Factory.Resolve <IWebSite>(); }
private IImage ExtractFromSimpleContent(SimpleContent simpleContent) { IImage result = null; if (simpleContent != null && simpleContent.HttpStatusCode == System.Net.HttpStatusCode.OK) { var imageFile = Factory.ResolveSingleton <IImageFile>(); result = imageFile.LoadFromByteArray(simpleContent.Content); } return(result); }
public async Task <ActionResult> Create(SimpleContent model) { try { var savedItem = await base.CreateContentModelAsync <SimpleContent>(model); return(View("Confirm", savedItem)); } catch (ContentIdAlreadyExistsException) { ModelState.AddModelError("Id", "Content with this id already exists"); return(View("Create", model)); } }
public async Task AttemptingToCreateSimpleContentWithIdAlreadyInUse() { await s_repo.CreateContentAsync(new SimpleContent { Id = "existing", Title = "Exists", Content = "Already here" }); var toAdd = new SimpleContent { Id = "existing", Title = "Usurper", Content = "Trying to overwrite" }; var controller = new ManageSimpleController(s_repo, s_mapRepo); var result = await controller.Create(toAdd) as ViewResult; Assert.AreEqual("Create", result.ViewName, "Shows Create view again"); Assert.AreSame(toAdd, result.Model, "Passes model back to view"); Assert.AreEqual("Content with this id already exists", controller.ModelState["Id"].Errors.Single().ErrorMessage); }
private Image ExtractFromSimpleContent(SimpleContent simpleContent) { Image result = null; if (simpleContent != null && simpleContent.HttpStatusCode == System.Net.HttpStatusCode.OK) { using (var memoryStream = new MemoryStream(simpleContent.Content)) { using (var image = Image.FromStream(memoryStream)) { result = new Bitmap(image); // work around the problem that GDI+ has with images built from streams being accessed after the stream has been disposed } } } return(result); }
public void IndexWithSimpleContent() { ContentController controller = new ContentController(_repo, _mapRepo, null); var result = controller.Index("page1").Result as ViewResult; Assert.IsNotNull(result); Assert.AreEqual <string>("Simple", result.ViewName); //test the view model is populated correctly SimpleContent model = (SimpleContent)result.ViewData.Model; Assert.AreEqual <string>("<b>page1</b>", model.Content); Assert.AreEqual <ContentType>(ContentType.Simple, model.ContentType); Assert.AreEqual <string>("Page 1", model.Title); }
public void AddingSimpleContent() { //Assemble var controller = new ManageSimpleController(s_repo, s_mapRepo); SimpleContent content = new SimpleContent { Title = "Added", Content = "<b>Added</b>" }; //Act var result = controller.Create(content).GetAwaiter().GetResult() as ViewResult; var items = s_repo.GetListOfItemsAsync(ContentType.Simple.ToString()).GetAwaiter().GetResult(); var targetItem = items.Where((i) => i.Title == "Added").FirstOrDefault(); //Assert Assert.AreEqual <string>("Confirm", result.ViewName, "Confirmation view not returned"); Assert.IsNotNull(targetItem, "Item not found after adding"); }
public void TestInitialise() { _OriginalClassFactory = Factory.TakeSnapshot(); _Configuration = new Configuration(); _ConfigurationStorage = TestUtilities.CreateMockSingleton <IConfigurationStorage>(); _ConfigurationStorage.Setup(r => r.Load()).Returns(_Configuration); _Bundler = Factory.Singleton.Resolve <IBundler>(); _Minifier = TestUtilities.CreateMockImplementation <IMinifier>(); _Minifier.Setup(r => r.MinifyJavaScript(It.IsAny <string>())).Returns((string js) => js); _WebServer = TestUtilities.CreateMockImplementation <IWebServer>(); _WebServer.Setup(r => r.Root).Returns("/Root/"); _WebSite = TestUtilities.CreateMockImplementation <IWebSite>(); _WebSite.Setup(r => r.WebServer).Returns(_WebServer.Object); _Request = new Mock <IRequest>() { DefaultValue = DefaultValue.Mock }.SetupAllProperties(); _Response = new Mock <IResponse>() { DefaultValue = DefaultValue.Mock }.SetupAllProperties(); _Request.Setup(m => m.ContentLength64).Returns(() => { return(_Request.Object.InputStream == null ? 0L : _Request.Object.InputStream.Length); }); _OutputStream = new MemoryStream(); _Response.Setup(m => m.OutputStream).Returns(_OutputStream); _PathAndFileToContent = new Dictionary <string, SimpleContent>(); _WebSite.Setup(r => r.RequestSimpleContent(It.IsAny <string>())).Returns((string pathAndFile) => { SimpleContent simpleContent; if (!_PathAndFileToContent.TryGetValue(pathAndFile, out simpleContent)) { simpleContent = new SimpleContent() { Content = new byte[] { }, HttpStatusCode = HttpStatusCode.NotFound }; } return(simpleContent); }); }
public void RemoveSimpleContent() { //assemble var content = new SimpleContent { Id = "DeleteMe", Title = "To be deleted" }; s_repo.CreateContentAsync(content).GetAwaiter().GetResult(); var controller = new ManageSimpleController(s_repo, s_mapRepo); //act var result = controller.Delete("DeleteMe", content); var items = s_repo.GetListOfItemsAsync(ContentType.Simple.ToString()).GetAwaiter().GetResult(); var missingItem = items.Where((i) => i.Id == "DeleteMe").FirstOrDefault(); //assert Assert.IsNull(missingItem, "Item should not be found in repository"); }
public void EditSimpleContentReturnsItem() { //assemble var content = new SimpleContent { Id = "EditMe", Title = "To be edited" }; s_repo.CreateContentAsync(content).GetAwaiter().GetResult(); var controller = new ManageSimpleController(s_repo, s_mapRepo); //act var result = controller.Edit(content.Id).GetAwaiter().GetResult() as ViewResult; var model = result.Model as SimpleContent; //assert Assert.IsNotNull(model, "Item should be set as the model from repository"); Assert.AreEqual <string>(content.Id, model.Id); Assert.AreEqual <string>(content.Title, model.Title); }
/// <summary> /// See interface docs. /// </summary> /// <param name="pathAndFile"></param> /// <returns></returns> public SimpleContent RequestSimpleContent(string pathAndFile) { if (pathAndFile == null) { throw new ArgumentNullException("pathAndFile"); } var result = new SimpleContent(); const string root = "/Root"; using (var simpleRequest = new SimpleRequest(root, pathAndFile)) { using (var memoryStream = new MemoryStream()) { var simpleResponse = new SimpleResponse(memoryStream); var args = new RequestReceivedEventArgs(simpleRequest, simpleResponse, root); RequestContent(args); result.HttpStatusCode = simpleResponse.StatusCode; result.Content = memoryStream.ToArray(); } } return(result); }
public List <SimpleContent> GetSimpleContentList(string sql) { List <SimpleContent> lp = new List <SimpleContent>(); using (DataTable dt = helper.GetDataTable(sql)) { if (dt != null && dt.Rows.Count > 0) { foreach (DataRow r in dt.Rows) { SimpleContent b = new SimpleContent { id = Convert.ToInt16(r["id"]), title = r["title"].ToString(), imgUrl = r["imgUrl"].ToString(), source = r["source"].ToString(), }; lp.Add(b); } } } return(lp); }
public void EditSimpleContent() { //Assemble var controller = new ManageSimpleController(s_repo, s_mapRepo); controller.ControllerContext = new ControllerContext(new FakeHttpContext(), new System.Web.Routing.RouteData(), controller); SimpleContent content = new SimpleContent { Id = "Edit", Title = "Edit", Content = "<b>Edit</b>" }; s_repo.CreateContentAsync(content); content.Title = "Edited"; content.Content = "<i>Edited</i>"; //Act var result = controller.Edit(content.Id, content).GetAwaiter().GetResult() as ViewResult; var items = s_repo.GetListOfItemsAsync(ContentType.Simple.ToString()).GetAwaiter().GetResult(); var targetItem = items.Where((i) => i.Id == "Edit").FirstOrDefault(); //Assert Assert.AreEqual <string>("Confirm", result.ViewName, "Confirmation view not returned"); Assert.IsNotNull(targetItem, "Item not found after editing"); Assert.AreEqual <string>("Edited", targetItem.Title, "Title does not reflect edits"); }
public async Task <ActionResult> Delete(string id, SimpleContent model) { await base.DeleteItemAsync(id); return(RedirectToRoute("ManageContent")); }
public async Task <ActionResult> Edit(string id, SimpleContent model) { var updatedModel = await base.SaveContentModelAsync <SimpleContent>(model); return(View("Confirm", updatedModel)); }