Exemple #1
0
        public async Task WhenValidationFails_ShouldReturnNegativeOne()
        {
            // Arrange
            var validator = new Mock <IValidator <IFiscalData> >();

            validator
            .Setup(x => x.IsValid(It.IsAny <IFiscalData>()))
            .Returns(false);

            // Act
            var service     = new FiscalDataService(null, validator.Object);
            var returnValue = await service.CreateFiscalData(new FiscalData());

            // Assert
            Assert.Equal(-1, returnValue);
        }
Exemple #2
0
        public async Task WhenCallingRepositoryCreate_ShouldReturnPrimaryKeyReturnedByRepository()
        {
            // Arrange
            var validator  = new Mock <IValidator <IFiscalData> >();
            var repository = new Mock <IFiscalDataRepository>();

            validator
            .Setup(x => x.IsValid(It.IsAny <IFiscalData>()))
            .Returns(true);

            var rando = new Random().Next(1, 1000);

            repository
            .Setup(x => x.CreateItem(It.IsAny <IFiscalData>()))
            .Returns(Task.FromResult(rando));

            // Act
            var service     = new FiscalDataService(repository.Object, validator.Object);
            var returnValue = await service.CreateFiscalData(new FiscalData());

            // Assert
            Assert.Equal(rando, returnValue);
        }