public async Task DeleteLightScene_Ok() { var hueLightProvider = Substitute.For <IHueLightProvider>(); var lightSceneRepository = Substitute.For <IAsyncRepository <LightScene> >(); var lightScene = new LightScene() { Id = 5, Name = "Test", Data = "abc" }; lightSceneRepository.GetAsync(Arg.Is <int>(5)).Returns(lightScene); var controller = new LightingController(hueLightProvider, lightSceneRepository); var result = await controller.DeleteLightScene(5); await lightSceneRepository.Received(1).RemoveAsync(Arg.Is <LightScene>(x => x.Id.Equals(5) && x.Name.Equals("Test") && x.Data.Equals("abc"))); var okResult = Assert.IsType <OkObjectResult>(result.Result); var scene = Assert.IsType <LightScene>(okResult.Value); Assert.Equal(5, scene.Id); Assert.Equal("Test", scene.Name); Assert.Equal("abc", scene.Data); }
public async Task UpdateLightScene_BadRequest_SceneNull() { var hueLightProvider = Substitute.For <IHueLightProvider>(); var lightSceneRepository = Substitute.For <IAsyncRepository <LightScene> >(); LightScene lightScene = null; var controller = new LightingController(hueLightProvider, lightSceneRepository); var result = await controller.UpdateLightScene(5, lightScene); Assert.IsType <BadRequestResult>(result.Result); }
public async Task <ActionResult <LightScene> > UpdateLightScene(int id, [FromBody] LightScene modifiedScene) { if ((modifiedScene == null) || (id != modifiedScene.Id)) { return(BadRequest()); } await lightSceneRepository.UpdateAsync(modifiedScene); return(Ok(modifiedScene)); }
public async Task ApplyLightScene_SceneNotFound() { var hueLightProvider = Substitute.For <IHueLightProvider>(); var lightSceneRepository = Substitute.For <IAsyncRepository <LightScene> >(); LightScene lightScene = null; lightSceneRepository.GetAsync(Arg.Is <int>(5)).Returns(lightScene); var controller = new LightingController(hueLightProvider, lightSceneRepository); var result = await controller.ApplyLightScene(5); Assert.IsType <NotFoundResult>(result); }
public async Task GetLightScene_NotFound() { var hueLightProvider = Substitute.For <IHueLightProvider>(); var lightSceneRepository = Substitute.For <IAsyncRepository <LightScene> >(); LightScene lightScene = null; lightSceneRepository.GetAsync(5).Returns(Task.FromResult(lightScene)); var controller = new LightingController(hueLightProvider, lightSceneRepository); var result = await controller.GetLightScene(2); Assert.IsType <NotFoundResult>(result.Result); }
/// <summary> /// Call to update constant buffer for per frame /// </summary> public void UpdatePerFrameData() { if (matrixChanged) { globalTransform.View = ViewMatrix; globalTransform.Projection = ProjectionMatrix; globalTransform.ViewProjection = globalTransform.View * globalTransform.Projection; screenViewProjectionMatrix = ViewMatrix * ProjectionMatrix * ViewportMatrix; matrixChanged = false; } cbuffer.UploadDataToBuffer(DeviceContext, ref globalTransform); LightScene.UploadToBuffer(DeviceContext); }
public async Task <ActionResult <LightScene> > AddLightScene([FromBody] LightScene scene) { if (scene == null) { return(BadRequest()); } // id is set via auto-increment: scene.Id = 0; await lightSceneRepository.AddAsync(scene); return(CreatedAtAction(nameof(GetLightScene), new { id = scene.Id }, scene)); }
public async Task UpdateLightScene_BadRequest_InvalidId() { var hueLightProvider = Substitute.For <IHueLightProvider>(); var lightSceneRepository = Substitute.For <IAsyncRepository <LightScene> >(); LightScene lightScene = new LightScene() { Id = 5, Name = "Test", Data = "abc" }; var controller = new LightingController(hueLightProvider, lightSceneRepository); var result = await controller.UpdateLightScene(7, lightScene); Assert.IsType <BadRequestResult>(result.Result); }
public static void Render(int _bpp, byte[] buffer) { Stopwatch st = new Stopwatch(); st.Start(); bpp = _bpp; //IScene scene = new ToyPathTracerScene(); //IScene scene = new BookScene(); //IScene scene = new TwoSpheresScene(); IScene scene = new LightScene(); World = scene.GetSceneWorld(); Camera = scene.GetDefaultCamera((1f * IMG_WIDTH) / IMG_HEIGHT); World.RebuildBvhTree(); Parallel.For(0, IMG_HEIGHT, y => { for (int x = 0; x < IMG_WIDTH; x++) { Vector3 color = Vector3.Zero; for (uint sample = 0; sample < AA_POINTS; sample++) { double xOffset = (x + VectorHelpers.RandomFloat() - 0.5f) / ((double)IMG_WIDTH); double yOffset = (y + VectorHelpers.RandomFloat() - 0.5f) / ((double)IMG_HEIGHT); Ray r = Camera.GetRay(xOffset, yOffset); color += Color(r, 0); } color /= AA_POINTS; int offset = CoordsToBufferIndex(x, y); buffer[offset++] = DoubleToByte(color.X); buffer[offset++] = DoubleToByte(color.Y); buffer[offset++] = DoubleToByte(color.Z); } }); st.Stop(); Console.WriteLine("Scene rendered in " + st.ElapsedMilliseconds + " ms."); }
public async Task <bool> ApplyLightSceneAsync(LightScene scene) { bool success = true; try { var lightStateUpdates = JsonConvert.DeserializeObject <Dictionary <int, LightStateUpdate> >(scene.Data); foreach (var keyValue in lightStateUpdates) { success &= await SetLightStateAsync(keyValue.Key, keyValue.Value); } } catch (Exception) { success = false; } return(success); }
public async Task ApplyLightScene_NotSuccessful() { var hueLightProvider = Substitute.For <IHueLightProvider>(); hueLightProvider.ApplyLightSceneAsync(Arg.Any <LightScene>()).Returns(false); var lightSceneRepository = Substitute.For <IAsyncRepository <LightScene> >(); LightScene lightScene = new LightScene() { Id = 5, Name = "Test", Data = "abc" }; lightSceneRepository.GetAsync(Arg.Is <int>(5)).Returns(lightScene); var controller = new LightingController(hueLightProvider, lightSceneRepository); var result = await controller.ApplyLightScene(5); await hueLightProvider.Received(1).ApplyLightSceneAsync(Arg.Is <LightScene>(x => x.Id.Equals(5) && x.Name.Equals("Test") && x.Data.Equals("abc"))); Assert.IsType <NotFoundResult>(result); }
public async Task AddLightScene_Created() { var hueLightProvider = Substitute.For <IHueLightProvider>(); var lightSceneRepository = Substitute.For <IAsyncRepository <LightScene> >(); var newLightScene = new LightScene() { Id = 5, Name = "Test", Data = "abc" }; var controller = new LightingController(hueLightProvider, lightSceneRepository); var result = await controller.AddLightScene(newLightScene); await lightSceneRepository.Received(1).AddAsync(Arg.Is <LightScene>(x => x.Id.Equals(0) && x.Name.Equals("Test") && x.Data.Equals("abc"))); var createdResult = Assert.IsType <CreatedAtActionResult>(result.Result); var scene = Assert.IsType <LightScene>(createdResult.Value); Assert.Equal("Test", scene.Name); Assert.Equal("abc", scene.Data); }
public async Task GetLightScene_Ok() { var hueLightProvider = Substitute.For <IHueLightProvider>(); var lightSceneRepository = Substitute.For <IAsyncRepository <LightScene> >(); var lightScene = new LightScene() { Id = 5, Name = "Test", Data = "abc" }; lightSceneRepository.GetAsync(5).Returns(Task.FromResult(lightScene)); var controller = new LightingController(hueLightProvider, lightSceneRepository); var result = await controller.GetLightScene(5); var okResult = Assert.IsType <OkObjectResult>(result.Result); var scene = Assert.IsType <LightScene>(okResult.Value); Assert.Equal(5, scene.Id); Assert.Equal("Test", scene.Name); Assert.Equal("abc", scene.Data); }