VS 2010, 4.0....C# and NUnit
Hoping someone can help me out. I am trying to store and retrieve items from an interface and create Nunit tests on them and am lost. I believe the impl and interface are correct but I am having problems figuring out how to write the tests to test that the item was stored, retrieved and then compare the two to see if they are the same.

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, serv1); 
        }

        public void ValidateRetrieveItem()
        {

        }
    }
}
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();
        }
    }
}
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();
    }
}
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;
        }
    }
}
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);
}

Any assistance would be greatly appreciated :-)

I've changed the test and the compare is failing. Any ideas as to why??

using NUnit.Framework;
    [TestFixture]

    public class ItemSvcIntTest 
    {
        [Test]
        public void ValidateItem()
        {       
            IitemSvcInt itemA = new ItemSvcBinaryImpl();
            itemA.StoreItem(new Item("Stock", "Dark Rival", "Masters of Time", "Brenda Joyce", "Book", "Time Travel", true));
            Assert.IsNotNull(itemA);
            
            IitemSvcInt itemB = new ItemSvcBinaryImpl();
            itemB.RetrieveItem();
            Assert.IsNotNull(itemB);
            
            Assert.AreEqual(itemA, itemB);
        }
    }
}
This article has been dead for over six months. Start a new discussion instead.