コード例 #1
0
        public async Task ListAllApplications_NoApplications_EmptyViewResult()
        {
            // Arrange
            const string expectedJson        = "";
            var          httpResponseMessage = new HttpResponseMessage {
                StatusCode = HttpStatusCode.OK, Content = new StringContent(expectedJson)
            };

            var httpRequestMessage = new HttpRequestMessage();

            _httpMessageHandler.WhenForAnyArgs(x => x.Send(httpRequestMessage)).DoNotCallBase();
            _httpMessageHandler.Send(httpRequestMessage).ReturnsForAnyArgs(httpResponseMessage);

            // Act
            IActionResult result = await _jobApplicationsController.ListAllApplications().ConfigureAwait(false);

            // Assert
            Assert.IsType <ViewResult>(result);
            var viewResult = (ViewResult)result;

            Assert.Equal(new List <JobApplication>(), viewResult.Model);
        }
コード例 #2
0
        public async Task Greet_Name_Greeting(string name, string expected)
        {
            // Arrange
            var httpResponseMessage = new HttpResponseMessage {
                StatusCode = HttpStatusCode.OK, Content = new StringContent(expected)
            };

            var httpRequestMessage = new HttpRequestMessage();

            _httpMessageHandler.WhenForAnyArgs(x => x.Send(httpRequestMessage)).DoNotCallBase();
            _httpMessageHandler.Send(httpRequestMessage).ReturnsForAnyArgs(httpResponseMessage);

            // Act
            IActionResult result = await _helloController.Greet(name).ConfigureAwait(false);

            // Assert
            Assert.IsType <OkObjectResult>(result);
            var okResult = (OkObjectResult)result;
            var actual   = okResult.Value as string;

            Assert.Equal(expected, actual);
        }
コード例 #3
0
        public JobApplicationControllerTest()
        {
            _httpMessageHandler = Substitute.ForPartsOf <FakeHttpMessageHandler>();

            var httpClient = new HttpClient(_httpMessageHandler)
            {
                BaseAddress = new Uri("http://localhost/api/")
            };

            _httpRequestMessage = new HttpRequestMessage();
            _httpMessageHandler.WhenForAnyArgs(x => x.Send(_httpRequestMessage)).DoNotCallBase();

            _jobApplicationsController = new JobApplicationsController(httpClient);

            _expectedJobApplications = new List <JobApplication>
            {
                new JobApplication
                {
                    CompanyName     = "Company 1",
                    ApplicationDate = new DateTime(2017, 11, 13),
                    Status          = Status.Interview
                },
                new JobApplication
                {
                    CompanyName     = "Company 2",
                    ApplicationDate = new DateTime(2017, 11, 14),
                    Status          = Status.Applied
                },
                new JobApplication
                {
                    CompanyName     = "Company 3",
                    ApplicationDate = new DateTime(2017, 11, 14),
                    Status          = Status.Offer
                }
            };
        }