public void Test_AttachmentUpdate_Validate()
        {
            var value = new AttachmentUpdate();

            value.Validate();

            Assert.AreEqual(1, value.Errors.Count, "Errors");
        }
        public void Test_AttachmentUpdate_Initialize()
        {
            var value = new AttachmentUpdate();

            value.Initialize(new Attachment());

            Assert.IsNotNull(value.Attachment, "Attachment");
        }
        public void Test_AttachmentUpdate_ValueToModel()
        {
            var value = new AttachmentUpdate
            {
                FileName = "test"
            };

            var attachment = new Attachment();

            value.ValueToModel(attachment);

            Assert.AreEqual("test", value.FileName, "FileName");
        }
        public void Test_AttachmentUpdate()
        {
            var value = new AttachmentUpdate(
                new Attachment
                {
                    Id = 1,
                    FileName = "test"
                }
            );

            Assert.AreEqual(1, value.Id, "Id");
            Assert.AreEqual("test", value.FileName, "FileName");
            Assert.IsNotNull(value.Attachment, "Attachment");
        }
        /// <summary>
        /// Load content for the screen.
        /// </summary>
        /// <param name="GraphicInfo"></param>
        /// <param name="factory"></param>
        /// <param name="contentManager"></param>
        protected override void LoadContent(GraphicInfo GraphicInfo, GraphicFactory factory, IContentManager contentManager)
        {
            base.LoadContent(GraphicInfo, factory, contentManager);

            {
                SimpleModel simpleModel = new SimpleModel(factory, "Model//block");
                simpleModel.SetTexture(factory.CreateTexture2DColor(1, 1, Color.White), TextureType.DIFFUSE);
                ///Physic info (position, rotation and scale are set here)
                BoxObject tmesh = new BoxObject(Vector3.Zero, 1, 1, 1, 10, new Vector3(1000, 1, 1000), Matrix.Identity, MaterialDescription.DefaultBepuMaterial());
                tmesh.isMotionLess = true;
                ///Forward Shader (look at this shader construction for more info)
                ForwardXNABasicShader shader = new ForwardXNABasicShader();
                ///Deferred material
                ForwardMaterial fmaterial = new ForwardMaterial(shader);
                ///The object itself
                IObject obj = new IObject(fmaterial, simpleModel, tmesh);
                ///Add to the world
                this.World.AddObject(obj);

                ///create the fsm
                fsm = new StateMachine();
                ///atach the fsm to the object using the attachment property (there are lots of ways of doing this like extending the iobject class)
                AttachmentUpdate atachment = new AttachmentUpdate(
                    (a, b) => fsm.UpdateFSM(b)
                    );
                obj.IObjectAttachment.Add(atachment);

                ////Sample usage
                ///Press Space to go to state2 and press enter in state 2 to get back to state1 =P
                ///create state 1
                {
                    StateSample state1 = new StateSample("state1", obj);
                    state1.NextStateFunc =
                        (a) =>
                    {
                        KeyboardState kstate = Keyboard.GetState();
                        if (kstate.IsKeyDown(Keys.Space))
                        {
                            return("state2");
                        }
                        return(null);
                    };
                    fsm.AddState(state1);

                    ///SET THE CURRENT STATE
                    fsm.SetCurrentState(state1.Name);
                }



                ///create state 2
                {
                    StateSample state2 = new StateSample("state2", obj);
                    state2.NextStateFunc =
                        (a) =>
                    {
                        KeyboardState kstate = Keyboard.GetState();
                        if (kstate.IsKeyDown(Keys.Enter))
                        {
                            return("state1");
                        }
                        return(null);
                    };
                    fsm.AddState(state2);
                }
            }

            ///add a camera
            this.World.CameraManager.AddCamera(new CameraFirstPerson(GraphicInfo));
        }
Example #6
0
        public IActionResult UpdateAttachment(string volume, ulong documentId, string oldName, [FromBody] AttachmentUpdate attachmentUpdate)
        {
            if (!TryGetSession(User, out Session session))
            {
                return(Unauthorized());
            }

            if (!session.IsVolumeExist(volume))
            {
                return(NotFound(Resources.ErrorVolumeNotFound));
            }

            DocIdentity docId = new DocIdentity(documentId);

            if (!session.IsDocumentExist(volume, docId))
            {
                return(NotFound(Resources.ErrorDocumentNotFound));
            }

            AttachmentInfo updatedAttachment = session.RenameAttachment(volume, docId, oldName, attachmentUpdate.NewName);

            return(Ok(updatedAttachment));
        }
        public ActionResult Update(AttachmentUpdate value)
        {
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            var attachment = this.AttachmentService.GetById(value.Id);

            if (attachment == null)
            {
                return base.HttpNotFound();
            }

            var privilege = new AttachmentPrivilege();

            if (!privilege.CanUpdate(attachment))
            {
                return NotAuthorized();
            }

            value.Validate();

            if (value.IsValid)
            {
                value.ValueToModel(attachment);

                this.AttachmentService.Update(attachment);

                value.SuccessMessage(Messages.AttachmentUpdated);
            }
            else
            {
                value.CopyToModel(ModelState);
            }

            value.Initialize(attachment);

            return base.View(Views.Update, value);
        }
        public void Test_AttachmentController_Update_Post()
        {
            PrincipalHelper.Create();

            var value = new AttachmentUpdate
            {
                Id = 0,
                FileName = "test.jpg"
            };

            var notFoundResult = this.AttachmentController.Update(value) as HttpNotFoundResult;

            Assert.IsNotNull(notFoundResult, "HttpNotFoundResult");

            value.Id = 1;

            var viewResult = this.AttachmentController.Update(value) as ViewResult;

            Assert.IsNotNull(viewResult, "ViewResult");
            Assert.AreEqual(Views.Update, viewResult.ViewName, "ViewName");
            Assert.AreEqual(Messages.AttachmentUpdated, value.Message.Message);

            value.FileName = null;

            var errorResult = this.AttachmentController.Update(value) as ViewResult;

            Assert.IsNotNull(errorResult, "ErrorResult");
            Assert.AreEqual(Views.Update, viewResult.ViewName, "ErrorViewName");
            Assert.AreEqual(1, value.Errors.Count, "Errors");

            PrincipalHelper.Clear();

            var notAuthorizedResult = this.AttachmentController.Update(value) as NotAuthorizedResult;

            Assert.IsNotNull(notAuthorizedResult, "NotAuthorizedResult");
        }