Exemplo n.º 1
0
        /// <summary>
        /// Constructs a MockRegistry instance that contains bindings for mock/fake objects
        /// </summary>
        public MockRegistry()
        {
            Mock <IDateTime> mockDateProvider = new Mock <IDateTime>(MockBehavior.Strict);

            mockDateProvider.SetupGet(x => x.Now).Returns(new DateTimeWrap(new DateTime(2011, 1, 2)));
            For <IDateTime>().Use(() => mockDateProvider.Object);
            For <HttpClient>().Use(() => HttpClientTestHelper.CreateStandardFakeClient(new MockHabitatServer()));

            Profile(NoHttpConnection, x => x.For <HttpClient>().Use(HttpClientTestHelper.CreateClientSimulatingServerWithNoHttpEndpoint));
            Profile(BadHttpAddress, x => x.For <HttpClient>().Use(HttpClientTestHelper.CreateClientSimulatingABadAddress));
            Profile(ConnectionTimeout, x => x.For <HttpClient>().Use(HttpClientTestHelper.CreateClientSimulatingRequestTimeout));
            Profile(ServerAlwaysReturns500Error, x => x.For <HttpClient>().Use(HttpClientTestHelper.CreateClientThatAlwaysThrowsServerError));
            Profile(ServerReturnsGibberish, x => x.For <HttpClient>().Use(HttpClientTestHelper.CreateClientThatAlwaysReturnsGibberish));
            Profile(ServerAlwaysReturnsJsonArray, x => x.For <HttpClient>().Use(HttpClientTestHelper.CreateClientThatAlwaysReturnsJsonArray));
            Profile(ServerAlwaysReturnsJsonObject, x => x.For <HttpClient>().Use(HttpClientTestHelper.CreateClientThatAlwaysReturnsJsonObject));
        }
Exemplo n.º 2
0
        public void Test_provider_behavior_when_config_service_returns_404()
        {
            HttpClient mockClient = HttpClientTestHelper.CreateStandardFakeClient(new MockHabitatServer());
            var        provider   = new ConfigServiceProvider("foo2", mockClient);

            ConfigServiceResponse response = provider.GetConfig();

            Assert.IsNotNull(response);
            Assert.IsNotNull(response.Config);
            Assert.AreEqual("foo2", response.Config.ComponentName);
            Assert.AreEqual(default(DateTime), response.Config.LastModified);
            Assert.IsNull(response.Config.Data);
            Assert.AreEqual(HttpStatusCode.NotFound, response.StatusCode);
            Assert.IsNotNull(response.Exception);
            Assert.AreEqual(typeof(UnableToAccessConfigurationException), response.Exception.GetType());
            Assert.IsNull(response.Exception.InnerException);
        }
Exemplo n.º 3
0
        public void Test_provider_behavior_when_config_service_returns_valid_data()
        {
            ConfigRoot testConfig   = MockHabitatServer.GetConfigRoot(ResourceName);
            DateTime   expectedDate = testConfig.LastModified;

            HttpClient mockClient = HttpClientTestHelper.CreateStandardFakeClient(new MockHabitatServer());
            var        provider   = new ConfigServiceProvider(ResourceName, mockClient);

            ConfigServiceResponse response = provider.GetConfig();

            Assert.IsNotNull(response);
            Assert.IsNotNull(response.Config);
            Assert.AreEqual(ResourceName, response.Config.ComponentName);
            Assert.AreEqual(expectedDate, response.Config.LastModified);
            Assert.IsNotNull(response.Config.Data);
            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
            Assert.IsNull(response.Exception);
            Assert.IsNotNull(response.Config);
            Assert.IsTrue(_objectComparer.Compare(testConfig, response.Config).AreEqual);
        }
 public void SetUp()
 {
     _mockFileSystem = _mockFileSystemProvider.MockFileSystem;
     _mockFileSystem.Setup(x => x.GetTempDirectoryPath()).Returns(TestTempPath);
     _mockConfigServiceHttpClient = HttpClientTestHelper.CreateStandardFakeClient(new MockHabitatServer());
 }