Skip to content

Commit

Permalink
feat(FileWithMetadata): Add FileWithMetadata model
Browse files Browse the repository at this point in the history
  • Loading branch information
mediumTaj committed Sep 24, 2019
1 parent 40c28d1 commit e9e892e
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/IBM.Cloud.SDK.Core/Model/FileWithMetadata.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* Copyright 2019 IBM Corp. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

namespace IBM.Cloud.SDK.Core.Model
{
/// <summary>
/// A file and its associated metadata.
/// </summary>
public class FileWithMetadata
{
/// <summary>
/// The file data
/// </summary>
public System.IO.MemoryStream Data { get; set; }

/// <summary>
/// The filename
/// </summary>
public string Filename { get; set; }

/// <summary>
/// The file contentType
/// </summary>
public string ContentType { get; set; }
}
}
66 changes: 66 additions & 0 deletions test/IBM.Cloud.SDK.Core.Tests/FileWithMetadataTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/**
* Copyright 2019 IBM Corp. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

using IBM.Cloud.SDK.Core.Model;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.IO;
using System.Text;

namespace IBM.Cloud.SDK.Core.Tests
{
[TestClass]
public class FileWithMetadataTests
{
[TestMethod]
public void TestFileWithMetadata()
{
string fileText = "This is a test";
string fileName = "testFile.txt";
string fileContentType = "text/plain";

using (FileStream fs = File.Create(fileName))
{
byte[] fileData = Encoding.UTF8.GetBytes(fileText);
fs.Write(fileData, 0, fileData.Length);
}

FileWithMetadata fileWithMetadata = new FileWithMetadata();

using (FileStream fs = File.OpenRead(fileName))
{
using (MemoryStream ms = new MemoryStream())
{
fs.CopyTo(ms);
fileWithMetadata.Data = ms;
fileWithMetadata.ContentType = fileContentType;
fileWithMetadata.Filename = fileName;
}
}

string text = Encoding.UTF8.GetString(fileWithMetadata.Data.ToArray());

Assert.IsTrue(fileText == text);
Assert.IsTrue(fileWithMetadata.Filename == fileName);
Assert.IsTrue(fileWithMetadata.ContentType == fileContentType);

if(File.Exists(fileName))
{
File.Delete(fileName);
}
}
}
}

0 comments on commit e9e892e

Please sign in to comment.