public WebHostBuilderServiceFabricExtensionTests()
        {
            settings = new Dictionary <string, string>();
            // create mock IWebHostBuilder to test functionality of Service Fabric WebHostBuilder extension
            var mockBuilder = new Mock <IWebHostBuilder>();

            // setup call backs for Getting and setting settings.
            mockBuilder.Setup(y => y.GetSetting(It.IsAny <string>())).Returns <string>(name =>
            {
                string value;
                this.settings.TryGetValue(name, out value);
                return(value);
            });

            mockBuilder.Setup(y => y.UseSetting(It.IsAny <string>(), It.IsAny <string>())).Callback <string, string>((name, value) =>
            {
                this.settings.Add(name, value);
            });

            mockBuilder.Setup(y => y.ConfigureServices(It.IsAny <Action <IServiceCollection> >())).Callback(() => this.servicesConfigured = true);

            this.builder            = mockBuilder.Object;
            this.servicesConfigured = false;

            var context = TestMocksRepository.GetMockStatelessServiceContext();

            this.listener = new KestrelCommunicationListener(context, (uri, listen) => BuildFunc(uri, listen));
        }
        public void VerifyWithoutUseUniqueServiceUrlOption()
        {
            var context = TestMocksRepository.GetMockStatelessServiceContext();

            context.CodePackageActivationContext.GetEndpoints().Add(GetTestEndpoint());
            this.Listener = new KestrelCommunicationListener(context, EndpointName, (uri, listen) => BuildFunc(uri, listen));
            this.WithoutUseUniqueServiceUrlOptionVerifier();
        }
        public void VerifyExceptionForEmptyEndpointName()
        {
            Action action =
                () =>
                new KestrelCommunicationListener(TestMocksRepository.GetMockStatelessServiceContext(), string.Empty,
                                                 (uri, listen) => BuildFunc(uri, listen));

            action.ShouldThrow <ArgumentException>();
        }
        public void VerifyListenerOpenClose()
        {
            var context = TestMocksRepository.GetMockStatelessServiceContext();

            context.CodePackageActivationContext.GetEndpoints().Add(GetTestEndpoint());
            this.Listener = new WebListenerCommunicationListener(context, EndpointName, (uri, listen) => BuildFunc(uri, listen));

            this.ListenerOpenCloseVerifier();
        }
        public void VerifyExceptionForNullOrEmptyEndpointName()
        {
            Action action =
                () =>
                new WebListenerCommunicationListener(TestMocksRepository.GetMockStatelessServiceContext(), null,
                                                     BuildFunc);

            action.ShouldThrow <ArgumentException>();

            action =
                () =>
                new WebListenerCommunicationListener(TestMocksRepository.GetMockStatelessServiceContext(),
                                                     string.Empty, BuildFunc);
            action.ShouldThrow <ArgumentException>();
        }
        public ServiceFabricMiddlewareTests()
        {
            // setup HttpRequest mock
            var mockHttpRequest = new Mock <HttpRequest>();

            mockHttpRequest.SetupAllProperties();

            // setup HttpResponse mock
            var mockHttpResponse = new Mock <HttpResponse>();

            mockHttpResponse.SetupAllProperties();

            // setup HttpContext mock
            var mockHttpContext = new Mock <HttpContext>();

            mockHttpContext.Setup(y => y.Response).Returns(mockHttpResponse.Object);
            mockHttpContext.Setup(y => y.Request).Returns(mockHttpRequest.Object);
            this.httpContext = mockHttpContext.Object;

            var context = TestMocksRepository.GetMockStatelessServiceContext();

            this.listener = new KestrelCommunicationListener(context, BuildFunc);
        }
 public void ExceptionForEndpointNotFound()
 {
     this.Listener = new KestrelCommunicationListener(TestMocksRepository.GetMockStatelessServiceContext(), "NoEndPoint", (uri, listen) => BuildFunc(uri, listen));
     this.ExceptionForEndpointNotFoundVerifier();
 }