Kolletjie NET
Friday, June 11, 2010
WCE400 vs WCE500
Friday, May 7, 2010
Converting an Image to Base64 String
DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void LinkButton1_Click(object sender, EventArgs e)
{
using (StreamReader sr = new StreamReader(MapPath("TestPicture.JPG")))
{
BinaryReader br = new BinaryReader(sr.BaseStream);
byte[] data = br.ReadBytes((int)br.BaseStream.Length);
string dataToSave = Convert.ToBase64String(data);
// show it
TextBox1.Text = dataToSave;
}
}
script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Pagetitle>
head>
<body>
<form id="form1" runat="server">
<div>
<asp:LinkButton ID="LinkButton1" runat="server" OnClick="LinkButton1_Click">GetPictureAsTextasp:LinkButton>div>
<asp:TextBox ID="TextBox1" runat="server" TextMode="MultiLine" Width="100%" Height="24em">asp:TextBox>
form>
body>
html>
Add nunit to Visual Sutdio Project
1. Download and install nunit 2.0
2. In your VS project add a reference to nunit.framework
3. In your VS project create a new class. Name doesn't matter.
4. Add using NUnit.Framework to your using statements for the new class
5. Prefix your new class with [TestFixture]. example [TestFixture] public class MyTest{}
6. Prefix a method to setup your class with [SetUp]. example: [SetUp] protected void setup() {}
7. Prefix your test methods with [Test]. example [Test] public void ThisIsATest() {}
8. In your ThisIsATest() method type Assert. (PS type Assert dot so you can see the auto-complete)
And then look at the list of options available to you. Each test method should have one assert method which does a test.
To run the test, first build your project, then find nunit on your start menu and open it up. Use it to browse for the dll or exe in your bin folder you just compiled.
Use NUnit to run the test.
Thats all there is to it