public void GetAsync_Return_All_Auditoriums() { //Arrange List <AuditoriumDomainModel> auditoriumsDomainModelsList = new List <AuditoriumDomainModel>(); AuditoriumDomainModel auditoriumDomainModel = new AuditoriumDomainModel { Id = 1, Name = "Auditorium1", CinemaId = 5, SeatsList = new List <SeatDomainModel>() }; auditoriumsDomainModelsList.Add(auditoriumDomainModel); IEnumerable <AuditoriumDomainModel> auditoriumDomainModels = auditoriumsDomainModelsList; Task <IEnumerable <AuditoriumDomainModel> > responseTask = Task .FromResult(auditoriumDomainModels); int expectedResultCount = 1; int expectedStatusCode = 200; _auditoriumService = new Mock <IAuditoriumService>(); _auditoriumService.Setup(x => x.GetAllAsync()).Returns(responseTask); AuditoriumsController auditoriumsController = new AuditoriumsController(_auditoriumService.Object); //Act var result = auditoriumsController.GetAsync().ConfigureAwait(false).GetAwaiter().GetResult().Result; var resultList = ((OkObjectResult)result).Value; var auditoriumDomainModelResultList = (List <AuditoriumDomainModel>)resultList; //Assert Assert.IsNotNull(auditoriumDomainModelResultList); Assert.AreEqual(expectedResultCount, auditoriumDomainModelResultList.Count); Assert.AreEqual(auditoriumDomainModel.Id, auditoriumDomainModelResultList[0].Id); Assert.IsInstanceOfType(result, typeof(OkObjectResult)); Assert.AreEqual(expectedStatusCode, ((OkObjectResult)result).StatusCode); }
public void GetAsync_Return_New_List() { //Arrange IEnumerable <AuditoriumDomainModel> auditoriumDomainModels = null; Task <IEnumerable <AuditoriumDomainModel> > responseTask = Task.FromResult(auditoriumDomainModels); int expectedResultCount = 0; int expectedStatusCode = 200; _auditoriumService = new Mock <IAuditoriumService>(); _auditoriumService.Setup(x => x.GetAllAsync()).Returns(responseTask); AuditoriumsController auditoriumsController = new AuditoriumsController(_auditoriumService.Object); //Act var result = auditoriumsController.GetAsync().ConfigureAwait(false).GetAwaiter().GetResult().Result; var resultList = ((OkObjectResult)result).Value; var auditoriumDomainModelResultList = (List <AuditoriumDomainModel>)resultList; //Assert Assert.IsNotNull(auditoriumDomainModelResultList); Assert.AreEqual(expectedResultCount, auditoriumDomainModelResultList.Count); Assert.IsInstanceOfType(result, typeof(OkObjectResult)); Assert.AreEqual(expectedStatusCode, ((OkObjectResult)result).StatusCode); }