コード例 #1
0
 public IActionResult GetByName(string name)
 {
     try
     {
         return(Ok(_citiesService.GetByName(name)));
     }
     catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
 }
コード例 #2
0
        public void ReturnNull_WhenNameIsNull()
        {
            // Arrange
            var repoMock      = new Mock <IEfRepository <City> >();
            var dbContextMock = new Mock <ISaveContext>();

            CitiesService citiesService = new CitiesService(repoMock.Object, dbContextMock.Object);

            // Act
            City city = citiesService.GetByName(null);

            // Assert
            Assert.IsNull(city);
        }
コード例 #3
0
        public void ReturnNull_WhenThereIsNoModelWithThePassedName()
        {
            // Arrange
            var repoMock      = new Mock <IEfRepository <City> >();
            var dbContextMock = new Mock <ISaveContext>();

            repoMock.Setup(m => m.Add(new City()
            {
                Name = "PeshoCity"
            }));

            CitiesService citiesService = new CitiesService(repoMock.Object, dbContextMock.Object);

            // Act
            City city = citiesService.GetByName("Pesho");

            // Assert
            Assert.IsNull(city);
        }