Пример #1
0
        public void TestSignInAsync_CredentialsAreIncorrect_ReturnsFalse()
        {
            var mockedHttpClient = new Mock <INfieldHttpClient>();
            var mockedResolver   = new Mock <IDependencyResolver>();

            DependencyResolver.Register(mockedResolver.Object);
            mockedResolver
            .Setup(resolver => resolver.Resolve(typeof(INfieldHttpClient)))
            .Returns(mockedHttpClient.Object);
            mockedHttpClient
            .Setup(httpClient => httpClient.PostAsync(It.IsAny <string>(), It.IsAny <HttpContent>()))
            .Returns(CreateTask(HttpStatusCode.BadRequest));

            var target = new NfieldConnection();
            var result = target.SignInAsync("", "", "").Result;

            Assert.False(result);
        }
Пример #2
0
        public void TestDispose_HasClient_CallsDisposeOnClient()
        {
            var mockedHttpClient = new Mock <INfieldHttpClient>();
            var mockedResolver   = new Mock <IDependencyResolver>();

            DependencyResolver.Register(mockedResolver.Object);
            mockedResolver
            .Setup(resolver => resolver.Resolve(typeof(INfieldHttpClient)))
            .Returns(mockedHttpClient.Object);
            mockedHttpClient
            .Setup(client => client.PostAsync(It.IsAny <string>(), It.IsAny <HttpContent>()))
            .Returns(CreateTask(HttpStatusCode.OK));

            var target = new NfieldConnection();
            var result = target.SignInAsync("", "", "").Result;

            target.Dispose();

            mockedHttpClient.Verify(client => client.Dispose());
        }
Пример #3
0
        public void TestSignInAsync_CredentialsAreCorrect_ReturnsTrue()
        {
            Uri ServerUri = new Uri(@"http://localhost/");

            const string Domain   = "Domain";
            const string Username = "******";
            const string Password = "******";

            var mockedHttpClient = new Mock <INfieldHttpClient>();
            var mockedResolver   = new Mock <IDependencyResolver>();

            DependencyResolver.Register(mockedResolver.Object);
            mockedResolver
            .Setup(resolver => resolver.Resolve(typeof(INfieldHttpClient)))
            .Returns(mockedHttpClient.Object);
            var content = new FormUrlEncodedContent(new Dictionary <string, string>
            {
                { "Domain", Domain },
                { "Username", Username },
                { "Password", Password }
            });

            mockedHttpClient
            .Setup(httpClient => httpClient.PostAsync(It.IsAny <string>(), It.IsAny <HttpContent>()))
            .Returns(CreateTask(HttpStatusCode.BadRequest));
            mockedHttpClient
            .Setup(httpClient => httpClient.PostAsync(ServerUri + "SignIn", It.Is <HttpContent>(c => CheckContent(c, content))))
            .Returns(CreateTask(HttpStatusCode.OK));

            var target = new NfieldConnection();

            target.NfieldServerUri = ServerUri;
            var result = target.SignInAsync(Domain, Username, Password).Result;

            Assert.True(result);
        }