Created
July 21, 2019 17:02
-
-
Save obegendi/4b542b66c55ae8add4e6d4c155c6996e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class UberQualityService | |
{ | |
DateTimeService _dateService; | |
public UberQualityService(DateTimeService dateService) | |
{ | |
_dateService = dateService | |
} | |
public async bool SaveCustomer(string data) | |
{ | |
if (data != null) | |
{ | |
var customer = JsonConvert.DeserializeObject<Customer>(data); | |
if(_dateService.GetDayOfWeek() == DayOfWeek.Friday) | |
{ | |
//Database save logic | |
return true; | |
} | |
else | |
{ | |
return false; | |
} | |
} | |
} | |
} | |
public class DateTimeService | |
{ | |
public DayOfWeek GetDayOfWeek(); | |
} | |
[Fact] | |
public void SaveMethodShouldCallOnce() | |
{ | |
//Arrange | |
var mockValidator = new Mock<DateTimeService>(); | |
mockValidator.Setup(x => x.GetDayOfWeek()).Returns(DayOfWeek.Friday); | |
var sut = new UberQualityService(mockValidator.Object); | |
var customer = new Customer { Age = 30 }; | |
//Act | |
var returnValue = sut.Evaluate(customer.Serialize()); | |
//Assert | |
Assert.True(returnValue); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment