コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        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);
        }
コード例 #6
0
        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);
        }