public void Send_ServiceConfigurationProviderReturnsNull_SystemInformationSenderSetupExceptionIsThrown() { // Arrange var systemInformation = new SystemInformation(); IRESTServiceConfiguration serviceConfiguration = null; var systemInformationSenderConfigurationProvider = new Mock<IRESTBasedSystemInformationSenderConfigurationProvider>(); systemInformationSenderConfigurationProvider.Setup(s => s.GetConfiguration()).Returns(serviceConfiguration); var restClientFactory = new Mock<IRESTClientFactory>(); var requestFactory = new Mock<IRESTRequestFactory>(); var systemInformationSender = new RESTBasedSystemInformationSender(systemInformationSenderConfigurationProvider.Object, restClientFactory.Object, requestFactory.Object); // Act systemInformationSender.Send(systemInformation); }
public void Send_RequestCannotBeCreated_FatalSystemInformationSenderExceptionIsThrown() { // Arrange var systemInformation = new SystemInformation(); var configuration = new Mock<IRESTServiceConfiguration>(); configuration.Setup(c => c.Hostaddress).Returns("127.0.0.1"); configuration.Setup(c => c.Hostname).Returns("localhost"); configuration.Setup(c => c.ResourcePath).Returns("api/systeminformation"); configuration.Setup(c => c.IsValid()).Returns(true); var systemInformationSenderConfigurationProvider = new Mock<IRESTBasedSystemInformationSenderConfigurationProvider>(); systemInformationSenderConfigurationProvider.Setup(s => s.GetConfiguration()).Returns(configuration.Object); var client = new Mock<IRestClient>(); var restClientFactory = new Mock<IRESTClientFactory>(); restClientFactory.Setup(r => r.GetRESTClient(It.IsAny<string>())).Returns(client.Object); IRestRequest request = null; var requestFactory = new Mock<IRESTRequestFactory>(); requestFactory.Setup(r => r.CreatePutRequest(It.IsAny<string>(), It.IsAny<string>())).Returns(request); var systemInformationSender = new RESTBasedSystemInformationSender( systemInformationSenderConfigurationProvider.Object, restClientFactory.Object, requestFactory.Object); // Act systemInformationSender.Send(systemInformation); }
public void Send_ResponseContainsException_SendSystemInformationFailedExceptionIsThrown() { // Arrange var systemInformation = new SystemInformation(); var configuration = new Mock<IRESTServiceConfiguration>(); configuration.Setup(c => c.Hostaddress).Returns("127.0.0.1"); configuration.Setup(c => c.Hostname).Returns("localhost"); configuration.Setup(c => c.ResourcePath).Returns("api/systeminformation"); configuration.Setup(c => c.IsValid()).Returns(true); var systemInformationSenderConfigurationProvider = new Mock<IRESTBasedSystemInformationSenderConfigurationProvider>(); systemInformationSenderConfigurationProvider.Setup(s => s.GetConfiguration()).Returns(configuration.Object); var response = new Mock<IRestResponse<SystemInformation>>(); response.Setup(r => r.ErrorException).Returns(new Exception("Some exception")); var client = new Mock<IRestClient>(); client.Setup(c => c.Execute<SystemInformation>(It.IsAny<IRestRequest>())).Returns(response.Object); var restClientFactory = new Mock<IRESTClientFactory>(); restClientFactory.Setup(r => r.GetRESTClient(It.IsAny<string>())).Returns(client.Object); var request = new Mock<IRestRequest>(); var requestFactory = new Mock<IRESTRequestFactory>(); requestFactory.Setup(r => r.CreatePutRequest(It.IsAny<string>(), It.IsAny<string>())).Returns(request.Object); var systemInformationSender = new RESTBasedSystemInformationSender( systemInformationSenderConfigurationProvider.Object, restClientFactory.Object, requestFactory.Object); // Act systemInformationSender.Send(systemInformation); }