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 = new NfieldConnection(); 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 = new NfieldConnection(); var result = target.GetService<INfieldConnectionClientObject>(); mockedNfieldConnectionClientObject.Verify(client => client.InitializeNfieldConnection(target)); }
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()); }
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); }
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 = new NfieldConnection(); var result = target.GetService<INfieldConnectionClientObject>(); Assert.Equal(result, stubbedNfieldConnectionClientObject); }
public void TestGetService_RequestedServiceTypeIsNull_ThrowsArgumentNullException() { var target = new NfieldConnection(); Assert.Throws(typeof(ArgumentNullException), () => target.GetService(null)); }
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); }