public async void RequestCorrectETagReceivesNotModified() { var bytes = LoadSampleJpeg(); var content = new StaticContent(bytes, ContentTypes.ImageJpeg); await Context.Application.Start(); var address = LaraUI.GetFirstURL(Context.Application.GetHost()); Context.Application.PublishFile("/", content); var request = new HttpRequestMessage { Method = new HttpMethod("GET"), RequestUri = new Uri(address) }; request.Headers.TryAddWithoutValidation("If-None-Match", content.ETag); using var response = await Client.SendAsync(request); var downloaded = await response.Content.ReadAsByteArrayAsync(); Assert.Equal(HttpStatusCode.NotModified, response.StatusCode); Assert.False(response.Headers.Contains("ETag")); Assert.Empty(downloaded); }
public async void RequestWrongETagReceivesFile() { var bytes = LoadSampleJpeg(); var content = new StaticContent(bytes, ContentTypes.ImageJpeg); await Context.Application.Start(new StartServerOptions { AllowLocalhostOnly = true }); var address = LaraUI.GetFirstURL(Context.Application.GetHost()); Context.Application.PublishFile("/", content); var request = new HttpRequestMessage { Method = new HttpMethod("GET"), RequestUri = new Uri(address) }; request.Headers.TryAddWithoutValidation("If-None-Match", "lalalalala"); using var response = await Client.SendAsync(request); var downloaded = await response.Content.ReadAsByteArrayAsync(); Assert.Equal(HttpStatusCode.OK, response.StatusCode); Assert.True(response.Headers.TryGetValues("ETag", out var values)); Assert.Equal(content.ETag, values.FirstOrDefault()); Assert.Equal(bytes, downloaded); }
public void LaraUiDefaultStatic() { lock (_MyLock) { LaraUI.Publish("/a", new StaticContent(Encoding.UTF8.GetBytes("hello"), "text")); Assert.True(LaraUI.DefaultApplication.TryGetNode("/a", out _)); } }
public async void ContentNotFound() { await Context.Application.Start(); var address = LaraUI.GetFirstURL(Context.Application.GetHost()); using var response = await Client.GetAsync(address + "/lalala"); Assert.Equal(HttpStatusCode.NotFound, response.StatusCode); }
public void LaraUiDocument() { var x = new Mock <IPageContext>(); var doc = new Document(new MyPage(), 100); x.Setup(x1 => x1.Document).Returns(doc); LaraUI.InternalContext.Value = x.Object; Assert.Same(doc, LaraUI.Document); Assert.Null(LaraUI.GetContextDocument(null)); }
public void LaraUiDefaultPage() { lock (_MyLock) { LaraUI.Publish("/b", () => new MyPage()); Assert.True(LaraUI.DefaultApplication.TryGetNode("/b", out _)); LaraUI.UnPublish("/b"); Assert.False(LaraUI.DefaultApplication.TryGetNode("/b", out _)); } }
public void RegisterComponentSucceeds() { _app.PublishComponent(new WebComponentOptions { ComponentTagName = "x-caca", ComponentType = typeof(MyComponent) }); Assert.True(LaraUI.TryGetComponent("x-caca", out var type)); _app.UnPublishWebComponent("x-caca"); Assert.Equal(typeof(MyComponent), type); Assert.False(LaraUI.TryGetComponent("x-caca", out _)); }
public void LaraUiDefaultService() { lock (_MyLock) { LaraUI.Publish(new WebComponentOptions { ComponentTagName = "lala-lala", ComponentType = typeof(RemovableComponent) }); Assert.True(LaraUI.DefaultApplication.TryGetComponent("lala-lala", out _)); LaraUI.UnPublishWebComponent("lala-lala"); Assert.False(LaraUI.DefaultApplication.TryGetComponent("lala-lala", out _)); } }
public void UnpublishWebservice() { const string address = "/mylalala"; using var app = new Application(); LaraUI.Publish(new WebServiceContent { Address = address, Factory = () => new MyWebService() }); LaraUI.UnPublish("/mylalala", "POST"); var combined = Published.CombinePathMethod(address, "POST"); Assert.False(app.TryGetNode(combined, out _)); }
public static void Main() { // create home page LaraUI.Publish("/", () => new KitchenSinkForm()); // start web server var host = LaraUI.StartServer().Result; // get address (default setting is to assign a dynamic port) string address = LaraUI.GetFirstURL(host); // run application using (var session = MagnetoApp.CreateForm(new Uri(address))) { ConfigureConfirmExit(session); session.RunApplication(); } }
private static async Task Main() { // create application using var app = new Application(); KitchenSinkPage.PublishMugImage(app); app.PublishPage("/", () => new KitchenSinkPage()); app.PublishPage("/upload", () => new UploadFilePage()); app.PublishPage("/server", () => new ServerEventsPage()); // start application await app.Start(new StartServerOptions { Port = 8182 }); Console.WriteLine("Listening on http://localhost:8182/"); LaraUI.LaunchBrowser("http://localhost:8182"); // wait for shutdown await app.WaitForShutdown(); }
public async void RequestWithoutETagReceivesFile() { var bytes = LoadSampleJpeg(); var content = new StaticContent(bytes, ContentTypes.ImageJpeg); await Context.Application.Start(); var address = LaraUI.GetFirstURL(Context.Application.GetHost()); Context.Application.PublishFile("/", content); using var response = await Client.GetAsync(address); var downloaded = await response.Content.ReadAsByteArrayAsync(); Assert.Equal(HttpStatusCode.OK, response.StatusCode); Assert.True(response.Headers.TryGetValues("ETag", out var values)); Assert.Equal(content.ETag, values.FirstOrDefault()); Assert.Equal(bytes, downloaded); }
public async void CompressibleFileIsSentCompressed() { var bytes = LoadCompressibleBmp(); var content = new StaticContent(bytes, "image"); await Context.Application.Start(); var address = LaraUI.GetFirstURL(Context.Application.GetHost()); Context.Application.PublishFile("/", content); using var response = await Client.GetAsync(address); var downloaded = await response.Content.ReadAsByteArrayAsync(); Assert.Equal(HttpStatusCode.OK, response.StatusCode); Assert.True(response.Headers.TryGetValues("ETag", out var values)); Assert.Equal(content.ETag, values.FirstOrDefault()); Assert.Equal(bytes, downloaded); }
public static async Task Main() { // create and start application const int port = 8182; using var app = new Application(); app.PublishPage("/", () => new HttpContextExample()); await app.Start(new StartServerOptions { Port = port }); // print address on console (set project's output type to WinExe to avoid console) var address = $"http://localhost:{port}"; Console.WriteLine($"Listening on {address}/"); // helper function to launch browser (comment out as needed) LaraUI.LaunchBrowser(address); // wait for ASP.NET Core shutdown await app.WaitForShutdown(); }
public void PublishAssembliesComponent() { Assert.True(LaraUI.TryGetComponent("x-com", out var type)); Assert.Same(typeof(Xcom), type); }