public async Task Post_Accepts_Contact_With_Name_Mocked_Repo()
        {
            var mockRepo = new DataRepositoryCodeMock {
                AllContacts = new List <ContactInfo>()
            };
            var webHost = new Microsoft.AspNetCore.Hosting.WebHostBuilder()
                          .UseStartup <Demo4.WebApp.Startup>()
                          .ConfigureServices(
                services =>
            {
                services.AddSingleton <IDataRepository>(t => mockRepo);
            }
                );;
            var server = new Microsoft.AspNetCore.TestHost.TestServer(webHost);

            var client = server.CreateClient();

            var content = new StringContent(@"{'name':'Bobby Tables','email': '*****@*****.**'}", Encoding.UTF8, "application/json");

            var response = await client.PostAsync("api/contact", content);

            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);

            var responseString = await response.Content.ReadAsStringAsync();

            mockRepo.AllContacts.Any(c => c.Name == "Bobby Tables");
        }
Example #2
0
 public void Setup()
 {
     _contacts = new List <ContactInfo>();
     _mockRepo = new DataRepositoryCodeMock {
         AllContacts = _contacts
     };
     _mockApiKeyValidator = Substitute.For <IApiKeyValidator>();
     _testObject          = new ContactController(_mockRepo, _mockApiKeyValidator);
 }