예제 #1
0
        public void Should_add_computed_value_to_cache()
        {
            // Arrange
            var calculationServiceMock = new Mock <ICalculationService>();

            calculationServiceMock.Setup(x => x.Calculate(It.IsAny <decimal>(), It.IsAny <decimal>()))
            .Returns(ComputedResult);

            var sut = new CachedCalculationService(calculationServiceMock.Object);

            // Act
            var firstCall  = sut.Calculate(FirstParameter, SecondParameter);
            var secondCall = sut.Calculate(FirstParameter, SecondParameter);

            // Assert
            calculationServiceMock.Verify(x => x.Calculate(FirstParameter, SecondParameter), Times.Once);
        }
        public void CachedCalculationService_ShouldNotDoRequest_WhenValueIsCached()
        {
            var sut = new CachedCalculationService(new CalculationService());

            Action calculation = () => sut.Calculate(1, 2);

            calculation();

            calculation.ExecutionTime().Should().BeLessThan(TimeSpan.FromMilliseconds(10));
        }
예제 #3
0
        public void Should_return_correct_result()
        {
            // Arrange
            var sut = new CachedCalculationService(new CalculationService());

            // Act
            var result = sut.Calculate(FirstParameter, SecondParameter);

            // Assert
            result.Should().Be(ComputedResult);
        }