lundi 2 mars 2015

Unit test Nsubstitute

I am learning unittesting and I am using Nsubstitute as a choice of mocking framework. so I have this small imaginary app I am writing for a guest inn. I am trying to write a test to ensure that once a reservation is made on a friday, room prices should be discounted by 20%. But I don't understand how this Nsubstitute works (mind you still learning) so I thought using the when() do() should help me test the scenario I aim. can someone help me understand the when() do() methods of the Nsubstitute framework? How do I complete this test? Hope y'all can help!!



public void DiscountRoomPricesAtWeekends(){
//Arrange
//prices at weekends should be discounted by 20%
//get price of a particular room and discount price
var roomprice = new Rooms() { Price = 100M };
//if day to check in is a friday or saturday its 20% off
var reserve = Substitute.For<Reservation>();
//Make sure that the date of reservation is always friday.
//reserve.ReservationDate.DayOfWeek.Returns(DayOfWeek.Friday);
//(double) roomprice.Price * 0.20)
var percentage = (double) roomprice.Price * 0.20;
reserve.When(r => r.ReservationDate.DayOfWeek.Returns(DayOfWeek.Friday))
.Do(p => );
//Act
//Assert
//Assert.AreEqual(percentage, 20);
Assert.AreEqual();}


Thanks everyone


Aucun commentaire:

Enregistrer un commentaire