BDD: Should infected, Implementierung

by robert 13. June 2009 17:05

Hier nochmal die Anforderung der Entwicklung (CTRL F12):

6-13-2009 4-52-50 PM

Die Tests sind grün. Nach der Umsetzung bleibt folgender Eindruck:

Positives

  • Erst die Spezifikation zu schreiben fokussiert auf das Ziel
  • Die Entwicklung geht einfach von der Hand
  • Die Benamung von Klassen und Methoden sind selbstsprechend

Negatives

  • Die Hilfsmethoden wollen nicht so recht passen
  • Richtig Ästhetisch scheint der Code nicht (aber vielleicht ist as manchmal bei real-world code einfach so?)

Hier die Testklasse nach der Implementierung.

namespace Tests.Domain.Campsites
{
    public class CampsiteImageSearchBehaviour : BaseTest
    {
        private int _createdImadeId { get { return _imageSetup.Created[8].Id; } }
 
        public void Arrange_n_images_in_storage(int amountOfImages)
        {
            _nHibernateHelper.TruncateTableCampsiteImages();
            _imageSetup.Add(amountOfImages).Persist();
        }
 
        private CampsiteImageSearchDescription Get_search_desc_for_id(int imageId)
        {
            var searchDesc = new CampsiteImageSearchDescription();
            searchDesc.Filter.CampsiteImageIds.Add(imageId);
 
            return searchDesc;
        }
 
        [Test]
        public void Should_retrieve_pager_from_search()
        {
            Arrange_n_images_in_storage(10);
 
            var searchDesc = Get_search_desc_for_id(_createdImadeId);
            _campsiteImageService.GetBy(searchDesc);
 
            Assert.That(searchDesc.PageCount, Is.EqualTo(1));
            Assert.That(searchDesc.TotalItems, Is.EqualTo(1));
        }
 
        [Test]
        public void Should_return_image_by_id_using_search_description()
        {
            Arrange_n_images_in_storage(10);
 
            var searchDesc = Get_search_desc_for_id(_createdImadeId);
            var campsiteImages = _campsiteImageService.GetBy(searchDesc);
 
            Assert.That(campsiteImages.Count, Is.EqualTo(1));
            Assert.That(campsiteImages[0].Id, Is.EqualTo(_createdImadeId));            
        }
    }
}

enjoyed the post?

Tags:

BDD

Comments are closed

About Oliver

shades-of-orange.com code blog logo I build web applications using ASP.NET and have a passion for javascript. Enjoy MVC 4 and Orchard CMS, and I do TDD whenever I can. I like clean code. Love to spend time with my wife and our children. My profile on Stack Exchange, a network of free, community-driven Q&A sites

About Anton

shades-of-orange.com code blog logo I'm a software developer at teamaton. I code in C# and work with MVC, Orchard, SpecFlow, Coypu and NHibernate. I enjoy beach volleyball, board games and Coke.