Пример #1
0
        public void CreateCreatesAnNfieldConnection()
        {
            var expectedUri      = new Uri("http://fake/");
            var actualConnection = NfieldConnectionFactory.Create(expectedUri);

            Assert.Equal(expectedUri, actualConnection.NfieldServerUri);
        }
Пример #2
0
        public void CreateCreatesAnNfieldConnection()
        {
            var expectedConnection = new NfieldConnection();
            var expectedUri        = new Uri("http://fake/");

            DependencyResolver.Register(type => expectedConnection, type => null);

            var actualConnection = NfieldConnectionFactory.Create(expectedUri);

            Assert.Same(expectedConnection, actualConnection);
            Assert.Equal(expectedUri, actualConnection.NfieldServerUri);
        }
        public void TestGetService_ServiceDoesNotExist_ReturnsNull()
        {
            var mockedResolver = new Mock <IDependencyResolver>();

            DependencyResolver.Register(mockedResolver.Object);
            mockedResolver
            .Setup(resolver => resolver.Resolve(typeof(INfieldConnectionClientObject)))
            .Returns(null);

            var target = NfieldConnectionFactory.Create(new Uri("http://fake/"));
            var result = target.GetService <INfieldConnectionClientObject>();

            Assert.Null(result);
        }
        public void TestGetService_ServiceExistsAndImplementsINfieldConnectionClientObject_CallsInitializeConnectionOnService()
        {
            var mockedNfieldConnectionClientObject = new Mock <INfieldConnectionClientObject>();
            var stubbedHttpClientObject            = new Mock <INfieldHttpClient>().Object;
            var mockedResolver = new Mock <IDependencyResolver>();

            DependencyResolver.Register(mockedResolver.Object);
            mockedResolver
            .Setup(resolver => resolver.Resolve(typeof(INfieldConnectionClientObject)))
            .Returns(mockedNfieldConnectionClientObject.Object);
            mockedResolver
            .Setup(resolver => resolver.Resolve(typeof(INfieldHttpClient)))
            .Returns(stubbedHttpClientObject);
            var target = (NfieldConnection)NfieldConnectionFactory.Create(new Uri("http://fake/"));
            var result = target.GetService <INfieldConnectionClientObject>();

            mockedNfieldConnectionClientObject.Verify(client => client.InitializeNfieldConnection(target));
        }
        public void TestGetService_ServiceExists_ReturnsService()
        {
            var stubbedNfieldConnectionClientObject = new Mock <INfieldConnectionClientObject>().Object;
            var stubbedHttpClientObject             = new Mock <INfieldHttpClient>().Object;
            var mockedResolver = new Mock <IDependencyResolver>();

            DependencyResolver.Register(mockedResolver.Object);
            mockedResolver
            .Setup(resolver => resolver.Resolve(typeof(INfieldConnectionClientObject)))
            .Returns(stubbedNfieldConnectionClientObject);
            mockedResolver
            .Setup(resolver => resolver.Resolve(typeof(INfieldHttpClient)))
            .Returns(stubbedHttpClientObject);
            var target = NfieldConnectionFactory.Create(new Uri("http://fake/"));
            var result = target.GetService <INfieldConnectionClientObject>();

            Assert.Equal(result, stubbedNfieldConnectionClientObject);
        }
        public void TestGetService_RequestedServiceTypeIsNull_ThrowsArgumentNullException()
        {
            var target = NfieldConnectionFactory.Create(new Uri("http://fake/"));

            Assert.Throws(typeof(ArgumentNullException), () => target.GetService(null));
        }