コード例 #1
0
        // -------------------------------------------------------
        // 查询
        // -------------------------------------------------------

        #region 函数:FindOne(string id)
        /// <summary>查询某条记录</summary>
        /// <param name="id">AccountInfo Id号</param>
        /// <returns>返回一个 实例<see cref="IAttachmentFileInfo"/>的详细信息</returns>
        public IAttachmentFileInfo FindOne(string id)
        {
            AttachmentFileInfo param = (AttachmentFileInfo)provider.FindOne(id);

            IAttachmentParentObject parent = new AttachmentParentObject();

            parent.EntityId                  = param.EntityId;
            parent.EntityClassName           = param.EntityClassName;
            parent.AttachmentEntityClassName = KernelContext.ParseObjectType(typeof(AttachmentFileInfo));
            parent.AttachmentFolder          = UploadPathHelper.GetAttachmentFolder(param.VirtualPath, param.FolderRule);

            param.Parent = parent;

            return(param);
        }
コード例 #2
0
        public void TestFindOne()
        {
            IAttachmentParentObject parent = new AttachmentParentObject(StringHelper.ToGuid(),
                                                                        KernelContext.ParseObjectType(typeof(AttachmentFileInfo)),
                                                                        KernelContext.ParseObjectType(typeof(AttachmentFileInfo)),
                                                                        "test");

            IAttachmentFileInfo param = new AttachmentFileInfo(parent);

            param.Id             = "test-" + DigitalNumberContext.Generate("Key_RunningNumber");
            param.AttachmentName = "test-" + StringHelper.ToRandom(8);
            param.FileType       = ".tXT";

            AttachmentStorageContext.Instance.AttachmentFileService.Save(param);

            param = AttachmentStorageContext.Instance.AttachmentFileService.FindOne(param.Id);

            Assert.IsNotNull(param);
        }
コード例 #3
0
        public void TestSave()
        {
            Mock <IAttachmentParentObject> mock = this.factory.CreateMock <IAttachmentParentObject>(); //产生一个mock对象

            mock.Expects.Between(0, 5).GetProperty(m => m.EntityId, "test_" + DateHelper.GetTimestamp());
            mock.Expects.Between(0, 5).GetProperty(m => m.EntityClassName, KernelContext.ParseObjectType(typeof(AttachmentParentObject)));
            mock.Expects.Between(0, 5).GetProperty(m => m.AttachmentEntityClassName, KernelContext.ParseObjectType(typeof(AttachmentFileInfo)));
            mock.Expects.Between(0, 5).GetProperty(m => m.AttachmentFolder, "test");

            IAttachmentParentObject parent = mock.MockObject;

            IAttachmentFileInfo param = new AttachmentFileInfo(parent);

            param.Id             = UploadFileHelper.NewIdentity();
            param.AttachmentName = "test_" + DateHelper.GetTimestamp();
            param.FileType       = ".txt";

            param = AttachmentStorageContext.Instance.AttachmentFileService.Save(param);

            Assert.IsNotNull(param);
        }
コード例 #4
0
        public void TestGetVirtualPathFormat()
        {
            string attachmentFolder = "test";

            AttachmentFileInfo attachment = new AttachmentFileInfo();

            attachment.Id             = StringHelper.ToGuid();
            attachment.FileType       = ".doc";
            attachment.AttachmentName = "123.doc";
            attachment.CreatedDate    = new DateTime(2001, 1, 1);

            DateTime datetime = attachment.CreatedDate;

            string path1 = "{uploads}" + attachmentFolder + "/"
                           + datetime.Year + "/" + (((datetime.Month - 1) / 3) + 1) + "Q/" + datetime.Month + "/"
                           + attachment.Id
                           + attachment.FileType;

            string path2 = UploadPathHelper.GetVirtualPathFormat(attachmentFolder, attachment);

            Assert.AreEqual(path1, path2);
        }