public void GetResponse_SingleModeResponseIndexOutOfBounds_DefaultsToFirstResponse(int singleResponseIndex)
        {
            // Arrange
            var random    = new Mock <IRandomService>();
            var response1 = new Response();
            var response2 = new Response();
            var response3 = new Response();

            var action = new EndpointAction
            {
                Mode = EndpointActionMode.Single,
                SingleResponseIndex = singleResponseIndex,
                Responses           = new List <Response>
                {
                    response1,
                    response2,
                    response3
                }
            };

            // Act
            var actualResponse = action.GetResponse(random.Object);

            // Assert
            Assert.Same(response1, actualResponse);
        }
        public void GetResponse_SingleModeSpecificIndexManyResponses_ReturnsExpectedResponse(int singleResponseIndex, int expectedResponseIndex)
        {
            // Arrange
            var random = new Mock <IRandomService>();

            var response1 = new Response();
            var response2 = new Response();
            var response3 = new Response();
            var response4 = new Response();
            var response5 = new Response();

            var responses = new List <Response>()
            {
                response1,
                response2,
                response3,
                response4,
                response5
            };

            var action = new EndpointAction
            {
                Mode = EndpointActionMode.Single,
                SingleResponseIndex = singleResponseIndex,
                Responses           = responses
            };

            // Act
            var actualResponse = action.GetResponse(random.Object);

            // Assert
            Assert.Same(responses[expectedResponseIndex], actualResponse);
        }
        public void GetResponse_SingleModeDefaultIndexManyResponses_ReturnsFirstResponse()
        {
            // Arrange
            var random    = new Mock <IRandomService>();
            var response1 = new Response();
            var response2 = new Response();
            var response3 = new Response();
            var response4 = new Response();
            var response5 = new Response();

            var action = new EndpointAction
            {
                Mode      = EndpointActionMode.Single,
                Responses = new List <Response>
                {
                    response1,
                    response2,
                    response3,
                    response4,
                    response5
                }
            };

            // Act
            var actualResponse = action.GetResponse(random.Object);

            // Assert
            Assert.Same(response1, actualResponse);
        }
        public void GetResponse_RandomModeMultipleResponsesRandomHigherThanMinumum_ReturnsFirst()
        {
            // Arrange
            var random = new Mock <IRandomService>();

            random.Setup(m => m.GetRandomIntegerInclusive(It.IsAny <int>(), It.IsAny <int>())).Returns(3);

            var response1 = new Response
            {
                RandomWeight = 1
            };
            var response2 = new Response
            {
                RandomWeight = 1
            };

            var action = new EndpointAction
            {
                Mode      = EndpointActionMode.Random,
                Responses = new List <Response>
                {
                    response1,
                    response2
                }
            };

            // Act
            var actualResponse = action.GetResponse(random.Object);

            // Assert
            Assert.Same(response1, actualResponse);
        }
        public void GetResponse_NoResponsesAvailable_ReturnsNull()
        {
            // Arrange
            var random = new Mock <IRandomService>();
            var action = new EndpointAction
            {
                Responses = null,
            };

            // Act
            var response = action.GetResponse(random.Object);

            // Assert
            Assert.Null(response);
        }
        public void GetResponse_SingleModeNullResponses_ReturnsNull()
        {
            // Arrange
            var random = new Mock <IRandomService>();
            var action = new EndpointAction
            {
                Mode      = EndpointActionMode.Single,
                Responses = null
            };

            // Act
            var actualResponse = action.GetResponse(random.Object);

            // Assert
            Assert.Null(actualResponse);
        }
        public void GetResponse_InterceptMode_ThrowsException()
        {
            // Arrange
            var random = new Mock <IRandomService>();
            var action = new EndpointAction
            {
                Mode      = EndpointActionMode.Intercept,
                Responses = new List <Response>
                {
                    new Response()
                }
            };

            // Act
            var exception = Assert.Throws <NotImplementedException>(() => action.GetResponse(random.Object));

            // Assert
            Assert.Equal("Intercept mode is not currently supported", exception.Message);
        }
        [InlineData(10, 0)]         // Out of bounds
        public void GetResponse_RandomModeMultipleResponsesVaryingWeights_ReturnsCorrectWeightedResponse(int randomValue, int responseIndex)
        {
            // Arrange
            var random = new Mock <IRandomService>();

            random.Setup(m => m.GetRandomIntegerInclusive(It.IsAny <int>(), It.IsAny <int>())).Returns(randomValue);

            var response1 = new Response
            {
                RandomWeight = 3
            };
            var response2 = new Response
            {
                RandomWeight = 5
            };
            var response3 = new Response
            {
                RandomWeight = 1
            };

            var responses = new List <Response>
            {
                response1,
                response2,
                response3
            };

            var action = new EndpointAction
            {
                Mode      = EndpointActionMode.Random,
                Responses = responses
            };

            // Act
            var actualResponse = action.GetResponse(random.Object);

            // Assert
            Assert.Same(responses[responseIndex], actualResponse);
        }
        public void GetResponse_RandomModeSingleResponse_ReturnsSingleResponse(int weight)
        {
            // Arrange
            var random   = new Mock <IRandomService>();
            var response = new Response
            {
                RandomWeight = weight
            };
            var action = new EndpointAction
            {
                Mode      = EndpointActionMode.Random,
                Responses = new List <Response>
                {
                    response
                }
            };

            // Act
            var actualResponse = action.GetResponse(random.Object);

            // Assert
            Assert.Same(response, actualResponse);
        }
        public void GetResponse_InvalidModeMultipleResponses_DefaultsToSingleMode()
        {
            // Arrange
            var random    = new Mock <IRandomService>();
            var response1 = new Response();
            var response2 = new Response();

            var action = new EndpointAction
            {
                Mode = "Something that's not even a mode and never will be",
                SingleResponseIndex = 0,
                Responses           = new List <Response>
                {
                    response1,
                    response2
                }
            };

            // Act
            var actualResponse = action.GetResponse(random.Object);

            // Assert
            Assert.Same(response1, actualResponse);
        }
        public void GetResponse_SingleModeSecondIndexTwoResponses_ReturnsFirstResponse()
        {
            // Arrange
            var random    = new Mock <IRandomService>();
            var response1 = new Response();
            var response2 = new Response();

            var action = new EndpointAction
            {
                Mode = EndpointActionMode.Single,
                SingleResponseIndex = 1,
                Responses           = new List <Response>
                {
                    response1,
                    response2
                }
            };

            // Act
            var actualResponse = action.GetResponse(random.Object);

            // Assert
            Assert.Same(response2, actualResponse);
        }