vendredi 24 avril 2015

Assert.AreEqual failed

I wrote service layer code as follows:

public GetAllCategoriesResponse GetAllCategories()
{
     GetAllCategoriesResponse response = new GetAllCategoriesResponse();
     IEnumerable<Category> categories = _categoryRepository.GetAll();
     response.Categories = categories.ConvertToCategoryViews();

     return response;
}

Then I wrote my Test class as follows:

[TestClass]
    public class ProductCatalogServiceTest
    {
       Mock<ICategoryRepository> _categoryRepository;
       ProductCatalogService _catalogService;

        [TestInitialize]
        public void Setup()
        {
            _categoryRepository = new Mock<ICategoryRepository>();
            _catagoryService = new ProductCatagoryService( _categoryRepository.Object);
        }

        [TestMethod]
        public void Test_All_Catagories()
        {
            AutoMapperBootStrapper.ConfigureAutoMapper();
            var catagories = new List<Category>();
            catagories.Add(new Category() {Id=1, Name = "Half Shirt" });
            catagories.Add(new Category() {Id=2, Name = "Full Shirt" });
            catagories.Add(new Category() {Id=4, Name = "Pant" });

            _categoryRepository.Setup(m => m.GetAll()).Returns(catagories.AsEnumerable());

            var result = _catagoryService.GetAllCategories();

            var response = new GetAllCategoriesResponse();
            response.Categories = catagories.ConvertToCategoryViews();

            Assert.AreEqual(response, result);
        }
    }

The mapping between Category and CategoryView as follows:

public class AutoMapperBootStrapper
    {

        public static void ConfigureAutoMapper()
        {
            // Category
            Mapper.CreateMap<Category, CategoryView>();
         }
    }

When I run my test is shows me following message: Assert.AreEqual failed. Expected: Shoppingcart.Services.Messages.GetAllCategoriesResponse>. Actual:Shoppingcart.Services.Messages.GetAllCategoriesResponse>.

Aucun commentaire:

Enregistrer un commentaire