public async Task GetAllBottlesAsync_ReturnsListReturnedByRepo_WhenNonEmpty() { //Arrange var listToReturn = new List <BottleDomainModel> { new BottleDomainModel { BottleId = "bottle1" }, new BottleDomainModel { BottleId = "bottle2" } }; _mockRepository.Setup( c => c.GetAllAsync()) .ReturnsAsync(listToReturn); var bottleService = new Domain.Services.BottleService(_mockRepository.Object); //Act var result = await bottleService.GetAllBottlesAsync() as List <BottleDomainModel>; //Assert Assert.AreEqual(listToReturn[0].BottleId, result[0].BottleId); Assert.AreEqual(listToReturn[1].BottleId, result[1].BottleId); }
public async Task GetBottleAsync_ReturnsNull_WhenNullReturnedByRepository() { //Arrange _mockRepository.Setup( c => c.GetByIdAsync(It.IsAny <string>())) .ReturnsAsync((BottleDomainModel)null); var bottleService = new Domain.Services.BottleService(_mockRepository.Object); //Act var result = await bottleService.GetBottleAsync("bottleId"); //Assert Assert.AreEqual(null, null); }
public async Task DeleteBottleAsync_ReturnsFalse_WhenRepoReturnsFalse() { //Arrange _mockRepository.Setup( c => c.DeleteAsync(It.IsAny <string>())) .ReturnsAsync(false); var bottleService = new Domain.Services.BottleService(_mockRepository.Object); //Act var result = await bottleService.DeleteBottleAsync("bottleId"); //Assert Assert.AreEqual(false, result); }
public async Task PostBottleAsync_ReturnsNull_WhenRepoReturnsNull() { //Arrange _mockRepository.Setup( c => c.InsertAsync(It.IsAny <BottleDomainModel>())) .ReturnsAsync((BottleDomainModel)null); var bottleService = new Domain.Services.BottleService(_mockRepository.Object); //Act var result = await bottleService.PostBottleAsync(new BottleDomainModel()); //Assert Assert.AreEqual(null, result); }
public async Task GetAllBottlesAsync_ReturnsEmptyList_WhenRepoReturnsEmptyList() { //Arrange var listToReturn = new List <BottleDomainModel>(); _mockRepository.Setup( c => c.GetAllAsync()) .ReturnsAsync(listToReturn); var bottleService = new Domain.Services.BottleService(_mockRepository.Object); //Act var result = await bottleService.GetAllBottlesAsync(); //Assert Assert.IsInstanceOf(typeof(List <BottleDomainModel>), result); Assert.IsEmpty(result); }
public async Task GetBottleAsync_ReturnsResultReturnedByRepository_WhenNotNull() { //Arrange var bottleToReturn = new BottleDomainModel { BottleId = "bottleId" }; _mockRepository.Setup( c => c.GetByIdAsync(It.IsAny <string>())) .ReturnsAsync(bottleToReturn); var bottleService = new Domain.Services.BottleService(_mockRepository.Object); //Act var result = await bottleService.GetBottleAsync("bottleId"); //Assert Assert.AreEqual(bottleToReturn.BottleId, result.BottleId); }