NUnit testing on service for storage and retrieval
I am trying to create a service test for the storage and retrieval of an Item. I am not sure how to specify this test to store my item or how to retrieve it, then compare it to the item that I stored. I know I need a compare, but unsure how to get there.
[code]
using System;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ReneApp.Domain
{
using ReneApp.Service;
using NUnit.Framework;
[TestFixture]
public class ItemSvcIntTest
{
[Test]
public void ValidateStoreItem()
{
IitemSvcInt serv1 = new ItemSvcBinaryImpl();
serv1.StoreItem(new Item("Stock", "Dark Rival", "Masters of Time", "Brenda Joyce", "Book", "Time Travel", true));
//Assert.AreEqual(serv1, "Stock", "Dark Rival", "Masters of Time", "Brenda Joyce", "Book", "Time Travel", true);
}
public void ValidateRetrieveItem()
{
}
}
}
[/code]
[code]
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ReneApp.Service
{
using ReneApp.Domain;
public interface IitemSvcInt
{
void StoreItem(Item itemx);
Item RetrieveItem();
}
}
[/code]
[code]
using System;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters;
using System.Runtime.Serialization.Formatters.Binary;
using ReneApp.Domain;
namespace ReneApp.Service
{
public class ItemSvcBinaryImpl : IitemSvcInt
{
public void StoreItem(Item itemX)
{
FileStream fileStream = new FileStream
("Item.bin", FileMode.Create, FileAccess.Write);
IFormatter formatter = new BinaryFormatter();
formatter.Serialize(fileStream, itemX);
fileStream.Close();
}
public Item RetrieveItem()
{
FileStream fileStream = new FileStream
("Item.bin", FileMode.Open, FileAccess.Read);
IFormatter formatter = new BinaryFormatter();
Item itemX = formatter.Deserialize(fileStream) as Item;
fileStream.Close();
return itemX;
}
}
}
[/code]
[code]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ReneApp.Domain;
namespace ReneApp.Service
{
public class TransFactory
{
public IitemSvcInt GetItemSvc()
{
return new ItemSvcBinaryImpl();
}
}
}
[/code]
[code]
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ReneApp.Domain
{
[Serializable]
public class Item
{
private string Status; // Status of the item.
private string Title; // Title of the item.
private string Series; // Series of the item.
private string Author; // Author of the item.
private string Type; // Type of item.
private string Description; // Description of the item.
private bool Addition; // Addition of item.
public Item() { }
public Item(string status, string title, string series, string author, string type, string description, bool addition)
{
Status = status;
Title = title;
Series = series;
Author = author;
Type = type;
Description = description;
Addition = addition;
}
public string status
{
get { return Status; }
set { Status = value; }
}
public string title
{
get { return Title; }
set { Title = value; }
}
public string series
{
get { return Series; }
set { Series = value; }
}
public string author
{
get { return Author; }
set { Author = value; }
}
public string type
{
get { return Type; }
set { Type = value; }
}
public string description
{
get { return Description; }
set { Description = value; }
}
public bool addition
{
get { return Addition; }
set { Addition = value; }
}
public bool ValidateItem()
{
if (status == null)
return false;
if (title == null)
return false;
return true;
}
}
// Declare type to process item.
public delegate void ProcessItemDelegate(Item item);
}
[/code]
Any help would be appreciated :-)