Exemplo n.º 1
0
            public void SetupTheScenario()
            {
                _graph = new Graph
                {
                    IsTraversable = true,
                    Path          = new [] { 0, 2, 4 }
                };
                CalculationServiceMock.Setup(m => m.Traverse(It.IsAny <int[]>())).Returns(_graph);

                // Mocking methods called by extension
                object value;
                var    cacheEntryMock = new Mock <ICacheEntry>();

                MemoryCacheMock.Setup(m => m.TryGetValue(It.IsAny <object>(), out value)).Returns(false);
                MemoryCacheMock.Setup(m => m.CreateEntry(It.IsAny <string>())).Returns(cacheEntryMock.Object);
            }
Exemplo n.º 2
0
            public void ItShouldOnlyCallCalculationServiceTraversalMethodOnceIfItemIsCached()
            {
                object value;

                MemoryCacheMock.SetupSequence(m => m.TryGetValue(It.IsAny <object>(), out value))
                .Returns(false)
                .Returns(true);

                var input    = new[] { 1, 2, 3, 4 };
                var response = Sut.Traverse(input);

                // Checking if it was called with correct params and with any params only once
                CalculationServiceMock.Verify(m => m.Traverse(It.IsAny <int[]>()), Times.Once);
                CalculationServiceMock.Verify(m => m.Traverse(It.Is((int[] path) => path.Equals(input))), Times.Once);
                response.Should().Be(_graph);
            }
Exemplo n.º 3
0
        public TrainingProgrammeApiClient CreateClient()
        {
            TrainingProgrammeApiClient.ProgrammeLists programmes = null;

            if (PopulateCache)
            {
                programmes = new TrainingProgrammeApiClient.ProgrammeLists(_frameworks, _standards);
            }

            object tempProgrammes = programmes;

            MemoryCacheMock
            .Setup(mc => mc.TryGetValue(It.IsAny <object>(), out tempProgrammes))
            .Returns(PopulateCache);

            return(new TrainingProgrammeApiClient(MemoryCache, FrameworkApiClient, StandardApiClient));
        }