예제 #1
0
        public void Add_InvalidObjectPassed_ReturnsBadRequest()
        {
            // Arrange
            var nameMissingItem = new PhonebookEntryViewModel()
            {
                Name   = "Test",
                Number = "12"
            };

            _controller.ModelState.AddModelError("Name", "Required");

            // Act
            var badResponse = _controller.Post(nameMissingItem);

            // Assert
            Assert.IsType <BadRequestObjectResult>(badResponse.Result);
        }
        public async Task Create_ShouldReturnOK()
        {
            var PhoneBook = FakeObjects.FakeObjects.GetListPhoneBook();
            await _phoneBookService.CreatePhoneBook(PhoneBook[0]);

            var actionResult = await _sut.Post(PhoneBook[0]);

            actionResult.Result.Equals(typeof(OkObjectResult));
        }
예제 #3
0
        public void AddPhoneBookTest()
        {
            Random ran = new Random();

            var listWithNumbers = new List <NumberToCreateDTO>()
            {
                new NumberToCreateDTO {
                    Id = ran.Next(100, 199), Number = "06868685", TypeId = "1"
                },
                new NumberToCreateDTO {
                    Id = ran.Next(100, 199), Number = "06867777", TypeId = "2"
                }
            };
            //arrange
            var phoneBook = new PhoneBookToCreateDTO()
            {
                Id         = ran.Next(5, 100),
                Firstname  = "TestName",
                Lastname   = "TestLastName",
                NumberInfo = listWithNumbers
            };


            var createdResponse = _controller.Post(phoneBook);

            _controller.ModelState.AddModelError("Id", "Id is a required field");

            //assert
            Assert.IsType <PhoneBookForReturnDTO>(createdResponse);

            var item = createdResponse as PhoneBookForReturnDTO;

            Assert.Equal(phoneBook.Id, item.Id);
            Assert.Equal(phoneBook.Firstname, item.Firstname);
            Assert.Equal(phoneBook.Lastname, item.Lastname);
            Assert.Equal(phoneBook.NumberInfo.ToString(), item.NumberInfo.ToString());
        }