コード例 #1
0
        public void CreateRecordTest()
        {
            // Arrange
            personController.Request = new HttpRequestMessage(HttpMethod.Post, "");
            personController.Request.Properties.Add(HttpPropertyKeys.HttpConfigurationKey, new HttpConfiguration());

            //Act
            HttpResponseMessage result1 = personController.CreateRecord(DUMMY_RECORD);
            HttpResponseMessage result2 = personController.CreateRecord(string.Empty);

            // Assert
            Assert.AreNotEqual(result1, null);
            Assert.AreEqual(result1.StatusCode, HttpStatusCode.OK);
            Assert.AreEqual(result2.StatusCode, HttpStatusCode.BadRequest);
        }
コード例 #2
0
        public async Task Create_Record_With_Bad_Formatting_Returns_Bad_Request()
        {
            using (var context = new DataContext(ContextOptions))
            {
                var    loggerMock = new Mock <ILogger <PersonController> >();
                var    controller = new PersonController(context, loggerMock.Object);
                string person     = "Test ------- Person, Male, Red [][][[[] 1/5/1960";

                var items = await controller.CreateRecord(person);

                var pers = items.Value;

                ///Our return value on a BadRequest should be null
                Assert.Null(pers);
            }
        }
コード例 #3
0
        public async Task Create_Record_Returns_Created_Person()
        {
            using (var context = new DataContext(ContextOptions))
            {
                var    loggerMock = new Mock <ILogger <PersonController> >();
                var    controller = new PersonController(context, loggerMock.Object);
                string person     = "Test, Person, Male, Red, 1/5/1960";

                var items = await controller.CreateRecord(person);

                Person pers = items.Value;

                ///return value should be the person object we tried to create
                Assert.Equal("Test", pers.LastName);
                Assert.Equal("Person", pers.FirstName);
                Assert.Equal("Male", pers.Gender);
                Assert.Equal("Red", pers.FavoriteColor);
                Assert.Equal("1/5/1960", pers.DateOfBirth.ToShortDateString());
            }
        }