Exemplo n.º 1
0
        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 <Demo.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");
        }
Exemplo n.º 2
0
 public ContactController_UT()
 {
     _contacts = new List <ContactInfo>();
     _mockRepo = new DataRepositoryCodeMock {
         AllContacts = _contacts
     };
     _mockApiKeyValidator = A.Fake <IApiKeyValidator>();
     _testObject          = new ContactController(_mockRepo, _mockApiKeyValidator);
 }