Esempio n. 1
0
        public async Task TrySaveAsync_SaveImage_Image()
        {
            // Arrange
            var imageRepository = new Mock <IRepositoryAsync <ImageEntity> >();

            var imageRepositorySystem = new ImageRepositorySystem(
                imageRepository.Object);

            // Act
            var result = await imageRepositorySystem.TrySaveAsync(_image);

            // Assert
            Assert.NotNull(result);
            Assert.Equal(_image, result);
        }
        public async Task TrySaveAsync_AddImageIfImageAlreadyExist_ObjectAlreadyExistException()
        {
            // Arrange
            var imageRepository = new Mock <IRepositoryAsync <ImageEntity> >();

            var imageRepositorySystem = new ImageRepositorySystem(
                imageRepository.Object);

            imageRepository.Setup(ir => ir.GetAll())
            .Returns(_images.AsQueryable());

            // Act
            Func <Task> act = async() => await imageRepositorySystem.TrySaveAsync(_images.ElementAt(0));

            // Assert
            await Assert.ThrowsAsync <ObjectAlreadyExistException>(act);
        }
        public async Task TrySaveAsync_ReturnDefaultImageIfImageIsNull_DefaultImage()
        {
            // Arrange
            var imageRepository = new Mock <IRepositoryAsync <ImageEntity> >();

            var imageRepositorySystem = new ImageRepositorySystem(
                imageRepository.Object);

            imageRepository.Setup(ir => ir.GetAsync(_defaultImage.Id))
            .ReturnsAsync(_defaultImage);

            // Act
            var result = await imageRepositorySystem.TrySaveAsync(null);

            // Assert
            Assert.Equal(DefaultImageConfig.DEFAULT_IMAGE_ID, result.Id);
        }