public void Can_write_bytes_to_blank_BE() { var be = new ResourceContentBE(true); var v = 42; be.SetData(BitConverter.GetBytes(v)); Assert.AreEqual(v, BitConverter.ToInt32(be.ToBytes(), 0)); }
public void Can_create_BE_from_Stream() { var stream = new MemoryStream(); var bytes = Encoding.UTF8.GetBytes("foo"); stream.Write(bytes, 0, bytes.Length); stream.Position = 0; var be = new ResourceContentBE(stream, MimeType.TEXT_UTF8); Assert.AreEqual(MimeType.TEXT_UTF8, be.MimeType); Assert.AreEqual(stream.Length, be.Size); Assert.AreEqual(stream.Length, be.ToBytes().Length); }
private ResourceContentBE Resources_ContentInsert(ResourceContentBE contents) { string query = @" /* ResourceDA::ContentInsert */ insert into resourcecontents (rescontent_res_id, rescontent_res_rev, rescontent_location, rescontent_mimetype, rescontent_size, rescontent_value) values (?RESCONTENT_RES_ID, ?RESCONTENT_RES_REV, ?RESCONTENT_LOCATION, ?RESCONTENT_MIMETYPE, ?RESCONTENT_SIZE, ?RESCONTENT_VALUE); select last_insert_id();"; contents.ContentId = Catalog.NewQuery(query) .With("RESCONTENT_RES_ID", contents.ResourceId) .With("RESCONTENT_RES_REV", contents.Revision) .With("RESCONTENT_LOCATION", contents.Location) .With("RESCONTENT_MIMETYPE", contents.MimeType.ToString()) .With("RESCONTENT_SIZE", contents.Size) .With("RESCONTENT_VALUE", contents.IsDbBased ? contents.ToBytes() : null) .ReadAsUInt() ?? 0; return(contents); }
private ResourceContentBE Resources_ContentInsert(ResourceContentBE contents) { string query = @" /* ResourceDA::ContentInsert */ insert into resourcecontents (rescontent_res_id, rescontent_res_rev, rescontent_location, rescontent_mimetype, rescontent_size, rescontent_value) values (?RESCONTENT_RES_ID, ?RESCONTENT_RES_REV, ?RESCONTENT_LOCATION, ?RESCONTENT_MIMETYPE, ?RESCONTENT_SIZE, ?RESCONTENT_VALUE); select last_insert_id();"; contents.ContentId = Catalog.NewQuery(query) .With("RESCONTENT_RES_ID", contents.ResourceId) .With("RESCONTENT_RES_REV", contents.Revision) .With("RESCONTENT_LOCATION", contents.Location) .With("RESCONTENT_MIMETYPE", contents.MimeType.ToString()) .With("RESCONTENT_SIZE", contents.Size) .With("RESCONTENT_VALUE", contents.IsDbBased ? contents.ToBytes() : null) .ReadAsUInt() ?? 0; return contents; }