public async void GetBAUWithSpecificDateShouldReturnCorrectBAUs(DateTime date) { //arrange var mockBusinessService = new Mock <IBusinessService>(); var listOfBAUs = CreateBAUs(); var expectedBAUs = listOfBAUs.Where(x => x.Date == date); mockBusinessService.Setup(x => x.GetBAU(date)).Returns(expectedBAUs); var controller = new BAUsController(mockBusinessService.Object); //act var actionResult = await controller.GetBAU(date); //assert var result = actionResult as OkObjectResult; var resultBAUs = result?.Value as IEnumerable <BAU>; Assert.NotNull(resultBAUs); Assert.Equal(expectedBAUs.Count(), resultBAUs.Count()); foreach (var bau in expectedBAUs) { Assert.True(resultBAUs.Contains(bau, new BAUEqualityComparer())); } mockBusinessService.Verify(x => x.GetBAU(date), Times.Once); }
public async void GetBAU_ShouldReturnAllBAUs() { //arrange var mockBusinessService = new Mock <IBusinessService>(); var listOfBAUs = CreateBAUs(); mockBusinessService.Setup(x => x.GetAllBAUs()).Returns(listOfBAUs); var controller = new BAUsController(mockBusinessService.Object); //act var actionResult = await controller.GetBAU(); //assert var result = actionResult as OkObjectResult; var resultBAUs = result?.Value as IEnumerable <BAU>; Assert.NotNull(resultBAUs); Assert.Equal(listOfBAUs.Count(), resultBAUs.Count()); mockBusinessService.Verify(x => x.GetAllBAUs(), Times.Once); }